1 #define MICO_CONF_IMR
2 #include <CORBA-SMALL.h>
3 #include "xmlBlaster.h" // xmlBlaster.h generated from 'xmlBlaster.idl'
4 #include <iostream>
5
6 using namespace std;
7 using namespace authenticateIdl;
8 using namespace serverIdl;
9
10 namespace clientIdl {
11 /**
12 * This is the callback implementation
13 */
14 class BlasterCallback_impl : virtual public BlasterCallback_skel {
15 MessageUnit msgUnit; // private Data of this object-implementation
16 public:
17 BlasterCallback_impl() {}
18 ~BlasterCallback_impl() {}
19
20 /*
21 * implement the update method, which was promised in "xmlBlaster.idl"
22 */
23 serverIdl::StringArr* update(const char* sessionId, const serverIdl::MessageUnitArr& msgUnitArr)
24 {
25 cout << "******* Callback invoked *******" << endl;
26 }
27 void updateOneway(const char* sessionId, const serverIdl::MessageUnitArr& msgUnitArr)
28 {
29 cout << "******* Oneway callback invoked *******" << endl;
30 }
31 char *ping(const char *qos)
32 {
33 cout << "******* ping callback invoked *******" << endl;
34 }
35 };
36 }
37
38
39 /**
40 */
41 int main(int argc, char* argv[])
42 {
43 AuthServer_var authServer_obj;
44 CORBA::ORB_var orb;
45 CORBA::BOA_var boa;
46 char objref_str[1024];
47
48 try {
49 // initialize
50 orb = CORBA::ORB_init(argc, argv, "mico-local-orb");
51
52 //--------------- find server object reference IOR -------
53 if (argc == 2) {
54 strncpy(objref_str, argv[1], 1024);
55 }
56 else {
57 cout << "Enter IOR from AuthServer-Server: ";
58 cin >> objref_str;
59 }
60
61 // narrow IOR-String to object reference
62 authServer_obj= AuthServer::_narrow(orb->string_to_object(objref_str));
63
64
65 //--------------- create my BlasterCallback server ----
66 clientIdl::BlasterCallback_impl *callback_impl;
67 boa= orb->BOA_init(argc, argv, "mico-local-boa");
68 callback_impl = new clientIdl::BlasterCallback_impl();
69 // cout << "\t" << orb->object_to_string(callback_impl) << endl;
70 boa->impl_is_ready (CORBA::ImplementationDef::_nil());
71
72
73
74 //-------------- login() to AuthServer_obj ---------
75 serverIdl::Server_ptr xmlBlaster = authServer_obj->login("Ben", "secret", callback_impl, "");
76 cout << "Successful login!" << endl;
77
78
79 //-------------- publish() a message -------------
80 string xmlKey("<key oid='' contentMime='text/plain'>\n"
81 " <AGENT id='192.168.124.10' subId='1' type='generic'>"
82 " <DRIVER id='FileProof' pollingFreq='10'>"
83 " </DRIVER>"
84 " </AGENT>"
85 "</key>");
86
87 MessageUnit message;
88 message.xmlKey = xmlKey.c_str();
89 string content = "Hello xmlBlaster, i'm a C++ client";
90 //??? message.content(MICO_ULong(content.size()), MICO_ULong(content.size()), (CORBA::Octet*)content.c_str());
91
92 string publishOid = xmlBlaster->publish(message, "");
93 cout << "Successful published message with new oid=" << publishOid << endl;
94
95
96 //-------------- subscribe() to the previous message OID -------
97 cout << "Subscribing using the exact oid ..." << endl;
98 xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
99 "<key oid='" + publishOid + "'>\n"
100 "</key>";
101 string qualityOfService = "";
102 try {
103 xmlBlaster->subscribe(xmlKey.c_str(), qualityOfService.c_str());
104 } catch(XmlBlasterException e) {
105 cerr << "XmlBlasterException: " << e.reason << endl;
106 }
107 cout << "Subscribed to '" << publishOid << "' ..." << endl;
108
109
110 //-------------- wait for something to happen -------------------
111 orb->run ();
112
113 } catch(serverIdl::XmlBlasterException e) {
114 cerr << "Caught Server Exception: " << e.reason << endl;
115 } catch( ... ) {
116 cerr << "Login to xmlBlaster failed" << endl;
117 }
118 return 0;
119 }
syntax highlighted by Code2HTML, v. 0.9.1