LogService
libdadi: utility tools for distributed applications
LogORBMgr.hh
1 /****************************************************************************/
2 /* ORB manager v. 2.0 - CORBA management with DIET forwarders */
3 /* */
4 /* Author(s): */
5 /* - GaĆ«l Le Mahec (gael.le.mahec@ens-lyon.fr) */
6 /* */
7 /* This file is part of DIET . */
8 /* */
9 /* Copyright (C) 2000-2003 ENS Lyon, LIFC, INSA, INRIA and SysFera (2000) */
10 /* */
11 /* - Frederic.Desprez@ens-lyon.fr (Project Manager) */
12 /* - Eddy.Caron@ens-lyon.fr (Technical Manager) */
13 /* - Tech@sysfera.com (Maintainer and Technical Support) */
14 /* */
15 /* This software is a computer program whose purpose is to provide an */
16 /* distributed logging services. */
17 /* */
18 /* */
19 /* This software is governed by the CeCILL license under French law and */
20 /* abiding by the rules of distribution of free software. You can use, */
21 /* modify and/ or redistribute the software under the terms of the CeCILL */
22 /* license as circulated by CEA, CNRS and INRIA at the following URL */
23 /* "http://www.cecill.info". */
24 /* */
25 /* As a counterpart to the access to the source code and rights to copy, */
26 /* modify and redistribute granted by the license, users are provided */
27 /* only with a limited warranty and the software's author, the holder */
28 /* of the economic rights, and the successive licensors have only */
29 /* limited liability. */
30 /* */
31 /* In this respect, the user's attention is drawn to the risks */
32 /* associated with loading, using, modifying and/or developing or */
33 /* reproducing the software by the user in light of its specific status */
34 /* of free software, that may mean that it is complicated to */
35 /* manipulate, and that also therefore means that it is reserved for */
36 /* developers and experienced professionals having in-depth computer */
37 /* knowledge. Users are therefore encouraged to load and test the */
38 /* software's suitability as regards their requirements in conditions */
39 /* enabling the security of their systems and/or data to be ensured and, */
40 /* more generally, to use and operate it in the same conditions as */
41 /* regards security. */
42 /* */
43 /* The fact that you are presently reading this means that you have had */
44 /* knowledge of the CeCILL license and that you accept its terms. */
45 /* */
46 /****************************************************************************/
47 
48 #ifndef LOGORBMGR_HH
49 #define LOGORBMGR_HH
50 
51 #include <list>
52 #include <map>
53 #include <string>
54 #include <sys/types.h>
55 #include <omniORB4/CORBA.h>
56 #include <omnithread.h>
57 #include "CorbaLogForwarder.hh"
58 
59 
60 #define LOGCOMPCTXT "LogServiceC"
61 #define LOGTOOLCTXT "LogServiceT"
62 #define LOGCOMPCONFCTXT "LogServiceC2"
63 #define LOGTOOLMSGCTXT "LogServiceT2"
64 #define LOGFWRDCTXT "LogForwarder"
65 #define DIETFWRD "DietForwarder"
66 
67 
68 class LogORBMgr {
69 public:
70  /* Constructors. */
71  LogORBMgr(int argc, char* argv[]);
72 
73  explicit LogORBMgr(CORBA::ORB_ptr ORB);
74 
75  LogORBMgr(CORBA::ORB_ptr ORB, PortableServer::POA_var POA);
76 
77  /* Destructor. */
78  ~LogORBMgr();
79 
80  /* Bind the object using its ctxt/name */
81  void
82  bind(const std::string& ctxt, const std::string& name,
83  CORBA::Object_ptr object, const bool rebind = false) const;
84 
85  /* Bind an object using its IOR. */
86  void
87  bind(const std::string& ctxt, const std::string& name,
88  const std::string& IOR, const bool rebind = false) const;
89 
90  /* Rebind objects. */
91  void
92  rebind(const std::string& ctxt, const std::string& name,
93  CORBA::Object_ptr object) const;
94 
95  void
96  rebind(const std::string& ctxt, const std::string& name,
97  const std::string& IOR) const;
98 
99  /* Unbind an object. */
100  void
101  unbind(const std::string& ctxt, const std::string& name) const;
102 
103  /* Forwarders binding. */
104  void
105  fwdsBind(const std::string& ctxt, const std::string& name,
106  const std::string& ior, const std::string& fwName = "") const;
107 
108  /* Forwarders unbinding. */
109  void
110  fwdsUnbind(const std::string& ctxt, const std::string& name,
111  const std::string& fwName = "") const;
112 
113  /* Resolve an object using its IOR or ctxt/name. */
114  CORBA::Object_ptr
115  resolveObject(const std::string& IOR) const;
116 
117  CORBA::Object_ptr
118  resolveObject(const std::string& ctxt, const std::string& name,
119  const std::string& fwdName = "") const;
120 
121  /* Resolve objects without object caching or invoking forwarders. */
122  CORBA::Object_ptr
123  simpleResolve(const std::string& ctxt, const std::string& name) const;
124 
125  /* Get the list of the objects id binded in the omniNames server
126  for a given context. */
127  std::list<std::string>
128  list(CosNaming::NamingContext_var& ctxt) const;
129 
130  std::list<std::string>
131  list(const std::string& ctxtName) const;
132 
133  /* Get the list of declared CORBA contexts. */
134  std::list<std::string>
135  contextList() const;
136 
137  /* Return true if the object is local, false if it is reachable
138  through a forwarder. */
139  bool
140  isLocal(const std::string& ctxt, const std::string& name) const;
141 
142  /* Return the name of the forwarder that manage the object. */
143  std::string
144  forwarderName(const std::string& ctxt, const std::string& name) const;
145 
146  template <typename CORBA_object, typename CORBA_ptr>
147  CORBA_ptr
148  resolve(const std::string& ctxt, const std::string& name,
149  const std::string& fwdName = "") const {
150  return CORBA_object::_duplicate(
151  CORBA_object::_narrow(resolveObject(ctxt, name, fwdName)));
152  }
153 
154  template <typename CORBA_object, typename CORBA_ptr>
155  CORBA_ptr
156  resolve(const std::string& IOR) const {
157  return CORBA_object::_duplicate(CORBA_object::_narrow(resolveObject(IOR)));
158  }
159 
160  /* Return the IOR of the passed object. */
161  std::string
162  getIOR(CORBA::Object_ptr object) const;
163 
164  std::string
165  getIOR(const std::string& ctxt, const std::string& name) const;
166 
167  /* Activate an object. */
168  void
169  activate(PortableServer::ServantBase* object) const;
170 
171  /* Deactivate an object. */
172  void
173  deactivate(PortableServer::ServantBase* object) const;
174 
175  /* Wait for the request on activated objects. */
176  void
177  wait() const;
178 
179  void
180  shutdown(bool waitForCompletion);
181 
182  static void
183  init(int argc, char* argv[]);
184 
185  static LogORBMgr*
186  getMgr();
187 
188  std::list<std::string>
189  forwarderObjects(const std::string& fwdName, const std::string& ctxt) const;
190 
191  std::list<std::string>
192  localObjects(const std::string& ctxt) const;
193 
194  /* IOR management functions. */
195  static void
196  makeIOR(const std::string& strIOR, IOP::IOR& ior);
197 
198  static void
199  makeString(const IOP::IOR& ior, std::string& strIOR);
200 
201  static std::string
202  getHost(IOP::IOR& ior);
203 
204  static std::string
205  getHost(const std::string& strIOR);
206 
207  static unsigned int
208  getPort(IOP::IOR& ior);
209 
210  static unsigned int
211  getPort(const std::string& strIOR);
212 
213  static std::string
214  getTypeID(IOP::IOR& ior);
215 
216  static std::string
217  getTypeID(const std::string& strIOR);
218 
219  static std::string
220  convertIOR(IOP::IOR& ior, const std::string& host,
221  const unsigned int port);
222 
223  static std::string
224  convertIOR(const std::string& ior, const std::string& host,
225  const unsigned int port);
226 
227  /* Object cache management functions. */
228  void
229  resetCache() const;
230 
231  void
232  removeObjectFromCache(const std::string& name) const;
233 
234  void
235  removeObjectFromCache(const std::string& ctxt,
236  const std::string& name) const;
237  void
238  cleanCache() const;
239 
240  static void
241  hexStringToBuffer(const char* ptr, const size_t size,
242  cdrMemoryStream& buffer);
243 
244 private:
245  /* The omniORB Object Request Broker for this manager. */
246  CORBA::ORB_ptr ORB;
247  /* The Portable Object Adaptor. */
248  PortableServer::POA_var POA;
249 
250  /* Is the ORB down? */
251  bool down;
252 
253  /* CORBA initialization. */
254  void
255  init(CORBA::ORB_ptr ORB);
256 
257  /* Object cache to avoid to contact OmniNames too many times. */
258  mutable std::map<std::string, CORBA::Object_ptr> cache;
259  /* Cache mutex. */
260  mutable omni_mutex cacheMutex;
261 
262  /* The manager instance. */
263  static LogORBMgr* theMgr;
264 
265  static void
266  sigIntHandler(int sig);
267 #ifndef __cygwin__
268  static omni_mutex waitLock;
269 #else
270  static sem_t waitLock;
271 #endif
272 };
273 
274 
275 #endif
Definition: LogORBMgr.hh:68