1 // -*- Mode: C++; -*- 2 // Package : omniNames 3 // log.h Author : Tristan Richardson (tjr) 4 // 5 // Copyright (C) 2003-2013 Apasphere Ltd 6 // Copyright (C) 1997-1999 AT&T Laboratories Cambridge 7 // 8 // This file is part of omniNames. 9 // 10 // omniNames is free software; you can redistribute it and/or modify 11 // it under the terms of the GNU General Public License as published by 12 // the Free Software Foundation; either version 2 of the License, or 13 // (at your option) any later version. 14 // 15 // This program 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 18 // GNU General Public License for more details. 19 // 20 // You should have received a copy of the GNU General Public License 21 // along with this program. If not, see http://www.gnu.org/licenses/ 22 // 23 24 #ifndef _log_h_ 25 #define _log_h_ 26 27 #include <omniORB4/CORBA.h> 28 29 #ifdef HAVE_STD 30 # include <fstream> 31 using namespace std; 32 #else 33 # include <fstream.h> 34 #endif 35 36 #ifndef DATADIR_ENV_VAR 37 # define DATADIR_ENV_VAR "OMNINAMES_DATADIR" 38 #endif 39 40 #ifndef LOGDIR_ENV_VAR 41 # define LOGDIR_ENV_VAR "OMNINAMES_LOGDIR" 42 #endif 43 44 // Tracing/logging 45 46 #define LOG(level, msg) \ 47 do { \ 48 if (omniORB::trace(level)) { \ 49 omniORB::logger _log("omniNames: "); \ 50 _log << msg << '\n'; \ 51 } \ 52 } while(0) 53 54 55 class omniNameslog { 56 57 CORBA::ORB_ptr orb; 58 PortableServer::POA_ptr poa; 59 PortableServer::POA_ptr ins_poa; 60 61 CORBA::String_var active; 62 CORBA::String_var backup; 63 CORBA::String_var checkpt; 64 CORBA::String_var active_new; 65 CORBA::String_var active_old; 66 67 ofstream logf; 68 69 int port; 70 PortableServer::ObjectId persistentId; 71 72 int startingUp; // true while reading log file initially. 73 int firstTime; // true if running for the first time 74 int checkpointNeeded; // true if changes have been made since last checkpoint 75 76 int line; // current line number when reading log file initially. 77 78 // 79 // functions to write to a file 80 // 81 82 void putPort(int port, ostream& file); 83 84 void putPersistent(const PortableServer::ObjectId& id, ostream& file); 85 86 void putCreate(const PortableServer::ObjectId& id, ostream& file); 87 88 void putDestroy(CosNaming::NamingContext_ptr nc, ostream& file); 89 90 void putBind(CosNaming::NamingContext_ptr nc, 91 const CosNaming::Name& n, CORBA::Object_ptr obj, 92 CosNaming::BindingType t, ostream& file); 93 94 void putUnbind(CosNaming::NamingContext_ptr nc, const CosNaming::Name& n, 95 ostream& file); 96 97 void putKey(const PortableServer::ObjectId& id, ostream& file); 98 99 void putString(const char* str, ostream& file); 100 101 // 102 // functions to read from a file 103 // 104 105 void getPort(istream& file); 106 107 void getPersistent(istream& file); 108 109 void getCreate(istream& file); 110 111 void getDestroy(istream& file); 112 113 void getBind(istream& file); 114 115 void getUnbind(istream& file); 116 117 void getKey(PortableServer::ObjectId& id, istream& file); 118 119 void getFinalString(char*& buf, istream& file); 120 121 void getNonfinalString(char*& buf, istream& file); 122 123 int getString(char*& buf, istream& file); 124 125 public: 126 127 class IOError {}; 128 class ParseError {}; 129 130 omniNameslog(int& port, const char* logdir, int nohostname, int always); 131 132 void init(CORBA::ORB_ptr o, 133 PortableServer::POA_ptr p, 134 PortableServer::POA_ptr ip); 135 136 void create(const PortableServer::ObjectId& id); 137 void destroy(CosNaming::NamingContext_ptr nc); 138 void bind(CosNaming::NamingContext_ptr nc, 139 const CosNaming::Name& n, CORBA::Object_ptr obj, 140 CosNaming::BindingType t); 141 void unbind(CosNaming::NamingContext_ptr nc, const CosNaming::Name& n); 142 143 void checkpoint(); 144 145 }; 146 147 #endif 148