// ********************************************************************** // // Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. // // This copy of Ice-E is licensed to you under the terms described in the // ICEE_LICENSE file included in this distribution. // // ********************************************************************** #include #include using namespace std; using namespace Demo; void menu() { printf("usage:\nh: say hello\nx: 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()) { fprintf(stderr, "%s: property `%s' not set\n", argv[0], proxyProperty); return EXIT_FAILURE; } HelloPrx hello = HelloPrx::checkedCast(communicator->stringToProxy(proxy)); if(!hello) { fprintf(stderr, "%s: invalid proxy\n", argv[0]); return EXIT_FAILURE; } menu(); char c = EOF; do { try { printf("==> "); do { c = getchar(); } while(c != EOF && c == '\n'); if(c == 'h') { hello->sayHello(); } else if(c == 'x') { // Nothing to do } else if(c == '?') { menu(); } else { printf("unknown command `%c'\n", c); menu(); } } catch(const Ice::Exception& ex) { fprintf(stderr, "%s\n", ex.toString().c_str()); } } while(c != EOF && c != 'x'); return EXIT_SUCCESS; } int main(int argc, char* argv[]) { int status; Ice::CommunicatorPtr communicator; try { Ice::InitializationData initData; initData.properties = Ice::createProperties(); initData.properties->load("config"); communicator = Ice::initialize(argc, argv, initData); status = run(argc, argv, communicator); } catch(const Ice::Exception& ex) { fprintf(stderr, "%s\n", ex.toString().c_str()); status = EXIT_FAILURE; } if(communicator) { try { communicator->destroy(); } catch(const Ice::Exception& ex) { fprintf(stderr, "%s\n", ex.toString().c_str()); status = EXIT_FAILURE; } } return status; }