1 /*------------------------------------------------------------------------------
2 Name: CorbaDriver.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: The client driver for the corba protocol
6 ------------------------------------------------------------------------------*/
7
8 #ifndef _CLIENT_PROTOCOL_CORBA_CORBA_DRIVER
9 #define _CLIENT_PROTOCOL_CORBA_CORBA_DRIVER
10
11 #include <util/xmlBlasterDef.h>
12 #include <util/plugin/I_Plugin.h>
13 #include <client/protocol/corba/CorbaConnection.h>
14 #include <client/protocol/corba/DefaultCallback.h>
15 #include <string>
16 #include <vector>
17 #include <util/MessageUnit.h>
18 #include <client/I_Callback.h>
19 #include <client/protocol/I_CallbackServer.h>
20 #include <client/protocol/I_XmlBlasterConnection.h>
21 #include <util/XmlBlasterException.h>
22
23 #include <util/qos/StatusQosFactory.h>
24 #include <util/qos/MsgQosFactory.h>
25 #include <util/thread/ThreadImpl.h>
26 #include <map>
27
28 namespace org {
29 namespace xmlBlaster {
30 namespace client {
31 namespace protocol {
32 namespace corba {
33
34 class Dll_Export CorbaDriver
35 : public virtual org::xmlBlaster::client::protocol::I_CallbackServer,
36 public virtual org::xmlBlaster::client::protocol::I_XmlBlasterConnection,
37 public virtual org::xmlBlaster::util::plugin::I_Plugin
38 {
39 friend class CorbaDriverFactory; // To be able to create a CorbaDriver instance
40
41 private:
42 org::xmlBlaster::util::thread::Mutex& mutex_;
43 std::string instanceName_;
44 CorbaConnection* connection_;
45 DefaultCallback* defaultCallback_;
46 const std::string ME;
47 org::xmlBlaster::util::Global& global_;
48 org::xmlBlaster::util::I_Log& log_;
49 org::xmlBlaster::util::qos::StatusQosFactory statusQosFactory_;
50 bool orbIsThreadSafe_;
51
52 /**
53 * frees the resources used. It only frees the resource specified with
54 * 'true'.
55 */
56 void freeResources(bool deleteConnection=true, bool deleteCallback=true);
57
58 /**
59 * Only used by getInstance()
60 * @param global
61 * @param mutex org::xmlBlaster::util::Global thread synchronization (to avoid static variable)
62 * @param doRun Only for internal main loop for single threaded orbs. false stops the loop
63 *
64 * @param isRunning Feedback is doRun has stopped
65 * @param instanceName
66 * @param orb
67 */
68 CorbaDriver(org::xmlBlaster::util::Global& global, org::xmlBlaster::util::thread::Mutex& mutex, const std::string instanceName, CORBA::ORB_ptr orb=NULL);
69
70 CorbaDriver(const CorbaDriver& corbaDriver);
71
72 CorbaDriver& operator =(const CorbaDriver& corbaDriver);
73
74 virtual ~CorbaDriver();
75
76 /**
77 * For single threaded CORBA implementations only (like MICO).
78 * One instance (the first) starts a main loop and checks if the
79 * orb has some work to perform (every 20 millis).
80 * In your real application this should be done by your main loop (e.g. from X-Window)
81 * E.g. mico has a helper implementation to register its file descriptors with another main loop.
82 */
83 // void run();
84
85 public:
86
87 bool orbIsThreadSafe() const {
88 return this->orbIsThreadSafe_;
89 }
90
91 // methods inherited from org::xmlBlaster::client::protocol::I_CallbackServer
92 void initialize(const std::string& name, org::xmlBlaster::client::I_Callback &client);
93 std::string getCbProtocol();
94 std::string getCbAddress();
95 bool shutdownCb();
96
97 // methods inherited from org::xmlBlaster::client::protocol::I_XmlBlasterConnection
98 org::xmlBlaster::util::qos::ConnectReturnQosRef connect(const org::xmlBlaster::util::qos::ConnectQosRef& qos);
99 bool disconnect(const org::xmlBlaster::util::qos::DisconnectQos& qos);
100 std::string getProtocol();
101 // std::string loginRaw();
102 bool shutdown();
103 std::string getLoginName();
104 bool isLoggedIn();
105
106 std::string ping(const std::string& qos);
107
108 org::xmlBlaster::client::qos::SubscribeReturnQos subscribe(const org::xmlBlaster::client::key::SubscribeKey& key, const org::xmlBlaster::client::qos::SubscribeQos& qos);
109
110 std::vector<org::xmlBlaster::util::MessageUnit> get(const org::xmlBlaster::client::key::GetKey& key, const org::xmlBlaster::client::qos::GetQos& qos);
111
112 std::vector<org::xmlBlaster::client::qos::UnSubscribeReturnQos> unSubscribe(const org::xmlBlaster::client::key::UnSubscribeKey& key, const org::xmlBlaster::client::qos::UnSubscribeQos& qos);
113
114 org::xmlBlaster::client::qos::PublishReturnQos publish(const org::xmlBlaster::util::MessageUnit& msgUnit);
115
116 void publishOneway(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr);
117
118 std::vector<org::xmlBlaster::client::qos::PublishReturnQos> publishArr(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr);
119
120 std::vector<org::xmlBlaster::client::qos::EraseReturnQos> erase(const org::xmlBlaster::client::key::EraseKey& key, const org::xmlBlaster::client::qos::EraseQos& qos);
121
122 /**
123 * @see org::xmlBlaster::client::protocol::I_CallbackServer#registerProgressListener
124 */
125 org::xmlBlaster::client::protocol::I_ProgressListener* registerProgressListener(org::xmlBlaster::client::protocol::I_ProgressListener *listener);
126
127
128 // following methods are not defined in any parent class
129 static std::string usage();
130 // Exception conversion ....
131 static org::xmlBlaster::util::XmlBlasterException
132 convertFromCorbaException(const serverIdl::XmlBlasterException& ex);
133 static serverIdl::XmlBlasterException
134 convertToCorbaException(org::xmlBlaster::util::XmlBlasterException& ex);
135
136 /**
137 * Get the name of the plugin.
138 * @return "IOR"
139 * @enforcedBy I_Plugin
140 */
141 std::string getType() { static std::string type = org::xmlBlaster::util::Constants::IOR; return type; }
142
143 /**
144 * Get the version of the plugin.
145 * @return "1.0"
146 * @enforcedBy I_Plugin
147 */
148 std::string getVersion() { static std::string version = "1.0"; return version; }
149 };
150
151 }}}}} // namespaces
152
153 #endif
syntax highlighted by Code2HTML, v. 0.9.1