source: trunk/FACT++/src/DimErrorRedirecter.cc @ 10511

Last change on this file since 10511 was 10511, checked in by tbretz, 9 years ago
Added exit handler; call exit handler in case of fatal error; add Dim id to messages.
File size: 2.3 KB
Line 
1// **************************************************************************
2/** @class DimErrorRedirecter
3
4*/
5// **************************************************************************
6#include "DimErrorRedirecter.h"
7
8#include <dic.hxx>
9
10#include "WindowLog.h"
11#include "MessageImp.h"
12
13using namespace std;
14
15int DimErrorRedirecter::cnt = 0;
16
17DimErrorRedirecter::DimErrorRedirecter(MessageImp &imp) : fMsg(imp)
18{
19    if (cnt++)
20    {
21        fMsg.Error("ERROR - More than one instance of MyHandlers.");
22        exit(-1);
23    }
24
25    dic_disable_padding();
26    dis_disable_padding();
27
28    DimClient::addErrorHandler(this);
29    DimServer::addExitHandler(this);
30}
31
32DimErrorRedirecter::~DimErrorRedirecter()
33{
34    DimClient::addErrorHandler(0);
35    DimServer::addExitHandler(0);
36}
37
38void DimErrorRedirecter::errorHandler(int severity, int code, char *msg)
39{
40    static const string id = "DIM|";
41
42    switch (severity)
43    {
44    case DIM_FATAL:   fMsg.Error(id+msg); break;
45    case DIM_ERROR:   fMsg.Error(id+msg); break;
46    case DIM_WARNING: fMsg.Warn(id+msg);  break;
47    case DIM_INFO:    fMsg.Info(id+msg);  break;
48    default:
49        stringstream str;
50        str << "DIM message with unknown severity (" << severity << "): ";
51        str << msg << " (" << code << ")";
52        fMsg.Message(str);
53        break;
54    }
55
56    if (severity==DIM_FATAL && code==DIMDNSDUPLC)
57        exitHandler(DIMDNSDUPLC);
58
59    /*
60     DIMDNSUNDEF        DIM_FATAL       DIM_DNS_NODE undefined
61     DIMDNSREFUS        DIM_FATAL       DIM_DNS refuses connection
62     DIMDNSDUPLC        DIM_FATAL       Service already exists in DNS
63     DIMDNSEXIT         DIM_FATAL       DNS requests server to EXIT
64     DIMDNSTMOUT        DIM_WARNING     Server failed sending Watchdog
65
66     DIMDNSCNERR        DIM_ERROR       Connection to DNS failed
67     DIMDNSCNEST        DIM_INFO        Connection to DNS established
68
69     DIMSVCDUPLC        DIM_ERROR       Service already exists in Server
70     DIMSVCFORMT        DIM_ERROR       Bad format string for service
71     DIMSVCINVAL        DIM_ERROR       Invalid Service ID
72
73     DIMTCPRDERR        DIM_ERROR       TCP/IP read error
74     DIMTCPWRRTY        DIM_WARNING     TCP/IP write error - Retrying
75     DIMTCPWRTMO        DIM_ERROR       TCP/IP write error - Disconnected
76     DIMTCPLNERR        DIM_ERROR       TCP/IP listen error
77     DIMTCPOPERR        DIM_ERROR       TCP/IP open server error
78     DIMTCPCNERR        DIM_ERROR       TCP/IP connection error
79     DIMTCPCNEST        DIM_INFO        TCP/IP connection established
80     */
81}
82
Note: See TracBrowser for help on using the repository browser.