omniEventsLog.h

Go to the documentation of this file.
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, 2004 Alex Tingle.
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.6.2.2  2005/04/27 20:49:31  alextingle
00030   Merge across changes from HEAD branch (see CHANGES_262. Change version number ready for release 2.6.2.
00031 
00032   Revision 1.6.2.1  2004/11/16 21:46:11  alextingle
00033   Made several methods virtual to allow users of libomniEvents to override
00034   the default persistency behaviour. (Dirk O. Siebnich)
00035 
00036   Revision 1.6  2004/09/11 23:08:39  alextingle
00037   WriteLock now non-copyable.
00038 
00039   Revision 1.5  2004/07/26 16:27:08  alextingle
00040   Support for NT service on windows: main() moved into daemon.cc.
00041   New (laxer) start up syntax. Port is now set with -p (not -s). There is no
00042   special cold start mode.
00043   More flexible naming service name option -N. (No more -K option).
00044 
00045   Revision 1.4  2004/04/20 17:16:17  alextingle
00046   Corrected openOfstream() arg name/comments.
00047 
00048   Revision 1.3  2004/03/28 01:03:58  alextingle
00049   Refactored class omniEventsLog to allow for more EventChannelFactory parameters.\nNew omniEvents params: -v, -a (alternate endPoint).
00050 
00051   Revision 1.2  2004/01/11 16:57:26  alextingle
00052   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.
00053 
00054   Revision 1.1  2003/12/21 16:19:49  alextingle
00055   Moved into 'src' directory as part of the change to POA implementation.
00056 
00057   Revision 1.4  2003/11/14 13:54:48  alextingle
00058   New output() members functions. Eliminates the need for friend ostream
00059   functions that are problematic on earlier versions of Microsoft
00060   VisualC++.
00061 
00062   Revision 1.3  2003/11/03 22:35:08  alextingle
00063   Removed all platform specific switches. Now uses autoconf, config.h.
00064   Added private helper functions initializeFileNames(), setFilename() &
00065   openOfstream() to simplify the implementation.
00066   Removed member `logdir', as it's only used during object construction.
00067   Renamed configuration macro LOGDIR_ENV_VAR to OMNIEVENTS_LOGDIR_ENV_VAR
00068   for consistency with other configuration macros.
00069 
00070   Revision 1.1.1.1.2.1  2002/09/28 22:20:51  shamus13
00071   Added ifdefs to enable omniEvents to compile
00072   with both omniORB3 and omniORB4. If __OMNIORB4__
00073   is defined during compilation, omniORB4 headers
00074   and command line option syntax is used, otherwise
00075   fall back to omniORB3 style.
00076 
00077   Revision 1.1.1.1  2002/09/25 19:00:32  shamus13
00078   Import of OmniEvents source tree from release 2.1.1
00079 
00080   Revision 1.3  2000/08/30 04:21:56  naderp
00081   Port to omniORB 3.0.1.
00082 
00083   Revision 1.2  2000/03/02 04:19:17  naderp
00084   Passing factory by reference to init() for initialisation.
00085 
00086   Revision 1.1  1999/11/02 13:40:56  naderp
00087   Rearranged data member definitions to avoid compiler warnings during
00088   initialisation.
00089 
00090   Revision 1.0  1999/11/01 16:48:21  naderp
00091   Initial revision
00092 
00093 */
00094 
00095 #ifndef _OMNIEVENTSLOG_H_
00096 #define _OMNIEVENTSLOG_H_
00097 
00098 #ifdef HAVE_CONFIG_H
00099 #  include "config.h"
00100 #endif
00101 
00102 #ifdef HAVE_IOSTREAM
00103 #  include <iostream>
00104 #  include <fstream>
00105 #else
00106 #  include <iostream.h>
00107 #  include <fstream.h>
00108 #endif
00109 
00110 #ifdef HAVE_STD_IOSTREAM
00111 using namespace std;
00112 #endif
00113 
00114 #ifdef HAVE_OMNIORB3
00115 #  include <omniORB3/CORBA.h>
00116 #endif
00117 
00118 #ifdef HAVE_OMNIORB4
00119 #  include <omniORB4/CORBA.h>
00120 #endif
00121 
00122 namespace OmniEvents {
00123 
00124 class EventChannelFactory_i;
00125 class PersistNode;
00126 
00127 #ifndef OMNIEVENTS_LOGDIR_ENV_VAR
00128 #  define OMNIEVENTS_LOGDIR_ENV_VAR "OMNIEVENTS_LOGDIR"
00129 #endif
00130 
00131 class omniEventsLog
00132 {
00133 public:
00138    static bool exists() { return NULL!=omniEventsLog::theLog; }
00139 
00140    omniEventsLog(const char* logdir=NULL);
00141    virtual ~omniEventsLog();
00142 
00143    bool fileExists(const char* filename) const;
00144    const char* activeFilename() const { return _activeFilename; }
00145    const char* backupFilename() const { return _backupFilename; }
00146 
00151    PersistNode* bootstrap(int port, const char* endPointNoListen);
00152 
00157    virtual PersistNode* parse();
00158    
00162    void incarnateFactory(PersistNode* initialState);
00163 
00167    virtual void runWorker();
00168    
00170    EventChannelFactory_i* factory() {return _factory;}
00171    
00176    void checkpoint(void);
00177 
00178    virtual void output(ostream& os);
00179 
00180 public:
00181   class IOError {};
00182 
00183 protected:
00184   virtual void initializeFileNames(const char* logdir);
00185   void setFilename(
00186     char*&      filename, 
00187     const char* logdir,
00188     const char* sep,
00189     const char* logname,
00190     const char* hostname,
00191     const char* ext
00192   );
00193   virtual void openOfstream(
00194     ofstream&   s,
00195     const char* filename,
00196     int         flags=0,
00197     int*        fd=NULL
00198   );
00199 
00200 private:
00201   static omniEventsLog*  theLog;
00202 
00203   ofstream               _logstream;
00204   char*                  _activeFilename;
00205   char*                  _backupFilename;
00206   char*                  _checkpointFilename;
00207   omni_thread*           _workerThread;       
00208   EventChannelFactory_i* _factory;
00209   bool                   _checkpointNeeded;
00210   omni_mutex             _lock;
00211   
00212   friend class WriteLock;
00213 };
00214 
00215 class omniEventsLogWorker : public omni_thread
00216 {
00217 public:
00218     typedef void (omniEventsLog::*Method)(void);
00219     omniEventsLogWorker(
00220       omniEventsLog* object,
00221       Method         method,
00222       priority_t     priority=PRIORITY_NORMAL
00223     );
00224     void* run_undetached(void *);
00225     ~omniEventsLogWorker();
00226 private:
00227     omniEventsLog* _object;
00228     Method         _method;
00229     omniEventsLogWorker(); 
00230 };
00231 
00232 
00237 class WriteLock
00238 {
00239 public:
00240   WriteLock():
00241     os(omniEventsLog::theLog->_logstream),
00242     l(omniEventsLog::theLog->_lock)
00243   {}
00244   ~WriteLock()
00245   {
00246     os.flush();
00247     omniEventsLog::theLog->_checkpointNeeded=true;
00248   }
00249   ostream& os;
00250 private:
00251   omni_mutex_lock l;
00252   WriteLock(const WriteLock&); 
00253 };
00254 
00255 }; // end namespace OmniEvents
00256 
00257 #endif /* _OMNIEVENTSLOG_H_ */

Generated on Mon Jan 9 03:52:13 2006 for OmniEvents by  doxygen 1.4.6