From 1d5c04bb8c0e786a717e36467e17f34bcc4f1d95 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 10 Aug 2012 23:53:37 +0200 Subject: C++11 ami lambda support --- cpp/config/Make.rules | 5 +- cpp/config/Make.rules.Darwin | 9 +- cpp/config/Make.rules.FreeBSD | 2 +- cpp/config/Make.rules.Linux | 12 +- cpp/demo/Glacier2/winrt/chat/App.xaml.cpp | 10 +- cpp/demo/Glacier2/winrt/chat/App.xaml.h | 10 +- cpp/demo/Glacier2/winrt/chat/ChatView.xaml.cpp | 25 +- cpp/demo/Glacier2/winrt/chat/ChatView.xaml.h | 37 +- cpp/demo/Glacier2/winrt/chat/LoginView.xaml.cpp | 20 +- cpp/demo/Glacier2/winrt/chat/LoginView.xaml.h | 40 +- cpp/demo/Glacier2/winrt/chat/MainPage.xaml.cpp | 116 ++-- cpp/demo/Glacier2/winrt/chat/MainPage.xaml.h | 143 ++-- cpp/demo/Glacier2/winrt/chat/chat.vcxproj | 4 +- cpp/demo/Ice/winrt/bidir/App.xaml.cpp | 11 +- cpp/demo/Ice/winrt/bidir/App.xaml.h | 10 +- cpp/demo/Ice/winrt/bidir/MainPage.xaml.cpp | 49 +- cpp/demo/Ice/winrt/bidir/MainPage.xaml.h | 64 +- cpp/demo/Ice/winrt/bidir/bidir.vcxproj | 4 +- cpp/demo/Ice/winrt/hello/App.xaml.cpp | 10 +- cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp | 172 ++--- cpp/demo/Ice/winrt/hello/MainPage.xaml.h | 69 +- cpp/include/Ice/CommunicatorAsync.h | 33 +- cpp/include/Ice/ConnectionAsync.h | 32 +- cpp/include/Ice/Dispatcher.h | 37 ++ cpp/include/Ice/OutgoingAsync.h | 132 ++++ cpp/include/Ice/Proxy.h | 598 ++++++++++++++++- cpp/include/Ice/Stream.h | 19 +- cpp/include/Ice/StreamTraits.h | 22 + cpp/include/IceUtil/Config.h | 11 + cpp/src/Ice/CommunicatorI.h | 10 + cpp/src/Ice/ConnectionI.h | 10 + cpp/src/Ice/Initialize.cpp | 8 + cpp/src/Ice/Network.cpp | 2 +- cpp/src/Ice/Proxy.cpp | 20 + cpp/src/IceStorm/NodeI.cpp | 15 + cpp/src/IceStorm/Replica.h | 6 + cpp/src/IceUtil/FileUtil.cpp | 5 +- cpp/src/Slice/FileTracker.cpp | 6 +- cpp/src/slice2cpp/Gen.cpp | 296 ++++++++- cpp/src/slice2cpp/Main.cpp | 12 +- cpp/src/slice2cs/Main.cpp | 12 +- cpp/src/slice2freeze/Main.cpp | 14 +- cpp/src/slice2freezej/Main.cpp | 14 +- cpp/src/slice2html/Main.cpp | 14 +- cpp/src/slice2java/Main.cpp | 12 +- cpp/src/slice2php/Main.cpp | 12 +- cpp/src/slice2py/Main.cpp | 12 +- cpp/src/slice2rb/Main.cpp | 20 +- cpp/test/Ice/ami/AllTests.cpp | 437 ++++++++++++- cpp/test/Ice/custom/AllTests.cpp | 832 +++++++++++++++++++++++- cpp/test/Ice/dispatcher/AllTests.cpp | 4 + cpp/test/Ice/dispatcher/Client.cpp | 13 +- cpp/test/Ice/dispatcher/Server.cpp | 9 + cpp/test/Ice/info/Makefile.mak | 2 +- cpp/test/Ice/invoke/AllTests.cpp | 99 +++ cpp/test/Ice/operations/OnewaysNewAMI.cpp | 79 ++- cpp/test/Ice/operations/TwowaysNewAMI.cpp | 505 +++++++++++++- cpp/test/IceUtil/unicode/Client.cpp | 8 +- 58 files changed, 3587 insertions(+), 607 deletions(-) (limited to 'cpp') diff --git a/cpp/config/Make.rules b/cpp/config/Make.rules index 878b330e3ce..67335ca86f6 100644 --- a/cpp/config/Make.rules +++ b/cpp/config/Make.rules @@ -255,12 +255,11 @@ endif SLICE2CPPFLAGS = $(ICECPPFLAGS) ifeq ($(ice_dir), /usr) - CPPFLAGS = LDFLAGS = $(LDPLATFORMFLAGS) $(CXXFLAGS) else ifeq ($(MinGW), yes) includedir_win = $(shell $(top_srcdir)/../cpp/config/cygpath-win.sh $(includedir)) - CPPFLAGS = -I"$(includedir_win)" + CPPFLAGS += -I"$(includedir_win)" ice_dir_win = $(shell $(top_srcdir)/../cpp/config/cygpath-win.sh $(ice_dir)) ifdef ice_src_dist LDFLAGS = $(LDPLATFORMFLAGS) $(CXXFLAGS) -L$(libdir) @@ -268,7 +267,7 @@ else LDFLAGS = $(LDPLATFORMFLAGS) $(CXXFLAGS) -L"$(ice_dir_win)\$(binsubdir)" endif else - CPPFLAGS = -I$(includedir) + CPPFLAGS += -I$(includedir) ifdef ice_src_dist LDFLAGS = $(LDPLATFORMFLAGS) $(CXXFLAGS) -L$(libdir) else diff --git a/cpp/config/Make.rules.Darwin b/cpp/config/Make.rules.Darwin index 2ce8320aeb5..0ae8dde25e1 100644 --- a/cpp/config/Make.rules.Darwin +++ b/cpp/config/Make.rules.Darwin @@ -16,8 +16,7 @@ ifeq ($(DEVELOPER_PATH),) endif TOOLCHAIN_BIN_DIR = $(DEVELOPER_PATH)/Toolchains/XcodeDefault.xctoolchain/usr/bin -CXX = $(TOOLCHAIN_BIN_DIR)/clang++ - +CXX = $(TOOLCHAIN_BIN_DIR)/clang++ #CXX = g++ CXXFLAGS = -Wall -D_REENTRANT @@ -35,6 +34,12 @@ else CXXFLAGS := $(CXXARCHFLAGS) -g $(CXXFLAGS) endif +ifeq ($(CPP11), yes) +ifeq ($(CXX), $(TOOLCHAIN_BIN_DIR)/clang++) + CPPFLAGS += --std=c++11 + CXXFLAGS += --stdlib=libc++ +endif +endif # # C++ run-time libraries, necessary for linking some shared libraries. diff --git a/cpp/config/Make.rules.FreeBSD b/cpp/config/Make.rules.FreeBSD index 804f4529ddc..eded0d6bd78 100644 --- a/cpp/config/Make.rules.FreeBSD +++ b/cpp/config/Make.rules.FreeBSD @@ -18,7 +18,7 @@ $(warning ===================================================================) # This file is included by Make.rules when uname is FreeBSD # -CXX = c++ +CXX = g++ CXXFLAGS = -Wall -D_REENTRANT -D_THREAD_SAFE diff --git a/cpp/config/Make.rules.Linux b/cpp/config/Make.rules.Linux index f16b2ef558a..9e0128f6712 100644 --- a/cpp/config/Make.rules.Linux +++ b/cpp/config/Make.rules.Linux @@ -24,19 +24,23 @@ endif # Default compiler is c++ (aka g++). # ifeq ($(CXX),) - CXX = c++ + CXX = g++ endif -ifeq ($(CXX),g++) - CXX = c++ +ifeq ($(CXX),c++) + CXX = g++ endif -ifeq ($(CXX),c++) +ifeq ($(CXX),g++) ifneq ($(SUSE_i586),) CXXARCHFLAGS += -march=i586 endif + ifeq ($(CPP11), yes) + CPPFLAGS += -std=c++0x + endif + ifeq ($(MACHINE),sparc64) # # We are an ultra, at least, and so have the atomic instructions diff --git a/cpp/demo/Glacier2/winrt/chat/App.xaml.cpp b/cpp/demo/Glacier2/winrt/chat/App.xaml.cpp index f551ed4bccb..826dbb0322a 100644 --- a/cpp/demo/Glacier2/winrt/chat/App.xaml.cpp +++ b/cpp/demo/Glacier2/winrt/chat/App.xaml.cpp @@ -1,7 +1,11 @@ -// -// App.xaml.cpp -// Implementation of the App class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #include "pch.h" #include "MainPage.xaml.h" diff --git a/cpp/demo/Glacier2/winrt/chat/App.xaml.h b/cpp/demo/Glacier2/winrt/chat/App.xaml.h index 779bf1490be..b1b6a271204 100644 --- a/cpp/demo/Glacier2/winrt/chat/App.xaml.h +++ b/cpp/demo/Glacier2/winrt/chat/App.xaml.h @@ -1,7 +1,11 @@ -// -// App.xaml.h -// Declaration of the App class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #pragma once diff --git a/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.cpp b/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.cpp index a9c505c2aae..0b05884d269 100644 --- a/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.cpp +++ b/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.cpp @@ -1,7 +1,11 @@ -// -// ChatView.xaml.cpp -// Implementation of the ChatView class +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #include "pch.h" #include "ChatView.xaml.h" @@ -21,8 +25,6 @@ using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; -// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 - ChatView::ChatView() { InitializeComponent(); @@ -43,23 +45,12 @@ ChatView::appendMessage(String^ message) Scroller->ScrollToVerticalOffset(Scroller->ScrollableHeight); } -/// -/// Invoked when this page is about to be displayed in a Frame. -/// -/// Event data that describes how this page was reached. The Parameter -/// property is typically used to configure the page. -void ChatView::OnNavigatedTo(NavigationEventArgs^ e) -{ - (void) e; // Unused parameter -} - - void chat::ChatView::inputKeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) { if(e->Key == Windows::System::VirtualKey::Enter && !input->Text->IsEmpty()) { string msg = IceUtil::wstringToString(input->Text->Data()); - input->Text = ref new String(); + input->Text = ""; MainPage::instance()->coordinator()->say(msg); } } diff --git a/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.h b/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.h index 15de1de2aea..6ec11949560 100644 --- a/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.h +++ b/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.h @@ -1,7 +1,11 @@ -// -// ChatView.xaml.h -// Declaration of the ChatView class +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #pragma once @@ -9,25 +13,18 @@ namespace chat { - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - public ref class ChatView sealed - { - public: - - ChatView(); - - void setError(Platform::String^ err); - void appendMessage(Platform::String^ message); - - protected: +public ref class ChatView sealed +{ +public: - virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; + ChatView(); + void setError(Platform::String^ err); + void appendMessage(Platform::String^ message); - private: +private: - void inputKeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); - }; + void inputKeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); +}; + } diff --git a/cpp/demo/Glacier2/winrt/chat/LoginView.xaml.cpp b/cpp/demo/Glacier2/winrt/chat/LoginView.xaml.cpp index 7afa5d9320e..8c7ed5927b5 100644 --- a/cpp/demo/Glacier2/winrt/chat/LoginView.xaml.cpp +++ b/cpp/demo/Glacier2/winrt/chat/LoginView.xaml.cpp @@ -1,7 +1,11 @@ -// -// LoginView.xaml.cpp -// Implementation of the LoginView class +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #include "pch.h" #include "LoginView.xaml.h" @@ -20,8 +24,6 @@ using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; -// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 - LoginView::LoginView() { InitializeComponent(); @@ -36,12 +38,7 @@ LoginView::setError(String^ err) error->Text = err; } -/// -/// Invoked when this page is about to be displayed in a Frame. -/// -/// Event data that describes how this page was reached. The Parameter -/// property is typically used to configure the page. -void LoginView::OnNavigatedTo(NavigationEventArgs^ e) +void LoginView::OnNavigatedTo(NavigationEventArgs^) { LoginData loginData = MainPage::instance()->coordinator()->loginData(); if(!loginData.hostname.empty()) @@ -56,7 +53,6 @@ void LoginView::OnNavigatedTo(NavigationEventArgs^ e) { password->Password = ref new String(IceUtil::stringToWstring(loginData.password).c_str()); } - (void) e; // Unused parameter } void chat::LoginView::signinClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) diff --git a/cpp/demo/Glacier2/winrt/chat/LoginView.xaml.h b/cpp/demo/Glacier2/winrt/chat/LoginView.xaml.h index dc4e60f5118..87317e73b49 100644 --- a/cpp/demo/Glacier2/winrt/chat/LoginView.xaml.h +++ b/cpp/demo/Glacier2/winrt/chat/LoginView.xaml.h @@ -1,7 +1,11 @@ -// -// LoginView.xaml.h -// Declaration of the LoginView class +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #pragma once @@ -9,27 +13,25 @@ namespace chat { - ref class MainPage; - - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - public ref class LoginView sealed - { - public: - LoginView(); +public ref class LoginView sealed +{ +public: - void setError(Platform::String^ err); + LoginView(); + void setError(Platform::String^); + void signinCompleted() + { + signin->IsEnabled = true; + } - protected: +protected: - virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; + virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^) override; - private: +private: - void signinClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void signinClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^); +}; - friend ref class MainPage; - }; } diff --git a/cpp/demo/Glacier2/winrt/chat/MainPage.xaml.cpp b/cpp/demo/Glacier2/winrt/chat/MainPage.xaml.cpp index 20c74f86162..3f110ecd409 100644 --- a/cpp/demo/Glacier2/winrt/chat/MainPage.xaml.cpp +++ b/cpp/demo/Glacier2/winrt/chat/MainPage.xaml.cpp @@ -1,7 +1,11 @@ -// -// MainPage.xaml.cpp -// Implementation of the MainPage class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #include "pch.h" #include "MainPage.xaml.h" @@ -24,44 +28,28 @@ using namespace Windows::UI::Xaml::Interop; using namespace std; -// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 - MainPage^ MainPage::_instance = nullptr; -class DispatcherI : virtual public Ice::Dispatcher -{ -public: - - DispatcherI(CoreDispatcher^ dispatcher) : - _dispatcher(dispatcher) - { - } - - virtual void dispatch(const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr&) - { - _dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([=]() - { - call->run(); - }, CallbackContext::Any)); - } - -private: - - CoreDispatcher^ _dispatcher; -}; - Coordinator::Coordinator(CoreDispatcher^ dispatcher) : _dispatcher(dispatcher) { } void -Coordinator::signIn(LoginData loginData) +Coordinator::signIn(const LoginData& loginData) { _loginData = loginData; Ice::InitializationData id; id.properties = Ice::createProperties(); - id.dispatcher = new DispatcherI(_dispatcher); + id.dispatcher = Ice::newDispatcher( + [=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr&) + { + this->_dispatcher->RunAsync( + CoreDispatcherPriority::Normal, ref new DispatchedHandler([=]() + { + call->run(); + }, CallbackContext::Any)); + }); Glacier2::SessionFactoryHelperPtr factory = new Glacier2::SessionFactoryHelper(id, this); Ice::Identity identity; identity.name = "router"; @@ -82,9 +70,12 @@ Coordinator::say(const std::string& msg) { try { - Demo::Callback_ChatSession_sayPtr cb = Demo::newCallback_ChatSession_say(this, &Coordinator::sayCallbackSuccess, - &Coordinator::sayCallbackError); - _chat->begin_say(msg, cb); + _chat->begin_say(msg, nullptr, [](const Ice::Exception& ex) + { + ostringstream os; + os << "Connect failed:\n" << ex << endl; + MainPage::instance()->setError(os.str()); + }); } catch(const Ice::CommunicatorDestroyedException& ex) { @@ -94,38 +85,11 @@ Coordinator::say(const std::string& msg) } } -void -Coordinator::sayCallbackSuccess() -{ -} - -void -Coordinator::sayCallbackError(const Ice::Exception& ex) -{ - ostringstream os; - os << "Connect failed:\n" << ex << endl; - MainPage::instance()->setError(os.str()); -} - void Coordinator::createdCommunicator(const Glacier2::SessionHelperPtr&) { } -void -Coordinator::setCallbackSuccess() -{ - MainPage::instance()->setConnected(true); -} - -void -Coordinator::setCallbackError(const Ice::Exception& ex) -{ - ostringstream os; - os << "Connect failed:\n" << ex << endl; - MainPage::instance()->setError(os.str()); -} - void Coordinator::connected(const Glacier2::SessionHelperPtr& session) { @@ -136,9 +100,17 @@ Coordinator::connected(const Glacier2::SessionHelperPtr& session) try { _chat = Demo::ChatSessionPrx::uncheckedCast(session->session()); - Demo::Callback_ChatSession_setCallbackPtr cb = - Demo::newCallback_ChatSession_setCallback(this, &Coordinator::setCallbackSuccess, &Coordinator::setCallbackError); - _chat->begin_setCallback(Demo::ChatCallbackPrx::uncheckedCast(_session->addWithUUID(this)), cb); + _chat->begin_setCallback(Demo::ChatCallbackPrx::uncheckedCast(_session->addWithUUID(this)), + []() + { + MainPage::instance()->setConnected(true); + }, + [](const Ice::Exception& ex) + { + ostringstream os; + os << "Connect failed:\n" << ex << endl; + MainPage::instance()->setError(os.str()); + }); } catch(const Ice::CommunicatorDestroyedException& ex) { @@ -167,7 +139,7 @@ Coordinator::message(const string& msg, const Ice::Current&) { try { - MainPage::instance()->_chatView->appendMessage(ref new String(IceUtil::stringToWstring(msg).c_str())); + MainPage::instance()->appendMessage(ref new String(IceUtil::stringToWstring(msg).c_str())); } catch(const Ice::CommunicatorDestroyedException& ex) { @@ -195,6 +167,12 @@ MainPage::MainPage() setConnected(false); } +void +MainPage::appendMessage(String^ message) +{ + _chatView->appendMessage(message); +} + MainPage^ MainPage::instance() { @@ -217,7 +195,7 @@ MainPage::setConnected(bool connected) } TypeName page = {pageName, TypeKind::Custom}; main->Navigate(page, this); - _loginView->signin->IsEnabled = true; + _loginView->signinCompleted(); } void @@ -227,16 +205,6 @@ MainPage::setError(const std::string& err) _loginView->setError(ref new String(IceUtil::stringToWstring(err).c_str())); } -/// -/// Invoked when this page is about to be displayed in a Frame. -/// -/// Event data that describes how this page was reached. The Parameter -/// property is typically used to configure the page. -void MainPage::OnNavigatedTo(NavigationEventArgs^ e) -{ - (void) e; // Unused parameter -} - void chat::MainPage::signoutClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { _coordinator->destroy(); diff --git a/cpp/demo/Glacier2/winrt/chat/MainPage.xaml.h b/cpp/demo/Glacier2/winrt/chat/MainPage.xaml.h index 717930ecc99..9b503992663 100644 --- a/cpp/demo/Glacier2/winrt/chat/MainPage.xaml.h +++ b/cpp/demo/Glacier2/winrt/chat/MainPage.xaml.h @@ -1,7 +1,11 @@ -// -// MainPage.xaml.h -// Declaration of the MainPage class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #pragma once @@ -14,89 +18,80 @@ namespace chat { - struct LoginData - { - std::string hostname; - std::string username; - std::string password; - }; +struct LoginData +{ + std::string hostname; + std::string username; + std::string password; +}; - class Coordinator : virtual public Glacier2::SessionCallback, - virtual public Demo::ChatCallback - { - public: +class Coordinator : virtual public Glacier2::SessionCallback, + virtual public Demo::ChatCallback +{ +public: - Coordinator(Windows::UI::Core::CoreDispatcher^); + Coordinator(Windows::UI::Core::CoreDispatcher^); - void signIn(LoginData); - LoginData loginData(); + void signIn(const LoginData&); + LoginData loginData(); - // - // Session callback - // - virtual void createdCommunicator(const Glacier2::SessionHelperPtr& session); - virtual void connected(const Glacier2::SessionHelperPtr&); - virtual void disconnected(const Glacier2::SessionHelperPtr&); - virtual void connectFailed(const Glacier2::SessionHelperPtr&, const Ice::Exception&); + // + // Session callback + // + virtual void createdCommunicator(const Glacier2::SessionHelperPtr&); + virtual void connected(const Glacier2::SessionHelperPtr&); + virtual void disconnected(const Glacier2::SessionHelperPtr&); + virtual void connectFailed(const Glacier2::SessionHelperPtr&, const Ice::Exception&); - // - // Chat callback - // - virtual void message(const std::string& data, const Ice::Current&); - - void setCallbackSuccess(); - void setCallbackError(const Ice::Exception&); - - void say(const std::string&); - void sayCallbackSuccess(); - void sayCallbackError(const Ice::Exception&); + // + // Chat callback + // + virtual void message(const std::string& data, const Ice::Current&); + + // + // Chat session. + // + void say(const std::string&); + void destroy(); + +private: + + Demo::ChatSessionPrx _chat; + Glacier2::SessionHelperPtr _session; + Windows::UI::Core::CoreDispatcher^ _dispatcher; + LoginData _loginData; +}; +typedef IceUtil::Handle CoordinatorPtr; + +public ref class MainPage sealed +{ +public: - void destroy(); + MainPage(); - private: + static MainPage^ instance(); + void setConnected(bool); + void appendMessage(Platform::String^); - Demo::ChatSessionPrx _chat; - Glacier2::SessionHelperPtr _session; - Windows::UI::Core::CoreDispatcher^ _dispatcher; - LoginData _loginData; - }; - typedef IceUtil::Handle CoordinatorPtr; +private: + + virtual void setError(const std::string&); - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - public ref class MainPage sealed + CoordinatorPtr coordinator() { - public: - - MainPage(); - - static MainPage^ instance(); - - void setConnected(bool); - - protected: - - virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; - - private: - - virtual void setError(const std::string&); + return _coordinator; + } + CoordinatorPtr _coordinator; - CoordinatorPtr coordinator() - { - return _coordinator; - } - CoordinatorPtr _coordinator; + static MainPage^ _instance; - static MainPage^ _instance; + friend ref class LoginView; + friend ref class ChatView; + friend class Coordinator; - friend ref class LoginView; - friend ref class ChatView; - friend class Coordinator; + LoginView^ _loginView; + ChatView^ _chatView; + void signoutClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); +}; - LoginView^ _loginView; - ChatView^ _chatView; - void signoutClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - }; } diff --git a/cpp/demo/Glacier2/winrt/chat/chat.vcxproj b/cpp/demo/Glacier2/winrt/chat/chat.vcxproj index f10b56c07e7..5a422517ed5 100644 --- a/cpp/demo/Glacier2/winrt/chat/chat.vcxproj +++ b/cpp/demo/Glacier2/winrt/chat/chat.vcxproj @@ -209,10 +209,10 @@ - + - + diff --git a/cpp/demo/Ice/winrt/bidir/App.xaml.cpp b/cpp/demo/Ice/winrt/bidir/App.xaml.cpp index d2b443c3643..d3b64f4d024 100644 --- a/cpp/demo/Ice/winrt/bidir/App.xaml.cpp +++ b/cpp/demo/Ice/winrt/bidir/App.xaml.cpp @@ -1,7 +1,12 @@ -// -// App.xaml.cpp -// Implementation of the App class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + #include "pch.h" #include "MainPage.xaml.h" diff --git a/cpp/demo/Ice/winrt/bidir/App.xaml.h b/cpp/demo/Ice/winrt/bidir/App.xaml.h index 7cce50550bb..103a440e38e 100644 --- a/cpp/demo/Ice/winrt/bidir/App.xaml.h +++ b/cpp/demo/Ice/winrt/bidir/App.xaml.h @@ -1,7 +1,11 @@ -// -// App.xaml.h -// Declaration of the App class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #pragma once diff --git a/cpp/demo/Ice/winrt/bidir/MainPage.xaml.cpp b/cpp/demo/Ice/winrt/bidir/MainPage.xaml.cpp index 11f76249417..6f234cdfec5 100644 --- a/cpp/demo/Ice/winrt/bidir/MainPage.xaml.cpp +++ b/cpp/demo/Ice/winrt/bidir/MainPage.xaml.cpp @@ -1,7 +1,11 @@ -// -// MainPage.xaml.cpp -// Implementation of the MainPage class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #include "pch.h" #include "MainPage.xaml.h" @@ -29,23 +33,11 @@ CallbackReceiverI::callback(Ice::Int num, const Ice::Current& current) _page->callback(num, current); } -// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 - MainPage::MainPage() { InitializeComponent(); } -/// -/// Invoked when this page is about to be displayed in a Frame. -/// -/// Event data that describes how this page was reached. The Parameter -/// property is typically used to configure the page. -void MainPage::OnNavigatedTo(NavigationEventArgs^ e) -{ - (void) e; // Unused parameter -} - void bidir::MainPage::startClient_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { try @@ -58,7 +50,8 @@ void bidir::MainPage::startClient_Click(Platform::Object^ sender, Windows::UI::X _communicator = Ice::initialize(initData); CallbackSenderPrx server = CallbackSenderPrx::checkedCast( - _communicator->stringToProxy("sender:tcp -h " + IceUtil::wstringToString(hostname->Text->Data()) + " -p 10000")); + _communicator->stringToProxy("sender:tcp -h " + IceUtil::wstringToString(hostname->Text->Data()) + + " -p 10000")); if(!server) { @@ -75,7 +68,14 @@ void bidir::MainPage::startClient_Click(Platform::Object^ sender, Windows::UI::X adapter->add(cr, ident); adapter->activate(); server->ice_getConnection()->setAdapter(adapter); - server->addClient(ident); + server->begin_addClient(ident, nullptr, [=](const Ice::Exception& ex) + { + ostringstream os; + os << ex << endl; + print(os.str()); + startClient->IsEnabled = true; + stopClient->IsEnabled = false; + }); } catch(const Ice::Exception& ex) { @@ -121,10 +121,13 @@ bidir::MainPage::callback(Ice::Int num, const Ice::Current&) void bidir::MainPage::print(const std::string& message) { - this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([=] () - { - output->Text += ref new String(IceUtil::stringToWstring(message).c_str()); - output->UpdateLayout(); - scroller->ScrollToVerticalOffset(scroller->ScrollableHeight); - }, CallbackContext::Any)); + this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, + ref new DispatchedHandler( + [=] () + { + output->Text += ref new String(IceUtil::stringToWstring(message).c_str()); + output->UpdateLayout(); + scroller->ScrollToVerticalOffset(scroller->ScrollableHeight); + }, + CallbackContext::Any)); } diff --git a/cpp/demo/Ice/winrt/bidir/MainPage.xaml.h b/cpp/demo/Ice/winrt/bidir/MainPage.xaml.h index cec23cb50d5..a68c98d50c8 100644 --- a/cpp/demo/Ice/winrt/bidir/MainPage.xaml.h +++ b/cpp/demo/Ice/winrt/bidir/MainPage.xaml.h @@ -1,7 +1,11 @@ -// -// MainPage.xaml.h -// Declaration of the MainPage class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #pragma once @@ -12,44 +16,38 @@ namespace bidir { - ref class MainPage; +ref class MainPage; - class CallbackReceiverI : public Demo::CallbackReceiver - { - public: +class CallbackReceiverI : public Demo::CallbackReceiver +{ +public: - CallbackReceiverI(MainPage^ page) : _page(page) - { - } + CallbackReceiverI(MainPage^ page) : _page(page) + { + } - virtual void - callback(Ice::Int, const Ice::Current&); + virtual void + callback(Ice::Int, const Ice::Current&); - private: +private: - MainPage^ _page; - }; - - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - public ref class MainPage sealed - { - public: - MainPage(); + MainPage^ _page; +}; - protected: +public ref class MainPage sealed +{ +public: + MainPage(); - virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; +private: - private: + friend class CallbackReceiverI; - friend class CallbackReceiverI; + void callback(Ice::Int, const Ice::Current&); + void print(const std::string&); + void startClient_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void stopClient_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + Ice::CommunicatorPtr _communicator; +}; - void callback(Ice::Int, const Ice::Current&); - void print(const std::string&); - void startClient_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void stopClient_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - Ice::CommunicatorPtr _communicator; - }; } diff --git a/cpp/demo/Ice/winrt/bidir/bidir.vcxproj b/cpp/demo/Ice/winrt/bidir/bidir.vcxproj index 275b3cabf19..855d494f803 100644 --- a/cpp/demo/Ice/winrt/bidir/bidir.vcxproj +++ b/cpp/demo/Ice/winrt/bidir/bidir.vcxproj @@ -189,10 +189,10 @@ - + - + diff --git a/cpp/demo/Ice/winrt/hello/App.xaml.cpp b/cpp/demo/Ice/winrt/hello/App.xaml.cpp index e23a2601ed3..dd08ad621d1 100644 --- a/cpp/demo/Ice/winrt/hello/App.xaml.cpp +++ b/cpp/demo/Ice/winrt/hello/App.xaml.cpp @@ -1,7 +1,11 @@ -// -// App.xaml.cpp -// Implementation of the App class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #include "pch.h" #include "MainPage.xaml.h" diff --git a/cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp b/cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp index 25910c04340..711291d6bb5 100644 --- a/cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp +++ b/cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp @@ -1,7 +1,11 @@ -// -// MainPage.xaml.cpp -// Implementation of the MainPage class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #include "pch.h" #include "MainPage.xaml.h" @@ -22,105 +26,29 @@ using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; -class DispatcherI : virtual public Ice::Dispatcher -{ -public: - - DispatcherI(CoreDispatcher^ dispatcher) : - _dispatcher(dispatcher) - { - } - - virtual void dispatch(const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr&) - { - _dispatcher->RunAsync(CoreDispatcherPriority::Normal, - ref new DispatchedHandler([=]() - { - call->run(); - }, CallbackContext::Any)); - } - -private: - - CoreDispatcher^ _dispatcher; -}; - -// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 - MainPage::MainPage() { InitializeComponent(); mode->SelectedIndex = 0; Ice::InitializationData id; - id.dispatcher = new DispatcherI(this->Dispatcher); + id.dispatcher = Ice::newDispatcher( + [=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr&) + { + this->Dispatcher->RunAsync( + CoreDispatcherPriority::Normal, ref new DispatchedHandler([=]() + { + call->run(); + }, CallbackContext::Any)); + }); _communicator = Ice::initialize(id); } -/// -/// Invoked when this page is about to be displayed in a Frame. -/// -/// Event data that describes how this page was reached. The Parameter -/// property is typically used to configure the page. -void MainPage::OnNavigatedTo(NavigationEventArgs^ e) -{ - (void) e; // Unused parameter -} - -HelloCallback::HelloCallback(MainPage^ page) : - _page(page) -{ -} - -void -HelloCallback::helloSent(bool sent) -{ - _page->helloSent(sent); -} - -void -HelloCallback::helloSuccess() -{ - _page->helloSuccess(); -} - -void -HelloCallback::helloFailure(const Ice::Exception& ex) -{ - _page->helloFailure(ex); -} - -void -hello::MainPage::helloSuccess() -{ - print("Ready."); -} - -void -hello::MainPage::helloFailure(const Ice::Exception& ex) -{ - ostringstream os; - os << ex; - print(os.str()); -} - -void -hello::MainPage::helloSent(bool) -{ - if(mode->SelectedIndex == 0 || mode->SelectedIndex == 1) - { - print("Waiting for response."); - } - else - { - print("Ready."); - } -} - Demo::HelloPrx hello::MainPage::proxy() { string h = IceUtil::wstringToString(hostname->Text->Data()); - Ice::ObjectPrx prx = _communicator->stringToProxy("hello:tcp -h " + h + " -p 10000:ssl -h " + h + " -p 10001:udp -h " + h + " -p 10000"); + Ice::ObjectPrx prx = _communicator->stringToProxy("hello:tcp -h " + h + " -p 10000:ssl -h " + h + + " -p 10001:udp -h " + h + " -p 10000"); switch(mode->SelectedIndex) { case 0: @@ -196,16 +124,52 @@ hello::MainPage::hello_Click(Platform::Object^ sender, Windows::UI::Xaml::Routed if(!isBatch()) { print("Sending sayHello request."); - Demo::Callback_Hello_sayHelloPtr cb = - Demo::newCallback_Hello_sayHello(new HelloCallback(this), - &HelloCallback::helloSuccess, - &HelloCallback::helloFailure, - &HelloCallback::helloSent); - prx->begin_sayHello(static_cast(delay->Value * 1000), cb); + _response = false; + hello->IsEnabled = false; + int deliveryMode = mode->SelectedIndex; + Ice::AsyncResultPtr result = prx->begin_sayHello(static_cast(delay->Value * 1000), + [=]() + { + hello->IsEnabled = true; + this->_response = true; + print("Ready."); + }, + [=](const Ice::Exception& ex) + { + hello->IsEnabled = true; + this->_response = true; + ostringstream os; + os << ex; + print(os.str()); + }, + [=](bool sentSynchronously) + { + if(this->_response) + { + return; // Response was received already. + } + if(deliveryMode <= 1) + { + print("Waiting for response."); + } + else if(!sentSynchronously) + { + print("Ready."); + } + }); + + if(!result->sentSynchronously()) + { + print("Sending request"); + } + else if(deliveryMode > 1) + { + print("Ready"); + } } else { - print("Queued sayHello request."); + print("Queued hello request."); prx->sayHello((int)(delay->Value * 1000)); flush->IsEnabled = true; } @@ -243,10 +207,16 @@ void hello::MainPage::flush_Click(Platform::Object^ sender, Windows::UI::Xaml::R try { flush->IsEnabled = false; - Ice::Callback_Communicator_flushBatchRequestsPtr cb = - Ice::newCallback_Communicator_flushBatchRequests(new HelloCallback(this), &HelloCallback::helloFailure); - _communicator->begin_flushBatchRequests(cb); - print("Flushed batch requests."); + _communicator->begin_flushBatchRequests([=](const Ice::Exception& ex) + { + ostringstream os; + os << ex; + print(os.str()); + }, + [=](bool) + { + print("Flushed batch requests."); + }); } catch(const Ice::Exception& ex) { diff --git a/cpp/demo/Ice/winrt/hello/MainPage.xaml.h b/cpp/demo/Ice/winrt/hello/MainPage.xaml.h index 0ad44475d25..4bf197f8447 100644 --- a/cpp/demo/Ice/winrt/hello/MainPage.xaml.h +++ b/cpp/demo/Ice/winrt/hello/MainPage.xaml.h @@ -1,7 +1,11 @@ -// -// MainPage.xaml.h -// Declaration of the MainPage class. +// ********************************************************************** // +// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #pragma once @@ -12,56 +16,25 @@ namespace hello { - ref class MainPage; - - class HelloCallback : virtual public IceUtil::Shared - { - public: - - HelloCallback(MainPage^); - - void helloSent(bool); - - void helloSuccess(); - void helloFailure(const Ice::Exception&); - - private: - - MainPage^ _page; - }; - typedef IceUtil::Handle HelloCallbackPtr; - - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - public ref class MainPage sealed - { - public: - - MainPage(); - - protected: - - virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; - +public ref class MainPage sealed +{ +public: - private: + MainPage(); - friend class HelloCallback; +private: - Demo::HelloPrx proxy(); - bool isBatch(); + Demo::HelloPrx proxy(); + bool isBatch(); + void print(const std::string&); - void helloSuccess(); - void helloFailure(const Ice::Exception& ex); - void helloSent(bool); - void print(const std::string&); + void hello_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void shutdown_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void flush_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void hello_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void shutdown_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void flush_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + Ice::CommunicatorPtr _communicator; + bool _response; +}; - Ice::CommunicatorPtr _communicator; - }; } diff --git a/cpp/include/Ice/CommunicatorAsync.h b/cpp/include/Ice/CommunicatorAsync.h index 26915051f8d..cb7dfeb288c 100644 --- a/cpp/include/Ice/CommunicatorAsync.h +++ b/cpp/include/Ice/CommunicatorAsync.h @@ -42,11 +42,41 @@ public: catch(::Ice::Exception& ex) { ::IceInternal::CallbackNC::__exception(__result, ex); - return; } } }; +#ifdef ICE_CPP11 +class Cpp11FnCallbackNC_Communicator_flushBatchRequests : virtual public ::IceInternal::Cpp11FnCallbackNC +{ +public: + + Cpp11FnCallbackNC_Communicator_flushBatchRequests( + const ::IceInternal::Function& excb, + const ::IceInternal::Function& sentcb) : + ::IceInternal::Cpp11FnCallbackNC(excb, sentcb) + { + CallbackBase::checkCallback(true, excb != nullptr); + } + + virtual void + __completed(const ::Ice::AsyncResultPtr& __result) const + { + ::Ice::CommunicatorPtr __com = __result->getCommunicator(); + assert(__com); + try + { + __com->end_flushBatchRequests(__result); + assert(false); + } + catch(::Ice::Exception& ex) + { + ::IceInternal::Cpp11FnCallbackNC::__exception(__result, ex); + } + } +}; +#endif + template Callback_Communicator_flushBatchRequestsPtr newCallback_Communicator_flushBatchRequests(const IceUtil::Handle& instance, void (T::*excb)(const ::Ice::Exception&), @@ -90,7 +120,6 @@ public: catch(::Ice::Exception& ex) { ::IceInternal::Callback::__exception(__result, ex); - return; } } }; diff --git a/cpp/include/Ice/ConnectionAsync.h b/cpp/include/Ice/ConnectionAsync.h index 5d850e577f4..4a27138aa53 100644 --- a/cpp/include/Ice/ConnectionAsync.h +++ b/cpp/include/Ice/ConnectionAsync.h @@ -42,11 +42,40 @@ public: catch(::Ice::Exception& ex) { ::IceInternal::CallbackNC::__exception(__result, ex); - return; } } }; +#ifdef ICE_CPP11 +class Cpp11FnCallbackNC_Connection_flushBatchRequests : virtual public ::IceInternal::Cpp11FnCallbackNC +{ +public: + + Cpp11FnCallbackNC_Connection_flushBatchRequests(const ::IceInternal::Function& excb, + const ::IceInternal::Function& sentcb) : + ::IceInternal::Cpp11FnCallbackNC(excb, sentcb) + { + CallbackBase::checkCallback(true, excb != nullptr); + } + + virtual void + __completed(const ::Ice::AsyncResultPtr& __result) const + { + ::Ice::ConnectionPtr __con = __result->getConnection(); + assert(__con); + try + { + __con->end_flushBatchRequests(__result); + assert(false); + } + catch(::Ice::Exception& ex) + { + ::IceInternal::Cpp11FnCallbackNC::__exception(__result, ex); + } + } +}; +#endif + template Callback_Connection_flushBatchRequestsPtr newCallback_Connection_flushBatchRequests(const IceUtil::Handle& instance, void (T::*excb)(const ::Ice::Exception&), @@ -90,7 +119,6 @@ public: catch(::Ice::Exception& ex) { ::IceInternal::Callback::__exception(__result, ex); - return; } } }; diff --git a/cpp/include/Ice/Dispatcher.h b/cpp/include/Ice/Dispatcher.h index 323ca7afa68..5ad42625215 100644 --- a/cpp/include/Ice/Dispatcher.h +++ b/cpp/include/Ice/Dispatcher.h @@ -9,9 +9,13 @@ #pragma once +#include #include #include #include +#ifdef ICE_CPP11 +# include +#endif namespace Ice { @@ -37,3 +41,36 @@ public: typedef IceUtil::Handle DispatcherPtr; } + +#ifdef ICE_CPP11 +namespace IceInternal +{ +class ICE_API Cpp11Dispatcher : public ::Ice::Dispatcher +{ +public: + + Cpp11Dispatcher(const ::std::function& cb) : + _cb(cb) + { + } + + virtual void dispatch(const ::Ice::DispatcherCallPtr& call, const ::Ice::ConnectionPtr& conn); + +private: + + const ::std::function _cb; +}; + +} + +namespace Ice +{ + +inline DispatcherPtr +newDispatcher(const ::std::function& cb) +{ + return new ::IceInternal::Cpp11Dispatcher(cb); +} + +} +#endif diff --git a/cpp/include/Ice/OutgoingAsync.h b/cpp/include/Ice/OutgoingAsync.h index ff9c4e1a4fc..2b482e4bae5 100644 --- a/cpp/include/Ice/OutgoingAsync.h +++ b/cpp/include/Ice/OutgoingAsync.h @@ -22,6 +22,9 @@ #include #include +#ifdef ICE_CPP11 +# include // for std::function +#endif namespace IceInternal { @@ -411,6 +414,125 @@ public: Callback sent; }; +#ifdef ICE_CPP11 + +template struct callback_type +{ + static const int value = 1; +}; + +template<> struct callback_type +{ + static const int value = 2; +}; + +template<> struct callback_type +{ + static const int value = 3; +}; + +template struct callable_type +{ + static const int value = 1; +}; + +template struct callable_type::value && + !::std::is_bind_expression::value>::type> +{ + template struct TypeCheck; + template struct AsyncResultCallback + { + typedef void (T::*ok)(const ::Ice::AsyncResultPtr&) const; + }; + template struct ExceptionCallback + { + typedef void (T::*ok)(const ::Ice::Exception&) const; + }; + + typedef char (&other)[1]; + typedef char (&asyncResult)[2]; + typedef char (&exception)[3]; + + template static other check(...); + template static asyncResult check(TypeCheck::ok, &T::operator()>*); + template static exception check(TypeCheck::ok, &T::operator()>*); + + enum { value = sizeof(check(0)) }; +}; + +template<> struct callable_type +{ + static const int value = 2; +}; + +template<> struct callable_type +{ + static const int value = 3; +}; + +template struct is_callable +{ + static const bool value = callable_type::value == callback_type::value; +}; + +template class Function : public std::function +{ + +public: + + template Function(T f, typename ::std::enable_if::value>::type* = 0) : std::function(f) + { + } + + Function() + { + } + + Function(::std::nullptr_t) : ::std::function(nullptr) + { + } +}; + +class Cpp11AsyncCallback : public GenericCallbackBase +{ +public: + + Cpp11AsyncCallback(const ::std::function& completed, + const ::std::function& sent) : + _completed(completed), + _sent(sent) + { + checkCallback(true, completed != nullptr); + } + + virtual void __completed(const ::Ice::AsyncResultPtr& result) const + { + _completed(result); + } + + virtual CallbackBasePtr __verify(::Ice::LocalObjectPtr&) + { + return this; // Nothing to do, the cookie is not type-safe. + } + + virtual void __sent(const ::Ice::AsyncResultPtr& result) const + { + if(_sent != nullptr) + { + _sent(result); + } + } + + virtual bool __hasSentCallback() const + { + return _sent != nullptr; + } + + ::std::function< void (const ::Ice::AsyncResultPtr&)> _completed; + ::std::function< void (const ::Ice::AsyncResultPtr&)> _sent; +}; +#endif + } namespace Ice @@ -434,6 +556,16 @@ newCallback(T* instance, return new ::IceInternal::AsyncCallback(instance, cb, sentcb); } +#ifdef ICE_CPP11 +inline CallbackPtr +newCallback(const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) +{ + return new ::IceInternal::Cpp11AsyncCallback(completed, sent); +} +#endif + // // Operation callbacks are specified in Proxy.h // diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 8db60bcf9ed..c182ee79a9e 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -149,13 +149,84 @@ typedef IceUtil::Handle AMI_Object_ice_flushB } +#ifdef ICE_CPP11 +namespace IceInternal +{ + +class ICE_API Cpp11FnCallbackNC : virtual public CallbackBase +{ +public: + + Cpp11FnCallbackNC(const ::std::function& excb, + const ::std::function& sentcb) : + _exception(excb), + _sent(sentcb) + { + } + + virtual CallbackBasePtr __verify(::Ice::LocalObjectPtr& cookie) + { + return this; + } + + virtual void __sent(const ::Ice::AsyncResultPtr& result) const + { + if(_sent != nullptr) + { + _sent(result->sentSynchronously()); + } + } + + virtual bool __hasSentCallback() const + { + return _sent != nullptr; + } + +protected: + + void __exception(const ::Ice::AsyncResultPtr&, const ::Ice::Exception& ex) const + { + if(_exception != nullptr) + { + _exception(ex); + } + } + + ::std::function _exception; + ::std::function _sent; +}; + +class ICE_API Cpp11FnOnewayCallbackNC : virtual public ::IceInternal::Cpp11FnCallbackNC +{ +public: + + Cpp11FnOnewayCallbackNC(const ::std::function& cb, + const ::std::function& excb, + const ::std::function& sentcb) : + Cpp11FnCallbackNC(excb, sentcb), + _cb(cb) + { + CallbackBase::checkCallback(true, cb || excb != nullptr); + } + + virtual void + __completed(const ::Ice::AsyncResultPtr&) const; + +private: + + ::std::function _cb; +}; + +} +#endif + namespace IceProxy { namespace Ice { class ICE_API Object : public ::IceUtil::Shared, private ::IceUtil::Mutex { public: - + bool operator==(const Object&) const; bool operator!=(const Object&) const; bool operator<(const Object&) const; @@ -174,6 +245,48 @@ public: { return ice_isA(typeId, &context); } + +#ifdef ICE_CPP11 + ::Ice::AsyncResultPtr + begin_ice_isA(const ::std::string& typeId, + const ::Ice::Context& ctx, + const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_isA(typeId, &ctx, response, exception, sent); + } + + ::Ice::AsyncResultPtr + begin_ice_isA(const ::std::string& typeId, + const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_isA(typeId, 0, response, exception, sent); + } + + ::Ice::AsyncResultPtr + begin_ice_isA(const ::std::string& typeId, + const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_isA(typeId, 0, ::Ice::newCallback(completed, sent), 0); + } + + ::Ice::AsyncResultPtr + begin_ice_isA(const ::std::string& typeId, + const ::Ice::Context& ctx, + const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_isA(typeId, &ctx, ::Ice::newCallback(completed, sent), 0); + } +#endif ::Ice::AsyncResultPtr begin_ice_isA(const ::std::string& typeId) { @@ -226,6 +339,44 @@ public: ice_ping(&context); } +#ifdef ICE_CPP11 + ::Ice::AsyncResultPtr + begin_ice_ping(const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_ping(0, response, exception, sent); + } + + ::Ice::AsyncResultPtr + begin_ice_ping(const ::Ice::Context& ctx, + const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_ping(&ctx, response, exception, sent); + } + + ::Ice::AsyncResultPtr + begin_ice_ping(const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_ping(0, ::Ice::newCallback(completed, sent), 0); + } + + ::Ice::AsyncResultPtr + begin_ice_ping(const ::Ice::Context& ctx, + const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_ping(&ctx, ::Ice::newCallback(completed, sent), 0); + } +#endif + ::Ice::AsyncResultPtr begin_ice_ping() { return begin_ice_ping(0, ::IceInternal::__dummyCallback, 0); @@ -271,6 +422,44 @@ public: { return ice_ids(&context); } + +#ifdef ICE_CPP11 + ::Ice::AsyncResultPtr + begin_ice_ids(const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_ids(0, response, exception, sent); + } + + ::Ice::AsyncResultPtr + begin_ice_ids(const ::Ice::Context& ctx, + const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_ids(&ctx, response, exception, sent); + } + + ::Ice::AsyncResultPtr + begin_ice_ids(const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_ids(0, ::Ice::newCallback(completed, sent), 0); + } + + ::Ice::AsyncResultPtr + begin_ice_ids(const ::Ice::Context& ctx, + const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_ids(&ctx, ::Ice::newCallback(completed, sent), 0); + } +#endif ::Ice::AsyncResultPtr begin_ice_ids() { @@ -303,7 +492,7 @@ public: ::Ice::AsyncResultPtr begin_ice_ids(const ::Ice::Context& __ctx, const ::Ice::Callback_Object_ice_idsPtr& __del, - const ::Ice::LocalObjectPtr& __cookie = 0) + const ::Ice::LocalObjectPtr& __cookie = 0) { return begin_ice_ids(&__ctx, __del, __cookie); } @@ -318,6 +507,44 @@ public: { return ice_id(&context); } + +#ifdef ICE_CPP11 + ::Ice::AsyncResultPtr + begin_ice_id(const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_id(0, response, exception, sent); + } + + ::Ice::AsyncResultPtr + begin_ice_id(const ::Ice::Context& ctx, + const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_id(&ctx, response, exception, sent); + } + + ::Ice::AsyncResultPtr + begin_ice_id(const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_id(0, ::Ice::newCallback(completed, sent), 0); + } + + ::Ice::AsyncResultPtr + begin_ice_id(const ::Ice::Context& ctx, + const ::IceInternal::Function& completed, + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_id(&ctx, ::Ice::newCallback(completed, sent), 0); + } +#endif ::Ice::AsyncResultPtr begin_ice_id() { @@ -337,7 +564,7 @@ public: ::Ice::AsyncResultPtr begin_ice_id(const ::Ice::Context& __ctx, const ::Ice::CallbackPtr& __del, - const ::Ice::LocalObjectPtr& __cookie = 0) + const ::Ice::LocalObjectPtr& __cookie = 0) { return begin_ice_id(&__ctx, __del, __cookie); } @@ -350,7 +577,7 @@ public: ::Ice::AsyncResultPtr begin_ice_id(const ::Ice::Context& __ctx, const ::Ice::Callback_Object_ice_idPtr& __del, - const ::Ice::LocalObjectPtr& __cookie = 0) + const ::Ice::LocalObjectPtr& __cookie = 0) { return begin_ice_id(&__ctx, __del, __cookie); } @@ -380,6 +607,58 @@ public: bool ice_invoke_async(const ::Ice::AMI_Object_ice_invokePtr&, const ::std::string&, ::Ice::OperationMode, const ::std::vector< ::Ice::Byte>&, const ::Ice::Context&); +#ifdef ICE_CPP11 + ::Ice::AsyncResultPtr begin_ice_invoke(const ::std::string& operation, + ::Ice::OperationMode mode, + const ::std::vector< ::Ice::Byte>& inParams, + const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return __begin_ice_invoke(operation, mode, inParams, 0, response, exception, sent); + } + + ::Ice::AsyncResultPtr begin_ice_invoke(const ::std::string& operation, + ::Ice::OperationMode mode, + const ::std::vector< ::Ice::Byte>& inParams, + const ::Ice::Context& ctx, + const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return __begin_ice_invoke(operation, mode, inParams, &ctx, response, exception, sent); + } + + ::Ice::AsyncResultPtr begin_ice_invoke( + const ::std::string& operation, + ::Ice::OperationMode mode, + const ::std::pair& inParams, + const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_invoke(operation, mode, inParams, 0, response, exception, sent); + } + + ::Ice::AsyncResultPtr begin_ice_invoke( + const ::std::string& operation, + ::Ice::OperationMode mode, + const ::std::pair& inParams, + const ::Ice::Context& ctx, + const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return __begin_ice_invoke(operation, mode, inParams, &ctx, response, exception, sent); + } +#endif + ::Ice::AsyncResultPtr begin_ice_invoke(const ::std::string& operation, ::Ice::OperationMode mode, const ::std::vector< ::Ice::Byte>& inParams) @@ -577,6 +856,16 @@ public: void ice_flushBatchRequests(); bool ice_flushBatchRequests_async(const ::Ice::AMI_Object_ice_flushBatchRequestsPtr&); + +#ifdef ICE_CPP11 + ::Ice::AsyncResultPtr begin_ice_flushBatchRequests( + const ::IceInternal::Function& exception, + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return begin_ice_flushBatchRequestsInternal(new ::IceInternal::Cpp11FnOnewayCallbackNC(nullptr, exception, sent), 0); + } +#endif + ::Ice::AsyncResultPtr begin_ice_flushBatchRequests() { return begin_ice_flushBatchRequestsInternal(::IceInternal::__dummyCallback, 0); @@ -621,28 +910,283 @@ protected: virtual Object* __newInstance() const; private: + +#ifdef ICE_CPP11 + ::Ice::AsyncResultPtr __begin_ice_isA( + const ::std::string& typeId, + const ::Ice::Context* ctx, + const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC + { + public: + + Cpp11CB(const ::std::function& responseFunc, + const ::std::function& exceptionFunc, + const ::std::function& sentFunc) : + ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), + _response(responseFunc) + { + CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); + } + + virtual void __completed(const ::Ice::AsyncResultPtr& __result) const + { + ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); + bool __ret; + try + { + __ret = __proxy->end_ice_isA(__result); + } + catch(::Ice::Exception& ex) + { + Cpp11FnCallbackNC::__exception(__result, ex); + return; + } + if(_response != nullptr) + { + _response(__ret); + } + } + + private: + + ::std::function _response; + }; + return begin_ice_isA(typeId, ctx, new Cpp11CB(response, exception, sent), 0); + } + + ::Ice::AsyncResultPtr __begin_ice_ping( + const ::Ice::Context* ctx, + const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + return begin_ice_ping(ctx, new ::IceInternal::Cpp11FnOnewayCallbackNC(response, exception, sent), 0); + } + + ::Ice::AsyncResultPtr __begin_ice_id( + const ::Ice::Context* ctx, + const ::IceInternal::Function& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC + { + public: + + Cpp11CB(const ::std::function& responseFunc, + const ::std::function& exceptionFunc, + const ::std::function& sentFunc) : + ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), + _response(responseFunc) + { + CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); + } + + virtual void __completed(const ::Ice::AsyncResultPtr& __result) const + { + ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); + ::std::string __ret; + try + { + __ret = __proxy->end_ice_id(__result); + } + catch(::Ice::Exception& ex) + { + Cpp11FnCallbackNC::__exception(__result, ex); + return; + } + if(_response != nullptr) + { + _response(__ret); + } + } + + private: + + ::std::function _response; + }; + return begin_ice_id(ctx, new Cpp11CB(response, exception, sent), 0); + } + + ::Ice::AsyncResultPtr __begin_ice_ids( + const ::Ice::Context* ctx, + const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = + ::IceInternal::Function()) + { + class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC + { + public: + + Cpp11CB(const ::std::function&)>& responseFunc, + const ::std::function& exceptionFunc, + const ::std::function& sentFunc) : + ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), + _response(responseFunc) + { + CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); + } + + virtual void __completed(const ::Ice::AsyncResultPtr& __result) const + { + ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); + ::std::vector< ::std::string> __ret; + try + { + __ret = __proxy->end_ice_ids(__result); + } + catch(::Ice::Exception& ex) + { + Cpp11FnCallbackNC::__exception(__result, ex); + return; + } + if(_response != nullptr) + { + _response(__ret); + } + } + + private: + + ::std::function&)> _response; + }; + return begin_ice_ids(ctx, new Cpp11CB(response, exception, sent), 0); + } +#endif bool ice_isA(const ::std::string&, const ::Ice::Context*); ::Ice::AsyncResultPtr begin_ice_isA(const ::std::string&, const ::Ice::Context*, - const ::IceInternal::CallbackBasePtr&, - const ::Ice::LocalObjectPtr&); + const ::IceInternal::CallbackBasePtr&, + const ::Ice::LocalObjectPtr&); void ice_ping(const ::Ice::Context*); ::Ice::AsyncResultPtr begin_ice_ping(const ::Ice::Context*, const ::IceInternal::CallbackBasePtr&, - const ::Ice::LocalObjectPtr&); + const ::Ice::LocalObjectPtr&); ::std::vector< ::std::string> ice_ids(const ::Ice::Context*); ::Ice::AsyncResultPtr begin_ice_ids(const ::Ice::Context*, const ::IceInternal::CallbackBasePtr&, - const ::Ice::LocalObjectPtr&); + const ::Ice::LocalObjectPtr&); ::std::string ice_id(const ::Ice::Context*); ::Ice::AsyncResultPtr begin_ice_id(const ::Ice::Context*, const ::IceInternal::CallbackBasePtr&, - const ::Ice::LocalObjectPtr&); - + const ::Ice::LocalObjectPtr&); + +#ifdef ICE_CPP11 + ::Ice::AsyncResultPtr __begin_ice_invoke( + const ::std::string& operation, + ::Ice::OperationMode mode, + const ::std::vector< ::Ice::Byte>& inParams, + const ::Ice::Context* ctx, + const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC + { + public: + + Cpp11CB(const ::std::function&)>& responseFunc, + const ::std::function& exceptionFunc, + const ::std::function& sentFunc) : + ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), + _response(responseFunc) + { + CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); + } + + virtual void __completed(const ::Ice::AsyncResultPtr& __result) const + { + ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); + bool __ret; + ::std::vector< ::Ice::Byte> p1; + try + { + __ret = __proxy->end_ice_invoke(p1, __result); + } + catch(::Ice::Exception& ex) + { + Cpp11FnCallbackNC::__exception(__result, ex); + return; + } + if(_response != nullptr) + { + _response(__ret, p1); + } + } + + private: + + ::std::function&)> _response; + }; + return begin_ice_invoke(operation, mode, inParams, ctx, new Cpp11CB(response, exception, sent), 0); + } + + ::Ice::AsyncResultPtr __begin_ice_invoke( + const ::std::string& operation, + ::Ice::OperationMode mode, + const ::std::pair& inParams, + const ::Ice::Context* ctx, + const ::IceInternal::Function&)>& response, + const ::IceInternal::Function& exception = + ::IceInternal::Function(), + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC + { + public: + + Cpp11CB(const ::std::function&)>& responseFunc, + const ::std::function& exceptionFunc, + const ::std::function& sentFunc) : + ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), + _response(responseFunc) + { + CallbackBase::checkCallback(true, _response || _exception != nullptr); + } + + virtual void __completed(const ::Ice::AsyncResultPtr& __result) const + { + bool __ret; + ::std::pair p1; + try + { + __ret = __result->getProxy()->___end_ice_invoke(p1, __result); + } + catch(::Ice::Exception& ex) + { + Cpp11FnCallbackNC::__exception(__result, ex); + return; + } + if(_response != nullptr) + { + _response(__ret, p1); + } + } + + private: + + ::std::function&)> _response; + }; + return begin_ice_invoke(operation, mode, inParams, ctx, new Cpp11CB(response, exception, sent), 0); + } +#endif + bool ice_invoke(const ::std::string&, ::Ice::OperationMode, const ::std::vector< ::Ice::Byte>&, @@ -1053,19 +1597,19 @@ public: virtual CallbackBasePtr __verify(::Ice::LocalObjectPtr& cookie) { - if(cookie != 0) // Makes sure begin_ was called without a cookie - { - throw IceUtil::IllegalArgumentException(__FILE__, __LINE__, "cookie specified for callback without cookie"); - } + if(cookie != 0) // Makes sure begin_ was called without a cookie + { + throw IceUtil::IllegalArgumentException(__FILE__, __LINE__, "cookie specified for callback without cookie"); + } return this; } virtual void __sent(const ::Ice::AsyncResultPtr& result) const { - if(sent) - { - (callback.get()->*sent)(result->sentSynchronously()); - } + if(sent) + { + (callback.get()->*sent)(result->sentSynchronously()); + } } virtual bool __hasSentCallback() const @@ -1107,19 +1651,19 @@ public: virtual CallbackBasePtr __verify(::Ice::LocalObjectPtr& cookie) { - if(cookie && !CT::dynamicCast(cookie)) - { - throw IceUtil::IllegalArgumentException(__FILE__, __LINE__, "unexpected cookie type"); - } + if(cookie && !CT::dynamicCast(cookie)) + { + throw IceUtil::IllegalArgumentException(__FILE__, __LINE__, "unexpected cookie type"); + } return this; } virtual void __sent(const ::Ice::AsyncResultPtr& result) const { - if(sent) - { - (callback.get()->*sent)(result->sentSynchronously(), CT::dynamicCast(result->getCookie())); - } + if(sent) + { + (callback.get()->*sent)(result->sentSynchronously(), CT::dynamicCast(result->getCookie())); + } } virtual bool __hasSentCallback() const @@ -1161,6 +1705,8 @@ public: } }; + + template class TwowayCallback : public Callback { diff --git a/cpp/include/Ice/Stream.h b/cpp/include/Ice/Stream.h index 6ec33c5e2e1..3257def6c6a 100644 --- a/cpp/include/Ice/Stream.h +++ b/cpp/include/Ice/Stream.h @@ -331,7 +331,24 @@ public: virtual void write(const Float*, const Float*) = 0; virtual void write(const Double*, const Double*) = 0; - virtual void writeOptional(Int, OptionalType) = 0; + virtual void writeOptional(Int, OptionalType) = 0; + +// +// COMPILER FIX: clang using libc++ cannot use the StreamHelper to write +// vector, as vector get optimized to +// __bit_const_reference that has not size member function. +// +#if defined(__clang__) && defined(_LIBCPP_VERSION) + virtual void write(const ::std::vector& v) + { + writeSize(static_cast(v.size())); + for(::std::vector::const_iterator p = v.begin(); p != v.end(); ++p) + { + bool v = (*p); + write(v); + } + } +#endif template inline void write(const T& v) { diff --git a/cpp/include/Ice/StreamTraits.h b/cpp/include/Ice/StreamTraits.h index 9f37834d8cf..97638d5152b 100644 --- a/cpp/include/Ice/StreamTraits.h +++ b/cpp/include/Ice/StreamTraits.h @@ -402,6 +402,28 @@ struct StreamHelper, StreamTraitTypeSequence> } }; +template<> +struct StreamHelper::const_iterator, + ::std::vector::const_iterator>, StreamTraitTypeSequence> +{ + template static inline void + write(S* stream, const std::pair< ::std::vector::const_iterator, + ::std::vector::const_iterator>& v) + { + stream->writeSize(static_cast< ::Ice::Int>(IceUtilInternal::distance(v.first, v.second))); + for(::std::vector::const_iterator p = v.first; p != v.second; ++p) + { + stream->write(static_cast(*p)); + } + } + + template static inline void + read(S* stream, std::pair< ::std::vector::const_iterator, ::std::vector::const_iterator>&) + { + assert(false); // Only used for marshaling. + } +}; + // Helper for zero-copy array sequence parameters template struct StreamHelper, std::pair >, StreamTraitTypeSequence> diff --git a/cpp/include/IceUtil/Config.h b/cpp/include/IceUtil/Config.h index ea9371ca845..a18a473f3fd 100644 --- a/cpp/include/IceUtil/Config.h +++ b/cpp/include/IceUtil/Config.h @@ -88,6 +88,17 @@ # define ICE_DEPRECATED_API /**/ #endif +// +// Check for C++ 11 support +// + +#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) && \ + defined(__GXX_EXPERIMENTAL_CXX0X__)) || \ + (defined(__clang__) && (__clang_major__ >= 4) && __cplusplus >= 201103) || \ + (defined(_MSC_VER) && (_MSC_VER >= 1600)) +# define ICE_CPP11 1 +#endif + // // Let's use these extensions with IceUtil: // diff --git a/cpp/src/Ice/CommunicatorI.h b/cpp/src/Ice/CommunicatorI.h index dc5580180b2..782cbf13b96 100644 --- a/cpp/src/Ice/CommunicatorI.h +++ b/cpp/src/Ice/CommunicatorI.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace Ice { @@ -59,6 +60,15 @@ public: virtual void flushBatchRequests(); +#ifdef ICE_CPP11 + virtual ::Ice::AsyncResultPtr begin_flushBatchRequests( + const ::IceInternal::Function& exception, + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return begin_flushBatchRequestsInternal(new Cpp11FnCallbackNC_Communicator_flushBatchRequests(exception, sent), 0); + } +#endif + virtual AsyncResultPtr begin_flushBatchRequests(); virtual AsyncResultPtr begin_flushBatchRequests(const CallbackPtr&, const LocalObjectPtr& = 0); virtual AsyncResultPtr begin_flushBatchRequests(const Callback_Communicator_flushBatchRequestsPtr&, diff --git a/cpp/src/Ice/ConnectionI.h b/cpp/src/Ice/ConnectionI.h index 1f448693a38..946a24f0c79 100644 --- a/cpp/src/Ice/ConnectionI.h +++ b/cpp/src/Ice/ConnectionI.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -103,6 +104,15 @@ public: void abortBatchRequest(); virtual void flushBatchRequests(); // From Connection. + +#ifdef ICE_CPP11 + virtual ::Ice::AsyncResultPtr begin_flushBatchRequests( + const ::IceInternal::Function& exception, + const ::IceInternal::Function& sent = ::IceInternal::Function()) + { + return begin_flushBatchRequestsInternal(new Cpp11FnCallbackNC_Connection_flushBatchRequests(exception, sent), 0); + } +#endif virtual AsyncResultPtr begin_flushBatchRequests(); virtual AsyncResultPtr begin_flushBatchRequests(const CallbackPtr&, const LocalObjectPtr& = 0); diff --git a/cpp/src/Ice/Initialize.cpp b/cpp/src/Ice/Initialize.cpp index f8b7f2a3cd4..adbd58424dc 100644 --- a/cpp/src/Ice/Initialize.cpp +++ b/cpp/src/Ice/Initialize.cpp @@ -323,3 +323,11 @@ IceInternal::getInstance(const CommunicatorPtr& communicator) assert(p); return p->_instance; } + +#ifdef ICE_CPP11 +void +IceInternal::Cpp11Dispatcher::dispatch(const ::Ice::DispatcherCallPtr& call, const ::Ice::ConnectionPtr& conn) +{ + _cb(call, conn); +} +#endif diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp index 3a2f6d402e3..d3ed3c505ca 100644 --- a/cpp/src/Ice/Network.cpp +++ b/cpp/src/Ice/Network.cpp @@ -1631,7 +1631,7 @@ IceInternal::doBind(SOCKET fd, const Address& addr) size = 0; // Keep the compiler happy. } - if(bind(fd, reinterpret_cast(&addr), size) == SOCKET_ERROR) + if(::bind(fd, reinterpret_cast(&addr), size) == SOCKET_ERROR) { closeSocketNoThrow(fd); SocketException ex(__FILE__, __LINE__); diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index ecf1bfbde1d..a9768790b1b 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -70,6 +70,26 @@ IceInternal::checkedCastImpl(const ObjectPrx& b, const string& f, const string& return 0; } +#ifdef ICE_CPP11 +void +IceInternal::Cpp11FnOnewayCallbackNC::__completed(const ::Ice::AsyncResultPtr& result) const +{ + try + { + result->getProxy()->__end(result, result->getOperation()); + } + catch(const ::Ice::Exception& ex) + { + Cpp11FnCallbackNC::__exception(result, ex); + return; + } + if(_cb != nullptr) + { + _cb(); + } +} +#endif + bool IceProxy::Ice::Object::operator==(const Object& r) const { diff --git a/cpp/src/IceStorm/NodeI.cpp b/cpp/src/IceStorm/NodeI.cpp index 9933b18357a..f586edcaa86 100644 --- a/cpp/src/IceStorm/NodeI.cpp +++ b/cpp/src/IceStorm/NodeI.cpp @@ -107,6 +107,21 @@ GroupNodeInfo::operator==(const GroupNodeInfo& rhs) const return id == rhs.id; } +// +// COMPILER FIX: Clang using libc++ requires to define operator= +// +#if defined(__clang__) && defined(_LIBCPP_VERSION) +GroupNodeInfo& +GroupNodeInfo::operator=(const GroupNodeInfo& other) + +{ + const_cast(this->id) = other.id; + const_cast(this->llu) = other.llu; + const_cast(this->observer) = other.observer; + return *this; +} +#endif + Replica::~Replica() { //cout << "~Replica" << endl; diff --git a/cpp/src/IceStorm/Replica.h b/cpp/src/IceStorm/Replica.h index 60600c778d8..7e131904bf1 100644 --- a/cpp/src/IceStorm/Replica.h +++ b/cpp/src/IceStorm/Replica.h @@ -22,6 +22,12 @@ struct GroupNodeInfo GroupNodeInfo(int i, LogUpdate l, const Ice::ObjectPrx& o = Ice::ObjectPrx()); bool operator<(const GroupNodeInfo& rhs) const; bool operator==(const GroupNodeInfo& rhs) const; + // + // COMPILER FIX: Clang using libc++ requires to define operator= + // +#if defined(__clang__) && defined(_LIBCPP_VERSION) + GroupNodeInfo& operator=(const GroupNodeInfo&); +#endif const int id; const LogUpdate llu; const Ice::ObjectPrx observer; diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp index 9fe0a5f85d3..b09159619bf 100644 --- a/cpp/src/IceUtil/FileUtil.cpp +++ b/cpp/src/IceUtil/FileUtil.cpp @@ -16,10 +16,9 @@ #ifdef _WIN32 # include -#endif - -#ifdef _WIN32 # include +#else +# include #endif using namespace std; diff --git a/cpp/src/Slice/FileTracker.cpp b/cpp/src/Slice/FileTracker.cpp index a14638757a2..7dcd7e96e42 100644 --- a/cpp/src/Slice/FileTracker.cpp +++ b/cpp/src/Slice/FileTracker.cpp @@ -9,12 +9,10 @@ #include -#ifdef __sun -# include -#endif - #ifdef _WIN32 # include +#else +# include #endif using namespace std; diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index db170626d26..1d713299433 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1774,6 +1774,38 @@ Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p) _useWstring = resetUseWstring(_useWstringHist); } +namespace +{ + +bool +usePrivateEnd(const OperationPtr& p) +{ + TypePtr ret = p->returnType(); + bool retIsOpt = p->returnIsOptional(); + string retSEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIEnd); + string retSPrivateEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIPrivateEnd); + + ParamDeclList outParams; + vector outDeclsEnd; + vector outDeclsPrivateEnd; + + ParamDeclList paramList = p->parameters(); + for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + { + if((*q)->isOutParam()) + { + outDeclsEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), + TypeContextAMIEnd)); + outDeclsPrivateEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), + TypeContextAMIPrivateEnd)); + } + } + + return retSEnd != retSPrivateEnd || outDeclsEnd != outDeclsPrivateEnd; +} + +} + void Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) { @@ -1782,14 +1814,17 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) string scope = fixKwd(p->scope()); TypePtr ret = p->returnType(); + bool retIsOpt = p->returnIsOptional(); string retS = returnTypeToString(ret, retIsOpt, p->getMetaData(), _useWstring | TypeContextAMIEnd); string retSEndAMI = returnTypeToString(ret, retIsOpt, p->getMetaData(), _useWstring | TypeContextAMIPrivateEnd); + string retInS = retS != "void" ? inputTypeToString(ret, retIsOpt, p->getMetaData(), _useWstring) : ""; ContainerPtr container = p->container(); ClassDefPtr cl = ClassDefPtr::dynamicCast(container); + string clName = cl->name(); string clScope = fixKwd(cl->scope()); - string delName = "Callback_" + cl->name() + "_" + name; + string delName = "Callback_" + clName + "_" + name; string delNameScoped = clScope + delName; vector params; @@ -1800,12 +1835,18 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) vector paramsDeclAMI; vector argsAMI; vector outParamsAMI; + vector outParamNamesAMI; vector outParamsDeclAMI; vector outParamsDeclEndAMI; - + vector outDecls; + ParamDeclList paramList = p->parameters(); ParamDeclList inParams; ParamDeclList outParams; + + + vector outEndArgs; + for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) { string paramName = fixKwd((*q)->name()); @@ -1838,9 +1879,12 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) else { outParamsAMI.push_back(typeString); + outParamNamesAMI.push_back(paramName); outParamsDeclAMI.push_back(typeString + ' ' + paramName); outParamsDeclEndAMI.push_back(typeStringEndAMI + ' ' + paramName); outParams.push_back(*q); + outDecls.push_back(inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring)); + outEndArgs.push_back(getEndArg((*q)->type(), (*q)->getMetaData(), outParamNamesAMI.back())); } } @@ -1884,6 +1928,201 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) } H << fixKwd(name) << spar << args << "&__ctx" << epar << ';'; H << eb; + + H.zeroIndent(); + H << nl << "#ifdef ICE_CPP11"; + H.restoreIndent(); + + string retEndArg = getEndArg(ret, p->getMetaData(), "__ret"); + + H << nl << "::Ice::AsyncResultPtr"; + H << nl << "begin_" << name << spar << paramsDeclAMI + << "const ::IceInternal::Function& response, " + << "const ::IceInternal::Function& exception = " + "::IceInternal::Function(), " + << "const ::IceInternal::Function& sent = ::IceInternal::Function()" << epar; + + H << sb; + if(p->returnsData()) + { + H << nl << "return __begin_" << name << spar << argsAMI << "0, response, exception, sent" << epar << ";"; + } + else + { + H << nl << "return begin_" << name << spar << argsAMI + << "0, new ::IceInternal::Cpp11FnOnewayCallbackNC(response, exception, sent)" << epar << ";"; + + } + H << eb; + + H << nl << "::Ice::AsyncResultPtr"; + H << nl << "begin_" << name << spar << paramsDeclAMI + << "const ::IceInternal::Function& completed" + << "const ::IceInternal::Function& sent = " + "::IceInternal::Function()" << epar; + H << sb; + H << nl << "return begin_" << name << spar << argsAMI << "0, ::Ice::newCallback(completed, sent), 0" << epar << ";"; + H << eb; + + + H << nl << "::Ice::AsyncResultPtr"; + H << nl << "begin_" << name << spar << paramsDeclAMI << "const ::Ice::Context& ctx" + << "const ::IceInternal::Function& response, " + << "const ::IceInternal::Function& exception = " + "::IceInternal::Function(), " + << "const ::IceInternal::Function& sent = ::IceInternal::Function()" << epar; + + H << sb; + if(p->returnsData()) + { + H << nl << "return __begin_" << name << spar << argsAMI << "&ctx, response, exception, sent" << epar << ";"; + } + else + { + H << nl << "return begin_" << name << spar << argsAMI + << "&ctx, new ::IceInternal::Cpp11FnOnewayCallbackNC(response, exception, sent), 0" << epar << ";"; + } + H << eb; + + H << nl << "::Ice::AsyncResultPtr"; + H << nl << "begin_" << name << spar << paramsDeclAMI + << "const ::Ice::Context& ctx" + << "const ::IceInternal::Function& completed" + << "const ::IceInternal::Function& sent = " + "::IceInternal::Function()" << epar; + H << sb; + H << nl << "return begin_" << name << spar << argsAMI << "&ctx, ::Ice::newCallback(completed, sent)" << epar << ";"; + H << eb; + + if(p->returnsData()) + { + H << nl; + H.dec(); + H << nl << "private:"; + H.inc(); + + + H << sp << nl << "::Ice::AsyncResultPtr __begin_" << name << spar << paramsDeclAMI + << "const ::Ice::Context* ctx" << "const ::IceInternal::Function& response, " + << "const ::IceInternal::Function& exception, " + << "const ::IceInternal::Function& sent" << epar; + H << sb; + H << nl << "class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC"; + H << sb; + H.dec(); + H << nl << "public:"; + H.inc(); + H << sp << nl << "Cpp11CB" << spar << "const ::std::function& responseFunc, " + << "const ::std::function& exceptionFunc, " + << "const ::std::function& sentFunc" << epar << " :"; + H.inc(); + H << nl << "::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc),"; + H << nl << "_response(responseFunc)"; + H.dec(); + H << sb; + H << nl << "CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr);"; + H << eb; + + // + // completed. + // + H << sp << nl << "virtual void __completed(const ::Ice::AsyncResultPtr& __result) const"; + H << sb; + H << nl << clScope << clName << "Prx __proxy = " << clScope << clName + << "Prx::uncheckedCast(__result->getProxy());"; + writeAllocateCode(H, outParams, p, _useWstring | TypeContextInParam | TypeContextAMICallPrivateEnd); + H << nl << "try"; + H << sb; + H << nl; + if(!usePrivateEnd(p)) + { + if(ret) + { + H << retEndArg << " = "; + } + H << "__proxy->end_" << p->name() << spar << outEndArgs << "__result" << epar << ';'; + } + else + { + H << "__proxy->___end_" << p->name() << spar << outEndArgs; + if(ret) + { + H << retEndArg; + } + H << "__result" << epar << ';'; + } + writeEndCode(H, outParams, p); + H << eb; + H << nl << "catch(::Ice::Exception& ex)"; + H << sb; + H << nl << "Cpp11FnCallbackNC::__exception(__result, ex);"; + H << nl << "return;"; + H << eb; + H << nl << "if(_response != nullptr)"; + H << sb; + H << nl << "_response" << spar; + if(ret) + { + H << "__ret"; + } + H << outParamNamesAMI; + H << epar << ';'; + H << eb; + H << eb; + + H.dec(); + H << nl << nl << "private:"; + H.inc(); + H << nl; + H << nl << "::std::function _response;"; + + H << eb << ';'; + + H << nl << "return begin_" << name << spar << argsAMI << "ctx" << "new Cpp11CB(response, exception, sent)" + << epar << ';'; + H << eb; + H << nl; + H.dec(); + H << nl << "public:"; + H.inc(); + } + + H.zeroIndent(); + H << nl << "#endif"; + H.restoreIndent(); H << sp << nl << "::Ice::AsyncResultPtr begin_" << name << spar << paramsDeclAMI << epar; H << sb; @@ -1932,7 +2171,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) << "const ::Ice::AsyncResultPtr&" << epar << ';'; if(generatePrivateEnd) { - H << sp << nl << "void ___end_" << name << spar << outParamsDeclEndAMI; + H << sp << nl << _dllExport << " void ___end_" << name << spar << outParamsDeclEndAMI; H << "const ::Ice::AsyncResultPtr&" << epar << ';'; } @@ -1949,7 +2188,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) H.dec(); H << nl << "public:"; H.inc(); - + C << sp << nl << retS << nl << "IceProxy" << scoped << spar << paramsDecl << "const ::Ice::Context* __ctx" << epar; C << sb; C << nl << "int __cnt = 0;"; @@ -3971,6 +4210,7 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) ParamDeclList inParams; ParamDeclList outParams; ParamDeclList paramList = p->parameters(); + vector< string> outDecls; for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) { string paramName = fixKwd((*q)->name()); @@ -4012,6 +4252,10 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) argsAMD += paramName; argsAMD += ", "; } + else + { + outDecls.push_back(inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring)); + } } if(!cl->isLocal()) @@ -4202,6 +4446,18 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) outParamsDeclAMI.push_back(typeString + ' ' + paramName); } } + + H.zeroIndent(); + H << nl << "#ifdef ICE_CPP11"; + H.restoreIndent(); + + H << nl << "virtual ::Ice::AsyncResultPtr begin_" << name << spar << paramsDeclAMI + << "const ::IceInternal::Function& exception" + << "const ::IceInternal::Function& sent = ::IceInternal::Function()" << epar << " = 0;"; + + H.zeroIndent(); + H << nl << "#endif"; + H.restoreIndent(); H << sp << nl << "virtual ::Ice::AsyncResultPtr begin_" << name << spar << paramsDeclAMI << epar << " = 0;"; @@ -4730,38 +4986,6 @@ Slice::Gen::AsyncCallbackTemplateVisitor::visitClassDefEnd(const ClassDefPtr& p) _useWstring = resetUseWstring(_useWstringHist); } -namespace -{ - -bool -usePrivateEnd(const OperationPtr& p) -{ - TypePtr ret = p->returnType(); - bool retIsOpt = p->returnIsOptional(); - string retSEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIEnd); - string retSPrivateEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIPrivateEnd); - - ParamDeclList outParams; - vector outDeclsEnd; - vector outDeclsPrivateEnd; - - ParamDeclList paramList = p->parameters(); - for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) - { - if((*q)->isOutParam()) - { - outDeclsEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), - TypeContextAMIEnd)); - outDeclsPrivateEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), - TypeContextAMIPrivateEnd)); - } - } - - return retSEnd != retSPrivateEnd || outDeclsEnd != outDeclsPrivateEnd; -} - -} - void Slice::Gen::AsyncCallbackTemplateVisitor::visitOperation(const OperationPtr& p) { diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index a8b82aaa52d..e9d8a211d2d 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -22,7 +22,7 @@ using namespace Slice; namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -31,13 +31,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -48,7 +48,7 @@ Init init; void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); interrupted = true; } @@ -295,7 +295,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index 4ebc975b0f8..8539e303244 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -22,7 +22,7 @@ using namespace Slice; namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -31,13 +31,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -48,7 +48,7 @@ Init init; void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); interrupted = true; } @@ -303,7 +303,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index 9cf0e4477e3..2d2020f10a2 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -28,7 +28,7 @@ using namespace Slice; namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -37,13 +37,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -56,7 +56,7 @@ string ICE_ENCODING_COMPARE = "Freeze::IceEncodingCompare"; void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); interrupted = true; } @@ -1999,7 +1999,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { @@ -2046,7 +2046,7 @@ compile(int argc, char* argv[]) u->destroy(); { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp index 9f85a9f5536..a08642d2650 100755 --- a/cpp/src/slice2freezej/Main.cpp +++ b/cpp/src/slice2freezej/Main.cpp @@ -26,7 +26,7 @@ using namespace IceUtilInternal; namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -35,13 +35,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -52,7 +52,7 @@ Init init; void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock lock(mutex); + IceUtilInternal::MutexPtrLock lock(globalMutex); interrupted = true; } @@ -1841,7 +1841,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { @@ -1941,7 +1941,7 @@ compile(int argc, char* argv[]) u->destroy(); { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/src/slice2html/Main.cpp b/cpp/src/slice2html/Main.cpp index 26caf348009..861cbafb0bb 100755 --- a/cpp/src/slice2html/Main.cpp +++ b/cpp/src/slice2html/Main.cpp @@ -24,7 +24,7 @@ using namespace IceUtil; namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -33,13 +33,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -50,7 +50,7 @@ Init init; void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); interrupted = true; } @@ -254,7 +254,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { @@ -296,7 +296,7 @@ compile(int argc, char* argv[]) p->destroy(); { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 6ced6400644..02e92a9bd6b 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -23,7 +23,7 @@ using namespace Slice; namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -32,13 +32,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -49,7 +49,7 @@ Init init; void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); interrupted = true; } @@ -356,7 +356,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index a30a16eca2d..4a566ffb7c0 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -1491,7 +1491,7 @@ printHeader(IceUtilInternal::Output& out) namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -1500,13 +1500,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -1517,7 +1517,7 @@ Init init; static void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); interrupted = true; } @@ -1780,7 +1780,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 08e947d3ecb..dee21f342b1 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -40,7 +40,7 @@ using namespace Slice::Python; namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -49,13 +49,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -66,7 +66,7 @@ Init init; void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); interrupted = true; } @@ -631,7 +631,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index 9afaffeaf73..0f899485d02 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -23,11 +23,9 @@ #include #ifdef _WIN32 -#include -#endif - -#ifndef _WIN32 -#include +# include +#else +# include #endif #include @@ -39,7 +37,7 @@ using namespace Slice::Ruby; namespace { -IceUtil::Mutex* mutex = 0; +IceUtil::Mutex* globalMutex = 0; bool interrupted = false; class Init @@ -48,13 +46,13 @@ public: Init() { - mutex = new IceUtil::Mutex; + globalMutex = new IceUtil::Mutex; } ~Init() { - delete mutex; - mutex = 0; + delete globalMutex; + globalMutex = 0; } }; @@ -65,7 +63,7 @@ Init init; void interruptedCallback(int signal) { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); interrupted = true; } @@ -316,7 +314,7 @@ compile(int argc, char* argv[]) } { - IceUtilInternal::MutexPtrLock sync(mutex); + IceUtilInternal::MutexPtrLock sync(globalMutex); if(interrupted) { diff --git a/cpp/test/Ice/ami/AllTests.cpp b/cpp/test/Ice/ami/AllTests.cpp index 8fd66031174..4fdfb66dd44 100644 --- a/cpp/test/Ice/ami/AllTests.cpp +++ b/cpp/test/Ice/ami/AllTests.cpp @@ -945,6 +945,50 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 async callback... " << flush; + { + AsyncCallbackPtr cb = new AsyncCallback(); + Ice::Context ctx; + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), [=](const ::Ice::AsyncResultPtr& r){ cb->isA(r); }); + cb->check(); + p->begin_ice_isA(Test::TestIntf::ice_staticId(), ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->isA(r); }); + cb->check(); + + p->begin_ice_ping([=](const ::Ice::AsyncResultPtr& r){ cb->ping(r); }); + cb->check(); + p->begin_ice_ping(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->ping(r); }); + cb->check(); + + p->begin_ice_id([=](const ::Ice::AsyncResultPtr& r){ cb->id(r); }); + cb->check(); + p->begin_ice_id(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->id(r); }); + cb->check(); + + p->begin_ice_ids([=](const ::Ice::AsyncResultPtr& r){ cb->ids(r); }); + cb->check(); + p->begin_ice_ids(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->ids(r); }); + cb->check(); + + p->begin_op([=](const ::Ice::AsyncResultPtr& r){ cb->op(r); }); + cb->check(); + p->begin_op(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->op(r); }); + cb->check(); + + p->begin_opWithResult([=](const ::Ice::AsyncResultPtr& r){ cb->opWithResult(r); }); + cb->check(); + p->begin_opWithResult(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->opWithResult(r); }); + cb->check(); + + p->begin_opWithUE([=](const ::Ice::AsyncResultPtr& r){ cb->opWithUE(r); }); + cb->check(); + p->begin_opWithUE(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->opWithUE(r); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing response callback... " << flush; { @@ -1031,6 +1075,58 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 response callback... " << flush; + { + ResponseCallbackPtr cb = new ResponseCallback(); + Ice::Context ctx; + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), [=](bool is){ cb->isA(is); }); + cb->check(); + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), ctx, [=](bool is){ cb->isA(is); }); + cb->check(); + + p->begin_ice_ping([=](){ cb->ping(); }); + cb->check(); + + p->begin_ice_ping(ctx, [=](){ cb->ping(); }); + cb->check(); + + + p->begin_ice_id([=](const string& id){ cb->id(id); }); + cb->check(); + + p->begin_ice_id(ctx, [=](const string& id){ cb->id(id); }); + cb->check(); + + p->begin_ice_ids([=](const Ice::StringSeq& ids){ cb->ids(ids); }); + cb->check(); + + p->begin_ice_ids(ctx, [=](const Ice::StringSeq& ids){ cb->ids(ids); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }); + cb->check(); + + p->begin_op(ctx, [=](){ cb->op(); }); + cb->check(); + + p->begin_opWithResult([=](int ret){ cb->opWithResult(ret); }); + cb->check(); + + p->begin_opWithResult(ctx, [=](int ret){ cb->opWithResult(ret); }); + cb->check(); + + p->begin_opWithUE([](){ test(false); }, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + + p->begin_opWithUE(ctx, [](){ test(false); }, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif + cout << "testing local exceptions... " << flush; { Test::TestIntfPrx indirect = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); @@ -1111,7 +1207,7 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; - + cout << "testing local exceptions with response callback... " << flush; { Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); @@ -1151,6 +1247,30 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing local exceptions with C++11 response callback... " << flush; + { + Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ExceptionCallbackPtr cb = new ExceptionCallback(); + + i->begin_ice_isA(Test::TestIntf::ice_staticId(), std::function([](bool){ test(false); }), [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_ping([](){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_id([](const string&){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_ids([](const Ice::StringSeq&){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_op([](){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing exception callback... " << flush; { @@ -1200,6 +1320,32 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 exception callback... " << flush; + { + Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ExceptionCallbackPtr cb = new ExceptionCallback(); + + i->begin_ice_isA(Test::TestIntf::ice_staticId(), nullptr, [=](const Ice::Exception& ex){cb->ex(ex); }); + cb->check(); + + i->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_opWithUE(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + // Ensures no exception is called when response is received + p->begin_ice_isA(Test::TestIntf::ice_staticId(), nullptr, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + p->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + + // If response is a user exception, it should be received. + p->begin_opWithUE(nullptr, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing sent callback... " << flush; { @@ -1280,6 +1426,79 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 sent callback... " << flush; + { + SentCallbackPtr cb = new SentCallback; + + p->begin_ice_isA("", [=](bool v){ cb->isA(v); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_ping([=](){ cb->ping(); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_id([=](const string& id){ cb->id(id); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_ids([=](const Ice::StringSeq& ids){ cb->ids(ids); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + + p->begin_op([=](){ cb->op(); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }, + nullptr, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_op(nullptr, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + vector cbs; + 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(IceUtilInternal::random(255)); + } + testController->holdAdapter(); + try + { + cb = new SentCallback(); + while(p->begin_opWithPayload(seq, nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); })->sentSynchronously()) + { + cbs.push_back(cb); + cb = new SentCallback(); + } + } + catch(...) + { + testController->resumeAdapter(); + throw; + } + testController->resumeAdapter(); + for(vector::const_iterator r = cbs.begin(); r != cbs.end(); r++) + { + (*r)->check(); + } + } + cout << "ok" << endl; +#endif cout << "testing illegal arguments... " << flush; { @@ -1427,6 +1646,32 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing unexpected exceptions from C++11 callback... " << flush; + { + Test::TestIntfPrx q = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ThrowType throwEx[] = { LocalException, UserException, StandardException, OtherException }; + + for(int i = 0; i < 4; ++i) + { + ThrowerPtr cb = new Thrower(throwEx[i]); + + p->begin_op([=](){ cb->op(); }, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + p->begin_op([=](){ cb->noOp(); }, [=](const Ice::Exception& ex){ cb->noEx(ex); }, [=](bool sent){ cb->sent(sent); }); + cb->check(); + + q->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with proxy... " << flush; { @@ -1566,6 +1811,43 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with proxy... " << flush; + { + + { + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = b1->begin_ice_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushExCallbackPtr cb = new FlushExCallback(); + Ice::AsyncResultPtr r = b1->begin_ice_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(!r->isSent()); + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with connection... " << flush; { CookiePtr cookie = new Cookie(5); @@ -1702,6 +1984,48 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with connection... " << flush; + { + { + // + // Without cookie. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = b1->ice_getConnection()->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + // + // Exception without cookie. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushExCallbackPtr cb = new FlushExCallback(); + Ice::AsyncResultPtr r = b1->ice_getConnection()->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(!r->isSent()); + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with communicator... " << flush; { @@ -1973,6 +2297,117 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with communicator... " << flush; + { + { + // + // Without cookie - 1 connection. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + // + // Exception without cookie - 1 connection. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + + { + // + // 2 connections. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b1->opBatch(); + b2->opBatch(); + b2->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(4)); + } + + { + // + // Exception - 2 connections - 1 failure. + // + // All connections should be flushed even if there are failures on some connections. + // Exceptions should not be reported. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b2->opBatch(); + b1->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->waitForBatch(1)); + } + + { + // + // Exception - 2 connections - 2 failures. + // + // The sent callback should be invoked even if all connections fail. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b2->opBatch(); + b1->ice_getConnection()->close(false); + b2->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing AsyncResult operations... " << flush; { { diff --git a/cpp/test/Ice/custom/AllTests.cpp b/cpp/test/Ice/custom/AllTests.cpp index a4c3983c919..9206e98c3ac 100755 --- a/cpp/test/Ice/custom/AllTests.cpp +++ b/cpp/test/Ice/custom/AllTests.cpp @@ -1448,6 +1448,23 @@ public: test(false); } } + + void throwExcept1(const Ice::Exception& ex, const wstring& in) + { + try + { + ex.ice_throw(); + } + catch(const Test1::WstringException& e) + { + test(e.reason == in); + called(); + } + catch(...) + { + test(false); + } + } void throwExcept2(const Ice::AsyncResultPtr& result) { @@ -1467,10 +1484,28 @@ public: test(false); } } + + void throwExcept2(const Ice::Exception& ex, const wstring& in) + { + try + { + ex.ice_throw(); + } + catch(const Test2::WstringException& e) + { + test(e.reason == in); + called(); + } + catch(...) + { + test(false); + } + } void - noEx(const Ice::Exception&, const InParamPtr&) + noEx(const Ice::Exception& ex, const InParamPtr&) { + cerr << ex << endl; test(false); } }; @@ -3519,6 +3554,724 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing alternate sequences with C++11 AMI callbacks... " << flush; + + { + Test::DoubleSeq in(5); + in[0] = 3.14; + in[1] = 1 / 3; + in[2] = 0.375; + in[3] = 4 / 3; + in[4] = -5.725; + Ice::Double inArray[5]; + for(int i = 0; i < 5; ++i) + { + inArray[i] = in[i]; + } + pair inPair(inArray, inArray + 5); + + CallbackPtr cb = new Callback(); + t->begin_opDoubleArray(inPair, + [=](const pair& p1, const pair& p2) + { + cb->opDoubleArray(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::BoolSeq in(5); + in[0] = false; + in[1] = true; + in[2] = true; + in[3] = false; + in[4] = true; + bool inArray[5]; + for(int i = 0; i < 5; ++i) + { + inArray[i] = in[i]; + } + pair inPair(inArray, inArray + 5); + + CallbackPtr cb = new Callback(); + t->begin_opBoolArray(inPair, + [=](const pair& p1, const pair& p2) + { + cb->opBoolArray(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Ice::Byte in[5]; + in[0] = '1'; + in[1] = '2'; + in[2] = '3'; + in[3] = '4'; + in[4] = '5'; + pair inPair(in, in + 5); + + CallbackPtr cb = new Callback(); + t->begin_opByteArray(inPair, + [=](const pair& p1, + const pair& p2) + { + cb->opByteArray(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::VariableList in; + Test::Variable inArray[5]; + inArray[0].s = "These"; + in.push_back(inArray[0]); + inArray[1].s = "are"; + in.push_back(inArray[1]); + inArray[2].s = "five"; + in.push_back(inArray[2]); + inArray[3].s = "short"; + in.push_back(inArray[3]); + inArray[4].s = "strings."; + in.push_back(inArray[4]); + pair inPair(inArray, inArray + 5); + + CallbackPtr cb = new Callback(); + t->begin_opVariableArray(inPair, + [=](const pair& p1, + const pair& p2) + { + cb->opVariableArray(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::BoolSeq in(5); + in[0] = false; + in[1] = true; + in[2] = true; + in[3] = false; + in[4] = true; + pair inPair(in.begin(), in.end()); + + CallbackPtr cb = new Callback(); + t->begin_opBoolRange(inPair, + [=](const pair& p1, + const pair& p2) + { + cb->opBoolRange(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::ByteList in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + in.push_back('5'); + pair inPair(in.begin(), in.end()); + + CallbackPtr cb = new Callback(); + t->begin_opByteRange(inPair, + [=](const pair& p1, + const pair& p2) + { + cb->opByteRange(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::VariableList in; + Test::Variable v; + v.s = "These"; + in.push_back(v); + v.s = "are"; + in.push_back(v); + v.s = "five"; + in.push_back(v); + v.s = "short"; + in.push_back(v); + v.s = "strings."; + in.push_back(v); + pair inPair(in.begin(), in.end()); + + CallbackPtr cb = new Callback(); + t->begin_opVariableRange(inPair, + [=](const pair& p1, + const pair& p2) + { + cb->opVariableRange(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::BoolSeq in(5); + in[0] = false; + in[1] = true; + in[2] = true; + in[3] = false; + in[4] = true; + bool inArray[5]; + for(int i = 0; i < 5; ++i) + { + inArray[i] = in[i]; + } + pair inPair(inArray, inArray + 5); + + CallbackPtr cb = new Callback(); + Test::Callback_TestIntf_opBoolRangeTypePtr callback = + Test::newCallback_TestIntf_opBoolRangeType(cb, &Callback::opBoolRangeType, &Callback::noEx); + t->begin_opBoolRangeType(inPair, callback, newInParam(inPair)); + cb->check(); + } + + { + Test::ByteList in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + in.push_back('5'); + pair inPair(in.begin(), in.end()); + + CallbackPtr cb = new Callback(); + t->begin_opByteRangeType(inPair, + [=](const pair& p1, + const pair& p2) + { + cb->opByteRangeType(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::VariableList in; + deque inSeq; + Test::Variable v; + v.s = "These"; + in.push_back(v); + inSeq.push_back(v); + v.s = "are"; + in.push_back(v); + inSeq.push_back(v); + v.s = "five"; + in.push_back(v); + inSeq.push_back(v); + v.s = "short"; + in.push_back(v); + inSeq.push_back(v); + v.s = "strings."; + in.push_back(v); + inSeq.push_back(v); + pair::const_iterator, deque::const_iterator> inPair(inSeq.begin(), + inSeq.end()); + + CallbackPtr cb = new Callback(); + t->begin_opVariableRangeType(inPair, + [=](const pair::const_iterator, deque::const_iterator>& p1, + const pair::const_iterator, deque::const_iterator>& p2) + { + cb->opVariableRangeType(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + deque in(5); + in[0] = false; + in[1] = true; + in[2] = true; + in[3] = false; + in[4] = true; + + CallbackPtr cb = new Callback(); + t->begin_opBoolSeq(in, + [=](const deque& p1, const deque& p2) + { + cb->opBoolSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list in; + in.push_back(false); + in.push_back(true); + in.push_back(true); + in.push_back(false); + in.push_back(true); + + CallbackPtr cb = new Callback(); + t->begin_opBoolList(in, + [=](const list& p1, const list& p2) + { + cb->opBoolList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque< ::Ice::Byte> in(5); + in[0] = '1'; + in[1] = '2'; + in[2] = '3'; + in[3] = '4'; + in[4] = '5'; + + CallbackPtr cb = new Callback(); + t->begin_opByteSeq(in, + [=](const deque< ::Ice::Byte>& p1, const deque< ::Ice::Byte>& p2) + { + cb->opByteSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list< ::Ice::Byte> in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + in.push_back('5'); + + CallbackPtr cb = new Callback(); + t->begin_opByteList(in, + [=](const list< ::Ice::Byte>& p1, const list< ::Ice::Byte>& p2) + { + cb->opByteList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + MyByteSeq in(5); + int i = 0; + for(MyByteSeq::iterator p = in.begin(); p != in.end(); ++p) + { + *p = '1' + i++; + } + + CallbackPtr cb = new Callback(); + t->begin_opMyByteSeq(in, + [=](const MyByteSeq& p1, const MyByteSeq& p2) + { + cb->opMyByteSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque in(5); + in[0] = "These"; + in[1] = "are"; + in[2] = "five"; + in[3] = "short"; + in[4] = "strings."; + + CallbackPtr cb = new Callback(); + t->begin_opStringSeq(in, + [=](const deque& p1, const deque& p2) + { + cb->opStringSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list in; + in.push_back("These"); + in.push_back("are"); + in.push_back("five"); + in.push_back("short"); + in.push_back("strings."); + + CallbackPtr cb = new Callback(); + t->begin_opStringList(in, + [=](const list& p1, const list& p2) + { + cb->opStringList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque in(5); + in[0].s = 1; + in[1].s = 2; + in[2].s = 3; + in[3].s = 4; + in[4].s = 5; + + CallbackPtr cb = new Callback(); + t->begin_opFixedSeq(in, + [=](const deque& p1, const deque& p2) + { + cb->opFixedSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list in(5); + short num = 1; + for(list::iterator p = in.begin(); p != in.end(); ++p) + { + (*p).s = num++; + } + + CallbackPtr cb = new Callback(); + t->begin_opFixedList(in, + [=](const list p1, const list p2) + { + cb->opFixedList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque in(5); + in[0].s = "These"; + in[1].s = "are"; + in[2].s = "five"; + in[3].s = "short"; + in[4].s = "strings."; + + CallbackPtr cb = new Callback(); + t->begin_opVariableSeq(in, + [=](const deque& p1, const deque& p2) + { + cb->opVariableSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list in; + Test::Variable v; + v.s = "These"; + in.push_back(v); + v.s = "are"; + in.push_back(v); + v.s = "five"; + in.push_back(v); + v.s = "short"; + in.push_back(v); + v.s = "strings."; + in.push_back(v); + + CallbackPtr cb = new Callback(); + t->begin_opVariableList(in, + [=](const list& p1, const list& p2) + { + cb->opVariableList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque in(5); + in[0]["A"] = "a"; + in[1]["B"] = "b"; + in[2]["C"] = "c"; + in[3]["D"] = "d"; + in[4]["E"] = "e"; + + CallbackPtr cb = new Callback(); + t->begin_opStringStringDictSeq(in, + [=](const deque& p1, const deque& p2) + { + cb->opStringStringDictSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list in; + Test::StringStringDict ssd; + ssd["A"] = "a"; + in.push_back(ssd); + ssd["B"] = "b"; + in.push_back(ssd); + ssd["C"] = "c"; + in.push_back(ssd); + ssd["D"] = "d"; + in.push_back(ssd); + ssd["E"] = "e"; + in.push_back(ssd); + + CallbackPtr cb = new Callback(); + t->begin_opStringStringDictList(in, + [=](const list& p1, + const list& p2) + { + cb->opStringStringDictList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque in(5); + in[0] = Test::E1; + in[1] = Test::E2; + in[2] = Test::E3; + in[3] = Test::E1; + in[4] = Test::E3; + + CallbackPtr cb = new Callback(); + t->begin_opESeq(in, + [=](const deque& p1, const deque& p2) + { + cb->opESeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list in; + in.push_back(Test::E1); + in.push_back(Test::E2); + in.push_back(Test::E3); + in.push_back(Test::E1); + in.push_back(Test::E3); + + CallbackPtr cb = new Callback(); + t->begin_opEList(in, + [=](const list& p1, const list& p2) + { + cb->opEList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque in(5); + in[0] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C1:default -p 12010 -t 10000")); + in[1] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C2:default -p 12010 -t 10001")); + in[2] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C3:default -p 12010 -t 10002")); + in[3] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C4:default -p 12010 -t 10003")); + in[4] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C5:default -p 12010 -t 10004")); + + CallbackPtr cb = new Callback(); + t->begin_opCPrxSeq(in, + [=](const deque& p1, const deque& p2) + { + cb->opCPrxSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list in; + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C1:default -p 12010 -t 10000"))); + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C2:default -p 12010 -t 10001"))); + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C3:default -p 12010 -t 10002"))); + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C4:default -p 12010 -t 10003"))); + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C5:default -p 12010 -t 10004"))); + + CallbackPtr cb = new Callback(); + t->begin_opCPrxList(in, + [=](const list& p1, const list& p2) + { + cb->opCPrxList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque in(5); + in[0] = new Test::C(); + in[1] = in[0]; + in[2] = in[0]; + in[3] = in[0]; + in[4] = in[0]; + + CallbackPtr cb = new Callback(); + t->begin_opCSeq(in, + [=](const deque& p1, const deque& p2) + { + cb->opCSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list in; + in.push_back(new Test::C()); + in.push_back(new Test::C()); + in.push_back(new Test::C()); + in.push_back(new Test::C()); + in.push_back(new Test::C()); + + CallbackPtr cb = new Callback(); + t->begin_opCList(in, + [=](const list& p1, const list& p2) + { + cb->opCList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + + { + Test::ByteSeq in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + + CallbackPtr cb = new Callback(); + t->begin_opOutArrayByteSeq(in, + [=](const ::std::pair& p1) + { + cb->opOutArrayByteSeq(p1, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + Test::ByteSeq in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + + CallbackPtr cb = new Callback(); + t->begin_opOutRangeByteSeq(in, + [=](const ::std::pair< ::Test::ByteSeq::const_iterator, ::Test::ByteSeq::const_iterator>& p1) + { + cb->opOutRangeByteSeq(p1, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + cout << "ok" << endl; +#endif } cout << "testing class mapped structs ... " << flush; @@ -3568,6 +4321,25 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) cb->check(); } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing class mapped structs with C++11 AMI... " << flush; + { + CallbackPtr cb = new Callback(); + t->begin_opClassStruct(cs, csseq1, + [=](const ::Test::ClassStructPtr& p1, + const ::Test::ClassStructPtr& p2, + const ::Test::ClassStructSeq& p3) + { + cb->opClassStruct(p1, p2, p3, newInParam(make_pair(cs, csseq1))); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(make_pair(cs, csseq1))); + }); + cb->check(); + } + cout << "ok" << endl; +#endif } cout << "testing wstring... " << flush; @@ -3622,6 +4394,21 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) newInParam(wstr)); cb->check(); } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback(); + wsc1->begin_opString(wstr, + [=](const wstring& p1, const wstring& p2) + { + cb->opString(p1, p2, newInParam(wstr)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(wstr)); + }); + cb->check(); + } +#endif } ret = wsc2->opString(wstr, out); @@ -3648,6 +4435,27 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) &Callback::noEx), newInParam(wstr)); cb->check(); } + { + CallbackPtr cb = new Callback(); + wsc2->begin_opString(wstr, Test2::newCallback_WstringClass_opString(cb, &Callback::opString, + &Callback::noEx), newInParam(wstr)); + cb->check(); + } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback(); + wsc2->begin_opString(wstr, + [=](const wstring& p1, const wstring& p2) + { + cb->opString(p1, p2, newInParam(wstr)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(wstr)); + }); + cb->check(); + } +#endif } Test1::WstringStruct wss1; @@ -3697,6 +4505,17 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) wsc1->begin_throwExcept(wstr, Ice::newCallback(cb, &Callback::throwExcept1), newInParam(wstr)); cb->check(); } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback(); + wsc1->begin_throwExcept(wstr, nullptr, + [=](const Ice::Exception& ex) + { + cb->throwExcept1(ex, wstr); + }); + cb->check(); + } +#endif } try @@ -3732,6 +4551,17 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) wsc2->begin_throwExcept(wstr, Ice::newCallback(cb, &Callback::throwExcept2), newInParam(wstr)); cb->check(); } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback(); + wsc2->begin_throwExcept(wstr, nullptr, + [=](const Ice::Exception& ex) + { + cb->throwExcept2(ex, wstr); + }); + cb->check(); + } +#endif } cout << "ok" << endl; diff --git a/cpp/test/Ice/dispatcher/AllTests.cpp b/cpp/test/Ice/dispatcher/AllTests.cpp index 48af9c3754d..9bb283b6a07 100644 --- a/cpp/test/Ice/dispatcher/AllTests.cpp +++ b/cpp/test/Ice/dispatcher/AllTests.cpp @@ -104,7 +104,11 @@ allTests(const Ice::CommunicatorPtr& communicator) Test::TestIntfControllerPrx testController = Test::TestIntfControllerPrx::uncheckedCast(obj); +#ifdef ICE_CPP11 + cout << "testing C++11 dispatcher... " << flush; +#else cout << "testing dispatcher... " << flush; +#endif { p->op(); diff --git a/cpp/test/Ice/dispatcher/Client.cpp b/cpp/test/Ice/dispatcher/Client.cpp index da86ee480af..8060023eeac 100644 --- a/cpp/test/Ice/dispatcher/Client.cpp +++ b/cpp/test/Ice/dispatcher/Client.cpp @@ -29,13 +29,24 @@ main(int argc, char* argv[]) { int status; Ice::CommunicatorPtr communicator; - + try { Ice::InitializationData initData; initData.properties = Ice::createProperties(argc, argv); +#ifdef ICE_CPP11 + Ice::DispatcherPtr dispatcher = new Dispatcher(); + initData.dispatcher = Ice::newDispatcher( + [=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn) + { + dispatcher->dispatch(call, conn); + }); +#else initData.dispatcher = new Dispatcher(); +#endif communicator = Ice::initialize(argc, argv, initData); + + status = run(argc, argv, communicator); } catch(const Ice::Exception& ex) diff --git a/cpp/test/Ice/dispatcher/Server.cpp b/cpp/test/Ice/dispatcher/Server.cpp index e517301982b..53e4ce4a359 100644 --- a/cpp/test/Ice/dispatcher/Server.cpp +++ b/cpp/test/Ice/dispatcher/Server.cpp @@ -50,7 +50,16 @@ main(int argc, char* argv[]) { Ice::InitializationData initData; initData.properties = Ice::createProperties(argc, argv); +#ifdef ICE_CPP11 + Ice::DispatcherPtr dispatcher = new Dispatcher(); + initData.dispatcher = Ice::newDispatcher( + [=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn) + { + dispatcher->dispatch(call, conn); + }); +#else initData.dispatcher = new Dispatcher(); +#endif communicator = Ice::initialize(argc, argv, initData); status = run(argc, argv, communicator); } diff --git a/cpp/test/Ice/info/Makefile.mak b/cpp/test/Ice/info/Makefile.mak index 683d8b5d0b8..bfafa223556 100644 --- a/cpp/test/Ice/info/Makefile.mak +++ b/cpp/test/Ice/info/Makefile.mak @@ -40,7 +40,7 @@ CPPFLAGS = -I. -I../../include $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN !if "$(WINRT)" != "yes" LD_TESTFLAGS = $(LD_EXEFLAGS) $(SETARGV) -LIBS = $(LIBS) icessl$(LIBSUFFIX).lib +LIBS = $(LIBS) icessl$(LIBSUFFIX).lib !else LD_TESTFLAGS = $(LD_DLLFLAGS) /export:dllMain !endif diff --git a/cpp/test/Ice/invoke/AllTests.cpp b/cpp/test/Ice/invoke/AllTests.cpp index b51ab5469a7..5b8cde9fc4b 100644 --- a/cpp/test/Ice/invoke/AllTests.cpp +++ b/cpp/test/Ice/invoke/AllTests.cpp @@ -155,6 +155,26 @@ public: test(false); } } + + void opStringPairNC(bool ok, const pair& outParams) + { + if(ok) + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + in->startEncapsulation(); + string s; + in->read(s); + test(s == testString); + in->read(s); + test(s == testString); + in->endEncapsulation(); + called(); + } + else + { + test(false); + } + } void opStringWC(bool ok, const Ice::ByteSeq& outParams, const CookiePtr& cookie) { @@ -201,6 +221,32 @@ public: } } } + + void opExceptionPairNC(bool ok, const pair& outParams) + { + if(ok) + { + test(false); + } + else + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + in->startEncapsulation(); + try + { + in->throwException(); + } + catch(const Test::MyException&) + { + in->endEncapsulation(); + called(); + } + catch(...) + { + test(false); + } + } + } void opExceptionWC(bool ok, const Ice::ByteSeq& outParams, const CookiePtr& cookie) { @@ -479,6 +525,59 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing asynchronous ice_invoke with C++11 style callbacks... " << flush; + + { + Ice::ByteSeq inEncaps, outEncaps; + Ice::OutputStreamPtr out = Ice::createOutputStream(communicator); + out->startEncapsulation(); + out->write(testString); + out->endEncapsulation(); + out->finished(inEncaps); + + CallbackPtr cb = new Callback(communicator, false); + Ice::Context ctx; + cl->begin_ice_invoke("opString", Ice::Normal, inEncaps, ctx, + [=](bool ret, const vector< ::Ice::Byte>& args) + { + cb->opStringNC(ret, args); + }); + cb->check(); + + cb = new Callback(communicator, false); + pair inPair(&inEncaps[0], &inEncaps[0] + inEncaps.size()); + cl->begin_ice_invoke("opString", Ice::Normal, inPair, + [=](bool ret, const pair& args) + { + cb->opStringPairNC(ret, args); + }); + cb->check(); + } + + { + Ice::ByteSeq inEncaps, outEncaps; + CallbackPtr cb = new Callback(communicator, false); + cl->begin_ice_invoke("opException", Ice::Normal, inEncaps, + [=](bool ret, const vector< ::Ice::Byte>& args) + { + cb->opExceptionNC(ret, args); + } + ); + cb->check(); + + pair inPair(static_cast< ::Ice::Byte*>(0), static_cast< ::Ice::Byte*>(0)); + cb = new Callback(communicator, false); + cl->begin_ice_invoke("opException", Ice::Normal, inPair, + [=](bool ret, const pair& args) + { + cb->opExceptionPairNC(ret, args); + }); + cb->check(); + } + + cout << "ok" << endl; +#endif return cl; } diff --git a/cpp/test/Ice/operations/OnewaysNewAMI.cpp b/cpp/test/Ice/operations/OnewaysNewAMI.cpp index 21127c66d3c..e82afcab5f9 100644 --- a/cpp/test/Ice/operations/OnewaysNewAMI.cpp +++ b/cpp/test/Ice/operations/OnewaysNewAMI.cpp @@ -85,7 +85,7 @@ onewaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& Test::MyClassPrx p = Test::MyClassPrx::uncheckedCast(proxy->ice_oneway()); { - CallbackPtr cb = new Callback; + CallbackPtr cb = new Callback; Ice::Callback_Object_ice_pingPtr callback = Ice::newCallback_Object_ice_ping(cb, &Callback::noException, &Callback::sent); p->begin_ice_ping(callback); @@ -159,4 +159,81 @@ onewaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& { } } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback; + p->begin_ice_ping(nullptr, + [=](const Ice::Exception& ex){ cb->noException(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + } + + { + try + { + p->begin_ice_isA(Test::MyClass::ice_staticId(), [=](bool){ test(false); }); + test(false); + } + catch(const IceUtil::IllegalArgumentException&) + { + } + } + + { + try + { + p->begin_ice_id([=](const string&){ test(false); }); + test(false); + } + catch(const IceUtil::IllegalArgumentException&) + { + } + } + + { + try + { + p->begin_ice_ids([=](const Ice::StringSeq&){ test(false); }); + test(false); + } + catch(const IceUtil::IllegalArgumentException&) + { + } + } + + { + CallbackPtr cb = new Callback; + p->begin_opVoid(nullptr, + [=](const Ice::Exception& ex){ cb->noException(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opIdempotent(nullptr, + [=](const Ice::Exception& ex){ cb->noException(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opNonmutating(nullptr, + [=](const Ice::Exception& ex){ cb->noException(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + } + + { + try + { + p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f), [=](const Ice::Byte&, const Ice::Byte&){ test(false); }); + test(false); + } + catch(const IceUtil::IllegalArgumentException&) + { + } + } +#endif } diff --git a/cpp/test/Ice/operations/TwowaysNewAMI.cpp b/cpp/test/Ice/operations/TwowaysNewAMI.cpp index 0b156c55651..212bc12d6fd 100644 --- a/cpp/test/Ice/operations/TwowaysNewAMI.cpp +++ b/cpp/test/Ice/operations/TwowaysNewAMI.cpp @@ -556,8 +556,6 @@ twowaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& } { - Ice::Double d = 1278312346.0 / 13.0; - Test::DoubleS ds(5, d); CallbackPtr cb = new Callback; Test::Callback_MyClass_opBytePtr callback = Test::newCallback_MyClass_opByte(cb, &Callback::opByte, @@ -566,16 +564,6 @@ twowaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& cb->check(); } - - { - CallbackPtr cb = new Callback; - Test::Callback_MyClass_opVoidPtr callback = Test::newCallback_MyClass_opVoid(cb, - &Callback::opVoid, - &Callback::exCB); - p->begin_opVoid(callback); - cb->check(); - } - { CallbackPtr cb = new Callback; Test::Callback_MyClass_opBoolPtr callback = Test::newCallback_MyClass_opBool(cb, @@ -1067,4 +1055,497 @@ twowaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& derived->begin_opDerived(callback); cb->check(); } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback; + p->begin_ice_ping([=](){ cb->ping(); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_ice_isA(Test::MyClass::ice_staticId(), [=](bool isA){ cb->isA(isA); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_ice_id([=](const string& id){ cb->id(id); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_ice_ids([=](const Ice::StringSeq& ids){ cb->ids(ids); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opVoid([=](){ cb->opVoid(); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f), + [=](const Ice::Byte& p1, const Ice::Byte& p2){ cb->opByte(p1, p2); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Test::Callback_MyClass_opBoolPtr callback = Test::newCallback_MyClass_opBool(cb, + &Callback::opBool, + &Callback::exCB); + p->begin_opBool(true, false, [=](bool p1, bool p2){ cb->opBool(p1, p2); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opShortIntLong(10, 11, 12, + [=](Ice::Long p1, Ice::Short p2, Ice::Int p3, Ice::Long p4){ cb->opShortIntLong(p1, p2, p3, p4); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opFloatDouble(Ice::Float(3.14), Ice::Double(1.1E10), + [=](Ice::Double p1, Ice::Float p2, Ice::Double p3){ cb->opFloatDouble(p1, p2, p3); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opString("hello", "world", + [=](const string& p1, const string& p2){ cb->opString(p1, p2); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opMyEnum(Test::enum2, + [=](Test::MyEnum p1, Test::MyEnum p2){ cb->opMyEnum(p1, p2); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback(communicator); + p->begin_opMyClass(p, + [=](const Test::MyClassPrx& p1, const Test::MyClassPrx p2, const Test::MyClassPrx p3) + { + cb->opMyClass(p1, p2, p3); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::Structure si1; + si1.p = p; + si1.e = Test::enum3; + si1.s.s = "abc"; + Test::Structure si2; + si2.p = 0; + si2.e = Test::enum2; + si2.s.s = "def"; + + CallbackPtr cb = new Callback(communicator); + p->begin_opStruct(si1, si2, + [=](const Test::Structure& p1, const Test::Structure& p2) + { + cb->opStruct(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::ByteS bsi1; + Test::ByteS bsi2; + + bsi1.push_back(Ice::Byte(0x01)); + bsi1.push_back(Ice::Byte(0x11)); + bsi1.push_back(Ice::Byte(0x12)); + bsi1.push_back(Ice::Byte(0x22)); + + bsi2.push_back(Ice::Byte(0xf1)); + bsi2.push_back(Ice::Byte(0xf2)); + bsi2.push_back(Ice::Byte(0xf3)); + bsi2.push_back(Ice::Byte(0xf4)); + + CallbackPtr cb = new Callback; + Test::Callback_MyClass_opByteSPtr callback = Test::newCallback_MyClass_opByteS(cb, + &Callback::opByteS, + &Callback::exCB); + p->begin_opByteS(bsi1, bsi2, + [=](const Test::ByteS& p1, const Test::ByteS& p2) + { + cb->opByteS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::BoolS bsi1; + Test::BoolS bsi2; + + bsi1.push_back(true); + bsi1.push_back(true); + bsi1.push_back(false); + + bsi2.push_back(false); + + CallbackPtr cb = new Callback; + p->begin_opBoolS(bsi1, bsi2, + [=](const Test::BoolS& p1, const Test::BoolS& p2) + { + cb->opBoolS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::ShortS ssi; + Test::IntS isi; + Test::LongS lsi; + + ssi.push_back(1); + ssi.push_back(2); + ssi.push_back(3); + + isi.push_back(5); + isi.push_back(6); + isi.push_back(7); + isi.push_back(8); + + lsi.push_back(10); + lsi.push_back(30); + lsi.push_back(20); + + CallbackPtr cb = new Callback; + p->begin_opShortIntLongS(ssi, isi, lsi, + [=](const Test::LongS& p1, const Test::ShortS& p2, const Test::IntS& p3, const Test::LongS& p4) + { + cb->opShortIntLongS(p1, p2, p3, p4); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::FloatS fsi; + Test::DoubleS dsi; + + fsi.push_back(Ice::Float(3.14)); + fsi.push_back(Ice::Float(1.11)); + + dsi.push_back(Ice::Double(1.1E10)); + dsi.push_back(Ice::Double(1.2E10)); + dsi.push_back(Ice::Double(1.3E10)); + + CallbackPtr cb = new Callback; + p->begin_opFloatDoubleS(fsi, dsi, + [=](const Test::DoubleS& p1, const Test::FloatS& p2, const Test::DoubleS& p3) + { + cb->opFloatDoubleS(p1, p2, p3); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::StringS ssi1; + Test::StringS ssi2; + + ssi1.push_back("abc"); + ssi1.push_back("de"); + ssi1.push_back("fghi"); + + ssi2.push_back("xyz"); + + CallbackPtr cb = new Callback; + p->begin_opStringS(ssi1, ssi2, + [=](const Test::StringS& p1, const Test::StringS& p2) + { + cb->opStringS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::ByteSS bsi1; + bsi1.resize(2); + Test::ByteSS bsi2; + bsi2.resize(2); + + bsi1[0].push_back(Ice::Byte(0x01)); + bsi1[0].push_back(Ice::Byte(0x11)); + bsi1[0].push_back(Ice::Byte(0x12)); + bsi1[1].push_back(Ice::Byte(0xff)); + + bsi2[0].push_back(Ice::Byte(0x0e)); + bsi2[1].push_back(Ice::Byte(0xf2)); + bsi2[1].push_back(Ice::Byte(0xf1)); + + CallbackPtr cb = new Callback; + p->begin_opByteSS(bsi1, bsi2, + [=](const Test::ByteSS& p1, const Test::ByteSS& p2) + { + cb->opByteSS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::FloatSS fsi; + fsi.resize(3); + Test::DoubleSS dsi; + dsi.resize(1); + + fsi[0].push_back(Ice::Float(3.14)); + fsi[1].push_back(Ice::Float(1.11)); + + dsi[0].push_back(Ice::Double(1.1E10)); + dsi[0].push_back(Ice::Double(1.2E10)); + dsi[0].push_back(Ice::Double(1.3E10)); + + CallbackPtr cb = new Callback; + p->begin_opFloatDoubleSS(fsi, dsi, + [=](const Test::DoubleSS& p1, const Test::FloatSS& p2, const Test::DoubleSS& p3) + { + cb->opFloatDoubleSS(p1, p2, p3); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::StringSS ssi1; + ssi1.resize(2); + Test::StringSS ssi2; + ssi2.resize(3); + + ssi1[0].push_back("abc"); + ssi1[1].push_back("de"); + ssi1[1].push_back("fghi"); + + ssi2[2].push_back("xyz"); + + CallbackPtr cb = new Callback; + p->begin_opStringSS(ssi1, ssi2, + [=](const Test::StringSS& p1, const Test::StringSS& p2) + { + cb->opStringSS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::ByteBoolD di1; + di1[10] = true; + di1[100] = false; + Test::ByteBoolD di2; + di2[10] = true; + di2[11] = false; + di2[101] = true; + + CallbackPtr cb = new Callback; + p->begin_opByteBoolD(di1, di2, + [=](const Test::ByteBoolD& p1, const Test::ByteBoolD& p2) + { + cb->opByteBoolD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::ShortIntD di1; + di1[110] = -1; + di1[1100] = 123123; + Test::ShortIntD di2; + di2[110] = -1; + di2[111] = -100; + di2[1101] = 0; + + CallbackPtr cb = new Callback; + p->begin_opShortIntD(di1, di2, + [=](const Test::ShortIntD& p1, const Test::ShortIntD& p2) + { + cb->opShortIntD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::LongFloatD di1; + di1[999999110] = Ice::Float(-1.1); + di1[999999111] = Ice::Float(123123.2); + Test::LongFloatD di2; + di2[999999110] = Ice::Float(-1.1); + di2[999999120] = Ice::Float(-100.4); + di2[999999130] = Ice::Float(0.5); + + CallbackPtr cb = new Callback; + p->begin_opLongFloatD(di1, di2, + [=](const Test::LongFloatD& p1, const Test::LongFloatD& p2) + { + cb->opLongFloatD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::StringStringD di1; + di1["foo"] = "abc -1.1"; + di1["bar"] = "abc 123123.2"; + Test::StringStringD di2; + di2["foo"] = "abc -1.1"; + di2["FOO"] = "abc -100.4"; + di2["BAR"] = "abc 0.5"; + + CallbackPtr cb = new Callback; + p->begin_opStringStringD(di1, di2, + [=](const Test::StringStringD& p1, const Test::StringStringD& p2) + { + cb->opStringStringD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::StringMyEnumD di1; + di1["abc"] = Test::enum1; + di1[""] = Test::enum2; + Test::StringMyEnumD di2; + di2["abc"] = Test::enum1; + di2["qwerty"] = Test::enum3; + di2["Hello!!"] = Test::enum2; + + CallbackPtr cb = new Callback; + p->begin_opStringMyEnumD(di1, di2, + [=](const Test::StringMyEnumD& p1, const Test::StringMyEnumD& p2) + { + cb->opStringMyEnumD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::MyStruct s11 = { 1, 1 }; + Test::MyStruct s12 = { 1, 2 }; + Test::MyStructMyEnumD di1; + di1[s11] = Test::enum1; + di1[s12] = Test::enum2; + + Test::MyStruct s22 = { 2, 2 }; + Test::MyStruct s23 = { 2, 3 }; + Test::MyStructMyEnumD di2; + di2[s11] = Test::enum1; + di2[s22] = Test::enum3; + di2[s23] = Test::enum2; + + CallbackPtr cb = new Callback; + p->begin_opMyStructMyEnumD(di1, di2, + [=](const Test::MyStructMyEnumD& p1, const Test::MyStructMyEnumD& p2) + { + cb->opMyStructMyEnumD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + const int lengths[] = { 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 }; + + for(unsigned int l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l) + { + Test::IntS s; + for(int i = 0; i < lengths[l]; ++i) + { + s.push_back(i); + } + CallbackPtr cb = new Callback; + p->begin_opIntS(s, + [=](const Test::IntS& p1) + { + cb->opIntS(p1); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + } + + { + Ice::Double d = 1278312346.0 / 13.0; + Test::DoubleS ds(5, d); + CallbackPtr cb = new Callback; + p->begin_opDoubleMarshaling(d, ds, + [=](){ cb->opDoubleMarshaling(); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Test::Callback_MyClass_opIdempotentPtr callback = + Test::newCallback_MyClass_opIdempotent(cb, &Callback::opIdempotent, &Callback::exCB); + p->begin_opIdempotent([=](){ cb->opIdempotent(); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opNonmutating([=](){ cb->opNonmutating(); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::MyDerivedClassPrx derived = Test::MyDerivedClassPrx::checkedCast(p); + test(derived); + CallbackPtr cb = new Callback; + derived->begin_opDerived([=](){ cb->opDerived(); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } +#endif } diff --git a/cpp/test/IceUtil/unicode/Client.cpp b/cpp/test/IceUtil/unicode/Client.cpp index 0e9881deec5..c2184556ca7 100644 --- a/cpp/test/IceUtil/unicode/Client.cpp +++ b/cpp/test/IceUtil/unicode/Client.cpp @@ -13,6 +13,8 @@ #ifdef _WIN32 # include +#else +# include #endif using namespace IceUtil; @@ -209,9 +211,9 @@ main(int argc, char* argv[]) test(fd > 0); #if defined(_MSC_VER) test(_close(fd) == 0); -#else - test(close(fd) == 0); -#endif +# else + test(::close(fd) == 0); +# endif FILE* f = IceUtilInternal::fopen(filepath, "r"); test(f != 0); -- cgit v1.2.3