LogService
libdadi: utility tools for distributed applications
|
00001 /****************************************************************************/ 00002 /* Log forwarder implementation */ 00003 /* */ 00004 /* Author(s): */ 00005 /* - Gael 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 LOGFORWARDER_HH 00049 #define LOGFORWARDER_HH 00050 00051 #include <list> 00052 #include <map> 00053 #include <string> 00054 #include <omnithread.h> 00055 #include "CorbaLogForwarder.hh" 00056 #include "commonLogTypes.hh" 00057 00058 00059 class LogForwarder : public POA_CorbaLogForwarder, 00060 public PortableServer::RefCountServantBase { 00061 public: 00062 ~LogForwarder(); 00063 00064 explicit LogForwarder(const std::string& name); 00065 /* DIET object factory methods. */ 00066 00067 ComponentConfigurator_ptr 00068 getCompoConf(const char* name); 00069 00070 ToolMsgReceiver_ptr 00071 getToolMsgReceiver(const char* name); 00072 00073 LogCentralComponent_ptr 00074 getLogCentralComponent(const char* name); 00075 00076 LogCentralTool_ptr 00077 getLogCentralTool(const char* name); 00078 00079 /* Common methods implementations. */ 00080 void 00081 ping(const char* compoName, const char* objName); 00082 00083 /* To determine if the call is from another forwarder and 00084 * modify the object name. 00085 */ 00086 static bool 00087 remoteCall(std::string& objName); 00088 00089 /* CORBA remote management implementation. */ 00090 void 00091 bind(const char* objName, const char* ior); 00092 00093 void 00094 unbind(const char* objName); 00095 00096 LogSeqString* 00097 getBindings(const char* ctxt); 00098 00099 /* Connect the peer forwarder. */ 00100 void 00101 connectPeer(const char* ior, const char* host, const ::CORBA::Long port); 00102 00103 /* Set this forwarder peer object (not CORBA). */ 00104 void 00105 setPeer(CorbaLogForwarder_ptr peer); 00106 00107 CorbaLogForwarder_var 00108 getPeer(); 00109 00110 char* 00111 getIOR(); 00112 00113 /* Object caches management functions. */ 00114 void 00115 removeObjectFromCache(const std::string& name); 00116 00117 void 00118 cleanCaches(); 00119 00120 char* 00121 getName(); 00122 00123 char* 00124 getPeerName(); 00125 00126 char* 00127 getHost(); 00128 00129 char* 00130 getPeerHost(); 00131 00132 LogSeqString* routeTree(); 00133 00134 /* Utility function. */ 00135 std::list<std::string> 00136 otherForwarders() const; 00137 00138 /* LogComponentFwdr implementation. */ 00139 void 00140 setTagFilter(const ::tag_list_t& tagList, const char* objName); 00141 00142 void 00143 addTagFilter(const ::tag_list_t& tagList, const char* objName); 00144 00145 void 00146 removeTagFilter(const ::tag_list_t& tagList, const char* objName); 00147 00148 void 00149 test(const char* objName); 00150 00158 short 00159 disconnectTool(const char* toolName, const char* objName); 00160 00168 tag_list_t* 00169 getDefinedTags(const char* objName); 00170 00177 component_list_t* 00178 getDefinedComponents(const char* objName); 00179 00180 00188 short 00189 addFilter(const char* toolName, const filter_t& filter, const char* objName); 00190 00191 00192 void 00193 sendMsg(const log_msg_buf_t& msgBuf, const char* objName); 00194 00204 short 00205 connectTool(char*& toolName, const char* msgReceiver, const char* objName); 00206 00207 short 00208 flushAllFilters(const char* toolName, const char* objName); 00209 00210 short 00211 removeFilter(const char* toolName, const char* filterName, 00212 const char* objName); 00213 00214 00215 00216 /* Utility fonctions to extract name & context from context/name. */ 00217 static std::string 00218 getName(const std::string& namectxt); 00219 00220 static std::string 00221 getCtxt(const std::string& namectxt); 00222 00223 short 00224 connectComponent(char*&, const char*, const char*, const char*, 00225 const log_time_t&, tag_list_t&, const char*); 00226 00227 00228 short 00229 disconnectComponent(const char* componentName, const char* message, 00230 const char* objName); 00231 00232 00233 void 00234 sendBuffer(const log_msg_buf_t &buffer, const char* objName); 00235 00236 00237 void 00238 synchronize(const char* componentName, const log_time_t& componentTime, 00239 const char* objName); 00240 00241 private: 00242 /* When a new forwarder object is created, we cache it. 00243 * Because this kind of object contains only the object 00244 * name and a reference to this forwarder, there is no 00245 * risk to cache it, even if the object is restarted or 00246 * disappear. 00247 */ 00248 std::map<std::string, ::CORBA::Object_ptr> objectCache; 00249 /* We also maintain a list of activated servant objects. */ 00250 std::map<std::string, PortableServer::ServantBase*> servants; 00251 00252 ::CORBA::Object_ptr 00253 getObjectCache(const std::string& name); 00254 00255 /* The forwarder associated to this one. */ 00256 CorbaLogForwarder_var peer; 00257 /* Mutexes */ 00258 omni_mutex peerMutex; // To wait for the peer initialization 00259 omni_mutex cachesMutex; // Protect access to caches 00260 00261 std::string peerName; 00262 std::string name; 00263 std::string host; 00264 }; 00265 00266 #endif