1 #define MICO_CONF_IMR
  2 #include <CORBA-SMALL.h>
  3 #include <generated/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 messageUnit;  // 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 if (argc == 3) {
 57          strncpy(objref_str, argv[2], 1024); // allow -dispatch/connection/plugin/ior/iorString ...
 58       }
 59       else {
 60         cout << "Enter IOR from AuthServer-Server: ";
 61         cin  >> objref_str;
 62       }
 63 
 64       // narrow IOR-String to object reference
 65       authServer_obj= AuthServer::_narrow(orb->string_to_object(objref_str));
 66 
 67 
 68       //--------------- create my BlasterCallback server ----
 69       clientIdl::BlasterCallback_impl *callback_impl;
 70       boa= orb->BOA_init(argc, argv, "mico-local-boa");
 71       callback_impl = new clientIdl::BlasterCallback_impl();
 72       // cout << "\t" << orb->object_to_string(callback_impl) << endl;
 73       boa->impl_is_ready (CORBA::ImplementationDef::_nil());
 74       cout << "Successful created callback server!" << endl;
 75 
 76 
 77 
 78       //-------------- login() to AuthServer_obj ---------
 79       string xmlQos("<qos><callback type='IOR'>");
 80       xmlQos += orb->object_to_string(callback_impl);
 81       xmlQos += "</callback></qos>";
 82 
 83       serverIdl::Server_ptr xmlBlaster = authServer_obj->login("Ben", "secret", xmlQos.c_str());
 84       cout << "Successful login!" << endl;
 85 
 86 
 87       //-------------- publish() a message -------------
 88       string xmlKey("<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
 89                     "<key oid=''>\n"
 90                     "<AGENT id='192.168.124.10' subId='1' type='generic'>"
 91                     "<DRIVER id='FileProof' pollingFreq='10'>"
 92                     "</DRIVER>"
 93                     "</AGENT>"
 94                     "</key>");
 95 
 96       MessageUnit message;
 97       message.xmlKey = xmlKey.c_str();
 98       string content = "Hello xmlBlaster, i'm a C++ client";
 99       //??? message.content(MICO_ULong(content.size()), MICO_ULong(content.size()), (CORBA::Octet*)content.c_str());
100       message.qos = "<qos></qos>";
101 
102       string publishOid = xmlBlaster->publish(message);
103       cout << "Successful published message with new oid=" << publishOid << endl;
104 
105 
106       //-------------- subscribe() to the previous message OID -------
107       cout << "Subscribing using the exact oid ..." << endl;
108       xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
109                "<key oid='" + publishOid + "'>\n"
110                "</key>";
111       string qualityOfService = "";
112       try {
113          xmlBlaster->subscribe(xmlKey.c_str(), qualityOfService.c_str());
114       } catch(XmlBlasterException e) {
115          cerr << "XmlBlasterException: " << e.reason << endl;
116       }
117       cout << "Subscribed to '" << publishOid << "' ..." << endl;
118 
119 
120       //-------------- wait for something to happen -------------------
121       orb->run ();
122 
123    } catch(serverIdl::XmlBlasterException e) {
124       cerr << "Caught Server Exception: " << e.reason << endl;
125    } catch( ... ) {
126       cerr << "Login to xmlBlaster failed" << endl;
127    }
128    return 0;
129 }


syntax highlighted by Code2HTML, v. 0.9.1