#include #include #include using namespace std; using namespace Demo; class FCallBack : public AMI_DemoServer_g{ const AMD_DemoServer_fPtr cb_; public: FCallBack(const AMD_DemoServer_fPtr& cb) : cb_(cb) { } virtual void ice_response(int result) { cb_->ice_response(result); } virtual void ice_exception(const ::Ice::Exception& e) { cb_->ice_exception(e); } }; class DemoServerI : public DemoServer { private: DemoServerPrx other_; public: DemoServerI(const DemoServerPrx& other) : other_(other) {} virtual void f_async(const AMD_DemoServer_fPtr& cb, int val, const Ice::Current&) { cout << "fasync" << endl; try { AMI_DemoServer_gPtr fcb = new FCallBack(cb); other_->g_async(fcb, val); } catch (const Ice::Exception& e) { cb->ice_exception(e); } } virtual void g_async(const AMD_DemoServer_gPtr& cb, int val, const Ice::Current&) { cout << " gasync" << endl; cb->ice_response(val+1); } }; class App: public Ice::Application { int run(int argc, char* argv[]) { shutdownOnInterrupt(); Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints("OA", "tcp -p 2345"); Ice::ObjectPrx prx = communicator()->stringToProxy("server0:tcp -p 2345"); DemoServerPrx demo = DemoServerPrx::uncheckedCast(prx->ice_collocationOptimized(false)); Ice::ObjectPtr srv = new DemoServerI(demo); demo = DemoServerPrx::uncheckedCast(prx->ice_collocationOptimized(false)); adapter->add(srv, communicator()->stringToIdentity("server0")); adapter->activate(); demo->f(0); // why is this needed? communicator()->waitForShutdown(); return 0; } }; int main(int argc, char* argv[]) { App app; return app.main(argc,argv); }