00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 #ifndef _OMNIEVENTSLOG_H_
00089 #define _OMNIEVENTSLOG_H_
00090
00091 #ifdef HAVE_CONFIG_H
00092 # include "config.h"
00093 #endif
00094
00095 #ifdef HAVE_IOSTREAM
00096 # include <iostream>
00097 # include <fstream>
00098 #else
00099 # include <iostream.h>
00100 # include <fstream.h>
00101 #endif
00102
00103 #ifdef HAVE_STD_IOSTREAM
00104 using namespace std;
00105 #endif
00106
00107 #ifdef HAVE_OMNIORB3
00108 # include <omniORB3/CORBA.h>
00109 #endif
00110
00111 #ifdef HAVE_OMNIORB4
00112 # include <omniORB4/CORBA.h>
00113 #endif
00114
00115 namespace OmniEvents {
00116
00117 class EventChannelFactory_i;
00118 class PersistNode;
00119
00120 #ifndef OMNIEVENTS_LOGDIR_ENV_VAR
00121 # define OMNIEVENTS_LOGDIR_ENV_VAR "OMNIEVENTS_LOGDIR"
00122 #endif
00123
00124 class omniEventsLog
00125 {
00126 public:
00127 omniEventsLog(const char* logdir=NULL);
00128
00129 bool fileExists(const char* filename) const;
00130 const char* activeFilename() const { return _activeFilename; }
00131 const char* backupFilename() const { return _backupFilename; }
00132
00137 PersistNode* bootstrap(int port, const char* endPointNoListen);
00138
00143 PersistNode* parse();
00144
00148 void incarnateFactory(PersistNode* initialState);
00149
00153 void runWorker();
00154
00156 EventChannelFactory_i* factory() {return _factory;}
00157
00162 void checkpoint(void);
00163
00164 void output(ostream& os);
00165
00166 public:
00167 class IOError {};
00168
00169 private:
00170 void initializeFileNames(const char* logdir);
00171 void setFilename(
00172 char*& filename,
00173 const char* logdir,
00174 const char* sep,
00175 const char* logname,
00176 const char* hostname,
00177 const char* ext
00178 );
00179 void openOfstream(
00180 ofstream& s,
00181 const char* filename,
00182 int flags=0,
00183 int* fd=NULL
00184 );
00185
00186 private:
00187 static omniEventsLog* theLog;
00188
00189 ofstream _logstream;
00190 char* _activeFilename;
00191 char* _backupFilename;
00192 char* _checkpointFilename;
00193 omni_thread* _workerThread;
00194 EventChannelFactory_i* _factory;
00195 bool _checkpointNeeded;
00196 omni_mutex _lock;
00197
00198 friend class WriteLock;
00199 };
00200
00201 class omniEventsLogWorker : public omni_thread
00202 {
00203 public:
00204 typedef void (omniEventsLog::*Method)(void);
00205 omniEventsLogWorker(
00206 omniEventsLog* object,
00207 Method method,
00208 priority_t priority=PRIORITY_NORMAL
00209 );
00210 void* run_undetached(void *);
00211 ~omniEventsLogWorker();
00212 private:
00213 omniEventsLog* _object;
00214 Method _method;
00215 omniEventsLogWorker();
00216 };
00217
00218
00223 class WriteLock
00224 {
00225 public:
00226 WriteLock():
00227 os(omniEventsLog::theLog->_logstream),
00228 l(omniEventsLog::theLog->_lock)
00229 {}
00230 ~WriteLock()
00231 {
00232 os.flush();
00233 omniEventsLog::theLog->_checkpointNeeded=true;
00234 }
00235 ostream& os;
00236 private:
00237 omni_mutex_lock l;
00238 WriteLock(const WriteLock&);
00239 };
00240
00241 };
00242
00243 #endif