diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2009-11-26 14:18:59 -0330 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2009-11-26 14:18:59 -0330 |
commit | eb9894afe8da3a9ef6a7da0ca27e0a6b32676b0c (patch) | |
tree | b0abd1a4d60e7842b1b74ac8c9bbb02797db8a8b /cpp/demo/Ice/invoke/Client.cpp | |
parent | Removed getCookie from C# AsyncResult (diff) | |
download | ice-eb9894afe8da3a9ef6a7da0ca27e0a6b32676b0c.tar.bz2 ice-eb9894afe8da3a9ef6a7da0ca27e0a6b32676b0c.tar.xz ice-eb9894afe8da3a9ef6a7da0ca27e0a6b32676b0c.zip |
Added invoke test
Cleaned up invoke demo
Fixed order of paramaters in end_ice_invoke in C++
Diffstat (limited to 'cpp/demo/Ice/invoke/Client.cpp')
-rw-r--r-- | cpp/demo/Ice/invoke/Client.cpp | 267 |
1 files changed, 45 insertions, 222 deletions
diff --git a/cpp/demo/Ice/invoke/Client.cpp b/cpp/demo/Ice/invoke/Client.cpp index 4226899e60a..c13d94b57d0 100644 --- a/cpp/demo/Ice/invoke/Client.cpp +++ b/cpp/demo/Ice/invoke/Client.cpp @@ -31,106 +31,6 @@ operator<<(ostream& out, Demo::Color c) return out; } -class AMI_Object_ice_invokeI : public Ice::AMI_Object_ice_invoke -{ -public: - - virtual void - ice_response(bool result, const Ice::ByteSeq& outParams) - { - if(!result) - { - cout << "Unknown user exception" << endl; - } - } - - virtual void - ice_exception(const Ice::Exception& ex) - { - cout << ex << endl; - } -}; - -class AMI_Object_ice_invokeGetValuesI : public Ice::AMI_Object_ice_invoke -{ -public: - - AMI_Object_ice_invokeGetValuesI(const Ice::CommunicatorPtr& communicator) : - _communicator(communicator) - { - } - - virtual void - ice_response(bool result, const Ice::ByteSeq& outParams) - { - if(!result) - { - cout << "Unknown user exception" << endl; - } - else - { - // - // Unmarshal the results. - // - Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); - Demo::CPtr c; - in->read(c); - string str = in->readString(); - in->readPendingObjects(); - cout << "Got string `" << str << "' and class: s.name=" << c->s.name - << ", s.value=" << c->s.value << endl; - } - } - - virtual void - ice_exception(const Ice::Exception& ex) - { - cout << ex << endl; - } - -private: - - Ice::CommunicatorPtr _communicator; -}; - -class AMI_Object_ice_invokeThrowPrintFailureI : public Ice::AMI_Object_ice_invoke -{ -public: - - AMI_Object_ice_invokeThrowPrintFailureI(const Ice::CommunicatorPtr& communicator) : - _communicator(communicator) - { - } - - virtual void - ice_response(bool result, const Ice::ByteSeq& outParams) - { - Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); - try - { - in->throwException(); - } - catch(const Demo::PrintFailure&) - { - // Expected. - } - catch(const Ice::UserException&) - { - cout << "Unknown user exception" << endl; - } - } - - virtual void - ice_exception(const Ice::Exception& ex) - { - cout << ex << endl; - } - -private: - - Ice::CommunicatorPtr _communicator; -}; - class InvokeClient : public Ice::Application { public: @@ -163,14 +63,9 @@ InvokeClient::InvokeClient() : int InvokeClient::run(int argc, char* argv[]) { - bool async = false; - if(argc == 2 && strcmp(argv[1], "--async") == 0) - { - async = true; - } - else if(argc > 1) + if(argc > 1) { - cerr << "Usage: " << appName() << " [--async]" << endl; + cerr << appName() << ": too many arguments" << endl; return EXIT_FAILURE; } @@ -198,16 +93,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) - { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printString", Ice::Normal, inParams); - } - else + if(!obj->ice_invoke("printString", Ice::Normal, inParams, outParams)) { - if(!obj->ice_invoke("printString", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '2') @@ -228,16 +116,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) + if(!obj->ice_invoke("printStringSequence", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printStringSequence", Ice::Normal, inParams); - } - else - { - if(!obj->ice_invoke("printStringSequence", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '3') @@ -256,16 +137,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) + if(!obj->ice_invoke("printDictionary", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printDictionary", Ice::Normal, inParams); - } - else - { - if(!obj->ice_invoke("printDictionary", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '4') @@ -281,16 +155,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) - { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printEnum", Ice::Normal, inParams); - } - else + if(!obj->ice_invoke("printEnum", Ice::Normal, inParams, outParams)) { - if(!obj->ice_invoke("printEnum", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '5') @@ -309,16 +176,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) - { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printStruct", Ice::Normal, inParams); - } - else + if(!obj->ice_invoke("printStruct", Ice::Normal, inParams, outParams)) { - if(!obj->ice_invoke("printStruct", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '6') @@ -344,16 +204,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) + if(!obj->ice_invoke("printStructSequence", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printStructSequence", Ice::Normal, inParams); - } - else - { - if(!obj->ice_invoke("printStructSequence", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '7') @@ -373,16 +226,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) + if(!obj->ice_invoke("printClass", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printClass", Ice::Normal, inParams); - } - else - { - if(!obj->ice_invoke("printClass", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '8') @@ -391,30 +237,22 @@ InvokeClient::run(int argc, char* argv[]) // Invoke operation. // Ice::ByteSeq inParams, outParams; - if(async) + if(!obj->ice_invoke("getValues", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeGetValuesI(communicator()), "getValues", - Ice::Normal, inParams); + cout << "Unknown user exception" << endl; + continue; } - else - { - if(!obj->ice_invoke("getValues", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - continue; - } - // - // Unmarshal the results. - // - Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams); - Demo::CPtr c; - in->read(c); - string str = in->readString(); - in->readPendingObjects(); - cout << "Got string `" << str << "' and class: s.name=" << c->s.name - << ", s.value=" << c->s.value << endl; - } + // + // Unmarshal the results. + // + Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams); + Demo::CPtr c; + in->read(c); + string str = in->readString(); + in->readPendingObjects(); + cout << "Got string `" << str << "' and class: s.name=" << c->s.name + << ", s.value=" << c->s.value << endl; } else if(ch == '9') { @@ -422,46 +260,31 @@ InvokeClient::run(int argc, char* argv[]) // Invoke operation. // Ice::ByteSeq inParams, outParams; - if(async) + if(obj->ice_invoke("throwPrintFailure", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeThrowPrintFailureI(communicator()), - "throwPrintFailure", Ice::Normal, inParams); + cout << "Expected exception" << endl; + continue; } - else - { - if(obj->ice_invoke("throwPrintFailure", Ice::Normal, inParams, outParams)) - { - cout << "Expected exception" << endl; - continue; - } - Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams); - try - { - in->throwException(); - } - catch(const Demo::PrintFailure&) - { - // Expected. - } - catch(const Ice::UserException&) - { - cout << "Unknown user exception" << endl; - } + Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams); + try + { + in->throwException(); } - } - else if(ch == 's') - { - Ice::ByteSeq inParams, outParams; - if(async) + catch(const Demo::PrintFailure&) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "shutdown", Ice::Normal, inParams); + // Expected. } - else + catch(const Ice::UserException&) { - obj->ice_invoke("shutdown", Ice::Normal, inParams, outParams); + cout << "Unknown user exception" << endl; } } + else if(ch == 's') + { + Ice::ByteSeq inParams, outParams; + obj->ice_invoke("shutdown", Ice::Normal, inParams, outParams); + } else if(ch == 'x') { // Nothing to do. |