File: error.cpp

package info (click to toggle)
guymager 0.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 932 kB
  • ctags: 1,580
  • sloc: cpp: 8,522; ansic: 2,571; makefile: 49; sh: 23
file content (78 lines) | stat: -rw-r--r-- 2,123 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ****************************************************************************
//  Project:        GUYMAGER
// ****************************************************************************
//  Programmer:     Guy Voncken
//                  Police Grand-Ducale
//                  Service de Police Judiciaire
//                  Section Nouvelles Technologies
// ****************************************************************************
//  Module:         Error handling utilities
// ****************************************************************************


#include <stdarg.h>
#include <stdlib.h>

#include <QtGui>

#include "common.h"
#include "qtutil.h"


// -----------------------
//     Constants
// -----------------------

static const int EXIT_SLEEP_BEFORE_EXIT = 3000; // ms

// -----------------------
//     Local variables
// -----------------------

static int ErrorPopupCounter = 0;


// -----------------------
//       Functions
// -----------------------

void ErrorExit (int ExitCode)
{
   LOG_ERROR ("Exiting GUYMAGER with code %d", ExitCode)
   printf ("\n\n");

   (void) QtUtilSleep (EXIT_SLEEP_BEFORE_EXIT); // Quite often, the last messages of the slave cannot be
   exit (ExitCode);
}


void ErrorPopupExit (const char *pFileName, const char *pFunctionName, int LineNr, APIRET ec, const char *pMsg)
{
   const char *pErr;
   QString      MsgTxt;

   if (ErrorPopupCounter < 3)   // If there are already several windows, then they are most probably generated by a timer and we risk
   {                    // to fill up the screen without being able to click them all away. So, we simply exit here.
      ErrorPopupCounter++;
      (void) ToolErrorCheck (pFileName, pFunctionName, LineNr, ec);
      pErr = ToolErrorMessage(ec);
      if (pMsg)
           MsgTxt = QString(pMsg) + QString("\n") + QString(pErr);
      else MsgTxt = pErr;
      (void) QMessageBox::critical (0, "Internal error", MsgTxt);
   }
   ErrorExit ();
}

APIRET ErrorInit (void)
{
   CHK (TOOL_ERROR_REGISTER_CODE (ERROR_QT_UNSUCCESSFUL))
   return NO_ERROR;
}

APIRET ErrorDeInit (void)
{
   return NO_ERROR;
}