summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2015-12-15 18:35:14 +0100
committerJose <jose@zeroc.com>2015-12-15 18:35:14 +0100
commitde0939c485861ad124f64e213883c74571eefa2b (patch)
treec6dc163ddcee5aa0d878eb2463b57fc6a32a5f47 /cpp
parentRemoved iOS workaround from udp test (diff)
downloadice-de0939c485861ad124f64e213883c74571eefa2b.tar.bz2
ice-de0939c485861ad124f64e213883c74571eefa2b.tar.xz
ice-de0939c485861ad124f64e213883c74571eefa2b.zip
C++11 mapping: fixes to InitializationData
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Ice/Initialize.h13
-rw-r--r--cpp/src/Ice/BasicStream.cpp8
-rw-r--r--cpp/src/Ice/BatchRequestQueue.cpp4
-rw-r--r--cpp/src/Ice/BatchRequestQueue.h4
-rw-r--r--cpp/src/Ice/Initialize.cpp18
-rw-r--r--cpp/src/Ice/Instance.cpp9
-rw-r--r--cpp/src/Ice/Instance.h4
-rw-r--r--cpp/src/Ice/ThreadPool.cpp24
-rw-r--r--cpp/src/Ice/ThreadPool.h4
-rw-r--r--cpp/test/Ice/dispatcher/AllTests.cpp131
-rw-r--r--cpp/test/Ice/dispatcher/Client.cpp48
-rw-r--r--cpp/test/Ice/dispatcher/Collocated.cpp52
-rw-r--r--cpp/test/Ice/dispatcher/Dispatcher.cpp25
-rw-r--r--cpp/test/Ice/dispatcher/Dispatcher.h6
-rw-r--r--cpp/test/Ice/dispatcher/Server.cpp53
-rw-r--r--cpp/test/Ice/dispatcher/TestI.cpp4
-rw-r--r--cpp/test/Ice/dispatcher/TestI.h6
-rw-r--r--cpp/test/Ice/operations/BatchOneways.cpp8
18 files changed, 336 insertions, 85 deletions
diff --git a/cpp/include/Ice/Initialize.h b/cpp/include/Ice/Initialize.h
index ff80bed9582..9a026e2d42b 100644
--- a/cpp/include/Ice/Initialize.h
+++ b/cpp/include/Ice/Initialize.h
@@ -69,8 +69,11 @@ class ICE_API ThreadHookPlugin : public Ice::Plugin
{
public:
+#ifdef ICE_CPP11_MAPPING
+ ThreadHookPlugin(const CommunicatorPtr& communicator, std::function<void()>, std::function<void()>);
+#else
ThreadHookPlugin(const CommunicatorPtr& communicator, const ThreadNotificationPtr&);
-
+#endif
virtual void initialize();
virtual void destroy();
@@ -84,10 +87,18 @@ struct InitializationData
PropertiesPtr properties;
LoggerPtr logger;
Instrumentation::CommunicatorObserverPtr observer;
+#ifdef ICE_CPP11_MAPPING
+ std::function<void()> threadStart;
+ std::function<void()> threadStop;
+ std::function<void (std::function<void ()>, const std::shared_ptr<Ice::Connection>&)> dispatcher;
+ std::function<std::string (int)> compactIdResolver;
+ std::function<void(const Ice::BatchRequest&, int, int)> batchRequestInterceptor;
+#else
ThreadNotificationPtr threadHook;
DispatcherPtr dispatcher;
CompactIdResolverPtr compactIdResolver;
BatchRequestInterceptorPtr batchRequestInterceptor;
+#endif
};
ICE_API CommunicatorPtr initialize(int&, char*[], const InitializationData& = InitializationData(),
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp
index 7dabb6cd7e4..4e3de10edc8 100644
--- a/cpp/src/Ice/BasicStream.cpp
+++ b/cpp/src/Ice/BasicStream.cpp
@@ -2805,7 +2805,11 @@ IceInternal::BasicStream::EncapsDecoder11::readInstance(Int index, PatchFunc pat
startSlice();
const string mostDerivedId = _current->typeId;
Ice::ValuePtr v;
+#ifdef ICE_CPP11_MAPPING
+ function<string (int)> compactIdResolver = _stream->instance()->initializationData().compactIdResolver;
+#else
const CompactIdResolverPtr& compactIdResolver = _stream->instance()->initializationData().compactIdResolver;
+#endif
while(true)
{
if(_current->compactId >= 0)
@@ -2818,7 +2822,11 @@ IceInternal::BasicStream::EncapsDecoder11::readInstance(Int index, PatchFunc pat
{
try
{
+#ifdef ICE_CPP11_MAPPING
+ _current->typeId = compactIdResolver(_current->compactId);
+#else
_current->typeId = compactIdResolver->resolve(_current->compactId);
+#endif
}
catch(const LocalException&)
{
diff --git a/cpp/src/Ice/BatchRequestQueue.cpp b/cpp/src/Ice/BatchRequestQueue.cpp
index 04bee6e06d5..4f1c39c234f 100644
--- a/cpp/src/Ice/BatchRequestQueue.cpp
+++ b/cpp/src/Ice/BatchRequestQueue.cpp
@@ -127,7 +127,11 @@ BatchRequestQueue::finishBatchRequest(BasicStream* os, const Ice::ObjectPrxPtr&
if(_interceptor)
{
BatchRequestI request(*this, proxy, operation, static_cast<int>(_batchStream.b.size() - _batchMarker));
+#ifdef ICE_CPP11_MAPPING
+ _interceptor(request, _batchRequestNum, static_cast<int>(_batchMarker));
+#else
_interceptor->enqueue(request, _batchRequestNum, static_cast<int>(_batchMarker));
+#endif
}
else
{
diff --git a/cpp/src/Ice/BatchRequestQueue.h b/cpp/src/Ice/BatchRequestQueue.h
index e562e637197..359113a7973 100644
--- a/cpp/src/Ice/BatchRequestQueue.h
+++ b/cpp/src/Ice/BatchRequestQueue.h
@@ -44,7 +44,11 @@ private:
void waitStreamInUse(bool);
+#ifdef ICE_CPP11_MAPPING
+ std::function<void(const Ice::BatchRequest&, int, int)> _interceptor;
+#else
Ice::BatchRequestInterceptorPtr _interceptor;
+#endif
BasicStream _batchStream;
bool _batchStreamInUse;
bool _batchStreamCanFlush;
diff --git a/cpp/src/Ice/Initialize.cpp b/cpp/src/Ice/Initialize.cpp
index ebc2026d990..28cc59d3df0 100644
--- a/cpp/src/Ice/Initialize.cpp
+++ b/cpp/src/Ice/Initialize.cpp
@@ -140,9 +140,23 @@ Ice::createProperties(int& argc, char* argv[], const PropertiesPtr& defaults)
return properties;
}
+#ifdef ICE_CPP11_MAPPING
+Ice::ThreadHookPlugin::ThreadHookPlugin(const CommunicatorPtr& communicator,
+ function<void()> threadStart,
+ function<void()> threadStop)
+{
+ if(communicator == nullptr)
+ {
+ throw PluginInitializationException(__FILE__, __LINE__, "Communicator cannot be null");
+ }
+
+ IceInternal::InstancePtr instance = IceInternal::getInstance(communicator);
+ instance->setThreadHook(move(threadStart), move(threadStop));
+}
+#else
Ice::ThreadHookPlugin::ThreadHookPlugin(const CommunicatorPtr& communicator, const ThreadNotificationPtr& threadHook)
{
- if(communicator == ICE_NULLPTR)
+ if(communicator == 0)
{
throw PluginInitializationException(__FILE__, __LINE__, "Communicator cannot be null");
}
@@ -150,7 +164,7 @@ Ice::ThreadHookPlugin::ThreadHookPlugin(const CommunicatorPtr& communicator, con
IceInternal::InstancePtr instance = IceInternal::getInstance(communicator);
instance->setThreadHook(threadHook);
}
-
+#endif
void
Ice::ThreadHookPlugin::initialize()
{
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index e94431d3a2d..bcc79091555 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -1043,6 +1043,14 @@ IceInternal::Instance::setLogger(const Ice::LoggerPtr& logger)
_initData.logger = logger;
}
+#ifdef ICE_CPP11_MAPPING
+void
+IceInternal::Instance::setThreadHook(function<void ()> threadStart, function<void ()> threadStop)
+{
+ _initData.threadStart = move(threadStart);
+ _initData.threadStop = move(threadStop);
+}
+#else
void
IceInternal::Instance::setThreadHook(const Ice::ThreadNotificationPtr& threadHook)
{
@@ -1051,6 +1059,7 @@ IceInternal::Instance::setThreadHook(const Ice::ThreadNotificationPtr& threadHoo
//
_initData.threadHook = threadHook;
}
+#endif
namespace
{
diff --git a/cpp/src/Ice/Instance.h b/cpp/src/Ice/Instance.h
index 05b235c303b..c91e58de7f2 100644
--- a/cpp/src/Ice/Instance.h
+++ b/cpp/src/Ice/Instance.h
@@ -132,7 +132,11 @@ public:
void setDefaultRouter(const Ice::RouterPrxPtr&);
void setLogger(const Ice::LoggerPtr&);
+#ifdef ICE_CPP11_MAPPING
+ void setThreadHook(std::function<void ()>, std::function<void ()>);
+#else
void setThreadHook(const Ice::ThreadNotificationPtr&);
+#endif
IceUtil::StringConverterPtr getStringConverter() const { return _stringConverter; }
IceUtil::WstringConverterPtr getWstringConverter() const { return _wstringConverter; }
diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp
index 95ca1000e7d..2cea6bbc1ef 100644
--- a/cpp/src/Ice/ThreadPool.cpp
+++ b/cpp/src/Ice/ThreadPool.cpp
@@ -511,7 +511,15 @@ IceInternal::ThreadPool::dispatchFromThisThread(const DispatchWorkItemPtr& workI
{
try
{
+#ifdef ICE_CPP11_MAPPING
+ _dispatcher([workItem]()
+ {
+ workItem->run();
+ },
+ workItem->getConnection());
+#else
_dispatcher->dispatch(workItem, workItem->getConnection());
+#endif
}
catch(const std::exception& ex)
{
@@ -1165,11 +1173,19 @@ IceInternal::ThreadPool::EventHandlerThread::setState(Ice::Instrumentation::Thre
void
IceInternal::ThreadPool::EventHandlerThread::run()
{
+#ifdef ICE_CPP11_MAPPING
+ if(_pool->_instance->initializationData().threadStart)
+#else
if(_pool->_instance->initializationData().threadHook)
+#endif
{
try
{
+#ifdef ICE_CPP11_MAPPING
+ _pool->_instance->initializationData().threadStart();
+#else
_pool->_instance->initializationData().threadHook->start();
+#endif
}
catch(const exception& ex)
{
@@ -1200,11 +1216,19 @@ IceInternal::ThreadPool::EventHandlerThread::run()
_observer.detach();
+#ifdef ICE_CPP11_MAPPING
+ if(_pool->_instance->initializationData().threadStop)
+#else
if(_pool->_instance->initializationData().threadHook)
+#endif
{
try
{
+#ifdef ICE_CPP11_MAPPING
+ _pool->_instance->initializationData().threadStop();
+#else
_pool->_instance->initializationData().threadHook->stop();
+#endif
}
catch(const exception& ex)
{
diff --git a/cpp/src/Ice/ThreadPool.h b/cpp/src/Ice/ThreadPool.h
index c6db0465bee..3a440f5ca32 100644
--- a/cpp/src/Ice/ThreadPool.h
+++ b/cpp/src/Ice/ThreadPool.h
@@ -132,7 +132,11 @@ private:
std::string nextThreadId();
const InstancePtr _instance;
+#ifdef ICE_CPP11_MAPPING
+ std::function<void (std::function<void ()>, const std::shared_ptr<Ice::Connection>&)> _dispatcher;
+#else
const Ice::DispatcherPtr _dispatcher;
+#endif
ThreadPoolWorkQueuePtr _workQueue;
bool _destroyed;
const std::string _prefix;
diff --git a/cpp/test/Ice/dispatcher/AllTests.cpp b/cpp/test/Ice/dispatcher/AllTests.cpp
index 5427ba0639b..4aa41303ce6 100644
--- a/cpp/test/Ice/dispatcher/AllTests.cpp
+++ b/cpp/test/Ice/dispatcher/AllTests.cpp
@@ -18,7 +18,7 @@ using namespace std;
namespace
{
-class Callback : public IceUtil::Shared
+class Callback : public ICE_ENABLE_SHARED_FROM_THIS(Callback)
{
public:
@@ -80,6 +80,13 @@ public:
sent(bool sentSynchronously)
{
test(sentSynchronously || Dispatcher::isDispatcherThread());
+ _sentSynchronously = sentSynchronously;
+ }
+
+ bool
+ sentSynchronously()
+ {
+ return _sentSynchronously;
}
protected:
@@ -96,8 +103,9 @@ private:
IceUtil::Monitor<IceUtil::Mutex> _m;
bool _called;
+ bool _sentSynchronously;
};
-typedef IceUtil::Handle<Callback> CallbackPtr;
+ICE_DEFINE_PTR(CallbackPtr, Callback);
}
@@ -105,16 +113,16 @@ void
allTests(const Ice::CommunicatorPtr& communicator)
{
string sref = "test:default -p 12010";
- Ice::ObjectPrx obj = communicator->stringToProxy(sref);
+ Ice::ObjectPrxPtr obj = communicator->stringToProxy(sref);
test(obj);
- Test::TestIntfPrx p = Test::TestIntfPrx::uncheckedCast(obj);
+ Test::TestIntfPrxPtr p = ICE_UNCHECKED_CAST(Test::TestIntfPrx, obj);
sref = "testController:tcp -p 12011";
obj = communicator->stringToProxy(sref);
test(obj);
- Test::TestIntfControllerPrx testController = Test::TestIntfControllerPrx::uncheckedCast(obj);
+ Test::TestIntfControllerPrxPtr testController = ICE_UNCHECKED_CAST(Test::TestIntfControllerPrx, obj);
#ifdef ICE_CPP11_COMPILER
cout << "testing C++11 dispatcher... " << flush;
@@ -124,7 +132,117 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
p->op();
- CallbackPtr cb = new Callback;
+ CallbackPtr cb = ICE_MAKE_SHARED(Callback);
+#ifdef ICE_CPP11_MAPPING
+ p->op_async(
+ [cb]()
+ {
+ cb->response();
+ },
+ [cb](exception_ptr err)
+ {
+ try
+ {
+ rethrow_exception(err);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cb->exception(ex);
+ }
+ });
+ cb->check();
+
+ auto i = p->ice_adapterId("dummy");
+ i->op_async(
+ [cb]()
+ {
+ cb->response();
+ },
+ [cb](exception_ptr err)
+ {
+ try
+ {
+ rethrow_exception(err);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cb->exception(ex);
+ }
+ });
+ cb->check();
+
+ {
+ //
+ // Expect InvocationTimeoutException.
+ //
+ auto to = p->ice_invocationTimeout(250);
+ to->sleep_async(500,
+ [cb]()
+ {
+ cb->responseEx();
+ },
+ [cb](exception_ptr err)
+ {
+ try
+ {
+ rethrow_exception(err);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cb->exceptionEx(ex);
+ }
+ });
+ cb->check();
+ }
+
+ /*testController->holdAdapter();
+
+ Ice::ByteSeq seq;
+ seq.resize(1024); // Make sure the request doesn't compress too well.
+ for(Ice::ByteSeq::iterator q = seq.begin(); q != seq.end(); ++q)
+ {
+ *q = static_cast<Ice::Byte>(IceUtilInternal::random(255));
+ }
+
+ promise<void> completed;
+ while(true)
+ {
+ CallbackPtr cb = ICE_MAKE_SHARED(Callback);
+ promise<bool> call;
+ future<bool> sent = call.get_future();
+ p->opWithPayload_async(seq,
+ [cb, &sent, &completed]()
+ {
+ cb->payload();
+ if(cb->sentSynchronously())
+ {
+ completed.set_value();
+ }
+ },
+ [cb](exception_ptr err)
+ {
+ try
+ {
+ rethrow_exception(err);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cb->ignoreEx(ex);
+ }
+ },
+ [cb, &call](bool sentSynchronously)
+ {
+ cb->sent(sentSynchronously);
+ call.set_value(sentSynchronously);
+ });
+ if(!sent.get())
+ {
+ break;
+ }
+ }
+ testController->resumeAdapter();
+ completed.get_future().get();*/
+#else
Test::Callback_TestIntf_opPtr callback = Test::newCallback_TestIntf_op(cb,
&Callback::response,
&Callback::exception);
@@ -159,6 +277,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
while((result = p->begin_opWithPayload(seq, callback2))->sentSynchronously());
testController->resumeAdapter();
result->waitForCompleted();
+#endif
}
cout << "ok" << endl;
diff --git a/cpp/test/Ice/dispatcher/Client.cpp b/cpp/test/Ice/dispatcher/Client.cpp
index 4292b7a3398..5bdcdfd2af2 100644
--- a/cpp/test/Ice/dispatcher/Client.cpp
+++ b/cpp/test/Ice/dispatcher/Client.cpp
@@ -24,6 +24,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[])
{
@@ -31,8 +52,6 @@ main(int argc, char* argv[])
Ice::registerIceSSL();
#endif
int status;
- Ice::CommunicatorPtr communicator;
-
try
{
Ice::InitializationData initData;
@@ -44,7 +63,13 @@ main(int argc, char* argv[])
//
initData.properties->setProperty("Ice.TCP.SndSize", "50000");
-#ifdef ICE_CPP11_COMPILER
+#if defined(ICE_CPP11_MAPPING)
+ Ice::DispatcherPtr dispatcher = new Dispatcher();
+ initData.dispatcher = [=](function<void ()> call, const shared_ptr<Ice::Connection>& conn)
+ {
+ dispatcher->dispatch(new DispatcherCall(call), conn);
+ };
+#elif defined(ICE_CPP11_COMPILER)
Ice::DispatcherPtr dispatcher = new Dispatcher();
initData.dispatcher = Ice::newDispatcher(
[=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn)
@@ -54,27 +79,14 @@ main(int argc, char* argv[])
#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;
}
diff --git a/cpp/test/Ice/dispatcher/Collocated.cpp b/cpp/test/Ice/dispatcher/Collocated.cpp
index 34b5b235515..e76bfa09b08 100644
--- a/cpp/test/Ice/dispatcher/Collocated.cpp
+++ b/cpp/test/Ice/dispatcher/Collocated.cpp
@@ -26,9 +26,9 @@ run(int, char**, const Ice::CommunicatorPtr& communicator)
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,13 +67,17 @@ 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_COMPILER
+#if defined(ICE_CPP11_MAPPING)
+ Ice::DispatcherPtr dispatcher = new Dispatcher();
+ initData.dispatcher = [=](function<void ()> call, const shared_ptr<Ice::Connection>& conn)
+ {
+ dispatcher->dispatch(new DispatcherCall(call), conn);
+ };
+#elif defined(ICE_CPP11_COMPILER)
Ice::DispatcherPtr dispatcher = new Dispatcher();
initData.dispatcher = Ice::newDispatcher(
[=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn)
@@ -62,27 +87,14 @@ main(int argc, char* argv[])
#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;
}
diff --git a/cpp/test/Ice/dispatcher/Dispatcher.cpp b/cpp/test/Ice/dispatcher/Dispatcher.cpp
index 559852b4318..32e6109e1d6 100644
--- a/cpp/test/Ice/dispatcher/Dispatcher.cpp
+++ b/cpp/test/Ice/dispatcher/Dispatcher.cpp
@@ -10,6 +10,8 @@
#include <Dispatcher.h>
#include <TestCommon.h>
+using namespace std;
+
Dispatcher* Dispatcher::_instance = 0;
Dispatcher::Dispatcher()
@@ -22,17 +24,6 @@ Dispatcher::Dispatcher()
}
void
-Dispatcher::dispatch(const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr&)
-{
- Lock sync(*this);
- _calls.push_back(call);
- if(_calls.size() == 1)
- {
- notify();
- }
-}
-
-void
Dispatcher::terminate()
{
{
@@ -52,6 +43,18 @@ Dispatcher::isDispatcherThread()
}
void
+Dispatcher::dispatch(const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr&)
+
+{
+ Lock sync(*this);
+ _calls.push_back(call);
+ if(_calls.size() == 1)
+ {
+ notify();
+ }
+}
+
+void
Dispatcher::run()
{
while(true)
diff --git a/cpp/test/Ice/dispatcher/Dispatcher.h b/cpp/test/Ice/dispatcher/Dispatcher.h
index 0acf5d4f21d..d5573399301 100644
--- a/cpp/test/Ice/dispatcher/Dispatcher.h
+++ b/cpp/test/Ice/dispatcher/Dispatcher.h
@@ -22,18 +22,16 @@ class Dispatcher : public Ice::Dispatcher, IceUtil::Thread, IceUtil::Monitor<Ice
public:
Dispatcher();
-
virtual void dispatch(const Ice::DispatcherCallPtr&, const Ice::ConnectionPtr&);
+
+ void run();
static void terminate();
static bool isDispatcherThread();
private:
- void run();
-
static Dispatcher* _instance;
-
std::deque<Ice::DispatcherCallPtr> _calls;
bool _terminated;
};
diff --git a/cpp/test/Ice/dispatcher/Server.cpp b/cpp/test/Ice/dispatcher/Server.cpp
index 2f320a0f868..efbf63e3692 100644
--- a/cpp/test/Ice/dispatcher/Server.cpp
+++ b/cpp/test/Ice/dispatcher/Server.cpp
@@ -26,9 +26,9 @@ run(int, char**, const Ice::CommunicatorPtr& communicator)
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();
adapter2->add(testController, communicator->stringToIdentity("testController"));
@@ -40,6 +40,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[])
{
@@ -47,8 +68,6 @@ main(int argc, char* argv[])
Ice::registerIceSSL();
#endif
int status;
- Ice::CommunicatorPtr communicator;
-
try
{
Ice::InitializationData initData;
@@ -60,7 +79,13 @@ main(int argc, char* argv[])
//
initData.properties->setProperty("Ice.TCP.RcvSize", "50000");
-#ifdef ICE_CPP11_COMPILER
+#if defined(ICE_CPP11_MAPPING)
+ Ice::DispatcherPtr dispatcher = new Dispatcher();
+ initData.dispatcher = [=](function<void ()> call, const shared_ptr<Ice::Connection>& conn)
+ {
+ dispatcher->dispatch(new DispatcherCall(call), conn);
+ };
+#elif defined(ICE_CPP11_COMPILER)
Ice::DispatcherPtr dispatcher = new Dispatcher();
initData.dispatcher = Ice::newDispatcher(
[=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn)
@@ -70,28 +95,14 @@ main(int argc, char* argv[])
#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;
}
diff --git a/cpp/test/Ice/dispatcher/TestI.cpp b/cpp/test/Ice/dispatcher/TestI.cpp
index d06da693f78..03292582ca5 100644
--- a/cpp/test/Ice/dispatcher/TestI.cpp
+++ b/cpp/test/Ice/dispatcher/TestI.cpp
@@ -28,7 +28,11 @@ TestIntfI::sleep(Ice::Int to, const Ice::Current&)
}
void
+#ifdef ICE_CPP11_MAPPING
+TestIntfI::opWithPayload(Ice::ByteSeq, const Ice::Current&)
+#else
TestIntfI::opWithPayload(const Ice::ByteSeq&, const Ice::Current&)
+#endif
{
test(Dispatcher::isDispatcherThread());
}
diff --git a/cpp/test/Ice/dispatcher/TestI.h b/cpp/test/Ice/dispatcher/TestI.h
index 61d38815dcd..4018d596ee6 100644
--- a/cpp/test/Ice/dispatcher/TestI.h
+++ b/cpp/test/Ice/dispatcher/TestI.h
@@ -13,7 +13,7 @@
#include <Test.h>
class TestIntfControllerI;
-typedef IceUtil::Handle<TestIntfControllerI> TestIntfControllerIPtr;
+ICE_DEFINE_PTR(TestIntfControllerIPtr, TestIntfControllerI);
class TestIntfI : virtual public Test::TestIntf
{
@@ -21,7 +21,11 @@ public:
virtual void op(const Ice::Current&);
virtual void sleep(Ice::Int, const Ice::Current&);
+#ifdef ICE_CPP11_MAPPING
+ virtual void opWithPayload(Ice::ByteSeq, const Ice::Current&);
+#else
virtual void opWithPayload(const Ice::ByteSeq&, const Ice::Current&);
+#endif
virtual void shutdown(const Ice::Current&);
};
diff --git a/cpp/test/Ice/operations/BatchOneways.cpp b/cpp/test/Ice/operations/BatchOneways.cpp
index 05e2f391dde..2776f8cf445 100644
--- a/cpp/test/Ice/operations/BatchOneways.cpp
+++ b/cpp/test/Ice/operations/BatchOneways.cpp
@@ -147,7 +147,13 @@ batchOneways(const Test::MyClassPrxPtr& p)
initData.properties = p->ice_getCommunicator()->getProperties()->clone();
BatchRequestInterceptorIPtr interceptor = ICE_MAKE_SHARED(BatchRequestInterceptorI);
-#ifdef ICE_CPP11_COMPILER
+#if defined(ICE_CPP11_MAPPING)
+ initData.batchRequestInterceptor =
+ [=](const Ice::BatchRequest& request, int count, int size)
+ {
+ interceptor->enqueue(request, count, size);
+ };
+#elif defined(ICE_CPP11_COMPILER)
// Ensure lambda factory method works.
initData.batchRequestInterceptor = Ice::newBatchRequestInterceptor(
[=](const Ice::BatchRequest& request, int count, int size)