Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

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

Generated on Fri Nov 19 17:42:20 2004 for OmniEvents by doxygen1.2.15