testsuite/src/c++/clientBOA.cpp

Go to the documentation of this file.
00001 #define MICO_CONF_IMR
00002 #include <CORBA-SMALL.h>
00003 #include <generated/xmlBlaster.h>    // xmlBlaster.h generated from 'xmlBlaster.idl'
00004 #include <iostream>
00005 
00006 using namespace std;
00007 using namespace authenticateIdl;
00008 using namespace serverIdl;
00009 
00010 namespace clientIdl {
00014    class BlasterCallback_impl : virtual public BlasterCallback_skel   {
00015       MessageUnit messageUnit;  // private Data of this object-implementation
00016    public:
00017       BlasterCallback_impl() {}
00018       ~BlasterCallback_impl() {}
00019 
00020       /*
00021        * implement the update method, which was promised in "xmlBlaster.idl"
00022        */
00023       serverIdl::StringArr* update(const char* sessionId, const serverIdl::MessageUnitArr& msgUnitArr)
00024       {
00025          cout << "******* Callback invoked *******" << endl;
00026       }
00027       void updateOneway(const char* sessionId, const serverIdl::MessageUnitArr& msgUnitArr)
00028       {
00029          cout << "******* Oneway callback invoked *******" << endl;
00030       }
00031       char *ping(const char *qos)
00032       {
00033          cout << "******* ping callback invoked *******" << endl;
00034       }
00035    };
00036 }
00037 
00038 
00041 int main(int argc, char* argv[])
00042 {
00043    AuthServer_var  authServer_obj;
00044    CORBA::ORB_var  orb;
00045    CORBA::BOA_var  boa;
00046    char            objref_str[1024];
00047 
00048    try {
00049       // initialize
00050       orb = CORBA::ORB_init(argc, argv, "mico-local-orb");
00051 
00052       //--------------- find server object reference IOR -------
00053       if (argc == 2) {
00054          strncpy(objref_str, argv[1], 1024);
00055       }
00056       else if (argc == 3) {
00057          strncpy(objref_str, argv[2], 1024); // allow -dispatch/connection/plugin/ior/iorString ...
00058       }
00059       else {
00060         cout << "Enter IOR from AuthServer-Server: ";
00061         cin  >> objref_str;
00062       }
00063 
00064       // narrow IOR-String to object reference
00065       authServer_obj= AuthServer::_narrow(orb->string_to_object(objref_str));
00066 
00067 
00068       //--------------- create my BlasterCallback server ----
00069       clientIdl::BlasterCallback_impl *callback_impl;
00070       boa= orb->BOA_init(argc, argv, "mico-local-boa");
00071       callback_impl = new clientIdl::BlasterCallback_impl();
00072       // cout << "\t" << orb->object_to_string(callback_impl) << endl;
00073       boa->impl_is_ready (CORBA::ImplementationDef::_nil());
00074       cout << "Successful created callback server!" << endl;
00075 
00076 
00077 
00078       //-------------- login() to AuthServer_obj ---------
00079       string xmlQos("<qos><callback type='IOR'>");
00080       xmlQos += orb->object_to_string(callback_impl);
00081       xmlQos += "</callback></qos>";
00082 
00083       serverIdl::Server_ptr xmlBlaster = authServer_obj->login("Ben", "secret", xmlQos.c_str());
00084       cout << "Successful login!" << endl;
00085 
00086 
00087       //-------------- publish() a message -------------
00088       string xmlKey("<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
00089                     "<key oid=''>\n"
00090                     "<AGENT id='192.168.124.10' subId='1' type='generic'>"
00091                     "<DRIVER id='FileProof' pollingFreq='10'>"
00092                     "</DRIVER>"
00093                     "</AGENT>"
00094                     "</key>");
00095 
00096       MessageUnit message;
00097       message.xmlKey = xmlKey.c_str();
00098       string content = "Hello xmlBlaster, i'm a C++ client";
00099       //??? message.content(MICO_ULong(content.size()), MICO_ULong(content.size()), (CORBA::Octet*)content.c_str());
00100       message.qos = "<qos></qos>";
00101 
00102       string publishOid = xmlBlaster->publish(message);
00103       cout << "Successful published message with new oid=" << publishOid << endl;
00104 
00105 
00106       //-------------- subscribe() to the previous message OID -------
00107       cout << "Subscribing using the exact oid ..." << endl;
00108       xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
00109                "<key oid='" + publishOid + "'>\n"
00110                "</key>";
00111       string qualityOfService = "";
00112       try {
00113          xmlBlaster->subscribe(xmlKey.c_str(), qualityOfService.c_str());
00114       } catch(XmlBlasterException e) {
00115          cerr << "XmlBlasterException: " << e.reason << endl;
00116       }
00117       cout << "Subscribed to '" << publishOid << "' ..." << endl;
00118 
00119 
00120       //-------------- wait for something to happen -------------------
00121       orb->run ();
00122 
00123    } catch(serverIdl::XmlBlasterException e) {
00124       cerr << "Caught Server Exception: " << e.reason << endl;
00125    } catch( ... ) {
00126       cerr << "Login to xmlBlaster failed" << endl;
00127    }
00128    return 0;
00129 }
00130