1 /*----------------------------------------------------------------------------
2 Name: CorbaConnection.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Helper to connect to xmlBlaster: for now a simplified version
6 without caching and without failsafe mode.
7 Author: <Michele Laghi> laghi@swissinfo.org
8 -----------------------------------------------------------------------------*/
9
10 #ifndef _CLIENT_PROTOCOL_CORBA_CORBACONNECTION_H
11 #define _CLIENT_PROTOCOL_CORBA_CORBACONNECTION_H
12
13 #include <util/xmlBlasterDef.h>
14
15 #include <string>
16 #include <vector>
17 #include <fstream>
18 #include <client/protocol/corba/DefaultCallback.h>
19 #include <util/I_Log.h>
20 #include <client/protocol/corba/NameServerControl.h>
21 #include <util/qos/address/CallbackAddress.h>
22 #include <util/MessageUnit.h>
23 #include <util/qos/ConnectQosFactory.h>
24 #include <util/qos/MsgQosFactory.h>
25 #include <util/key/MsgKeyFactory.h>
26
27 #include <client/protocol/corba/CompatibleCorba.h> // client side headers
28 #include COSNAMING
29
30 // org::xmlBlaster::util::qos::ConnectQos + org::xmlBlaster::util::qos::ConnectReturnQos
31
32 namespace org {
33 namespace xmlBlaster {
34 namespace client {
35 namespace protocol {
36 namespace corba {
37
38 class Dll_Export CorbaConnection {
39
40 private:
41
42 std::string me() const {
43 return std::string("CorbaConnection");
44 }
45 /* static*/ CORBA::ORB_ptr orb_;
46 /*static*/ PortableServer::POA_ptr poa_;
47 NameServerControl* nameServerControl_;
48 authenticateIdl::AuthServer_ptr authServer_;
49 serverIdl::Server_ptr xmlBlaster_;
50 clientIdl::BlasterCallback_ptr callback_;
51 std::string loginName_;
52 std::string passwd_;
53 int numLogins_;
54 DefaultCallback* defaultCallback_;
55 org::xmlBlaster::util::qos::ConnectReturnQosRef connectReturnQos_;
56 std::string sessionId_;
57 std::string xmlBlasterIOR_;
58 std::string callbackIOR_;
59 org::xmlBlaster::util::Global& global_;
60 /* mutable */ org::xmlBlaster::util::I_Log& log_;
61 org::xmlBlaster::util::key::MsgKeyFactory msgKeyFactory_;
62 org::xmlBlaster::util::qos::MsgQosFactory msgQosFactory_;
63
64 public:
65 /**
66 * CORBA client access to xmlBlaster for <strong>normal client
67 * applications
68 * </strong>.
69 * <p />
70 * @param arg parameters given on command line
71 * <ul>
72 * <li>-dispatch/connection/plugin/ior/iorString IOR std::string is directly given</li>
73 * <li>-dispatch/connection/plugin/ior/iorFile IOR std::string is given through a file</li>
74 * <li>-bootstrapHostname host name or IP where xmlBlaster is running</li>
75 * <li>-bootstrapPort where the internal xmlBlaster-http server publishes
76 * its IOR (defaults to 3412)</li>
77 * <li>-dispatch/connection/plugin/ior/useNameService true/false, if a naming service shall be used</li>
78 * </ul>
79 */
80 CorbaConnection(org::xmlBlaster::util::Global& global, CORBA::ORB_ptr orb=NULL);
81
82 ~CorbaConnection();
83
84 std::string getAddress() const;
85
86 std::string getCbAddress() const;
87
88 /**
89 * Is used to perform work on the orb (if necessary).
90 * @return true if some work was done
91 */
92 bool orbPerformWork() {
93 if (orb_ != NULL) {
94 bool ret = (orb_->work_pending() != 0);
95 if (ret) orb_->perform_work();
96 return ret;
97 }
98 else
99 return false;
100 }
101
102
103 /**
104 * Run forever
105 */
106 void run() {
107 if (orb_ != NULL)
108 orb_->run();
109 }
110
111
112 /*
113 * Accessing the xmlBlaster handle.
114 * @return Server
115 * @exception if not logged in
116 serverIdl::Server_ptr getXmlBlaster();
117 */
118
119 private:
120 /**
121 * Locate the CORBA Name Service.
122 * <p />
123 * The found name service is cached, for better performance in
124 * subsequent calls
125 * @exception org::xmlBlaster::util::XmlBlasterException
126 * CORBA error handling if no naming service is found
127 */
128 void initNamingService();
129
130 public:
131 /**
132 * Access the authentication service.
133 * <p />
134 * There are several ways to bootstrap the authentication service:
135 * <br />
136 * <ul>
137 * <li>Give the authentication service std::string-IOR at command line,
138 * e.g.<br />
139 * <code> -dispatch/connection/plugin/ior/iorString "IOR:0000..."</code><br />
140 * or giving a file name<br />
141 * <code> -dispatch/connection/plugin/ior/iorFile yourIorFile</code></li>
142 * <li>Give the xmlBlaster host and bootstrap port where
143 * xmlBlaster-Authenticate serves the IOR via http, give at command line
144 * e.g.
145 * <code> -bootstrapHostname server.xmlBlaster.org -bootstrapPort 3412</code>
146 * </li>
147 * <li>Try to find a naming service which knows about
148 * 'xmlBlaster-Authenticate'</li>
149 * </ul>
150 * <p />
151 * @return a handle on the AuthServer IDL interface
152 *
153 */
154 void initAuthenticationService();
155
156 /**
157 * The new way to connect (i.e. login to xmlBlaster)
158 */
159 org::xmlBlaster::util::qos::ConnectReturnQosRef connect(const org::xmlBlaster::util::qos::ConnectQosRef& connectQos);
160
161 /**
162 * Disconnects from the xmlBlaster server (the callback server is not
163 * disconnected).
164 */
165 bool disconnect(const std::string& qos="");
166
167 /**
168 * Shutdown the connection without disconnecting (xmlBlaster does not know that we have disappeared)
169 */
170 bool shutdown();
171
172 bool shutdownCb();
173
174 /**
175 * Building a Callback server.
176 * @return the BlasterCallback server
177 */
178 void createCallbackServer(POA_clientIdl::BlasterCallback *implObj);
179
180
181 /**
182 * Access the login name.
183 * @return your login name or null if you are not logged in
184 */
185 const std::string &getLoginName() const {
186 return loginName_;
187 }
188
189
190 /**
191 * @return true if you are logged in
192 */
193 bool isLoggedIn() {
194 if (CORBA::is_nil(authServer_)) initAuthenticationService();
195 return (!CORBA::is_nil(xmlBlaster_ /*.in()*/ ));
196 }
197
198
199 /**
200 * Subscribe a message.
201 * <br />
202 * Note: You don't need to free anything
203 * @return The xml based QoS
204 */
205 std::string subscribe(const std::string &xmlKey, const std::string &qos=std::string("<qos/>"));
206
207
208 std::vector<std::string> unSubscribe(const std::string &xmlKey, const std::string &qos=std::string("<qos/>"));
209
210
211 /**
212 * Publish the given message.
213 * <p />
214 * This is a wrapper around the raw CORBA publish() method
215 * If the server disappears you get an exception.
216 * This call will not block.
217 * <p />
218 * @see xmlBlaster.idl
219 * @deprecated Please use the util::MessageUnit variant
220 */
221 std::string publish(const serverIdl::MessageUnit &msgUnit);
222
223 /**
224 * Publish with util org::xmlBlaster::util::MessageUnit (not CORBA specific client code).
225 * <br />
226 * This method has a common interface which is not CORBA depending.
227 * Prefer this to publish(const serverIdl::MessageUnit &msgUnit)
228 * <br />
229 * Note: You don't need to free anything
230 * @return The xml based QoS
231 */
232 std::string publish(const util::MessageUnit &msgUnitUtil);
233
234 /**
235 * Publish a bulk of messages.
236 * <br />
237 * This method has a common interface which is not CORBA depending.
238 * <br />
239 * Note: You don't need to free anything
240 * @param A std::vector with org::xmlBlaster::util::MessageUnit
241 * @return A std::vector of std::strings each is a publish return QoS.
242 * @see xmlBlaster.idl
243 */
244 std::vector<std::string> publishArr(const std::vector<util::MessageUnit> &msgVec);
245
246 /**
247 * @deprecated Please use the STL std::vector variant
248 */
249 serverIdl::XmlTypeArr* publishArr(const serverIdl::MessageUnitArr& msgUnitArr);
250
251 /**
252 * Publish a bulk of messages without ACK.
253 * <br />
254 * This method has a common interface which is not CORBA depending.
255 * <br />
256 * Note: You don't need to free anything
257 * @param The org::xmlBlaster::util::MessageUnit array as a STL std::vector
258 * @see xmlBlaster.idl
259 */
260 void publishOneway(const std::vector<util::MessageUnit>& msgVec);
261
262 /**
263 * Enforced by ServerOperations interface.
264 * @see xmlBlaster.idl
265 * @deprecated Use the std::vector<util::MessageUnit> variant
266 */
267 void publishOneway(const serverIdl::MessageUnitArr& msgUnitArr);
268
269 /**
270 * @see xmlBlaster.idl
271 */
272 std::vector<std::string> erase(const std::string &xmlKey, const std::string &qos=std::string("<qos/>"));
273
274
275 /**
276 * Access messages the synchronous way.
277 * <br />
278 * Note: You don't need to free anything
279 * @return The STL org::xmlBlaster::util::MessageUnit std::vector, its a copy so if you have the variable on the
280 * stack it will free itself
281 * @see xmlBlaster.idl
282 */
283 std::vector<util::MessageUnit> get(const std::string &xmlKey, const std::string &qos=std::string("<qos/>"));
284
285 //serverIdl::MessageUnitArr* get(const std::string &xmlKey, const std::string &qos);
286
287
288 /**
289 * Publish fault-tolerant the given message.
290 * <p />
291 * This is a wrapper around the raw CORBA publish() method
292 * If the server disappears you get an exception.
293 * This call will not block.
294 * <p />
295 * Enforced by ServerOperations interface (failsafe mode)
296 * @see xmlBlaster.idl
297 */
298 std::string ping(const std::string &qos=std::string("<qos/>"));
299
300 /**
301 * Transform a util::MessageUnit to the corba variant
302 */
303 void copyToCorba(serverIdl::MessageUnit &dest, const util::MessageUnit &src) const;
304
305 /**
306 * Transform STL std::vector to corba messageUnit array variant.
307 */
308 void copyToCorba(serverIdl::MessageUnitArr_var &units, const std::vector<util::MessageUnit> &msgVec) const;
309
310 void copyFromCorba(std::vector<util::MessageUnit> &vecArr, serverIdl::MessageUnitArr_var &units);
311
312 /**
313 * Command line usage.
314 * <p />
315 * These variables may be set in xmlBlaster.properties as well.
316 * Don't use the "-" prefix there.
317 */
318 static std::string usage();
319
320 }; // class CorbaConnection
321 }}}}} // namespace
322
323
324 #endif
syntax highlighted by Code2HTML, v. 0.9.1