summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2012-08-10 23:53:37 +0200
committerJose <jose@zeroc.com>2012-08-10 23:53:37 +0200
commit1d5c04bb8c0e786a717e36467e17f34bcc4f1d95 (patch)
treec1c91f034589260e97033131061d536ecfc2b9cb /cpp/demo/Ice
parentICE-4702 - Poor hash algorithm (diff)
downloadice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.tar.bz2
ice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.tar.xz
ice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.zip
C++11 ami lambda support
Diffstat (limited to 'cpp/demo/Ice')
-rw-r--r--cpp/demo/Ice/winrt/bidir/App.xaml.cpp11
-rw-r--r--cpp/demo/Ice/winrt/bidir/App.xaml.h10
-rw-r--r--cpp/demo/Ice/winrt/bidir/MainPage.xaml.cpp49
-rw-r--r--cpp/demo/Ice/winrt/bidir/MainPage.xaml.h64
-rw-r--r--cpp/demo/Ice/winrt/bidir/bidir.vcxproj4
-rw-r--r--cpp/demo/Ice/winrt/hello/App.xaml.cpp10
-rw-r--r--cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp172
-rw-r--r--cpp/demo/Ice/winrt/hello/MainPage.xaml.h69
8 files changed, 173 insertions, 216 deletions
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();
}
-/// <summary>
-/// Invoked when this page is about to be displayed in a Frame.
-/// </summary>
-/// <param name="e">Event data that describes how this page was reached. The Parameter
-/// property is typically used to configure the page.</param>
-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;
- };
-
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- 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 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
- <SDKReference Include="IceWinRT, Version=3.4" />
+ <Text Include="README.txt" />
</ItemGroup>
<ItemGroup>
- <Text Include="README.txt" />
+ <SDKReference Include="IceWinRT, Version=3.4" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
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);
}
-/// <summary>
-/// Invoked when this page is about to be displayed in a Frame.
-/// </summary>
-/// <param name="e">Event data that describes how this page was reached. The Parameter
-/// property is typically used to configure the page.</param>
-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<int>(delay->Value * 1000), cb);
+ _response = false;
+ hello->IsEnabled = false;
+ int deliveryMode = mode->SelectedIndex;
+ Ice::AsyncResultPtr result = prx->begin_sayHello(static_cast<int>(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<HelloCallback> HelloCallbackPtr;
-
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- 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;
- };
}