00001 // -*- Mode: C++; -*- 00002 // Package : omniEvents 00003 // omniEventsLog.h Created : 1/10/99 00004 // Author : Paul Nader (pwn) 00005 // 00006 // Copyright (C) 1998 Paul Nader. 00007 // 00008 // This file is part of the omniEvents application. 00009 // 00010 // omniEvents is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // omniEvents is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 // 00024 // Description: 00025 // 00026 00027 /* 00028 $Log: omniEventsLog.h,v $ 00029 Revision 1.4 2003/11/14 13:54:48 alextingle 00030 New output() members functions. Eliminates the need for friend ostream 00031 functions that are problematic on earlier versions of Microsoft 00032 VisualC++. 00033 00034 Revision 1.3 2003/11/03 22:35:08 alextingle 00035 Removed all platform specific switches. Now uses autoconf, config.h. 00036 Added private helper functions initializeFileNames(), setFilename() & 00037 openOfstream() to simplify the implementation. 00038 Removed member `logdir', as it's only used during object construction. 00039 Renamed configuration macro LOGDIR_ENV_VAR to OMNIEVENTS_LOGDIR_ENV_VAR 00040 for consistency with other configuration macros. 00041 00042 Revision 1.1.1.1.2.1 2002/09/28 22:20:51 shamus13 00043 Added ifdefs to enable omniEvents to compile 00044 with both omniORB3 and omniORB4. If __OMNIORB4__ 00045 is defined during compilation, omniORB4 headers 00046 and command line option syntax is used, otherwise 00047 fall back to omniORB3 style. 00048 00049 Revision 1.1.1.1 2002/09/25 19:00:32 shamus13 00050 Import of OmniEvents source tree from release 2.1.1 00051 00052 Revision 1.3 2000/08/30 04:21:56 naderp 00053 Port to omniORB 3.0.1. 00054 00055 Revision 1.2 2000/03/02 04:19:17 naderp 00056 Passing factory by reference to init() for initialisation. 00057 00058 Revision 1.1 1999/11/02 13:40:56 naderp 00059 Rearranged data member definitions to avoid compiler warnings during 00060 initialisation. 00061 00062 Revision 1.0 1999/11/01 16:48:21 naderp 00063 Initial revision 00064 00065 */ 00066 00067 #ifndef _OMNIEVENTSLOG_H_ 00068 #define _OMNIEVENTSLOG_H_ 00069 00070 #ifdef HAVE_CONFIG_H 00071 # include "config.h" 00072 #endif 00073 00074 #ifdef HAVE_IOSTREAM 00075 # include <iostream> 00076 # include <fstream> 00077 #else 00078 # include <iostream.h> 00079 # include <fstream.h> 00080 #endif 00081 00082 #ifdef HAVE_STD_IOSTREAM 00083 using namespace std; 00084 #endif 00085 00086 #include <omniORB4/CORBA.h> 00087 00088 namespace OmniEvents { 00089 00090 class EventChannelFactory_i; 00091 00092 #ifndef OMNIEVENTS_LOGDIR_ENV_VAR 00093 # define OMNIEVENTS_LOGDIR_ENV_VAR "OMNIEVENTS_LOGDIR" 00094 #endif 00095 00096 class omniEventsLog { 00097 00098 public: 00099 omniEventsLog(int port, const char* logdir=NULL); 00100 void init(EventChannelFactory_i *&); 00101 int getPort(); 00102 void checkpoint(void); 00103 static void persist(); 00104 void output(ostream& os); 00105 00106 public: 00107 class IOError {}; 00108 00109 private: 00110 void initializeFileNames(const char* logdir); 00111 void setFilename(char*& filename, const char* logdir, const char* sep, 00112 const char* logname, const char* hostname, const char* ext); 00113 void openOfstream(ofstream& s, const char* filename, 00114 int modeflags=0, int* fd=NULL); 00115 00116 private: 00117 int port; 00118 ofstream logfile; 00119 int firstTime; 00120 char *active; // Active file 00121 char *backup; // Backup file 00122 char *checkpt; // Checkpoint file 00123 omni_thread *recorder; // In charge of checkpoints. 00124 EventChannelFactory_i *factory; 00125 int checkpointNeeded; 00126 static omniEventsLog *theLog; 00127 omni_mutex _lock; 00128 }; 00129 00130 class omniEventsLogWorker : public omni_thread { 00131 00132 public: 00133 typedef void (omniEventsLog::*Method)(void); 00134 omniEventsLogWorker(omniEventsLog *object, 00135 Method method, 00136 priority_t priority = PRIORITY_NORMAL); 00137 void* run_undetached(void *); 00138 ~omniEventsLogWorker(); 00139 00140 private: 00141 omniEventsLog* _object; 00142 Method _method; 00143 omniEventsLogWorker(); 00144 }; 00145 00146 }; // end namespace OmniEvents 00147 00148 #endif /* _OMNIEVENTSLOG_H_ */ 00149