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_0::credential;
31  namespace idl_or = tecgraf::openbus::core::v2_0::services::offer_registry;
32  namespace idl_data_export = tecgraf::openbus::core::v2_0::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_0
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 
141  const std::string target() const
142  {
143  return _target;
144  }
145 
153  const idl_ac::LoginInfoSeq &originators() const
154  {
155  return _originators;
156  }
157 
162  const idl_ac::LoginInfo &caller() const
163  {
164  return _caller;
165  }
166 
181  {
182  std::memset(_signedCallChain.signature, ' ', idl::EncryptedBlockSize);
183  }
184 //private:
185 #ifndef OPENBUS_SDK_TEST
186 private:
187 #else
188 public:
189 #endif
190  CallerChain(const std::string &busid,
191  const std::string &target,
192  const idl_ac::LoginInfoSeq &originators,
193  const idl_ac::LoginInfo &caller,
194  const idl_cr::SignedCallChain &chain)
195  : _busid(busid), _target(target), _originators(originators),
196  _caller(caller), _signedCallChain(chain)
197  {
198  }
199 
200  CallerChain(const std::string &busid,
201  const std::string &target,
202  const idl_ac::LoginInfoSeq &originators,
203  const idl_ac::LoginInfo &caller)
204  : _busid(busid), _target(target), _originators(originators),
205  _caller(caller)
206  {
207  std::memset(_signedCallChain.signature, ' ', idl::EncryptedBlockSize);
208  }
209 
210  std::string _busid;
211  std::string _target;
212  idl_ac::LoginInfoSeq _originators;
213  idl_ac::LoginInfo _caller;
214  idl_cr::SignedCallChain _signedCallChain;
215 
216  bool is_legacy() const;
217 
218  friend class OpenBusContext;
219  friend struct openbus::interceptors::ClientInterceptor;
220  friend inline bool operator==(CallerChain const &lhs,
221  CallerChain const &rhs)
222  {
223  return lhs._busid == rhs._busid && lhs._originators == rhs._originators
224  && lhs._caller == rhs._caller;
225  }
226 };
227 
228 inline bool operator!=(CallerChain const &lhs, CallerChain const &rhs)
229 {
230  return !(lhs == rhs);
231 }
232 
233 
262 class OPENBUS_SDK_DECL OpenBusContext : public CORBA::LocalObject
263 {
264 public:
288  typedef boost::function<
289  Connection* (OpenBusContext &context,
290  const std::string busId,
291  const std::string loginId,
292  const std::string operation)>
294 
313  void onCallDispatch(CallDispatchCallback c);
314 
319  CallDispatchCallback onCallDispatch() const;
320 
353  std::auto_ptr<Connection> createConnection(
354  const std::string &host, unsigned short port,
355  const Connection::ConnectionProperties &props =
356  Connection::ConnectionProperties());
357 
370  Connection *setDefaultConnection(Connection *);
371 
381  Connection *getDefaultConnection() const;
382 
394  Connection *setCurrentConnection(Connection *);
395 
404  Connection *getCurrentConnection() const;
405 
428  CallerChain getCallerChain();
429 
441  void joinChain(const CallerChain &chain = CallerChain());
442 
453  void exitChain();
454 
476  CallerChain getJoinedChain() const;
477 
507  CallerChain makeChainFor(const std::string &loginId) const;
508 
522  CORBA::OctetSeq encodeChain(const CallerChain chain);
523 
550  CallerChain decodeChain(const CORBA::OctetSeq &encoded) const;
551 
562  CORBA::OctetSeq encodeSharedAuthSecret(const SharedAuthSecret &secret);
563 
573  SharedAuthSecret decodeSharedAuthSecret(const CORBA::OctetSeq &encoded);
574 
578  CORBA::ORB_ptr orb() const
579  {
580  return _orb;
581  }
582 
583  idl_or::OfferRegistry_ptr getOfferRegistry() const;
584  idl_ac::LoginRegistry_ptr getLoginRegistry() const;
585 private:
590  OpenBusContext(CORBA::ORB_ptr, interceptors::ORBInitializer *);
591 
593  OpenBusContext &operator=(const OpenBusContext &);
594 
595  void orb(CORBA::ORB_ptr o)
596  {
597  _orb = o;
598  }
599 
600  CORBA::OctetSeq encode_exported_versions(idl_data_export::ExportedVersionSeq,
601  const std::string &tag);
602 
603  std::string decode_exported_versions(
604  const CORBA::OctetSeq &stream,
605  idl_data_export::ExportedVersionSeq_out exported_version_seq) const;
606 
607  typedef std::map<std::string, Connection *> BusidConnection;
608 #ifdef OPENBUS_SDK_MULTITHREAD
609  mutable boost::mutex _mutex;
610 #endif
611  interceptors::ORBInitializer * _orb_init;
612  CORBA::ORB_ptr _orb;
613  Connection *_defaultConnection;
614  BusidConnection _busidConnection;
615  CallDispatchCallback _callDispatchCallback;
616 
617  friend boost::shared_ptr<orb_ctx> openbus::ORBInitializer(
618  int &argc, char **argv);
619 };
620 }
621 
622 #endif
623 
const std::string target() const
Entidade para a qual a chamada estava destinada.
Definition: OpenBusContext.hpp:141
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:153
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:293
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:180
CORBA::ORB_ptr orb() const
Definition: OpenBusContext.hpp:578
Permite controlar o contexto das chamadas de um ORB para acessar informações que identificam essas ch...
Definition: OpenBusContext.hpp:262
const idl_ac::LoginInfo & caller() const
Informação de login da entidade que realizou a última chamada da cadeia.
Definition: OpenBusContext.hpp:162