summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/invoke/Client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/demo/Ice/invoke/Client.cpp')
-rw-r--r--cpp/demo/Ice/invoke/Client.cpp304
1 files changed, 241 insertions, 63 deletions
diff --git a/cpp/demo/Ice/invoke/Client.cpp b/cpp/demo/Ice/invoke/Client.cpp
index 731f44ab2a1..ad92664a007 100644
--- a/cpp/demo/Ice/invoke/Client.cpp
+++ b/cpp/demo/Ice/invoke/Client.cpp
@@ -13,6 +13,124 @@
using namespace std;
using namespace Demo;
+static ostream&
+operator<<(ostream& out, Demo::Color c)
+{
+ switch(c)
+ {
+ case Demo::red:
+ out << "red";
+ break;
+ case Demo::green:
+ out << "green";
+ break;
+ case Demo::blue:
+ out << "blue";
+ break;
+ }
+ 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;
+ Demo::ice_readC(in, 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:
@@ -22,6 +140,7 @@ public:
private:
+ void usage(const string&);
void menu();
};
@@ -32,24 +151,6 @@ main(int argc, char* argv[])
return app.main(argc, argv, "config.client");
}
-static ostream&
-operator<<(ostream& out, Demo::Color c)
-{
- switch(c)
- {
- case Demo::red:
- out << "red";
- break;
- case Demo::green:
- out << "green";
- break;
- case Demo::blue:
- out << "blue";
- break;
- }
- return out;
-}
-
InvokeClient::InvokeClient() :
//
// Since this is an interactive demo we don't want any signal
@@ -62,9 +163,14 @@ InvokeClient::InvokeClient() :
int
InvokeClient::run(int argc, char* argv[])
{
- if(argc > 1)
+ bool async = false;
+ if(argc == 2 && strcmp(argv[1], "--async") == 0)
{
- cerr << appName() << ": too many arguments" << endl;
+ async = true;
+ }
+ else if(argc > 1)
+ {
+ cerr << "Usage: " << appName() << " [--async]" << endl;
return EXIT_FAILURE;
}
@@ -92,9 +198,16 @@ InvokeClient::run(int argc, char* argv[])
//
// Invoke operation.
//
- if(!obj->ice_invoke("printString", Ice::Normal, inParams, outParams))
+ if(async)
+ {
+ obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printString", Ice::Normal, inParams);
+ }
+ else
{
- cout << "Unknown user exception" << endl;
+ if(!obj->ice_invoke("printString", Ice::Normal, inParams, outParams))
+ {
+ cout << "Unknown user exception" << endl;
+ }
}
}
else if(ch == '2')
@@ -115,9 +228,16 @@ InvokeClient::run(int argc, char* argv[])
//
// Invoke operation.
//
- if(!obj->ice_invoke("printStringSequence", Ice::Normal, inParams, outParams))
+ if(async)
{
- cout << "Unknown user exception" << endl;
+ 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;
+ }
}
}
else if(ch == '3')
@@ -136,9 +256,16 @@ InvokeClient::run(int argc, char* argv[])
//
// Invoke operation.
//
- if(!obj->ice_invoke("printDictionary", Ice::Normal, inParams, outParams))
+ if(async)
+ {
+ obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printDictionary", Ice::Normal, inParams);
+ }
+ else
{
- cout << "Unknown user exception" << endl;
+ if(!obj->ice_invoke("printDictionary", Ice::Normal, inParams, outParams))
+ {
+ cout << "Unknown user exception" << endl;
+ }
}
}
else if(ch == '4')
@@ -154,9 +281,16 @@ InvokeClient::run(int argc, char* argv[])
//
// Invoke operation.
//
- if(!obj->ice_invoke("printEnum", Ice::Normal, inParams, outParams))
+ if(async)
{
- cout << "Unknown user exception" << endl;
+ obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printEnum", Ice::Normal, inParams);
+ }
+ else
+ {
+ if(!obj->ice_invoke("printEnum", Ice::Normal, inParams, outParams))
+ {
+ cout << "Unknown user exception" << endl;
+ }
}
}
else if(ch == '5')
@@ -175,9 +309,16 @@ InvokeClient::run(int argc, char* argv[])
//
// Invoke operation.
//
- if(!obj->ice_invoke("printStruct", Ice::Normal, inParams, outParams))
+ if(async)
+ {
+ obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printStruct", Ice::Normal, inParams);
+ }
+ else
{
- cout << "Unknown user exception" << endl;
+ if(!obj->ice_invoke("printStruct", Ice::Normal, inParams, outParams))
+ {
+ cout << "Unknown user exception" << endl;
+ }
}
}
else if(ch == '6')
@@ -203,9 +344,16 @@ InvokeClient::run(int argc, char* argv[])
//
// Invoke operation.
//
- if(!obj->ice_invoke("printStructSequence", Ice::Normal, inParams, outParams))
+ if(async)
{
- cout << "Unknown user exception" << endl;
+ 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;
+ }
}
}
else if(ch == '7')
@@ -225,9 +373,16 @@ InvokeClient::run(int argc, char* argv[])
//
// Invoke operation.
//
- if(!obj->ice_invoke("printClass", Ice::Normal, inParams, outParams))
+ if(async)
+ {
+ obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printClass", Ice::Normal, inParams);
+ }
+ else
{
- cout << "Unknown user exception" << endl;
+ if(!obj->ice_invoke("printClass", Ice::Normal, inParams, outParams))
+ {
+ cout << "Unknown user exception" << endl;
+ }
}
}
else if(ch == '8')
@@ -236,22 +391,30 @@ InvokeClient::run(int argc, char* argv[])
// Invoke operation.
//
Ice::ByteSeq inParams, outParams;
- if(!obj->ice_invoke("getValues", Ice::Normal, inParams, outParams))
+ if(async)
{
- cout << "Unknown user exception" << endl;
- continue;
+ obj->ice_invoke_async(new AMI_Object_ice_invokeGetValuesI(communicator()), "getValues",
+ Ice::Normal, inParams);
}
+ 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;
- Demo::ice_readC(in, 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;
+ Demo::ice_readC(in, 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')
{
@@ -259,30 +422,45 @@ InvokeClient::run(int argc, char* argv[])
// Invoke operation.
//
Ice::ByteSeq inParams, outParams;
- if(obj->ice_invoke("throwPrintFailure", Ice::Normal, inParams, outParams))
- {
- cout << "Expected exception" << endl;
- continue;
- }
-
- Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams);
- try
+ if(async)
{
- in->throwException();
+ obj->ice_invoke_async(new AMI_Object_ice_invokeThrowPrintFailureI(communicator()),
+ "throwPrintFailure", Ice::Normal, inParams);
}
- catch(const Demo::PrintFailure&)
+ else
{
- // Expected.
- }
- catch(const Ice::UserException&)
- {
- cout << "Unknown user exception" << endl;
+ 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;
+ }
}
}
else if(ch == 's')
{
Ice::ByteSeq inParams, outParams;
- obj->ice_invoke("shutdown", Ice::Normal, inParams, outParams);
+ if(async)
+ {
+ obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "shutdown", Ice::Normal, inParams);
+ }
+ else
+ {
+ obj->ice_invoke("shutdown", Ice::Normal, inParams, outParams);
+ }
}
else if(ch == 'x')
{