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

Last change on this file since 10842 was 10833, checked in by tbretz, 14 years ago
An unknown Dim message is a warning now.
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::cnt = 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 (cnt++)
47 {
48 fMsg.Error("ERROR - More than one instance of MyHandlers.");
49 exit(-1);
50 }
51
52 dic_disable_padding();
53 dis_disable_padding();
54
55 DimServer::addExitHandler(this);
56 DimServer::addErrorHandler(this);
57 DimClient::addErrorHandler(this);
58}
59
60// --------------------------------------------------------------------------
61//
62//! - reset DimClient error handler
63//! - reset DimServer error handler
64//! - reset exit handler of DimServer
65//
66DimErrorRedirecter::~DimErrorRedirecter()
67{
68 DimClient::addErrorHandler(0);
69 DimServer::addErrorHandler(0);
70 DimServer::addExitHandler(0);
71}
72
73void DimErrorRedirecter::errorHandler(int severity, int code, char *msg)
74{
75 static const string id = "DIM|";
76
77 switch (severity)
78 {
79 case DIM_FATAL: fMsg.Error(id+msg); break;
80 case DIM_ERROR: fMsg.Error(id+msg); break;
81 case DIM_WARNING: fMsg.Warn(id+msg); break;
82 case DIM_INFO: fMsg.Info(id+msg); break;
83 default:
84 ostringstream str;
85 str << "DIM message with unknown severity (" << severity << "): ";
86 str << msg << " (" << code << ")";
87 fMsg.Warn(str);
88 break;
89 }
90
91 // If the severity is FATAL after this the exitHandler
92 // is called with the errorcode by dim
93
94 //if (severity==DIM_FATAL && code==DIMDNSDUPLC)
95 // exit(3);//abort();
96
97
98 /*
99 DIMDNSUNDEF DIM_FATAL DIM_DNS_NODE undefined
100 DIMDNSREFUS DIM_FATAL DIM_DNS refuses connection
101 DIMDNSDUPLC DIM_FATAL Service already exists in DNS
102 DIMDNSEXIT DIM_FATAL DNS requests server to EXIT
103 DIMDNSTMOUT DIM_WARNING Server failed sending Watchdog
104
105 DIMDNSCNERR DIM_ERROR Connection to DNS failed
106 DIMDNSCNEST DIM_INFO Connection to DNS established
107
108 DIMSVCDUPLC DIM_ERROR Service already exists in Server
109 DIMSVCFORMT DIM_ERROR Bad format string for service
110 DIMSVCINVAL DIM_ERROR Invalid Service ID
111
112 DIMTCPRDERR DIM_ERROR TCP/IP read error
113 DIMTCPWRRTY DIM_WARNING TCP/IP write error - Retrying
114 DIMTCPWRTMO DIM_ERROR TCP/IP write error - Disconnected
115 DIMTCPLNERR DIM_ERROR TCP/IP listen error
116 DIMTCPOPERR DIM_ERROR TCP/IP open server error
117 DIMTCPCNERR DIM_ERROR TCP/IP connection error
118 DIMTCPCNEST DIM_INFO TCP/IP connection established
119 */
120}
121
Note: See TracBrowser for help on using the repository browser.