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

Generated on Fri Aug 26 20:56:14 2005 for OmniEvents by  doxygen 1.4.3-20050530