From 9e71a6bb6711d0f4deb9f7948b609356c8828803 Mon Sep 17 00:00:00 2001 From: atraczyk <andreastraczyk@gmail.com> Date: Fri, 18 Nov 2016 17:00:15 -0500 Subject: [PATCH] internal: re-order daemon initialization Change-Id: I63ee3b20f6d007fb32cc2a94608c44ae89b2ac08 Tuleap: #790 --- MainPage.xaml.cpp | 29 ++++++++++++++--------------- RingD.cpp | 30 ++++++++++++++++++++++++++---- RingD.h | 12 ++++++++++++ SmartPanel.xaml | 36 +++++++++++++++++++----------------- SmartPanel.xaml.cpp | 36 ++++++++++++++++++++++++++---------- SmartPanel.xaml.h | 4 ++-- Wizard.xaml.cpp | 7 +------ 7 files changed, 100 insertions(+), 54 deletions(-) diff --git a/MainPage.xaml.cpp b/MainPage.xaml.cpp index 191002e..c971a68 100644 --- a/MainPage.xaml.cpp +++ b/MainPage.xaml.cpp @@ -25,8 +25,6 @@ #include "PreviewPage.xaml.h" #include "WelcomePage.xaml.h" -#include "gnutls\gnutls.h" - #include "MainPage.xaml.h" using namespace RingClientUWP; @@ -133,10 +131,7 @@ RingClientUWP::MainPage::showFrame(Windows::UI::Xaml::Controls::Frame^ frame) void RingClientUWP::MainPage::OnNavigatedTo(NavigationEventArgs ^ e) { - gnutls_global_init(); - RingD::instance->registerCallbacks(); - RingD::instance->initDaemon( DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG ); - Video::VideoManager::instance->captureManager()->EnumerateWebcamsAsync(); + RingD::instance->init(); showLoadingOverlay(true, false); } @@ -334,13 +329,18 @@ MainPage::Application_VisibilityChanged(Object^ sender, VisibilityChangedEventAr } else if (vcm->isSettingsPreviewing) { vcm->CleanupCameraAsync() - .then([=](task<void> cleanupTask){ - cleanupTask.get(); - CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync( - CoreDispatcherPriority::High, ref new DispatchedHandler([=]() - { - vcm->InitializeCameraAsync(true); - })); + .then([=](task<void> cleanupCameraTask) { + try { + cleanupCameraTask.get(); + CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync( + CoreDispatcherPriority::High, ref new DispatchedHandler([=]() + { + vcm->InitializeCameraAsync(true); + })); + } + catch (Exception^ e) { + WriteException(e); + } }); } } @@ -416,8 +416,7 @@ MainPage::BeginExtendedExecution() RingDebug::instance->WriteLine("Clean up camera..."); Video::VideoManager::instance->captureManager()->CleanupCameraAsync(); RingDebug::instance->WriteLine("Hang up calls..."); - DRing::fini(); - gnutls_global_init(); + RingD::instance->deinit(); break; default: diff --git a/RingD.cpp b/RingD.cpp index c0fec34..851ef94 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -252,8 +252,6 @@ void RingClientUWP::RingD::placeCall(Contact^ contact) auto callId2 = DRing::placeCall(accountId2, to2); - - if (callId2.empty()) { WNG_("call not created, the daemon didn't return a call Id"); return; @@ -673,6 +671,32 @@ RingD::registerCallbacks() registerConfHandlers(nameRegistrationHandlers); } +void +RingD::init() +{ + if (daemonInitialized_) { + CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, + ref new DispatchedHandler([=]() { + finishCaptureDeviceEnumeration(); + })); + return; + } + + gnutls_global_init(); + RingD::instance->registerCallbacks(); + RingD::instance->initDaemon( DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG ); + Video::VideoManager::instance->captureManager()->EnumerateWebcamsAsync(); + + daemonInitialized_ = true; +} + +void +RingD::deinit() +{ + DRing::fini(); + gnutls_global_deinit(); +} + void RingD::initDaemon(int flags) { @@ -1099,7 +1123,5 @@ Vector<String^>^ RingClientUWP::RingD::translateKnownRingDevices(const std::map< devicesList->Append(deviceName); } - - return devicesList; } diff --git a/RingD.h b/RingD.h index 520139e..3a405ff 100644 --- a/RingD.h +++ b/RingD.h @@ -59,6 +59,14 @@ public: } } + property bool daemonInitialized + { + bool get() + { + return daemonInitialized_; + } + } + property bool daemonRunning { bool get() @@ -66,6 +74,7 @@ public: return daemonRunning_; } } + property StartingStatus _startingStatus; void cancelOutGoingCall2(String^ callId); // marche @@ -85,6 +94,8 @@ internal: void registerCallbacks(); void initDaemon(int flags); void startDaemon(); + void init(); + void deinit(); void reloadAccountList(); void sendAccountTextMessage(String^ message); void sendSIPTextMessage(String^ message); @@ -209,6 +220,7 @@ private: Windows::UI::Core::CoreDispatcher^ dispatcher; std::string localFolder_; + bool daemonInitialized_ = false; bool daemonRunning_ = false; std::queue<Task^> tasksList_; StartingStatus startingStatus_ = StartingStatus::NORMAL; diff --git a/SmartPanel.xaml b/SmartPanel.xaml index ea5421c..c0095cb 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -441,12 +441,12 @@ Style="{StaticResource ToggleButtonStyle1}"/> </StackPanel> </StackPanel> - <ToggleButton x:Name="_settingsTBtn_" + <ToggleButton x:Name="_settingsMenuButton_" Grid.Column="2" VerticalAlignment="Bottom" Content="" - Checked="_settings__Checked" - Unchecked="_settings__Unchecked" + Checked="_settingsMenu__Checked" + Unchecked="_settingsMenu__Unchecked" Style="{StaticResource ToggleButtonStyle1}"/> </Grid> @@ -1068,33 +1068,35 @@ ItemTemplate="{StaticResource SmartPanelItemsTemplate}"/> </Grid> <!-- settings. --> - <Grid x:Name="_settings_" + <Grid x:Name="_settingsMenu_" Grid.Row="0" Visibility="Collapsed"> <Grid.RowDefinitions> <RowDefinition Height="*"/> </Grid.RowDefinitions> - <Grid x:Name="_videoSettings_" + <ScrollViewer> + <Grid x:Name="_videoSettings_" Grid.Row="0"> - <StackPanel Margin="10"> - <TextBlock Text="Video Device" + <StackPanel Margin="10"> + <TextBlock Text="Video Device" Margin="10"/> - <ComboBox x:Name="_videoDeviceComboBox_" + <ComboBox x:Name="_videoDeviceComboBox_" Margin="10" SelectionChanged="_videoDeviceComboBox__SelectionChanged"> - </ComboBox> - <TextBlock Text="Video Resolution" Margin="10"/> - <ComboBox x:Name="_videoResolutionComboBox_" + </ComboBox> + <TextBlock Text="Video Resolution" Margin="10"/> + <ComboBox x:Name="_videoResolutionComboBox_" Margin="10" SelectionChanged="_videoResolutionComboBox__SelectionChanged"> - </ComboBox> - <TextBlock Text="Video Rate" Margin="10"/> - <ComboBox x:Name="_videoRateComboBox_" + </ComboBox> + <TextBlock Text="Video Rate" Margin="10"/> + <ComboBox x:Name="_videoRateComboBox_" Margin="10" SelectionChanged="_videoRateComboBox__SelectionChanged"> - </ComboBox> - </StackPanel> - </Grid> + </ComboBox> + </StackPanel> + </Grid> + </ScrollViewer> </Grid> </Grid> </Grid> diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 811415a..bbc88fb 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -193,6 +193,8 @@ void RingClientUWP::Views::SmartPanel::unselectContact() void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) { + _settingsMenu__Unchecked(nullptr,nullptr); + _settingsMenuButton_->IsChecked = false; _shareMenuButton_->IsChecked = false; _devicesMenuButton_->IsChecked = false; _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; @@ -208,10 +210,16 @@ void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ se _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; } -void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) +void RingClientUWP::Views::SmartPanel::_settingsMenu__Checked(Object^ sender, RoutedEventArgs^ e) { + _accountsMenuButton__Unchecked(nullptr,nullptr); + _accountsMenuButton_->IsChecked = false; + _shareMenuButton__Unchecked(nullptr,nullptr); + _shareMenuButton_->IsChecked = false; + _devicesMenuButton__Unchecked(nullptr,nullptr); + _devicesMenuButton_->IsChecked = false; _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Visible; auto vcm = Video::VideoManager::instance->captureManager(); if (!vcm->isInitialized) vcm->InitializeCameraAsync(true); @@ -220,9 +228,9 @@ void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, Routed summonPreviewPage(); } -void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) +void RingClientUWP::Views::SmartPanel::_settingsMenu__Unchecked(Object^ sender, RoutedEventArgs^ e) { - _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; Video::VideoManager::instance->captureManager()->StopPreviewAsync() .then([](task<void> stopPreviewTask) @@ -257,13 +265,16 @@ void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel: _selectedAccountAvatarContainer_->Width = _selectedAccountAvatarContainer_->Height; _shaderPhotoboothIcon_->Width = _shaderPhotoboothIcon_->Height; - _settingsTBtn_->IsChecked = false; + _settingsMenuButton_->IsChecked = false; _accountsMenuButton_->IsChecked = false; _shareMenuButton_->IsChecked = false; + _devicesMenuButton_->IsChecked = false; } void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { + _settingsMenu__Unchecked(nullptr,nullptr); + _settingsMenuButton_->IsChecked = false; _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; @@ -329,8 +340,6 @@ void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _accountsMenuButton__Checked(nullptr, nullptr); - - } @@ -547,8 +556,8 @@ void RingClientUWP::Views::SmartPanel::generateQRcode() for (int u = 0 ; u < widthBitmap ; u++) { for (int v = 0; v < widthBitmap; v++) { - int x = (float)u / (float)widthBitmap * (float)widthQrCode; - int y = (float)v / (float)widthBitmap * (float)widthQrCode; + int x = static_cast<int>((float)u / (float)widthBitmap * (float)widthQrCode); + int y = static_cast<int>((float)v / (float)widthBitmap * (float)widthQrCode); auto currPixelRow = desc.StartIndex + desc.Stride * u + BYTES_PER_PIXEL * v; row = (p + (y * widthQrCode)); @@ -774,6 +783,9 @@ void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Unchecked(Platform::O void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { + _settingsMenu__Unchecked(nullptr,nullptr); + _settingsMenuButton_->IsChecked = false; + _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Visible; _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; @@ -1345,7 +1357,11 @@ SmartPanel::_videoRateComboBox__SelectionChanged(Platform::Object^ sender, Windo .then([=](task<void> cleanupCameraTask) { try { cleanupCameraTask.get(); - vcm->InitializeCameraAsync(true); + CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync( + CoreDispatcherPriority::High, ref new DispatchedHandler([=]() + { + vcm->InitializeCameraAsync(true); + })); } catch (Exception^ e) { WriteException(e); diff --git a/SmartPanel.xaml.h b/SmartPanel.xaml.h index 4eb40cb..20f81af 100644 --- a/SmartPanel.xaml.h +++ b/SmartPanel.xaml.h @@ -101,8 +101,8 @@ private: /* functions */ void _accountsMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _accountsMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void _settings__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void _settings__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void _settingsMenu__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void _settingsMenu__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); diff --git a/Wizard.xaml.cpp b/Wizard.xaml.cpp index e87e2b6..75821e9 100644 --- a/Wizard.xaml.cpp +++ b/Wizard.xaml.cpp @@ -4,8 +4,6 @@ #include "MainPage.xaml.h" -#include "gnutls\gnutls.h" - using namespace RingClientUWP::Views; using namespace Concurrency; @@ -34,10 +32,7 @@ Wizard::Wizard() void RingClientUWP::Views::Wizard::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs ^ e) { - gnutls_global_init(); - RingD::instance->registerCallbacks(); - RingD::instance->initDaemon( DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG ); - Video::VideoManager::instance->captureManager()->EnumerateWebcamsAsync(); + RingD::instance->init(); } void -- GitLab