NLNET::CNetDisplayer Class Reference

#include <net_displayer.h>

Inheritance diagram for NLNET::CNetDisplayer:

NLMISC::IDisplayer

Detailed Description

Net Displayer. Sends the strings to a logger server (LOGS). log_howto

Bug:
When nlerror is called in a catch block, a connected NetDisplayer becomes an IDisplayer => pure virtual call
Author:
Olivier Cado

Nevrax France

Date:
2000

Definition at line 45 of file net_displayer.h.

Public Member Functions

 CNetDisplayer (bool autoConnect=true)
 Constructor.

bool connected ()
 Returns true if the displayer is connected to a Logging Service.

void display (const CLog::TDisplayInfo &args, const char *message)
 Display the string where it does.

void setLogServer (CCallbackClient *server)
void setLogServer (const CInetAddress &logServerAddr)
virtual ~CNetDisplayer ()
 Destructor.


Static Public Member Functions

const char * dateToComputerString (time_t date)
 Convert date to "784551148" string (time in second from 1975).

const char * dateToHumanString (time_t date)
 Convert date to "2000/01/14 10:05:17" string.

const char * dateToHumanString ()
 Convert the current date to human string.

const char * logTypeToString (CLog::TLogType logType, bool longFormat=false)
 Convert log type to string.


Data Fields

std::string DisplayerName
 This is the idenfiant for a displayer, it is used to fond or remove a displayer.


Protected Member Functions

virtual void doDisplay (const CLog::TDisplayInfo &args, const char *message)=0
 Method to implement in the deriver.

virtual void doDisplay (const NLMISC::CLog::TDisplayInfo &args, const char *message)
void findAndConnect ()
 Find the server (using the NS) and connect.


Static Protected Member Functions

const char * HeaderString ()

Private Attributes

CCallbackClient_Server
CInetAddress _ServerAddr
bool _ServerAllocated


Constructor & Destructor Documentation

NLNET::CNetDisplayer::CNetDisplayer bool  autoConnect = true  ) 
 

Constructor.

Definition at line 48 of file net_displayer.cpp.

References findAndConnect().

00048                                              :
00049         _Server(NULL), _ServerAllocated (false) // disable logging otherwise an infinite recursion may occur
00050 {
00051         if (autoConnect) findAndConnect();
00052 }

NLNET::CNetDisplayer::~CNetDisplayer  )  [virtual]
 

Destructor.

Definition at line 108 of file net_displayer.cpp.

References _ServerAllocated, and NLNET::CCallbackClient::disconnect().

00109 {
00110         if (_ServerAllocated)
00111         {
00112                 _Server->disconnect ();
00113                 delete _Server;
00114         }
00115 }


Member Function Documentation

bool NLNET::CNetDisplayer::connected  )  [inline]
 

Returns true if the displayer is connected to a Logging Service.

Definition at line 62 of file net_displayer.h.

References NLNET::CCallbackClient::connected().

00062 { return _Server->connected(); }

const char * NLMISC::IDisplayer::dateToComputerString time_t  date  )  [static, inherited]
 

Convert date to "784551148" string (time in second from 1975).

Definition at line 103 of file displayer.cpp.

References NLMISC::smprintf().

00104 {
00105         static char cstime[25];
00106         smprintf (cstime, 25, "%ld", &date);
00107         return cstime;
00108 }

const char * NLMISC::IDisplayer::dateToHumanString time_t  date  )  [static, inherited]
 

Convert date to "2000/01/14 10:05:17" string.

Definition at line 92 of file displayer.cpp.

References uint32.

00093 {
00094         static char cstime[25];
00095         struct tm *tms = localtime(&date);
00096         if (tms)
00097                 strftime (cstime, 25, "%Y/%m/%d %H:%M:%S", tms);
00098         else
00099                 sprintf(cstime, "bad date %d", (uint32)date);
00100         return cstime;
00101 }

const char * NLMISC::IDisplayer::dateToHumanString  )  [static, inherited]
 

Convert the current date to human string.

Definition at line 85 of file displayer.cpp.

Referenced by doDisplay(), NLMISC::CMemDisplayer::doDisplay(), NLMISC::CMsgBoxDisplayer::doDisplay(), NLMISC::CFileDisplayer::doDisplay(), and NLMISC::IDisplayer::HeaderString().

00086 {
00087         time_t date;
00088         time (&date);
00089         return dateToHumanString (date);
00090 }

void NLMISC::IDisplayer::display const CLog::TDisplayInfo args,
const char *  message
[inherited]
 

Display the string where it does.

Definition at line 132 of file displayer.cpp.

References NLMISC::IDisplayer::doDisplay().

00133 {
00134         _Mutex->enter();
00135         try
00136         {
00137                 doDisplay( args, message );
00138         }
00139         catch (Exception &)
00140         {
00141                 // silence
00142         }
00143         _Mutex->leave();
00144 }

virtual void NLMISC::IDisplayer::doDisplay const CLog::TDisplayInfo args,
const char *  message
[protected, pure virtual, inherited]
 

Method to implement in the deriver.

Implemented in NLMISC::CStdDisplayer, NLMISC::CFileDisplayer, NLMISC::CMsgBoxDisplayer, NLMISC::CMemDisplayer, and NLMISC::CLightMemDisplayer.

Referenced by NLMISC::IDisplayer::display().

void NLNET::CNetDisplayer::doDisplay const NLMISC::CLog::TDisplayInfo args,
const char *  message
[protected, virtual]
 

Sends the string to the logging server

Warning:
If not connected, tries to connect to the logging server each call. It can slow down your program a lot.

Definition at line 123 of file net_displayer.cpp.

References NLNET::CCallbackClient::connected(), NLMISC::CLog::TDisplayInfo::Date, NLMISC::IDisplayer::dateToHumanString(), NLNET::CCallbackNetBase::getSIDA(), NLMISC::CLog::TDisplayInfo::LogType, NLMISC::IDisplayer::logTypeToString(), NLMISC::CLog::TDisplayInfo::ProcessName, s, NLNET::CCallbackClient::send(), and NLMISC::CMemStream::serial().

00124 {
00125         try
00126         {
00127                 if (_Server == NULL || !_Server->connected())
00128                 {
00129                         return;
00130                 }
00131 
00132                 bool needSpace = false;
00133                 //stringstream ss;
00134                 string str;
00135 
00136                 if (args.Date != 0)
00137                 {
00138                         str += dateToHumanString(args.Date);
00139                         needSpace = true;
00140                 }
00141 
00142                 if (args.LogType != CLog::LOG_NO)
00143                 {
00144                         if (needSpace) { str += " "; needSpace = false; }
00145                         str += logTypeToString(args.LogType);
00146                         needSpace = true;
00147                 }
00148 
00149                 if (!args.ProcessName.empty())
00150                 {
00151                         if (needSpace) { str += " "; needSpace = false; }
00152                         str += args.ProcessName;
00153                         needSpace = true;
00154                 }
00155                 
00156                 if (needSpace) { str += ": "; needSpace = false; }
00157 
00158                 str += message;
00159 
00160                 CMessage msg(_Server->getSIDA(), "LOG" );
00161                 string s = str;
00162                 msg.serial( s );
00163                 _Server->send (msg, 0, false);
00164         }
00165         catch( NLMISC::Exception& )
00166         {
00167                 // Silence
00168         }
00169 }

void NLNET::CNetDisplayer::findAndConnect  )  [protected]
 

Find the server (using the NS) and connect.

Definition at line 58 of file net_displayer.cpp.

References _ServerAllocated, and nldebug.

Referenced by CNetDisplayer().

00059 {
00060         if (_Server == NULL)
00061         {
00062                 _Server = new CCallbackClient();
00063                 _ServerAllocated = true;
00064         }
00065 
00066         if ( CNamingClient::lookupAndConnect( "LOGS", *_Server ) )
00067         {
00068                 nldebug( "Connected to logging service" );
00069         }
00070 }

const char * NLMISC::IDisplayer::HeaderString  )  [static, protected, inherited]
 

Definition at line 110 of file displayer.cpp.

References NLMISC::IDisplayer::dateToHumanString(), and NLMISC::smprintf().

Referenced by NLMISC::CMemDisplayer::doDisplay(), and NLMISC::CFileDisplayer::doDisplay().

00111 {
00112         static char header[1024];
00113         smprintf(header, 1024, "\nLog Starting [%s]\n", dateToHumanString());
00114         return header;
00115 }

const char * NLMISC::IDisplayer::logTypeToString CLog::TLogType  logType,
bool  longFormat = false
[static, inherited]
 

Convert log type to string.

Definition at line 77 of file displayer.cpp.

References NLMISC::LogTypeToString.

Referenced by NLMISC::CWindowDisplayer::doDisplay(), doDisplay(), NLMISC::CMemDisplayer::doDisplay(), NLMISC::CMsgBoxDisplayer::doDisplay(), NLMISC::CFileDisplayer::doDisplay(), and NLMISC::CStdDisplayer::doDisplay().

00078 {
00079         if (logType < CLog::LOG_NO || logType > CLog::LOG_UNKNOWN)
00080                 return "<NotDefined>";
00081 
00082         return LogTypeToString[longFormat?1:0][logType];
00083 }

void NLNET::CNetDisplayer::setLogServer CCallbackClient server  ) 
 

Sets logging server with an already connected server.

Definition at line 97 of file net_displayer.cpp.

References NLNET::CCallbackClient::connected().

00098 {
00099         if (_Server != NULL && _Server->connected()) return;
00100 
00101         _Server = server;
00102 }

void NLNET::CNetDisplayer::setLogServer const CInetAddress logServerAddr  ) 
 

Sets logging server address. Call this method from outside only if you want to use a LOGS not registered within the NS. It does nothing if the displayer is already connected to a server.

Definition at line 75 of file net_displayer.cpp.

References _ServerAddr, _ServerAllocated, NLNET::CCallbackClient::connect(), and NLNET::CCallbackClient::connected().

00076 {
00077         if (_Server != NULL && _Server->connected()) return;
00078 
00079         _ServerAddr = logServerAddr;
00080 
00081         if (_Server == NULL)
00082         {
00083                 _Server = new CCallbackClient();
00084                 _ServerAllocated = true;
00085         }
00086         
00087         try
00088         {
00089                 _Server->connect (_ServerAddr);
00090         }
00091         catch( ESocket& )
00092         {
00093                 // Silence
00094         }
00095 }


Field Documentation

CCallbackClient* NLNET::CNetDisplayer::_Server [private]
 

Definition at line 81 of file net_displayer.h.

CInetAddress NLNET::CNetDisplayer::_ServerAddr [private]
 

Definition at line 79 of file net_displayer.h.

Referenced by setLogServer().

bool NLNET::CNetDisplayer::_ServerAllocated [private]
 

Definition at line 82 of file net_displayer.h.

Referenced by findAndConnect(), setLogServer(), and ~CNetDisplayer().

std::string NLMISC::IDisplayer::DisplayerName [inherited]
 

This is the idenfiant for a displayer, it is used to fond or remove a displayer.

Definition at line 63 of file displayer.h.

Referenced by NLMISC::IDisplayer::IDisplayer().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 14:00:51 2004 for NeL by doxygen 1.3.6