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"
26 #include "FApp_AppArg.h"
27 #include "FApp_IAppControlPluginProvider.h"
30 using namespace Tizen::Base::Runtime;
33 namespace Tizen { namespace App
36 _ResultInfo::~_ResultInfo(void)
42 _InProcessInfo::~_InProcessInfo(void)
50 _DataControlInfo::~_DataControlInfo(void)
57 _RequestManagerT<T>::_RequestManagerT(void)
60 __requestList.Construct();
64 _RequestManagerT<T>::~_RequestManagerT(void)
66 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
72 while (pIter->MoveNext() == E_SUCCESS)
75 result r = pIter->GetValue(pInfo);
88 template<typename T> int
89 _RequestManagerT<T>::InsertItem(T* pItem)
91 SysTryReturn(NID_APP, pItem != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
94 // [INFO] temporary disable due to OBS build system
95 __sync_add_and_fetch(&__reqId, 1);
97 // [TODO] awkward implementation after overflow
99 __sync_bool_compare_and_swap(&__reqId, INT_MAX, 1);
102 if (__reqId >= INT_MAX)
107 SysLog(NID_APP, "Current request ID : %d.", __reqId);
109 pItem->reqId = __reqId;
110 __requestList.Add(__reqId, pItem);
115 template<typename T> void
116 _RequestManagerT<T>::RemoveItem(int reqId)
118 T* pItem = FindItem(reqId);
121 __requestList.Remove(reqId);
126 template<typename T> void
127 _RequestManagerT<T>::RemoveItem(T* pItem)
129 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
130 if (pItem == null || pIter == null)
135 while (pIter->MoveNext() == E_SUCCESS)
138 result r = pIter->GetValue(pInfo);
143 r = pIter->GetKey(id);
146 __requestList.Remove(id);
159 template<typename T> T*
160 _RequestManagerT<T>::FindItem(int reqId) const
163 result r = __requestList.GetValue(reqId, pItem);
165 return (r == E_SUCCESS) ? pItem : null;
168 template<typename T> T*
169 _RequestManagerT<T>::FindItemWithListener(Pred pred, IEventListener* pListener) const
171 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
177 while (pIter->MoveNext() == E_SUCCESS)
180 result r = pIter->GetValue(pInfo);
184 if (pred(*pInfo, pListener))
197 _RequestManagerT<_ResultInfo>::~_RequestManagerT(void)
200 _ResultInfo* pItem = FindItem(0);
203 __requestList.Remove(0);
208 RequestListEnumType* pIter = __requestList.GetMapEnumeratorN();
214 while (pIter->MoveNext() == E_SUCCESS)
216 _ResultInfo* pInfo = null;
217 result r = pIter->GetValue(pInfo);
232 _RequestManagerT<_ResultInfo>::RemoveItem(int reqId)
234 // 1st request is launch request itself and do not remove it ever.
240 _ResultInfo* pItem = FindItem(reqId);
243 __requestList.Remove(reqId);
249 // explicit template initialization
250 template class _RequestManagerT<_DataControlInfo>;
251 template class _RequestManagerT<_InProcessInfo>;
252 template class _RequestManagerT<_ResultInfo>;