OpenBus SDK C++ TAO  2.0.2.0
 Tudo Classes Namespaces Ficheiros Funções Definições de tipos Páginas
OpenBusContext.hpp
Ir para a documentação deste ficheiro.
1 // -*- coding: iso-8859-1-unix -*-
7 #ifndef TECGRAF_SDK_OPENBUS_OPENBUS_CONTEXT_H_
8 #define TECGRAF_SDK_OPENBUS_OPENBUS_CONTEXT_H_
9 
10 #include "openbus/ORBInitializer.hpp"
11 #include "openbus/decl.hpp"
12 #include "openbus/Connection.hpp"
13 #include "credentialC.h"
14 #include "access_controlC.h"
15 #include "offer_registryC.h"
16 #include "data_exportC.h"
17 
18 #include <tao/LocalObject.h>
19 
20 #include <boost/function.hpp>
21 #ifdef OPENBUS_SDK_MULTITHREAD
22  #include <boost/thread.hpp>
23 #endif
24 #include <boost/shared_ptr.hpp>
25 #include <string>
26 
27 namespace openbus
28 {
30  namespace idl_cr = tecgraf::openbus::core::v2_1::credential;
31  namespace idl_or = tecgraf::openbus::core::v2_1::services::offer_registry;
32  namespace idl_data_export = tecgraf::openbus::core::v2_1::data_export;
33 
34  namespace interceptors
35  {
36  struct orb_info;
37  struct ClientInterceptor;
38  }
39 }
40 
41 namespace tecgraf
42 {
43 namespace openbus
44 {
45 namespace core
46 {
47 namespace v2_1
48 {
49 namespace services
50 {
51 namespace access_control
52 {
53 
54 inline bool operator==(const LoginInfo &lhs, const LoginInfo &rhs)
55 {
56  return lhs.id.in() == rhs.id.in()
57  || (lhs.id.in() && rhs.id.in() && !std::strcmp(lhs.id.in(), rhs.id.in()));
58 }
59 
60 inline bool operator!=(const LoginInfo &lhs, const LoginInfo &rhs)
61 {
62  return !(lhs == rhs);
63 }
64 
65 inline bool operator==(const LoginInfoSeq &lhs, const LoginInfoSeq &rhs)
66 {
67  if (lhs.length() != rhs.length())
68  {
69  return false;
70  }
71  for (CORBA::ULong i(0); i < rhs.length(); ++i)
72  {
73  if (lhs[i] != rhs[i])
74  {
75  return false;
76  }
77  }
78  return true;
79 }
80 
81 inline bool operator!=(const LoginInfoSeq &lhs, const LoginInfoSeq &rhs)
82 {
83  return !(lhs == rhs);
84 }
85 
86 }}}}}}
87 
91 namespace openbus
92 {
93 
94 struct OPENBUS_SDK_DECL InvalidEncodedStream : public std::exception
95 {
96  InvalidEncodedStream();
97  InvalidEncodedStream(const std::string &msg);
98  ~InvalidEncodedStream() throw();
99  const char *what() const throw()
100  {
101  return msg_.c_str();
102  }
103 private:
104  std::string msg_;
105 };
106 
116 struct OPENBUS_SDK_DECL CallerChain
117 {
121  const std::string busid() const
122  {
123  return _busid;
124  }
125 
135  const std::string target() const
136  {
137  return _target;
138  }
139 
147  const idl_ac::LoginInfoSeq &originators() const
148  {
149  return _originators;
150  }
151 
156  const idl_ac::LoginInfo &caller() const
157  {
158  return _caller;
159  }
160 
175  {
176  std::memset(_signedCallChain.signature, ' ', idl::EncryptedBlockSize);
177  }
178 //private:
179 #ifndef OPENBUS_SDK_TEST
180 private:
181 #else
182 public:
183 #endif
184  CallerChain(const std::string &busid,
185  const std::string &target,
186  const idl_ac::LoginInfoSeq &originators,
187  const idl_ac::LoginInfo &caller,
188  const idl_cr::SignedData &chain)
189  : _busid(busid), _target(target), _originators(originators),
190  _caller(caller), _signedCallChain(chain)
191  {
192  }
193 
194  CallerChain(const std::string &busid,
195  const std::string &target,
196  const idl_ac::LoginInfoSeq &originators,
197  const idl_ac::LoginInfo &caller)
198  : _busid(busid), _target(target), _originators(originators),
199  _caller(caller)
200  {
201  std::memset(_signedCallChain.signature, ' ', idl::EncryptedBlockSize);
202  }
203 
204  std::string _busid;
205  std::string _target;
206  idl_ac::LoginInfoSeq _originators;
207  idl_ac::LoginInfo _caller;
208  idl_cr::SignedData _signedCallChain;
209 
210  friend class OpenBusContext;
211  friend struct openbus::interceptors::ClientInterceptor;
212  friend inline bool operator==(CallerChain const &lhs,
213  CallerChain const &rhs)
214  {
215  return lhs._busid == rhs._busid && lhs._originators == rhs._originators
216  && lhs._caller == rhs._caller;
217  }
218 };
219 
220 inline bool operator!=(CallerChain const &lhs, CallerChain const &rhs)
221 {
222  return !(lhs == rhs);
223 }
224 
225 
254 class OPENBUS_SDK_DECL OpenBusContext : public CORBA::LocalObject
255 {
256 public:
280  typedef boost::function<
281  Connection* (OpenBusContext &context,
282  const std::string busId,
283  const std::string loginId,
284  const std::string operation)>
286 
305  void onCallDispatch(CallDispatchCallback c);
306 
311  CallDispatchCallback onCallDispatch() const;
312 
331  std::auto_ptr<Connection> connectByReference(
332  scs::core::IComponent_ptr ref,
333  const Connection::ConnectionProperties &props =
334  Connection::ConnectionProperties());
335 
357  std::auto_ptr<Connection> connectByAddress(
358  const std::string &host, unsigned short port,
359  const Connection::ConnectionProperties &props =
360  Connection::ConnectionProperties());
361 
383  std::auto_ptr<Connection> createConnection(
384  const std::string &host, unsigned short port,
385  const Connection::ConnectionProperties &props =
386  Connection::ConnectionProperties());
387 
400  Connection *setDefaultConnection(Connection *);
401 
411  Connection *getDefaultConnection() const;
412 
424  Connection *setCurrentConnection(Connection *);
425 
434  Connection *getCurrentConnection() const;
435 
458  CallerChain getCallerChain();
459 
471  void joinChain(const CallerChain &chain = CallerChain());
472 
483  void exitChain();
484 
506  CallerChain getJoinedChain() const;
507 
537  CallerChain makeChainFor(const std::string &loginId) const;
538 
552  CORBA::OctetSeq encodeChain(const CallerChain chain);
553 
580  CallerChain decodeChain(const CORBA::OctetSeq &encoded) const;
581 
592  CORBA::OctetSeq encodeSharedAuthSecret(const SharedAuthSecret &secret);
593 
603  SharedAuthSecret decodeSharedAuthSecret(const CORBA::OctetSeq &encoded);
604 
608  CORBA::ORB_ptr orb() const
609  {
610  return _orb;
611  }
612 
613  idl_or::OfferRegistry_ptr getOfferRegistry() const;
614  idl_ac::LoginRegistry_ptr getLoginRegistry() const;
615 private:
620  OpenBusContext(CORBA::ORB_ptr, interceptors::ORBInitializer *);
621 
623  OpenBusContext &operator=(const OpenBusContext &);
624 
625  void orb(CORBA::ORB_ptr o)
626  {
627  _orb = o;
628  }
629 
630  CORBA::OctetSeq encode_exported_versions(idl_data_export::ExportedVersionSeq,
631  const std::string &tag);
632 
633  std::string decode_exported_versions(
634  const CORBA::OctetSeq &stream,
635  idl_data_export::ExportedVersionSeq_out exported_version_seq) const;
636 
637  typedef std::map<std::string, Connection *> BusidConnection;
638 #ifdef OPENBUS_SDK_MULTITHREAD
639  mutable boost::mutex _mutex;
640 #endif
641  interceptors::ORBInitializer * _orb_init;
642  CORBA::ORB_ptr _orb;
643  Connection *_defaultConnection;
644  BusidConnection _busidConnection;
645  CallDispatchCallback _callDispatchCallback;
646 
647  friend boost::shared_ptr<orb_ctx> openbus::ORBInitializer(
648  int &argc, char **argv);
649 };
650 }
651 
652 #endif
653 
const std::string target() const
Entidade para a qual a chamada estava destinada.
Definition: OpenBusContext.hpp:135
const idl_ac::LoginInfoSeq & originators() const
Lista de informações de login de todas as entidades que originaram as chamadas nessa cadeia...
Definition: OpenBusContext.hpp:147
boost::function< Connection *(OpenBusContext &context, const std::string busId, const std::string loginId, const std::string operation)> CallDispatchCallback
Callback de despacho de chamadas.
Definition: OpenBusContext.hpp:285
openbus
Definition: Connection.hpp:41
const std::string busid() const
Barramento através do qual as chamadas foram originadas.
Definition: OpenBusContext.hpp:121
Cadeia de chamadas oriundas de um barramento.
Definition: OpenBusContext.hpp:116
Segredo para compartilhamento de autenticação.
Definition: Connection.hpp:121
OPENBUS_SDK_DECL boost::shared_ptr< orb_ctx > ORBInitializer(int &argc, char **argv)
Inicializa um ORB utilizado exclusivamente para chamadas através de barramentos OpenBus.
Definition: OpenBusContext.hpp:41
Conexão para acesso identificado a um barramento.
Definition: Connection.hpp:177
CallerChain()
Construtor default que indica há ausência de uma cadeia.
Definition: OpenBusContext.hpp:174
CORBA::ORB_ptr orb() const
Definition: OpenBusContext.hpp:608
Permite controlar o contexto das chamadas de um ORB para acessar informações que identificam essas ch...
Definition: OpenBusContext.hpp:254
const idl_ac::LoginInfo & caller() const
Informação de login da entidade que realizou a última chamada da cadeia.
Definition: OpenBusContext.hpp:156