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

Last change on this file since 10858 was 10858, checked in by tbretz, 9 years ago
Changed the data member cnt's name -- it sometimes gave warnings using cnt locally in derived classes.
File size: 3.6 KB
Line 
1// **************************************************************************
2/** @class DimErrorRedirecter
3
4@brief A base class taking care of padding, exit handler and error handlers
5
6This class first switches off padding for the DimServer and the DimClient
7(dis and dic). Furthermore, it redirects both error handlers to the
8DimErrorRedirecter. Redirect the exit handler.
9
10Only one instance of this class is allowed, since all Dim handlers are
11global.
12
13In the destructor of the class the handlers are correctly restored.
14The padding setup is kept.
15
16For FACT++ all Dim data is transmitted without padding!
17
18To catch the error messages overwrite the errorHandler. The errorHandler
19of the DimErrorRedirecter redirects the error messages to the logging
20stream given in the constructor.
21
22To catch the exit requests overwrite the exitHandler.
23
24*/
25// **************************************************************************
26#include "DimErrorRedirecter.h"
27
28#include <dic.hxx>
29
30#include "WindowLog.h"
31#include "MessageImp.h"
32
33using namespace std;
34
35int DimErrorRedirecter::fDimErrorRedireterCnt = 0;
36
37// --------------------------------------------------------------------------
38//
39//! - disable padding for dim server and dim client
40//! - redirect DimClient error handler
41//! - redirect DimServer error handler
42//! - set exit handler of DimServer
43//
44DimErrorRedirecter::DimErrorRedirecter(MessageImp &imp) : fMsg(imp)
45{
46    if (fDimErrorRedireterCnt++)
47        throw logic_error("ERROR - More than one instance of MyHandlers.");
48
49    dic_disable_padding();
50    dis_disable_padding();
51
52    DimServer::addExitHandler(this);
53    DimServer::addErrorHandler(this);
54    DimClient::addErrorHandler(this);
55}
56
57// --------------------------------------------------------------------------
58//
59//! - reset DimClient error handler
60//! - reset DimServer error handler
61//! - reset exit handler of DimServer
62//
63DimErrorRedirecter::~DimErrorRedirecter()
64{
65    DimClient::addErrorHandler(0);
66    DimServer::addErrorHandler(0);
67    DimServer::addExitHandler(0);
68}
69
70void DimErrorRedirecter::errorHandler(int severity, int code, char *msg)
71{
72    static const string id = "DIM|";
73
74    switch (severity)
75    {
76    case DIM_FATAL:   fMsg.Error(id+msg); break;
77    case DIM_ERROR:   fMsg.Error(id+msg); break;
78    case DIM_WARNING: fMsg.Warn(id+msg);  break;
79    case DIM_INFO:    fMsg.Info(id+msg);  break;
80    default:
81        ostringstream str;
82        str << "DIM message with unknown severity (" << severity << "): ";
83        str << msg << " (" << code << ")";
84        fMsg.Warn(str);
85        break;
86    }
87
88    // If the severity is FATAL after this the exitHandler
89    // is called with the errorcode by dim
90
91    //if (severity==DIM_FATAL && code==DIMDNSDUPLC)
92    //    exit(3);//abort();
93
94
95    /*
96     DIMDNSUNDEF        DIM_FATAL       DIM_DNS_NODE undefined
97     DIMDNSREFUS        DIM_FATAL       DIM_DNS refuses connection
98     DIMDNSDUPLC        DIM_FATAL       Service already exists in DNS
99     DIMDNSEXIT         DIM_FATAL       DNS requests server to EXIT
100     DIMDNSTMOUT        DIM_WARNING     Server failed sending Watchdog
101
102     DIMDNSCNERR        DIM_ERROR       Connection to DNS failed
103     DIMDNSCNEST        DIM_INFO        Connection to DNS established
104
105     DIMSVCDUPLC        DIM_ERROR       Service already exists in Server
106     DIMSVCFORMT        DIM_ERROR       Bad format string for service
107     DIMSVCINVAL        DIM_ERROR       Invalid Service ID
108
109     DIMTCPRDERR        DIM_ERROR       TCP/IP read error
110     DIMTCPWRRTY        DIM_WARNING     TCP/IP write error - Retrying
111     DIMTCPWRTMO        DIM_ERROR       TCP/IP write error - Disconnected
112     DIMTCPLNERR        DIM_ERROR       TCP/IP listen error
113     DIMTCPOPERR        DIM_ERROR       TCP/IP open server error
114     DIMTCPCNERR        DIM_ERROR       TCP/IP connection error
115     DIMTCPCNEST        DIM_INFO        TCP/IP connection established
116     */
117}
118
Note: See TracBrowser for help on using the repository browser.