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.
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  2004/09/11 23:08:39  alextingle
00030   WriteLock now non-copyable.
00031 
00032   Revision 1.5  2004/07/26 16:27:08  alextingle
00033   Support for NT service on windows: main() moved into daemon.cc.
00034   New (laxer) start up syntax. Port is now set with -p (not -s). There is no
00035   special cold start mode.
00036   More flexible naming service name option -N. (No more -K option).
00037 
00038   Revision 1.4  2004/04/20 17:16:17  alextingle
00039   Corrected openOfstream() arg name/comments.
00040 
00041   Revision 1.3  2004/03/28 01:03:58  alextingle
00042   Refactored class omniEventsLog to allow for more EventChannelFactory parameters.\nNew omniEvents params: -v, -a (alternate endPoint).
00043 
00044   Revision 1.2  2004/01/11 16:57:26  alextingle
00045   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.
00046 
00047   Revision 1.1  2003/12/21 16:19:49  alextingle
00048   Moved into 'src' directory as part of the change to POA implementation.
00049 
00050   Revision 1.4  2003/11/14 13:54:48  alextingle
00051   New output() members functions. Eliminates the need for friend ostream
00052   functions that are problematic on earlier versions of Microsoft
00053   VisualC++.
00054 
00055   Revision 1.3  2003/11/03 22:35:08  alextingle
00056   Removed all platform specific switches. Now uses autoconf, config.h.
00057   Added private helper functions initializeFileNames(), setFilename() &
00058   openOfstream() to simplify the implementation.
00059   Removed member `logdir', as it's only used during object construction.
00060   Renamed configuration macro LOGDIR_ENV_VAR to OMNIEVENTS_LOGDIR_ENV_VAR
00061   for consistency with other configuration macros.
00062 
00063   Revision 1.1.1.1.2.1  2002/09/28 22:20:51  shamus13
00064   Added ifdefs to enable omniEvents to compile
00065   with both omniORB3 and omniORB4. If __OMNIORB4__
00066   is defined during compilation, omniORB4 headers
00067   and command line option syntax is used, otherwise
00068   fall back to omniORB3 style.
00069 
00070   Revision 1.1.1.1  2002/09/25 19:00:32  shamus13
00071   Import of OmniEvents source tree from release 2.1.1
00072 
00073   Revision 1.3  2000/08/30 04:21:56  naderp
00074   Port to omniORB 3.0.1.
00075 
00076   Revision 1.2  2000/03/02 04:19:17  naderp
00077   Passing factory by reference to init() for initialisation.
00078 
00079   Revision 1.1  1999/11/02 13:40:56  naderp
00080   Rearranged data member definitions to avoid compiler warnings during
00081   initialisation.
00082 
00083   Revision 1.0  1999/11/01 16:48:21  naderp
00084   Initial revision
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 }; // end namespace OmniEvents
00242 
00243 #endif /* _OMNIEVENTSLOG_H_ */

Generated on Fri Oct 8 15:52:51 2004 for OmniEvents by doxygen1.2.15