From 19d8e62c16a73712226ee3f07a14d943a586d09f Mon Sep 17 00:00:00 2001 From: Denis Dolzhenko Date: Tue, 4 Jul 2017 13:01:46 +0300 Subject: [PATCH] Refactor AppControlLauncher class. Change-Id: Ia9ca75b7625852cb3b81154af8aebb6c886b8711 Signed-off-by: Denis Dolzhenko --- src/Common/AppControl/inc/AppControlHandle.h | 65 ++++++++++++++++++ .../AppControl/inc/AppControlLauncher.h | 31 +-------- src/Common/AppControl/inc/InputSelector.h | 2 - .../AppControl/src/AppControlHandle.cpp | 67 +++++++++++++++++++ .../AppControl/src/AppControlLauncher.cpp | 27 -------- src/Common/AppControl/src/InputSelector.cpp | 9 +-- 6 files changed, 135 insertions(+), 66 deletions(-) create mode 100644 src/Common/AppControl/inc/AppControlHandle.h create mode 100644 src/Common/AppControl/src/AppControlHandle.cpp diff --git a/src/Common/AppControl/inc/AppControlHandle.h b/src/Common/AppControl/inc/AppControlHandle.h new file mode 100644 index 0000000..a8fb00a --- /dev/null +++ b/src/Common/AppControl/inc/AppControlHandle.h @@ -0,0 +1,65 @@ +/* + * Copyright 2016 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AppControlHandle_h_ +#define AppControlHandle_h_ + +#include "AppControlUtils.h" + +namespace Msg { + + class AppControlLauncher; + + class AppControlHandle { + + friend class AppControlLauncher; + + public: + AppControlHandle(app_control_launch_mode_e launchMode = APP_CONTROL_LAUNCH_MODE_GROUP); + virtual ~AppControlHandle(); + + /** + *@brief Terminate launch request related with this handle. + */ + void terminate(); + + /** + *@brief Sends the launch request. + *@return bool is launch success, false otherwise + */ + bool launch(); + + /** + *@brief Returns internal handle to app_control_h + */ + operator app_control_h(); + + void setOperation(const char *operation); + void setUri(const char *uri); + void setLaunchMode(app_control_launch_mode_e mode); + + protected: + virtual void onReply(app_control_h request, app_control_h reply, app_control_result_e result) {}; + + AppControlHandle(const AppControlHandle&) = delete; + AppControlHandle& operator=(AppControlHandle) = delete; + + protected: + app_control_h m_Handle; + }; +} + +#endif /* AppControlHandle_h_ */ diff --git a/src/Common/AppControl/inc/AppControlLauncher.h b/src/Common/AppControl/inc/AppControlLauncher.h index a1ae444..8fa3075 100644 --- a/src/Common/AppControl/inc/AppControlLauncher.h +++ b/src/Common/AppControl/inc/AppControlLauncher.h @@ -17,40 +17,13 @@ #ifndef AppControlLauncher_h_ #define AppControlLauncher_h_ -#include "AppControlUtils.h" +#include "AppControlHandle.h" #include namespace Msg { - class AppControlLauncher; - class AppControlHandle { - friend class AppControlLauncher; - - public: - AppControlHandle(app_control_launch_mode_e launchMode = APP_CONTROL_LAUNCH_MODE_GROUP); - virtual ~AppControlHandle(); - - /** - *@brief Terminate launch request related with this handle. - */ - void terminate(); - - /** - *@brief Returns internal handle to app_control_h - */ - operator app_control_h(); - - protected: - virtual void onReply(app_control_h request, app_control_h reply, app_control_result_e result) {}; - - AppControlHandle(const AppControlHandle&) = delete; - AppControlHandle& operator=(AppControlHandle) = delete; - - protected: - app_control_h m_Handle; - }; - class AppControlLauncher { + friend class AppControlHandle; public: diff --git a/src/Common/AppControl/inc/InputSelector.h b/src/Common/AppControl/inc/InputSelector.h index 831afc4..653dec3 100644 --- a/src/Common/AppControl/inc/InputSelector.h +++ b/src/Common/AppControl/inc/InputSelector.h @@ -27,8 +27,6 @@ namespace Msg { InputSelector(); virtual ~InputSelector(); - bool launch(); - protected: virtual void onKeyboardReply(const std::string &text) {}; virtual void onVoiceReply(const std::string &text, const std::string &filePath) {}; diff --git a/src/Common/AppControl/src/AppControlHandle.cpp b/src/Common/AppControl/src/AppControlHandle.cpp new file mode 100644 index 0000000..9a6167a --- /dev/null +++ b/src/Common/AppControl/src/AppControlHandle.cpp @@ -0,0 +1,67 @@ +/* + * Copyright 2016 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AppControlHandle.h" +#include "AppControlLauncher.h" + +using namespace Msg; + +AppControlHandle::AppControlHandle(app_control_launch_mode_e launchMode) + : m_Handle() +{ + app_control_create(&m_Handle); + if (m_Handle) + setLaunchMode(launchMode); +} + +AppControlHandle::~AppControlHandle() +{ + if (m_Handle) { + terminate(); + app_control_destroy(m_Handle); + } +} + +AppControlHandle::operator app_control_h() +{ + return m_Handle; +} + +bool AppControlHandle::launch() +{ + return AppControlLauncher::getInst().launch(*this); +} + +void AppControlHandle::terminate() +{ + if (m_Handle && AppControlLauncher::getInst().m_pHandle == this) + AppControlLauncher::getInst().terminate(); +} + +void AppControlHandle::setOperation(const char *operation) +{ + app_control_set_operation(m_Handle, operation); +} + +void AppControlHandle::setUri(const char *uri) +{ + app_control_set_uri(m_Handle, uri); +} + +void AppControlHandle::setLaunchMode(app_control_launch_mode_e mode) +{ + app_control_set_launch_mode(m_Handle, mode); +} diff --git a/src/Common/AppControl/src/AppControlLauncher.cpp b/src/Common/AppControl/src/AppControlLauncher.cpp index 187bcfc..740eb43 100644 --- a/src/Common/AppControl/src/AppControlLauncher.cpp +++ b/src/Common/AppControl/src/AppControlLauncher.cpp @@ -20,33 +20,6 @@ using namespace Msg; -AppControlHandle::AppControlHandle(app_control_launch_mode_e launchMode) - : m_Handle() -{ - app_control_create(&m_Handle); - if (m_Handle) - app_control_set_launch_mode(m_Handle, launchMode); -} - -AppControlHandle::~AppControlHandle() -{ - if (m_Handle) { - terminate(); - app_control_destroy(m_Handle); - } -} - -AppControlHandle::operator app_control_h() -{ - return m_Handle; -} - -void AppControlHandle::terminate() -{ - if (m_Handle && AppControlLauncher::getInst().m_pHandle == this) - AppControlLauncher::getInst().terminate(); -} - AppControlLauncher::AppControlLauncher() : m_LaunchInProgress(false) , m_pTimer(nullptr) diff --git a/src/Common/AppControl/src/InputSelector.cpp b/src/Common/AppControl/src/InputSelector.cpp index e083ea1..eb8bd84 100644 --- a/src/Common/AppControl/src/InputSelector.cpp +++ b/src/Common/AppControl/src/InputSelector.cpp @@ -21,18 +21,13 @@ using namespace Msg; InputSelector::InputSelector() { - app_control_set_operation(m_Handle, APP_CONTROL_OPERATION_GET_INPUT); + setOperation(APP_CONTROL_OPERATION_GET_INPUT); } InputSelector::~InputSelector() { } -bool InputSelector::launch() -{ - return AppControlLauncher::getInst().launch(*this); -} - void InputSelector::onReply(app_control_h request, app_control_h reply, app_control_result_e result) { MSG_LOG("result = ", result); @@ -53,5 +48,3 @@ void InputSelector::onReply(app_control_h request, app_control_h reply, app_cont } } - - -- 2.34.1