int CallbackClient::run(int argc, char* argv[]) { // // Since this is an interactive demo we want the custom interrupt // callback to be called when the process is interrupted. // callbackOnInterrupt(); CallbackSenderPrx twoway = CallbackSenderPrx::checkedCast( communicator()->propertyToProxy("Callback.CallbackServer")-> ice_twoway()->ice_timeout(-1)->ice_secure(false)); if(!twoway) { cerr << appName() << ": invalid proxy" << endl; return EXIT_FAILURE; } CallbackSenderPrx oneway = CallbackSenderPrx::uncheckedCast(twoway->ice_oneway()); CallbackSenderPrx batchOneway = CallbackSenderPrx::uncheckedCast(twoway->ice_batchOneway()); CallbackSenderPrx datagram = CallbackSenderPrx::uncheckedCast(twoway->ice_datagram()); CallbackSenderPrx batchDatagram = CallbackSenderPrx::uncheckedCast(twoway->ice_batchDatagram()); Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Callback.Client"); adapter->add(new CallbackReceiverI, communicator()->stringToIdentity("callbackReceiver")); adapter->activate(); CallbackReceiverPrx twowayR = CallbackReceiverPrx::uncheckedCast( adapter->createProxy(communicator()->stringToIdentity("callbackReceiver"))); CallbackReceiverPrx onewayR = CallbackReceiverPrx::uncheckedCast(twowayR->ice_oneway()); CallbackReceiverPrx datagramR = CallbackReceiverPrx::uncheckedCast(twowayR->ice_datagram()); bool secure = false; string secureStr = ""; menu(); char c; do { try { cout << "==> "; cin >> c; if(c == 't') { twoway->initiateCallback(twowayR); } else if(c == 'o') { oneway->initiateCallback(onewayR); } else if(c == 'O') { batchOneway->initiateCallback(onewayR); } else if(c == 'd') { if(secure) { cout << "secure datagrams are not supported" << endl; } else { datagram->initiateCallback(datagramR); } } else if(c == 'D') { if(secure) { cout << "secure datagrams are not supported" << endl; } else { batchDatagram->initiateCallback(datagramR); } } else if(c == 'f') { communicator()->flushBatchRequests(); } else if(c == 'S') { secure = !secure; secureStr = secure ? "s" : ""; twoway = CallbackSenderPrx::uncheckedCast(twoway->ice_secure(secure)); oneway = CallbackSenderPrx::uncheckedCast(oneway->ice_secure(secure)); batchOneway = CallbackSenderPrx::uncheckedCast(batchOneway->ice_secure(secure)); datagram = CallbackSenderPrx::uncheckedCast(datagram->ice_secure(secure)); batchDatagram = CallbackSenderPrx::uncheckedCast(batchDatagram->ice_secure(secure)); twowayR = CallbackReceiverPrx::uncheckedCast(twowayR->ice_secure(secure)); onewayR = CallbackReceiverPrx::uncheckedCast(onewayR->ice_secure(secure)); datagramR = CallbackReceiverPrx::uncheckedCast(datagramR->ice_secure(secure)); if(secure) { cout << "secure mode is now on" << endl; } else { cout << "secure mode is now off" << endl; } } else if(c == 's') { twoway->shutdown(); } 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 run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) { if(argc > 1) { fprintf(stderr, "%s: too many arguments\n", argv[0]); return EXIT_FAILURE; } Ice::PropertiesPtr properties = communicator->getProperties(); const char* proxyProperty = "CallbackSender.Proxy"; string proxy = properties->getProperty(proxyProperty); if(proxy.empty()) { fprintf(stderr, "%s: property `%s' not set\n", argv[0], proxyProperty); return EXIT_FAILURE; } Ice::ObjectPrx base = communicator->stringToProxy(proxy); CallbackSenderPrx twoway = CallbackSenderPrx::checkedCast(base->ice_twoway()->ice_timeout(-1)); if(!twoway) { fprintf(stderr, "%s: invalid proxy\n", argv[0]); return EXIT_FAILURE; } CallbackSenderPrx oneway = twoway->ice_oneway(); #ifdef ICEE_HAS_BATCH CallbackSenderPrx batchOneway = twoway->ice_batchOneway(); #endif Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("Callback.Client"); CallbackReceiverPtr cr = new CallbackReceiverI; adapter->add(cr, communicator->stringToIdentity("callbackReceiver")); adapter->activate(); CallbackReceiverPrx twowayR = CallbackReceiverPrx::uncheckedCast( adapter->createProxy(communicator->stringToIdentity("callbackReceiver"))); CallbackReceiverPrx onewayR = twowayR->ice_oneway(); menu(); char c = EOF; do { try { printf("==> "); fflush(stdout); do { c = getchar(); } while(c != EOF && c == '\n'); if(c == 't') { twoway->initiateCallback(twowayR); } else if(c == 'o') { oneway->initiateCallback(onewayR); } #ifdef ICEE_HAS_BATCH else if(c == 'O') { batchOneway->initiateCallback(onewayR); } else if(c == 'f') { batchOneway->ice_flushBatchRequests(); } #endif else if(c == 's') { twoway->shutdown(); } 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; }