00001 #define MICO_CONF_IMR 00002 #include <CORBA-SMALL.h> 00003 #include "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 msgUnit; // 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 { 00057 cout << "Enter IOR from AuthServer-Server: "; 00058 cin >> objref_str; 00059 } 00060 00061 // narrow IOR-String to object reference 00062 authServer_obj= AuthServer::_narrow(orb->string_to_object(objref_str)); 00063 00064 00065 //--------------- create my BlasterCallback server ---- 00066 clientIdl::BlasterCallback_impl *callback_impl; 00067 boa= orb->BOA_init(argc, argv, "mico-local-boa"); 00068 callback_impl = new clientIdl::BlasterCallback_impl(); 00069 // cout << "\t" << orb->object_to_string(callback_impl) << endl; 00070 boa->impl_is_ready (CORBA::ImplementationDef::_nil()); 00071 00072 00073 00074 //-------------- login() to AuthServer_obj --------- 00075 serverIdl::Server_ptr xmlBlaster = authServer_obj->login("Ben", "secret", callback_impl, ""); 00076 cout << "Successful login!" << endl; 00077 00078 00079 //-------------- publish() a message ------------- 00080 string xmlKey("<key oid='' contentMime='text/plain'>\n" 00081 " <AGENT id='192.168.124.10' subId='1' type='generic'>" 00082 " <DRIVER id='FileProof' pollingFreq='10'>" 00083 " </DRIVER>" 00084 " </AGENT>" 00085 "</key>"); 00086 00087 MessageUnit message; 00088 message.xmlKey = xmlKey.c_str(); 00089 string content = "Hello xmlBlaster, i'm a C++ client"; 00090 //??? message.content(MICO_ULong(content.size()), MICO_ULong(content.size()), (CORBA::Octet*)content.c_str()); 00091 00092 string publishOid = xmlBlaster->publish(message, ""); 00093 cout << "Successful published message with new oid=" << publishOid << endl; 00094 00095 00096 //-------------- subscribe() to the previous message OID ------- 00097 cout << "Subscribing using the exact oid ..." << endl; 00098 xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" 00099 "<key oid='" + publishOid + "'>\n" 00100 "</key>"; 00101 string qualityOfService = ""; 00102 try { 00103 xmlBlaster->subscribe(xmlKey.c_str(), qualityOfService.c_str()); 00104 } catch(XmlBlasterException e) { 00105 cerr << "XmlBlasterException: " << e.reason << endl; 00106 } 00107 cout << "Subscribed to '" << publishOid << "' ..." << endl; 00108 00109 00110 //-------------- wait for something to happen ------------------- 00111 orb->run (); 00112 00113 } catch(serverIdl::XmlBlasterException e) { 00114 cerr << "Caught Server Exception: " << e.reason << endl; 00115 } catch( ... ) { 00116 cerr << "Login to xmlBlaster failed" << endl; 00117 } 00118 return 0; 00119 } 00120