From 5fb4eb13230bf1c90c0f31760caaf5ec52adec95 Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 21 Sep 2017 08:45:10 +0200 Subject: Add support to set server address with UWP controller Added support set the server IP address to be use by the UWP servers. This allow to run UWP servers with clients from different platforms. --- cpp/test/uwp/controller/ViewController.xaml.cpp | 55 +++++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'cpp/test/uwp/controller/ViewController.xaml.cpp') diff --git a/cpp/test/uwp/controller/ViewController.xaml.cpp b/cpp/test/uwp/controller/ViewController.xaml.cpp index da938e00798..b1c8d682e54 100644 --- a/cpp/test/uwp/controller/ViewController.xaml.cpp +++ b/cpp/test/uwp/controller/ViewController.xaml.cpp @@ -101,14 +101,14 @@ class ProcessControllerI : public ProcessController { public: - ProcessControllerI(ViewController^, string); - virtual shared_ptr start(string, string, StringSeq, const Ice::Current&); + ProcessControllerI(ViewController^); + shared_ptr start(string, string, StringSeq, const Ice::Current&); virtual string getHost(string, bool, const Ice::Current&); private: ViewController^ _controller; - string _hostname; + string _host; }; class ControllerHelper @@ -315,9 +315,9 @@ ProcessI::terminate(const Ice::Current& current) return _helper->getOutput(); } -ProcessControllerI::ProcessControllerI(ViewController^ controller, string hostname) : +ProcessControllerI::ProcessControllerI(ViewController^ controller) : _controller(controller), - _hostname(hostname) + _host(_controller->getHost()) { } @@ -337,7 +337,7 @@ ProcessControllerI::start(string testSuite, string exe, StringSeq args, const Ic string ProcessControllerI::getHost(string, bool, const Ice::Current&) { - return _hostname; + return _host; } ControllerHelper::ControllerHelper(ViewController^ controller) @@ -357,8 +357,8 @@ ControllerHelper::ControllerHelper(ViewController^ controller) _communicator->stringToProxy("Util/ProcessControllerRegistry:tcp -h 127.0.0.1 -p 15001")); Ice::ObjectAdapterPtr adapter = _communicator->createObjectAdapterWithEndpoints("ControllerAdapter", ""); Ice::Identity ident = { "ProcessController", "UWP"}; - auto processController = Ice::uncheckedCast( - adapter->add(make_shared(controller, "127.0.0.1"), ident)); + auto processController = + Ice::uncheckedCast(adapter->add(make_shared(controller), ident)); adapter->activate(); registerProcessController(controller, adapter, registry, processController); @@ -390,6 +390,9 @@ ControllerHelper::registerProcessController(ViewController^ controller, { rethrow_exception(e); } + catch(const Ice::CommunicatorDestroyedException&) + { + } catch(const std::exception& ex) { ostringstream os; @@ -409,6 +412,14 @@ ControllerHelper::registerProcessController(ViewController^ controller, std::this_thread::sleep_for(2s); registerProcessController(controller, adapter, registry, processController); } + catch(const Ice::TimeoutException&) + { + std::this_thread::sleep_for(2s); + registerProcessController(controller, adapter, registry, processController); + } + catch(const Ice::CommunicatorDestroyedException&) + { + } catch(const std::exception& ex) { ostringstream os; @@ -428,6 +439,23 @@ static ControllerHelper* controllerHelper = 0; ViewController::ViewController() { InitializeComponent(); + auto hostnames = NetworkInformation::GetHostNames(); + ipv4Addresses->Items->Append("127.0.0.1"); + for(unsigned int i = 0; i < hostnames->Size; ++i) + { + auto hostname = hostnames->GetAt(i); + if(hostname->Type == Windows::Networking::HostNameType::Ipv4) + { + ipv4Addresses->Items->Append(hostname->RawName); + } + } + ipv4Addresses->SelectedIndex = 0; +} + +string +ViewController::getHost() const +{ + return Ice::wstringToString(ipv4Addresses->SelectedItem->ToString()->Data()); } void @@ -441,6 +469,17 @@ ViewController::OnNavigatedTo(NavigationEventArgs^) controllerHelper = new ControllerHelper(this); } +void +ViewController::Hostname_SelectionChanged(Platform::Object^, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^) +{ + if(controllerHelper) + { + delete controllerHelper; + controllerHelper = 0; + } + controllerHelper = new ControllerHelper(this); +} + void ViewController::println(const string& s) { -- cgit v1.2.3