diff options
Diffstat (limited to 'cpp/test/Ice/dispatcher')
-rw-r--r-- | cpp/test/Ice/dispatcher/Client.cpp | 25 | ||||
-rw-r--r-- | cpp/test/Ice/dispatcher/Collocated.cpp | 25 | ||||
-rw-r--r-- | cpp/test/Ice/dispatcher/Dispatcher.cpp | 11 | ||||
-rw-r--r-- | cpp/test/Ice/dispatcher/Dispatcher.h | 39 | ||||
-rw-r--r-- | cpp/test/Ice/dispatcher/Server.cpp | 25 |
5 files changed, 53 insertions, 72 deletions
diff --git a/cpp/test/Ice/dispatcher/Client.cpp b/cpp/test/Ice/dispatcher/Client.cpp index b94e3199616..6440ce065f3 100644 --- a/cpp/test/Ice/dispatcher/Client.cpp +++ b/cpp/test/Ice/dispatcher/Client.cpp @@ -24,27 +24,6 @@ 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[]) { @@ -64,10 +43,10 @@ main(int argc, char* argv[]) initData.properties->setProperty("Ice.TCP.SndSize", "50000"); #ifdef ICE_CPP11_MAPPING - Ice::DispatcherPtr dispatcher = new Dispatcher(); + IceUtil::Handle<Dispatcher> dispatcher = new Dispatcher; initData.dispatcher = [=](function<void()> call, const shared_ptr<Ice::Connection>& conn) { - dispatcher->dispatch(new DispatcherCall(call), conn); + dispatcher->dispatch(make_shared<DispatcherCall>(call), conn); }; #else initData.dispatcher = new Dispatcher(); diff --git a/cpp/test/Ice/dispatcher/Collocated.cpp b/cpp/test/Ice/dispatcher/Collocated.cpp index a83ee20a446..b08e2440643 100644 --- a/cpp/test/Ice/dispatcher/Collocated.cpp +++ b/cpp/test/Ice/dispatcher/Collocated.cpp @@ -39,27 +39,6 @@ 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[]) { @@ -72,10 +51,10 @@ main(int argc, char* argv[]) Ice::InitializationData initData; initData.properties = Ice::createProperties(argc, argv); #ifdef ICE_CPP11_MAPPING - Ice::DispatcherPtr dispatcher = new Dispatcher(); + IceUtil::Handle<Dispatcher> dispatcher = new Dispatcher; initData.dispatcher = [=](function<void()> call, const shared_ptr<Ice::Connection>& conn) { - dispatcher->dispatch(new DispatcherCall(call), conn); + dispatcher->dispatch(make_shared<DispatcherCall>(call), conn); }; #else initData.dispatcher = new Dispatcher(); diff --git a/cpp/test/Ice/dispatcher/Dispatcher.cpp b/cpp/test/Ice/dispatcher/Dispatcher.cpp index bbf991b0f65..8fb96f06e1b 100644 --- a/cpp/test/Ice/dispatcher/Dispatcher.cpp +++ b/cpp/test/Ice/dispatcher/Dispatcher.cpp @@ -42,9 +42,13 @@ Dispatcher::isDispatcherThread() return IceUtil::ThreadControl() == _instance->getThreadControl(); } +#ifdef ICE_CPP11_MAPPING +void +Dispatcher::dispatch(const shared_ptr<DispatcherCall>& call, const shared_ptr<Ice::Connection>&) +#else void Dispatcher::dispatch(const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr&) - +#endif { Lock sync(*this); _calls.push_back(call); @@ -59,7 +63,11 @@ Dispatcher::run() { while(true) { +#ifdef ICE_CPP11_MAPPING + shared_ptr<DispatcherCall> call; +#else Ice::DispatcherCallPtr call; +#endif { Lock sync(*this); @@ -95,3 +103,4 @@ Dispatcher::run() } } } + diff --git a/cpp/test/Ice/dispatcher/Dispatcher.h b/cpp/test/Ice/dispatcher/Dispatcher.h index 40236236356..b61b64f1dc3 100644 --- a/cpp/test/Ice/dispatcher/Dispatcher.h +++ b/cpp/test/Ice/dispatcher/Dispatcher.h @@ -14,17 +14,48 @@ #include <IceUtil/Monitor.h> #include <IceUtil/Mutex.h> #include <Ice/Dispatcher.h> +#include <Ice/Connection.h> #include <deque> -class Dispatcher : public Ice::Dispatcher, IceUtil::Thread, IceUtil::Monitor<IceUtil::Mutex> +#ifdef ICE_CPP11_MAPPING +class DispatcherCall +{ +public: + + DispatcherCall(std::function<void()> call) : + _call(std::move(call)) + { + } + + void run() + { + _call(); + } + +private: + + std::function<void()> _call; +}; +#endif + +class Dispatcher : +#ifndef ICE_CPP11_MAPPING + public Ice::Dispatcher, +#endif +public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex> { public: Dispatcher(); + +#ifdef ICE_CPP11_MAPPING + void dispatch(const std::shared_ptr<DispatcherCall>&, const std::shared_ptr<Ice::Connection>&); +#else virtual void dispatch(const Ice::DispatcherCallPtr&, const Ice::ConnectionPtr&); +#endif + - void run(); static void terminate(); static bool isDispatcherThread(); @@ -32,7 +63,11 @@ public: private: static Dispatcher* _instance; +#ifdef ICE_CPP11_MAPPING + std::deque<std::shared_ptr<DispatcherCall>> _calls; +#else std::deque<Ice::DispatcherCallPtr> _calls; +#endif bool _terminated; }; diff --git a/cpp/test/Ice/dispatcher/Server.cpp b/cpp/test/Ice/dispatcher/Server.cpp index 585bce0c16c..bdc490dd4eb 100644 --- a/cpp/test/Ice/dispatcher/Server.cpp +++ b/cpp/test/Ice/dispatcher/Server.cpp @@ -40,27 +40,6 @@ 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[]) { @@ -80,10 +59,10 @@ main(int argc, char* argv[]) initData.properties->setProperty("Ice.TCP.RcvSize", "50000"); #ifdef ICE_CPP11_MAPPING - Ice::DispatcherPtr dispatcher = new Dispatcher(); + IceUtil::Handle<Dispatcher> dispatcher = new Dispatcher; initData.dispatcher = [=](function<void()> call, const shared_ptr<Ice::Connection>& conn) { - dispatcher->dispatch(new DispatcherCall(call), conn); + dispatcher->dispatch(make_shared<DispatcherCall>(call), conn); }; #else initData.dispatcher = new Dispatcher(); |