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 "FApp_RequestManagerT.h"
25 #include "FApp_LaunchInfo.h"
28 namespace Tizen { namespace App
32 _RequestManagerT<T>::_RequestManagerT(void)
35 __requestList.Construct();
39 _RequestManagerT<T>::~_RequestManagerT(void)
41 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
47 while (pIter->MoveNext() == E_SUCCESS)
50 result r = pIter->GetValue(pInfo);
63 template<typename T> int
64 _RequestManagerT<T>::InsertItem(T* pItem)
66 SysTryReturn(NID_APP, pItem != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
69 // [INFO] temporary disable due to OBS build system
70 __sync_add_and_fetch(&__reqId, 1);
72 // [TODO] awkward implementation after overflow
74 __sync_bool_compare_and_swap(&__reqId, INT_MAX, 1);
77 if (__reqId >= INT_MAX)
82 SysLog(NID_APP, "Current request ID : %d.", __reqId);
84 pItem->reqId = __reqId;
85 __requestList.Add(__reqId, pItem);
90 template<typename T> void
91 _RequestManagerT<T>::RemoveItem(int reqId)
93 T* pItem = FindItem(reqId);
96 __requestList.Remove(reqId);
101 template<typename T> void
102 _RequestManagerT<T>::RemoveItem(T* pItem)
104 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
105 if (pItem == null || pIter == null)
110 while (pIter->MoveNext() == E_SUCCESS)
113 result r = pIter->GetValue(pInfo);
118 r = pIter->GetKey(id);
121 __requestList.Remove(id);
134 template<typename T> T*
135 _RequestManagerT<T>::FindItem(int reqId) const
138 result r = __requestList.GetValue(reqId, pItem);
140 return (r == E_SUCCESS) ? pItem : null;
144 // partial specialization
146 _RequestManagerT<_ResultInfo>::RemoveItem(int reqId)
148 // 1st request is launch request itself and do not remove it ever.
154 _ResultInfo* pItem = FindItem(reqId);
157 __requestList.Remove(reqId);
163 // explicit template initialization
164 template class _RequestManagerT<_LaunchInfo>;
165 template class _RequestManagerT<_InProcessInfo>;
166 template class _RequestManagerT<_ResultInfo>;