From 8d0eca06feabf0fad65a10b0168f0a7455b57107 Mon Sep 17 00:00:00 2001 From: Young Ik Cho Date: Fri, 9 Aug 2013 21:18:44 +0900 Subject: [PATCH] use explicit template initialization Change-Id: Ifb496daf7d04bdbc059d2075102f154d76ff1f67 Signed-off-by: Young Ik Cho --- src/app/CMakeLists.txt | 1 + src/app/FApp_AppControlImpl.cpp | 9 +- src/app/FApp_AppControlManager.cpp | 6 ++ src/app/FApp_AppControlRegistry.cpp | 2 +- src/app/FApp_AppControlRegistry.h | 4 +- src/app/FApp_RequestManagerT.cpp | 169 +++++++++++++++++++++++++++++++++++ src/app/FApp_ServiceAppImpl.cpp | 2 +- src/app/inc/FApp_AppControlManager.h | 127 ++------------------------ src/app/inc/FApp_LaunchInfo.h | 145 ++++++++++++++++++++++++++++++ src/app/inc/FApp_RequestManagerT.h | 125 +++----------------------- 10 files changed, 346 insertions(+), 244 deletions(-) create mode 100644 src/app/FApp_RequestManagerT.cpp create mode 100644 src/app/inc/FApp_LaunchInfo.h diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 6ba1638..86c07e8 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -66,6 +66,7 @@ SET (${this_target}_SOURCE_FILES FApp_AppControlResponseEvent.cpp FApp_AppLifecycleEvent.cpp FApp_ActiveWindowManager.cpp + FApp_RequestManagerT.cpp ) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SINGLETON_CLEANUP -fvisibility=hidden") diff --git a/src/app/FApp_AppControlImpl.cpp b/src/app/FApp_AppControlImpl.cpp index 496370c..74205ff 100644 --- a/src/app/FApp_AppControlImpl.cpp +++ b/src/app/FApp_AppControlImpl.cpp @@ -25,11 +25,13 @@ #include +#include +#include #include #include #include -#include -#include +#include +#include #include #include @@ -63,9 +65,6 @@ static const int _REQ_ID_INVALID = -1; namespace Tizen { namespace App { -class IAppControlEventListener; -class IAppControlResponseListener; - const wchar_t TIZEN_OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main"; _AppControlImpl::_AppControlImpl(const AppControl& value) diff --git a/src/app/FApp_AppControlManager.cpp b/src/app/FApp_AppControlManager.cpp index 4e264ab..8a8730a 100644 --- a/src/app/FApp_AppControlManager.cpp +++ b/src/app/FApp_AppControlManager.cpp @@ -910,6 +910,12 @@ _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap) SysLog(NID_APP, "Exit."); } +void +_AppControlManager::RemoveResultRequest(int reqId) +{ + __resultManager.RemoveItem(reqId); +} + const _AppArg* _AppControlManager::FindResultRequest(int reqId) const { diff --git a/src/app/FApp_AppControlRegistry.cpp b/src/app/FApp_AppControlRegistry.cpp index 8bcb653..4e09423 100644 --- a/src/app/FApp_AppControlRegistry.cpp +++ b/src/app/FApp_AppControlRegistry.cpp @@ -291,7 +291,7 @@ CATCH: AppControl* -_AppControlRegistry::GetTizenAppControlN(const String& aId, const String& oId) +_AppControlRegistry::GetTizenAppControlN(const String& aId, const String& oId) const { int count = 0; const String* pAppId = &aId; diff --git a/src/app/FApp_AppControlRegistry.h b/src/app/FApp_AppControlRegistry.h index 8554d54..c9f8201 100644 --- a/src/app/FApp_AppControlRegistry.h +++ b/src/app/FApp_AppControlRegistry.h @@ -85,7 +85,7 @@ public: static _AppControlRegistry* GetInstance(void); - AppControl* GetTizenAppControlN(const Tizen::Base::String& aId, const Tizen::Base::String& oId); + AppControl* GetTizenAppControlN(const Tizen::Base::String& aId, const Tizen::Base::String& oId) const; AppControl* GetAppControlN(const Tizen::Base::String& appId, const Tizen::Base::String& operationId) const; @@ -121,7 +121,7 @@ private: AliasMapType __aliasAppId; - RuntimeAliasType __runtimeAlias; + mutable RuntimeAliasType __runtimeAlias; static _AppControlRegistry* __pSelf; }; // _AppControlRegistry diff --git a/src/app/FApp_RequestManagerT.cpp b/src/app/FApp_RequestManagerT.cpp new file mode 100644 index 0000000..1457e58 --- /dev/null +++ b/src/app/FApp_RequestManagerT.cpp @@ -0,0 +1,169 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// 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. +// + +/** + * @file FApp_RequestManagerT.cpp + * @brief This is the implementationfor the _RequestManagerT class. + */ + +#include + +#include "FApp_RequestManagerT.h" +#include "FApp_LaunchInfo.h" + + +namespace Tizen { namespace App +{ + +template +_RequestManagerT::_RequestManagerT(void) +: __reqId(-1) +{ + __requestList.Construct(); +} + +template +_RequestManagerT::~_RequestManagerT(void) +{ + RequestListEnumType* pIter = __requestList.GetMapEnumeratorN(); + if (pIter == null) + { + return; + } + + while (pIter->MoveNext() == E_SUCCESS) + { + T* pInfo = null; + result r = pIter->GetValue(pInfo); + + if (IsFailed(r)) + { + continue; + } + + delete pInfo; + } + + delete pIter; +} + +template int +_RequestManagerT::InsertItem(T* pItem) +{ + SysTryReturn(NID_APP, pItem != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument."); + +#if 0 + // [INFO] temporary disable due to OBS build system + __sync_add_and_fetch(&__reqId, 1); + + // [TODO] awkward implementation after overflow + // overflow detection + __sync_bool_compare_and_swap(&__reqId, INT_MAX, 1); +#else + __reqId++; + if (__reqId >= INT_MAX) + { + __reqId = 1; + } +#endif + SysLog(NID_APP, "Current request ID : %d.", __reqId); + + pItem->reqId = __reqId; + __requestList.Add(__reqId, pItem); + + return __reqId; +} + +template void +_RequestManagerT::RemoveItem(int reqId) +{ + T* pItem = FindItem(reqId); + if (pItem) + { + __requestList.Remove(reqId); + delete pItem; + } +} + +template void +_RequestManagerT::RemoveItem(T* pItem) +{ + RequestListEnumType* pIter = __requestList.GetMapEnumeratorN(); + if (pItem == null || pIter == null) + { + return; + } + + while (pIter->MoveNext() == E_SUCCESS) + { + T* pInfo = null; + result r = pIter->GetValue(pInfo); + + if (pInfo == pItem) + { + int id = -1; + r = pIter->GetKey(id); + if (r == E_SUCCESS) + { + __requestList.Remove(id); + } + + delete pItem; + delete pIter; + + return; + } + } + + delete pIter; +} + +template T* +_RequestManagerT::FindItem(int reqId) const +{ + T* pItem = null; + result r = __requestList.GetValue(reqId, pItem); + + return (r == E_SUCCESS) ? pItem : null; +} + + +// partial specialization +template<> void +_RequestManagerT<_ResultInfo>::RemoveItem(int reqId) +{ + // 1st request is launch request itself and do not remove it ever. + if (reqId == 0) + { + return; + } + + _ResultInfo* pItem = FindItem(reqId); + if (pItem) + { + __requestList.Remove(reqId); + delete pItem; + } +} + + +// explicit template initialization +template class _RequestManagerT<_LaunchInfo>; +template class _RequestManagerT<_InProcessInfo>; +template class _RequestManagerT<_ResultInfo>; + +} } // Tizen::App + diff --git a/src/app/FApp_ServiceAppImpl.cpp b/src/app/FApp_ServiceAppImpl.cpp index d4011cd..dd80c88 100644 --- a/src/app/FApp_ServiceAppImpl.cpp +++ b/src/app/FApp_ServiceAppImpl.cpp @@ -55,7 +55,7 @@ static const RequestId HANDLER_REQUEST_ALARMID = 2; namespace Tizen { namespace App { -static const wchar_t* ALARM_PLUGIN_LIBRARY_PATH = L"/opt/apps/aospd00043/lib/libosp-cond-alarm.so"; +static const wchar_t* ALARM_PLUGIN_LIBRARY_PATH = L"/opt/usr/apps/aospd00043/lib/libosp-cond-alarm.so"; typedef void (*OnAlarmForLaunch)(int alarmId); _ServiceAppImpl* _ServiceAppImpl::__pServiceAppImpl = null; diff --git a/src/app/inc/FApp_AppControlManager.h b/src/app/inc/FApp_AppControlManager.h index 38c0246..002c73b 100644 --- a/src/app/inc/FApp_AppControlManager.h +++ b/src/app/inc/FApp_AppControlManager.h @@ -27,11 +27,8 @@ #include #include #include -#include #include #include -#include -#include #include #include "FApp_Types.h" @@ -41,14 +38,11 @@ #include "FApp_IAppManagerServiceEventListener.h" #include "FApp_RequestManagerT.h" #include "FApp_IAppControlResponseEventListener.h" +#include "FApp_LaunchInfo.h" namespace Tizen { namespace Base { class String; -namespace Runtime -{ -class _LibraryImpl; -} namespace Collection { class IMap; @@ -72,123 +66,14 @@ class _IAppManagerEventListener; class _AppManagerEventArg; class _AppMessageImpl; class _AppControlResponseEvent; - -typedef result (*LaunchCbType)(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId); +class IAppControlEventListener; +class IAppControlResponseListener; typedef void (*AppSvcResFn)(void* b, int requestCode, service_result_e res, void* data); -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// _LaunchInfo handles the launch request from this process -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -const long LAUNCH_INFO_MAGIC = 0x494C; const int RESPONSE_EVENT_REQID_MAGIC = 65536; -class _LaunchInfo -{ -public: - _LaunchInfo(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop) - : magic(LAUNCH_INFO_MAGIC) - , reqId(-1) - , pArg(pArg) - , launchCb(pCb) - , pUserData(pData) - , property(prop) - { - } - - ~_LaunchInfo(void); - -private: - _LaunchInfo(const _LaunchInfo& rhs); - _LaunchInfo& operator =(const _LaunchInfo& rhs); - -public: - const long magic; - int reqId; - _AppArg* pArg; - const LaunchCbType launchCb; - void* pUserData; - int property; -}; // _LaunchInfo - - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// _InAppRequestManager manges In-process AppControl request -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -struct _InProcessInfo -{ -public: - _InProcessInfo(const Tizen::Base::String& aId, const Tizen::Base::String& oId, int prop, bool legacy, Tizen::Base::Runtime::_LibraryImpl& lib, Tizen::Base::Runtime::IEventListener* pListener) - : reqId(-1) - , providerId(aId) - , operationId(oId) - , property(prop) - , pLib(&lib) - , pListener(pListener) - , isLegacy(legacy) - { - } - - ~_InProcessInfo(void); - -private: - _InProcessInfo(const _InProcessInfo& rhs); - _InProcessInfo& operator =(const _InProcessInfo& rhs); - -public: - int reqId; - const Tizen::Base::String providerId; - const Tizen::Base::String operationId; - const int property; - Tizen::Base::Runtime::_LibraryImpl* pLib; // non-empty - Tizen::Base::Runtime::IEventListener* pListener; - bool isLegacy; -}; // _InProcessInfo - - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// _RequestManager manges out-of-process launch request and handles the return arguments -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -class _ResultInfo -{ -public: - _ResultInfo(_AppArg& arg) - : reqId(-1) - , arg(arg) - { - } - - ~_ResultInfo(void) - { - } - -private: - _ResultInfo(const _ResultInfo& rhs); - _ResultInfo& operator =(const _ResultInfo& rhs); - -public: - int reqId; - _AppArg& arg; -}; // _ResultInfo - -// partial specialization -template<> inline void _RequestManagerT<_ResultInfo>::RemoveItem(int reqId) -{ - // 1st request is launch request itself and do not remove it ever. - if (reqId == 0) - { - return; - } - - _ResultInfo* pItem = FindItem(reqId); - if (pItem) - { - __requestList.Remove(reqId); - delete pItem; - } -} - class _OSP_EXPORT_ _AppControlManager : public Tizen::Base::Object @@ -238,12 +123,10 @@ public: _OSP_LOCAL_ result SendAppControlEvent(Tizen::Base::Runtime::IEventArg& arg); _OSP_LOCAL_ Tizen::Base::Collection::IMapT* GetAppControlResponseEventContainer(void); + _OSP_LOCAL_ result RegisterRequest(service_s* service, int& req, _AppHandler& handler); - _OSP_LOCAL_ void RemoveResultRequest(int reqId) - { - __resultManager.RemoveItem(reqId); - } + _OSP_LOCAL_ void RemoveResultRequest(int reqId); const _AppArg* FindResultRequest(int reqId) const; diff --git a/src/app/inc/FApp_LaunchInfo.h b/src/app/inc/FApp_LaunchInfo.h new file mode 100644 index 0000000..e8f6251 --- /dev/null +++ b/src/app/inc/FApp_LaunchInfo.h @@ -0,0 +1,145 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// 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. +// + +/** + * @file FApp_LaunchInfo.h + * @brief This is the header file for the _LaunchInfo class. + */ + +#ifndef _FAPP_INTERNAL_LAUNCH_INFO_H_ +#define _FAPP_INTERNAL_LAUNCH_INFO_H_ + +#include + +#include +#include +#include +#include + +namespace Tizen { namespace Base +{ +namespace Runtime +{ +class _LibraryImpl; +class IEventListener; +} +}} + +namespace Tizen { namespace App +{ + +class _AppArg; + +typedef result (*LaunchCbType)(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId); + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// _LaunchInfo handles the launch request from this process +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +const long LAUNCH_INFO_MAGIC = 0x494C; + +class _LaunchInfo +{ +public: + _LaunchInfo(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop) + : magic(LAUNCH_INFO_MAGIC) + , reqId(-1) + , pArg(pArg) + , launchCb(pCb) + , pUserData(pData) + , property(prop) + { + } + + ~_LaunchInfo(void); + +private: + _LaunchInfo(const _LaunchInfo& rhs); + _LaunchInfo& operator =(const _LaunchInfo& rhs); + +public: + const long magic; + int reqId; + _AppArg* pArg; + const LaunchCbType launchCb; + void* pUserData; + int property; +}; // _LaunchInfo + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// _InAppRequestManager manges In-process AppControl request +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +struct _InProcessInfo +{ +public: + _InProcessInfo(const Tizen::Base::String& aId, const Tizen::Base::String& oId, int prop, bool legacy, Tizen::Base::Runtime::_LibraryImpl& lib, Tizen::Base::Runtime::IEventListener* pListener) + : reqId(-1) + , providerId(aId) + , operationId(oId) + , property(prop) + , pLib(&lib) + , pListener(pListener) + , isLegacy(legacy) + { + } + + ~_InProcessInfo(void); + +private: + _InProcessInfo(const _InProcessInfo& rhs); + _InProcessInfo& operator =(const _InProcessInfo& rhs); + +public: + int reqId; + const Tizen::Base::String providerId; + const Tizen::Base::String operationId; + const int property; + Tizen::Base::Runtime::_LibraryImpl* pLib; // non-empty + Tizen::Base::Runtime::IEventListener* pListener; + bool isLegacy; +}; // _InProcessInfo + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// _RequestManager manges out-of-process launch request and handles the return arguments +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class _ResultInfo +{ +public: + _ResultInfo(_AppArg& arg) + : reqId(-1) + , arg(arg) + { + } + + ~_ResultInfo(void) + { + } + +private: + _ResultInfo(const _ResultInfo& rhs); + _ResultInfo& operator =(const _ResultInfo& rhs); + +public: + int reqId; + _AppArg& arg; +}; // _ResultInfo + + +}} // Tizen::App + +#endif // _FAPP_INTERNAL_LAUNCH_INFO_H_ diff --git a/src/app/inc/FApp_RequestManagerT.h b/src/app/inc/FApp_RequestManagerT.h index 7e3edc1..ff1e57a 100644 --- a/src/app/inc/FApp_RequestManagerT.h +++ b/src/app/inc/FApp_RequestManagerT.h @@ -22,18 +22,10 @@ #ifndef _FAPP_INTERNAL_REQUEST_MANAGERT_H_ #define _FAPP_INTERNAL_REQUEST_MANAGERT_H_ -#include - #include #include - #include -namespace Tizen { namespace Base -{ -class String; -}} - namespace Tizen { namespace App { @@ -44,111 +36,17 @@ public: typedef Tizen::Base::Collection::HashMapT RequestListType; typedef Tizen::Base::Collection::IMapEnumeratorT RequestListEnumType; - _RequestManagerT(void) - : __reqId(-1) - { - __requestList.Construct(); - } - - ~_RequestManagerT(void) - { - RequestListEnumType* pIter = __requestList.GetMapEnumeratorN(); - if (pIter == null) - { - return; - } - - while (pIter->MoveNext() == E_SUCCESS) - { - T* pInfo = null; - result r = pIter->GetValue(pInfo); - - if (IsFailed(r)) - { - continue; - } - - delete pInfo; - } - - delete pIter; - } - - int InsertItem(T* pItem) - { - SysTryReturn(NID_APP, pItem != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument."); - -#if 0 - // [INFO] temporary disable due to OBS build system - __sync_add_and_fetch(&__reqId, 1); - - // [TODO] awkward implementation after overflow - // overflow detection - __sync_bool_compare_and_swap(&__reqId, INT_MAX, 1); -#else - __reqId++; - if (__reqId >= INT_MAX) - { - __reqId = 1; - } -#endif - SysLog(NID_APP, "Current request ID : %d.", __reqId); - - pItem->reqId = __reqId; - __requestList.Add(__reqId, pItem); - - return __reqId; - } - - void RemoveItem(int reqId) - { - T* pItem = FindItem(reqId); - if (pItem) - { - __requestList.Remove(reqId); - delete pItem; - } - } - - void RemoveItem(T* pItem) - { - RequestListEnumType* pIter = __requestList.GetMapEnumeratorN(); - if (pItem == null || pIter == null) - { - return; - } - - while (pIter->MoveNext() == E_SUCCESS) - { - T* pInfo = null; - result r = pIter->GetValue(pInfo); - - if (pInfo == pItem) - { - int id = -1; - r = pIter->GetKey(id); - if (r == E_SUCCESS) - { - __requestList.Remove(id); - } - - delete pItem; - delete pIter; - - return; - } - } - - delete pIter; - } - - T* FindItem(int reqId) const - { - T* pItem = null; - result r = __requestList.GetValue(reqId, pItem); - - return (r == E_SUCCESS) ? pItem : null; - } + _RequestManagerT(void); + + ~_RequestManagerT(void); + + int InsertItem(T* pItem); + + void RemoveItem(int reqId); + + void RemoveItem(T* pItem); + + T* FindItem(int reqId) const; private: _RequestManagerT(const T& rhs); @@ -160,6 +58,7 @@ private: RequestListType __requestList; }; // _RequestManagerT + } } // Tizen::App #endif // _FAPP_INTERNAL_REQUEST_MANAGERT_H_ -- 2.7.4