OmniEvents
omniEventsLog.h
Go to the documentation of this file.
1 // -*- Mode: C++; -*-
2 // Package : omniEvents
3 // omniEventsLog.h Created : 1/10/99
4 // Author : Paul Nader (pwn)
5 //
6 // Copyright (C) 1998 Paul Nader, 2003-2005 Alex Tingle.
7 //
8 // This file is part of the omniEvents application.
9 //
10 // omniEvents is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // omniEvents is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //
24 // Description:
25 //
26 
27 /*
28  $Log: omniEventsLog.h,v $
29  Revision 1.6.2.4 2005/05/10 14:56:06 alextingle
30  All private members are now protected. Allows for flexible subclassing.
31 
32  Revision 1.6.2.3 2005/05/10 14:28:13 alextingle
33  Updated copyrights to 2005.
34 
35  Revision 1.6.2.2 2005/04/27 20:49:31 alextingle
36  Merge across changes from HEAD branch (see CHANGES_262. Change version number ready for release 2.6.2.
37 
38  Revision 1.6.2.1 2004/11/16 21:46:11 alextingle
39  Made several methods virtual to allow users of libomniEvents to override
40  the default persistency behaviour. (Dirk O. Siebnich)
41 
42  Revision 1.6 2004/09/11 23:08:39 alextingle
43  WriteLock now non-copyable.
44 
45  Revision 1.5 2004/07/26 16:27:08 alextingle
46  Support for NT service on windows: main() moved into daemon.cc.
47  New (laxer) start up syntax. Port is now set with -p (not -s). There is no
48  special cold start mode.
49  More flexible naming service name option -N. (No more -K option).
50 
51  Revision 1.4 2004/04/20 17:16:17 alextingle
52  Corrected openOfstream() arg name/comments.
53 
54  Revision 1.3 2004/03/28 01:03:58 alextingle
55  Refactored class omniEventsLog to allow for more EventChannelFactory parameters.\nNew omniEvents params: -v, -a (alternate endPoint).
56 
57  Revision 1.2 2004/01/11 16:57:26 alextingle
58  New persistancy log file format, implemented by PersistNode.h/cc. The new format enables new nodes to be added and old ones erased by appending a single line to the file, rather than by re-persisting the whole application. This is much more efficient when lots of proxies are being created all at once. It's also a much simpler solution, with far fewer lines of code.
59 
60  Revision 1.1 2003/12/21 16:19:49 alextingle
61  Moved into 'src' directory as part of the change to POA implementation.
62 
63  Revision 1.4 2003/11/14 13:54:48 alextingle
64  New output() members functions. Eliminates the need for friend ostream
65  functions that are problematic on earlier versions of Microsoft
66  VisualC++.
67 
68  Revision 1.3 2003/11/03 22:35:08 alextingle
69  Removed all platform specific switches. Now uses autoconf, config.h.
70  Added private helper functions initializeFileNames(), setFilename() &
71  openOfstream() to simplify the implementation.
72  Removed member `logdir', as it's only used during object construction.
73  Renamed configuration macro LOGDIR_ENV_VAR to OMNIEVENTS_LOGDIR_ENV_VAR
74  for consistency with other configuration macros.
75 
76  Revision 1.1.1.1.2.1 2002/09/28 22:20:51 shamus13
77  Added ifdefs to enable omniEvents to compile
78  with both omniORB3 and omniORB4. If __OMNIORB4__
79  is defined during compilation, omniORB4 headers
80  and command line option syntax is used, otherwise
81  fall back to omniORB3 style.
82 
83  Revision 1.1.1.1 2002/09/25 19:00:32 shamus13
84  Import of OmniEvents source tree from release 2.1.1
85 
86  Revision 1.3 2000/08/30 04:21:56 naderp
87  Port to omniORB 3.0.1.
88 
89  Revision 1.2 2000/03/02 04:19:17 naderp
90  Passing factory by reference to init() for initialisation.
91 
92  Revision 1.1 1999/11/02 13:40:56 naderp
93  Rearranged data member definitions to avoid compiler warnings during
94  initialisation.
95 
96  Revision 1.0 1999/11/01 16:48:21 naderp
97  Initial revision
98 
99 */
100 
101 #ifndef _OMNIEVENTSLOG_H_
102 #define _OMNIEVENTSLOG_H_
103 
104 #ifdef HAVE_CONFIG_H
105 # include "config.h"
106 #endif
107 
108 #ifdef HAVE_IOSTREAM
109 # include <iostream>
110 # include <fstream>
111 #else
112 # include <iostream.h>
113 # include <fstream.h>
114 #endif
115 
116 #ifdef HAVE_STD_IOSTREAM
117 using namespace std;
118 #endif
119 
120 #ifdef HAVE_OMNIORB3
121 # include <omniORB3/CORBA.h>
122 #endif
123 
124 #ifdef HAVE_OMNIORB4
125 # include <omniORB4/CORBA.h>
126 #endif
127 
128 namespace OmniEvents {
129 
130 class EventChannelFactory_i;
131 class PersistNode;
132 
133 #ifndef OMNIEVENTS_LOGDIR_ENV_VAR
134 # define OMNIEVENTS_LOGDIR_ENV_VAR "OMNIEVENTS_LOGDIR"
135 #endif
136 
138 {
139 public:
144  static bool exists() { return NULL!=omniEventsLog::theLog; }
145 
146  omniEventsLog(const char* logdir=NULL);
147  virtual ~omniEventsLog();
148 
149  bool fileExists(const char* filename) const;
150  const char* activeFilename() const { return _activeFilename; }
151  const char* backupFilename() const { return _backupFilename; }
152 
157  PersistNode* bootstrap(int port, const char* endPointNoListen);
158 
163  virtual PersistNode* parse();
164 
168  void incarnateFactory(PersistNode* initialState);
169 
173  virtual void runWorker();
174 
176  EventChannelFactory_i* factory() {return _factory;}
177 
182  void checkpoint(void);
183 
184  virtual void output(ostream& os);
185 
186 public:
187  class IOError {};
188 
189 protected:
190  virtual void initializeFileNames(const char* logdir);
191  void setFilename(
192  char*& filename,
193  const char* logdir,
194  const char* sep,
195  const char* logname,
196  const char* hostname,
197  const char* ext
198  );
199  virtual void openOfstream(
200  ofstream& s,
201  const char* filename,
202  int flags=0,
203  int* fd=NULL
204  );
205 
207 
208  ofstream _logstream;
212  omni_thread* _workerThread;
215  omni_mutex _lock;
216 
217  friend class WriteLock;
218 };
219 
220 class omniEventsLogWorker : public omni_thread
221 {
222 public:
223  typedef void (omniEventsLog::*Method)(void);
225  omniEventsLog* object,
226  Method method,
227  priority_t priority=PRIORITY_NORMAL
228  );
229  void* run_undetached(void *);
231 private:
233  Method _method;
235 };
236 
237 
243 {
244 public:
246  os(omniEventsLog::theLog->_logstream),
247  l(omniEventsLog::theLog->_lock)
248  {}
250  {
251  os.flush();
252  omniEventsLog::theLog->_checkpointNeeded=true;
253  }
254  ostream& os;
255 private:
256  omni_mutex_lock l;
258 };
259 
260 }; // end namespace OmniEvents
261 
262 #endif /* _OMNIEVENTSLOG_H_ */
static omniEventsLog * theLog
const char * backupFilename() const
EventChannelFactory_i * _factory
const char * activeFilename() const
EventChannelFactory_i * factory()
accessor method
omni_thread * _workerThread
In charge of checkpoints.
static bool exists()
Library code may create Event Service objects without the need for persistency.
omniEventsLogWorker()
No default construction allowed.
Obtains an output stream to the active persistancy logfile, and locks it for exclusive access.
omni_mutex_lock l
WriteLock(const WriteLock &)
No implementation.