diff options
author | Benoit Foucher <benoit@zeroc.com> | 2015-02-09 12:08:59 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2015-02-09 12:08:59 +0100 |
commit | 0ed6d032265bb1b27b35a4e60c6fb8eacdcbb86c (patch) | |
tree | b18264b937cdee7ff733b1917c7d625189f4dca2 /cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp | |
parent | Fixed bug in testsuite which would cause a crash on test failure (diff) | |
download | ice-0ed6d032265bb1b27b35a4e60c6fb8eacdcbb86c.tar.bz2 ice-0ed6d032265bb1b27b35a4e60c6fb8eacdcbb86c.tar.xz ice-0ed6d032265bb1b27b35a4e60c6fb8eacdcbb86c.zip |
Added IceDiscovery support to WinRT hello demo
Diffstat (limited to 'cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp')
-rw-r--r-- | cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp b/cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp index e33b0369d64..0156dfba8b2 100644 --- a/cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp +++ b/cpp/demo/Ice/winrt/hello/MainPage.xaml.cpp @@ -31,6 +31,8 @@ MainPage::MainPage() InitializeComponent(); mode->SelectedIndex = 0; Ice::InitializationData id; + id.properties = Ice::createProperties(); + id.properties->setProperty("Ice.Plugin.IceDiscovery", "1"); // Enable the IceDiscovery plugin id.dispatcher = Ice::newDispatcher( [=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr&) { @@ -53,14 +55,23 @@ hello::MainPage::updateProxy() } string h = IceUtil::wstringToString(hostname->Text->Data()); - if (h.empty()) + if (h.empty() && !useDiscovery->IsChecked->Value) { print("Host is empty."); _helloPrx = 0; return; } - Ice::ObjectPrx prx = _communicator->stringToProxy("hello:tcp -h " + h + " -p 10000:ssl -h " + h + - " -p 10001:udp -h " + h + " -p 10000"); + Ice::ObjectPrx prx; + if (useDiscovery->IsChecked->Value) + { + prx = _communicator->stringToProxy("hello"); + } + else + { + prx = _communicator->stringToProxy("hello:tcp -h " + h + " -p 10000:ssl -h " + h + + " -p 10001:udp -h " + h + " -p 10000"); + } + switch(mode->SelectedIndex) { case 0: @@ -156,6 +167,20 @@ hello::MainPage::hello_Click(Platform::Object^ sender, Windows::UI::Xaml::Routed }, [=](bool sentSynchronously) { + if(_helloPrx) + { + Ice::ConnectionPtr con = _helloPrx->ice_getCachedConnection(); + if(con) + { + Ice::IPConnectionInfoPtr info = + Ice::IPConnectionInfoPtr::dynamicCast(con->getInfo()); + if(info) + { + hostname->Text = ref new String( + IceUtil::stringToWstring(info->remoteAddress).c_str()); + } + } + } if(this->_response) { return; // Response was received already. @@ -276,7 +301,7 @@ MainPage::timeout_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Cont void MainPage::hostname_TextChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::TextChangedEventArgs^ e) { - if (hostname->Text->Length() == 0) + if (hostname->Text->Length() == 0 && !useDiscovery->IsChecked->Value) { hello->IsEnabled = false; shutdown->IsEnabled = false; @@ -291,8 +316,25 @@ MainPage::hostname_TextChanged(Platform::Object^ sender, Windows::UI::Xaml::Cont updateProxy(); } +void hello::MainPage::useDiscovery_Changed(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + if (useDiscovery->IsChecked->Value) + { + hostname->Text = ""; + hostname->IsEnabled = false; + } + else + { + hostname->Text = "127.0.0.1"; + hostname->IsEnabled = true; + } + updateProxy(); +} + void MainPage::print(const std::string& message) { output->Text = ref new String(IceUtil::stringToWstring(message).c_str()); } + + |