diff options
Diffstat (limited to 'cpp/demo/Ice/minimal/Client.cpp')
-rw-r--r-- | cpp/demo/Ice/minimal/Client.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/cpp/demo/Ice/minimal/Client.cpp b/cpp/demo/Ice/minimal/Client.cpp new file mode 100644 index 00000000000..6f2e4a966d9 --- /dev/null +++ b/cpp/demo/Ice/minimal/Client.cpp @@ -0,0 +1,116 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <Hello.h> + +using namespace std; +using namespace Demo; + +void +menu() +{ + cout << + "usage:\n" + "h: send greeting as twoway\n" + "x: exit\n" + "?: help\n"; +} + +int +run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) +{ + Ice::PropertiesPtr properties = communicator->getProperties(); + const char* proxyProperty = "Hello.Proxy"; + string proxy = properties->getProperty(proxyProperty); + if(proxy.empty()) + { + cerr << argv[0] << ": property `" << proxyProperty << "' not set" << endl; + return EXIT_FAILURE; + } + + Ice::ObjectPrx base = communicator->stringToProxy(proxy); + HelloPrx hello = HelloPrx::checkedCast(base->ice_twoway()->ice_timeout(-1)->ice_secure(false)); + if(!hello) + { + cerr << argv[0] << ": invalid proxy" << endl; + return EXIT_FAILURE; + } + + menu(); + + char c; + do + { + try + { + cout << "==> "; + cin >> c; + if(c == 'h') + { + hello->sayHello(); + } + else if(c == 'x') + { + // Nothing to do + } + else if(c == '?') + { + menu(); + } + else + { + cout << "unknown command `" << c << "'" << endl; + menu(); + } + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + } + } + while(cin.good() && c != 'x'); + + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + Ice::CommunicatorPtr communicator; + + try + { + Ice::PropertiesPtr properties = Ice::createProperties(); + properties->load("config"); + communicator = Ice::initializeWithProperties(argc, argv, properties); + status = run(argc, argv, communicator); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if(communicator) + { + try + { + communicator->destroy(); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} |