diff options
Diffstat (limited to 'cpp/test/Ice/dispatcher/Collocated.cpp')
-rw-r--r-- | cpp/test/Ice/dispatcher/Collocated.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/cpp/test/Ice/dispatcher/Collocated.cpp b/cpp/test/Ice/dispatcher/Collocated.cpp index 93c0f04908d..59eb3490b94 100644 --- a/cpp/test/Ice/dispatcher/Collocated.cpp +++ b/cpp/test/Ice/dispatcher/Collocated.cpp @@ -19,16 +19,16 @@ using namespace std; int run(int, char**, const Ice::CommunicatorPtr& communicator) { - communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default -p 12010"); - communicator->getProperties()->setProperty("ControllerAdapter.Endpoints", "tcp -p 12011"); + communicator->getProperties()->setProperty("TestAdapter.Endpoints", getTestEndpoint(communicator, 0)); + communicator->getProperties()->setProperty("ControllerAdapter.Endpoints", getTestEndpoint(communicator, 1, "tcp")); communicator->getProperties()->setProperty("ControllerAdapter.ThreadPool.Size", "1"); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); Ice::ObjectAdapterPtr adapter2 = communicator->createObjectAdapter("ControllerAdapter"); - TestIntfControllerIPtr testController = new TestIntfControllerI(adapter); + TestIntfControllerIPtr testController = ICE_MAKE_SHARED(TestIntfControllerI, adapter); - adapter->add(new TestIntfI(), communicator->stringToIdentity("test")); + adapter->add(ICE_MAKE_SHARED(TestIntfI), communicator->stringToIdentity("test")); //adapter->activate(); // Don't activate OA to ensure collocation is used. adapter2->add(testController, communicator->stringToIdentity("testController")); @@ -39,6 +39,27 @@ run(int, char**, const Ice::CommunicatorPtr& communicator) return EXIT_SUCCESS; } +#ifdef ICE_CPP11_MAPPING +class DispatcherCall : public Ice::DispatcherCall +{ +public: + + DispatcherCall(function<void ()> call) : + _call(move(call)) + { + } + + virtual void run() + { + _call(); + } + +private: + + function<void ()> _call; +}; +#endif + int main(int argc, char* argv[]) { @@ -46,43 +67,27 @@ main(int argc, char* argv[]) Ice::registerIceSSL(); #endif int status; - Ice::CommunicatorPtr communicator; - try { Ice::InitializationData initData; initData.properties = Ice::createProperties(argc, argv); -#ifdef ICE_CPP11 +#ifdef ICE_CPP11_MAPPING Ice::DispatcherPtr dispatcher = new Dispatcher(); - initData.dispatcher = Ice::newDispatcher( - [=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn) - { - dispatcher->dispatch(call, conn); - }); + initData.dispatcher = [=](function<void ()> call, const shared_ptr<Ice::Connection>& conn) + { + dispatcher->dispatch(new DispatcherCall(call), conn); + }; #else initData.dispatcher = new Dispatcher(); #endif - communicator = Ice::initialize(argc, argv, initData); - status = run(argc, argv, communicator); + Ice::CommunicatorHolder ich = Ice::initialize(argc, argv, initData); + status = run(argc, argv, ich.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; - } - } Dispatcher::terminate(); return status; } |