Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAlarmLogger.cpp

00001 // Author:
00002 //   Jason Venema
00003 //   NSCL
00004 //   Michigan State University
00005 //   East Lansing, MI 48824-1321
00006 //   mailto:venemaja@msu.edu
00007 //
00008 // Copyright
00009 //   NSCL All rights reserved.
00010 //
00011 // See Logger.h for a description of this class.
00012 //
00013 
00014 #include <CAlarmLogger.h>
00015 #include <stdio.h>
00016 #include <CDuplicateNameException.h>
00017 #include <CNoSuchObjectException.h>
00018 
00027 CAlarmLogger::CAlarmLogger(string facility, 
00028                            string host = "localhost", 
00029                            string port = "daqalarm") :
00030   m_sFacility(facility),
00031   m_sHost(host)
00032 {
00033   if(port == "daqalarm") {
00034     struct servent* pServ = getservbyname("daqalarm", "tcp");
00035     if(pServ) {
00036       Int_t nPort = pServ->s_port;
00037       char port[4];
00038       sprintf(port, "%d", nPort);
00039       m_sPort = string(port);
00040     }
00041     else {
00042       m_sPort = "2702";
00043     }
00044   }
00045 }
00046 
00053 CAlarmLogger::CAlarmLogger(const CAlarmLogger& aCAlarmLogger) :
00054   m_sFacility(aCAlarmLogger.m_sFacility),
00055   m_sHost(aCAlarmLogger.m_sHost),
00056   m_sPort(aCAlarmLogger.m_sPort)
00057 { }
00058 
00063 CAlarmLogger::~CAlarmLogger()
00064 { }
00065 
00098 void
00099 CAlarmLogger::Log(string message)
00100 {
00101   // 1. Prepare a message to write to the socket for EventLog.tcl to log. 
00102   //    This is the first message that we're writing. Subsequent writes
00103   //    will be to the display function...
00104   string entry("Alarm::Log [list ");
00105   entry += m_sFacility + " " + message + "]\n";
00106   void* pBuf = (void*)entry.c_str();
00107 
00108   // Construct a socket and log to the log file using the name of the first
00109   // host in the hostlist. Then try the write the command to log. Read the
00110   // date/time which is returned, and shutdown the connection.
00111   try {
00112     CSocket sock;
00113     sock.Connect(m_sHost, m_sPort);
00114     sock.Write(pBuf, entry.size());
00115     sock.Shutdown();
00116   }
00117   catch (CException& e) {
00118     cerr << "Caught exception while attempting to connect to host " 
00119          << m_sHost << endl;
00120     cerr << "Reason was: " << e.ReasonText() << endl;
00121     cerr << e.WasDoing() << endl;
00122   }
00123 }

Generated at Tue May 21 12:10:47 2002 for CAlarmLogger by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001