2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FApp_RequestManagerT.cpp
19 * @brief This is the implementationfor the _RequestManagerT class.
24 #include <FBaseRt_LibraryImpl.h>
26 #include "FApp_RequestManagerT.h"
27 #include "FApp_LaunchInfo.h"
28 #include "FApp_AppArg.h"
30 using namespace Tizen::Base::Runtime;
33 namespace Tizen { namespace App
36 _ResultInfo::~_ResultInfo(void)
42 _InProcessInfo::~_InProcessInfo(void)
47 _LaunchInfo::~_LaunchInfo(void)
54 _RequestManagerT<T>::_RequestManagerT(void)
57 __requestList.Construct();
61 _RequestManagerT<T>::~_RequestManagerT(void)
63 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
69 while (pIter->MoveNext() == E_SUCCESS)
72 result r = pIter->GetValue(pInfo);
85 template<typename T> int
86 _RequestManagerT<T>::InsertItem(T* pItem)
88 SysTryReturn(NID_APP, pItem != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
91 // [INFO] temporary disable due to OBS build system
92 __sync_add_and_fetch(&__reqId, 1);
94 // [TODO] awkward implementation after overflow
96 __sync_bool_compare_and_swap(&__reqId, INT_MAX, 1);
99 if (__reqId >= INT_MAX)
104 SysLog(NID_APP, "Current request ID : %d.", __reqId);
106 pItem->reqId = __reqId;
107 __requestList.Add(__reqId, pItem);
112 template<typename T> void
113 _RequestManagerT<T>::RemoveItem(int reqId)
115 T* pItem = FindItem(reqId);
118 __requestList.Remove(reqId);
123 template<typename T> void
124 _RequestManagerT<T>::RemoveItem(T* pItem)
126 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
127 if (pItem == null || pIter == null)
132 while (pIter->MoveNext() == E_SUCCESS)
135 result r = pIter->GetValue(pInfo);
140 r = pIter->GetKey(id);
143 __requestList.Remove(id);
156 template<typename T> T*
157 _RequestManagerT<T>::FindItem(int reqId) const
160 result r = __requestList.GetValue(reqId, pItem);
162 return (r == E_SUCCESS) ? pItem : null;
168 _RequestManagerT<_ResultInfo>::~_RequestManagerT(void)
171 _ResultInfo* pItem = FindItem(0);
174 __requestList.Remove(0);
179 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
185 while (pIter->MoveNext() == E_SUCCESS)
187 _ResultInfo* pInfo = null;
188 result r = pIter->GetValue(pInfo);
203 _RequestManagerT<_ResultInfo>::RemoveItem(int reqId)
205 // 1st request is launch request itself and do not remove it ever.
211 _ResultInfo* pItem = FindItem(reqId);
214 __requestList.Remove(reqId);
220 // explicit template initialization
221 template class _RequestManagerT<_LaunchInfo>;
222 template class _RequestManagerT<_InProcessInfo>;
223 template class _RequestManagerT<_ResultInfo>;