LogService
libdadi: utility tools for distributed applications
|
00001 /****************************************************************************/ 00002 /* ORB manager v. 2.0 - CORBA management with DIET forwarders */ 00003 /* */ 00004 /* Author(s): */ 00005 /* - Gaƫl Le Mahec (gael.le.mahec@ens-lyon.fr) */ 00006 /* */ 00007 /* This file is part of DIET . */ 00008 /* */ 00009 /* Copyright (C) 2000-2003 ENS Lyon, LIFC, INSA, INRIA and SysFera (2000) */ 00010 /* */ 00011 /* - Frederic.Desprez@ens-lyon.fr (Project Manager) */ 00012 /* - Eddy.Caron@ens-lyon.fr (Technical Manager) */ 00013 /* - Tech@sysfera.com (Maintainer and Technical Support) */ 00014 /* */ 00015 /* This software is a computer program whose purpose is to provide an */ 00016 /* distributed logging services. */ 00017 /* */ 00018 /* */ 00019 /* This software is governed by the CeCILL license under French law and */ 00020 /* abiding by the rules of distribution of free software. You can use, */ 00021 /* modify and/ or redistribute the software under the terms of the CeCILL */ 00022 /* license as circulated by CEA, CNRS and INRIA at the following URL */ 00023 /* "http://www.cecill.info". */ 00024 /* */ 00025 /* As a counterpart to the access to the source code and rights to copy, */ 00026 /* modify and redistribute granted by the license, users are provided */ 00027 /* only with a limited warranty and the software's author, the holder */ 00028 /* of the economic rights, and the successive licensors have only */ 00029 /* limited liability. */ 00030 /* */ 00031 /* In this respect, the user's attention is drawn to the risks */ 00032 /* associated with loading, using, modifying and/or developing or */ 00033 /* reproducing the software by the user in light of its specific status */ 00034 /* of free software, that may mean that it is complicated to */ 00035 /* manipulate, and that also therefore means that it is reserved for */ 00036 /* developers and experienced professionals having in-depth computer */ 00037 /* knowledge. Users are therefore encouraged to load and test the */ 00038 /* software's suitability as regards their requirements in conditions */ 00039 /* enabling the security of their systems and/or data to be ensured and, */ 00040 /* more generally, to use and operate it in the same conditions as */ 00041 /* regards security. */ 00042 /* */ 00043 /* The fact that you are presently reading this means that you have had */ 00044 /* knowledge of the CeCILL license and that you accept its terms. */ 00045 /* */ 00046 /****************************************************************************/ 00047 00048 #ifndef LOGORBMGR_HH 00049 #define LOGORBMGR_HH 00050 00051 #include <list> 00052 #include <map> 00053 #include <string> 00054 #include <sys/types.h> 00055 #include <omniORB4/CORBA.h> 00056 #include <omnithread.h> 00057 #include "CorbaLogForwarder.hh" 00058 00059 00060 #define LOGCOMPCTXT "LogServiceC" 00061 #define LOGTOOLCTXT "LogServiceT" 00062 #define LOGCOMPCONFCTXT "LogServiceC2" 00063 #define LOGTOOLMSGCTXT "LogServiceT2" 00064 #define LOGFWRDCTXT "LogForwarder" 00065 #define DIETFWRD "DietForwarder" 00066 00067 00068 class LogORBMgr { 00069 public: 00070 /* Constructors. */ 00071 LogORBMgr(int argc, char* argv[]); 00072 00073 explicit LogORBMgr(CORBA::ORB_ptr ORB); 00074 00075 LogORBMgr(CORBA::ORB_ptr ORB, PortableServer::POA_var POA); 00076 00077 /* Destructor. */ 00078 ~LogORBMgr(); 00079 00080 /* Bind the object using its ctxt/name */ 00081 void 00082 bind(const std::string& ctxt, const std::string& name, 00083 CORBA::Object_ptr object, const bool rebind = false) const; 00084 00085 /* Bind an object using its IOR. */ 00086 void 00087 bind(const std::string& ctxt, const std::string& name, 00088 const std::string& IOR, const bool rebind = false) const; 00089 00090 /* Rebind objects. */ 00091 void 00092 rebind(const std::string& ctxt, const std::string& name, 00093 CORBA::Object_ptr object) const; 00094 00095 void 00096 rebind(const std::string& ctxt, const std::string& name, 00097 const std::string& IOR) const; 00098 00099 /* Unbind an object. */ 00100 void 00101 unbind(const std::string& ctxt, const std::string& name) const; 00102 00103 /* Forwarders binding. */ 00104 void 00105 fwdsBind(const std::string& ctxt, const std::string& name, 00106 const std::string& ior, const std::string& fwName = "") const; 00107 00108 /* Forwarders unbinding. */ 00109 void 00110 fwdsUnbind(const std::string& ctxt, const std::string& name, 00111 const std::string& fwName = "") const; 00112 00113 /* Resolve an object using its IOR or ctxt/name. */ 00114 CORBA::Object_ptr 00115 resolveObject(const std::string& IOR) const; 00116 00117 CORBA::Object_ptr 00118 resolveObject(const std::string& ctxt, const std::string& name, 00119 const std::string& fwdName = "") const; 00120 00121 /* Resolve objects without object caching or invoking forwarders. */ 00122 CORBA::Object_ptr 00123 simpleResolve(const std::string& ctxt, const std::string& name) const; 00124 00125 /* Get the list of the objects id binded in the omniNames server 00126 for a given context. */ 00127 std::list<std::string> 00128 list(CosNaming::NamingContext_var& ctxt) const; 00129 00130 std::list<std::string> 00131 list(const std::string& ctxtName) const; 00132 00133 /* Get the list of declared CORBA contexts. */ 00134 std::list<std::string> 00135 contextList() const; 00136 00137 /* Return true if the object is local, false if it is reachable 00138 through a forwarder. */ 00139 bool 00140 isLocal(const std::string& ctxt, const std::string& name) const; 00141 00142 /* Return the name of the forwarder that manage the object. */ 00143 std::string 00144 forwarderName(const std::string& ctxt, const std::string& name) const; 00145 00146 template <typename CORBA_object, typename CORBA_ptr> 00147 CORBA_ptr 00148 resolve(const std::string& ctxt, const std::string& name, 00149 const std::string& fwdName = "") const { 00150 return CORBA_object::_duplicate( 00151 CORBA_object::_narrow(resolveObject(ctxt, name, fwdName))); 00152 } 00153 00154 template <typename CORBA_object, typename CORBA_ptr> 00155 CORBA_ptr 00156 resolve(const std::string& IOR) const { 00157 return CORBA_object::_duplicate(CORBA_object::_narrow(resolveObject(IOR))); 00158 } 00159 00160 /* Return the IOR of the passed object. */ 00161 std::string 00162 getIOR(CORBA::Object_ptr object) const; 00163 00164 std::string 00165 getIOR(const std::string& ctxt, const std::string& name) const; 00166 00167 /* Activate an object. */ 00168 void 00169 activate(PortableServer::ServantBase* object) const; 00170 00171 /* Deactivate an object. */ 00172 void 00173 deactivate(PortableServer::ServantBase* object) const; 00174 00175 /* Wait for the request on activated objects. */ 00176 void 00177 wait() const; 00178 00179 void 00180 shutdown(bool waitForCompletion); 00181 00182 static void 00183 init(int argc, char* argv[]); 00184 00185 static LogORBMgr* 00186 getMgr(); 00187 00188 std::list<std::string> 00189 forwarderObjects(const std::string& fwdName, const std::string& ctxt) const; 00190 00191 std::list<std::string> 00192 localObjects(const std::string& ctxt) const; 00193 00194 /* IOR management functions. */ 00195 static void 00196 makeIOR(const std::string& strIOR, IOP::IOR& ior); 00197 00198 static void 00199 makeString(const IOP::IOR& ior, std::string& strIOR); 00200 00201 static std::string 00202 getHost(IOP::IOR& ior); 00203 00204 static std::string 00205 getHost(const std::string& strIOR); 00206 00207 static unsigned int 00208 getPort(IOP::IOR& ior); 00209 00210 static unsigned int 00211 getPort(const std::string& strIOR); 00212 00213 static std::string 00214 getTypeID(IOP::IOR& ior); 00215 00216 static std::string 00217 getTypeID(const std::string& strIOR); 00218 00219 static std::string 00220 convertIOR(IOP::IOR& ior, const std::string& host, 00221 const unsigned int port); 00222 00223 static std::string 00224 convertIOR(const std::string& ior, const std::string& host, 00225 const unsigned int port); 00226 00227 /* Object cache management functions. */ 00228 void 00229 resetCache() const; 00230 00231 void 00232 removeObjectFromCache(const std::string& name) const; 00233 00234 void 00235 removeObjectFromCache(const std::string& ctxt, 00236 const std::string& name) const; 00237 void 00238 cleanCache() const; 00239 00240 static void 00241 hexStringToBuffer(const char* ptr, const size_t size, 00242 cdrMemoryStream& buffer); 00243 00244 private: 00245 /* The omniORB Object Request Broker for this manager. */ 00246 CORBA::ORB_ptr ORB; 00247 /* The Portable Object Adaptor. */ 00248 PortableServer::POA_var POA; 00249 00250 /* Is the ORB down? */ 00251 bool down; 00252 00253 /* CORBA initialization. */ 00254 void 00255 init(CORBA::ORB_ptr ORB); 00256 00257 /* Object cache to avoid to contact OmniNames too many times. */ 00258 mutable std::map<std::string, CORBA::Object_ptr> cache; 00259 /* Cache mutex. */ 00260 mutable omni_mutex cacheMutex; 00261 00262 /* The manager instance. */ 00263 static LogORBMgr* theMgr; 00264 00265 static void 00266 sigIntHandler(int sig); 00267 #ifndef __cygwin__ 00268 static omni_mutex waitLock; 00269 #else 00270 static sem_t waitLock; 00271 #endif 00272 }; 00273 00274 00275 #endif