From 759f7f34281a2c3d406ce93e52e63272a9d4beba Mon Sep 17 00:00:00 2001 From: Matthew Newhook Date: Mon, 12 Sep 2005 02:46:32 +0000 Subject: http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=335 --- cpp/demo/Ice/minimal/Client.cpp | 116 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 cpp/demo/Ice/minimal/Client.cpp (limited to 'cpp/demo/Ice/minimal/Client.cpp') 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 +#include + +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; +} -- cgit v1.2.3