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

Last change on this file since 14037 was 11062, checked in by tbretz, 13 years ago
Removed some old obsolete comments and changed fatal errors to Fatal()
File size: 3.4 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.Fatal(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 /*
89 DIMDNSUNDEF DIM_FATAL DIM_DNS_NODE undefined
90 DIMDNSREFUS DIM_FATAL DIM_DNS refuses connection
91 DIMDNSDUPLC DIM_FATAL Service already exists in DNS
92 DIMDNSEXIT DIM_FATAL DNS requests server to EXIT
93 DIMDNSTMOUT DIM_WARNING Server failed sending Watchdog
94
95 DIMDNSCNERR DIM_ERROR Connection to DNS failed
96 DIMDNSCNEST DIM_INFO Connection to DNS established
97
98 DIMSVCDUPLC DIM_ERROR Service already exists in Server
99 DIMSVCFORMT DIM_ERROR Bad format string for service
100 DIMSVCINVAL DIM_ERROR Invalid Service ID
101
102 DIMTCPRDERR DIM_ERROR TCP/IP read error
103 DIMTCPWRRTY DIM_WARNING TCP/IP write error - Retrying
104 DIMTCPWRTMO DIM_ERROR TCP/IP write error - Disconnected
105 DIMTCPLNERR DIM_ERROR TCP/IP listen error
106 DIMTCPOPERR DIM_ERROR TCP/IP open server error
107 DIMTCPCNERR DIM_ERROR TCP/IP connection error
108 DIMTCPCNEST DIM_INFO TCP/IP connection established
109 */
110}
111
Note: See TracBrowser for help on using the repository browser.