2 // Copyright (c) 2013 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_DataControlManager.cpp
19 * @brief This is the implementation for the _DataControlManager class.
28 #include <FBaseInteger.h>
29 #include <FBaseSysLog.h>
31 #include "FApp_DataControlManager.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace App
39 _DataControlManager* _DataControlManager::__pDataControlManagerInstance = null;
41 _DataControlManager::_DataControlManager(void)
42 : __pDataControlRequestList(null)
45 __pDataControlRequestList = new (std::nothrow) HashMap(SingleObjectDeleter);
46 SysTryReturnVoidResult(NID_APP, __pDataControlRequestList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
48 __pDataControlRequestList->Construct();
51 _DataControlManager::~_DataControlManager(void)
53 delete __pDataControlRequestList;
57 _DataControlManager::InitSingleton(void)
59 _DataControlManager* pInst = new (std::nothrow) _DataControlManager();
60 SysTryReturnVoidResult(NID_APP, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
62 __pDataControlManagerInstance = pInst;
64 std::atexit(DestroySingleton);
69 _DataControlManager::DestroySingleton(void)
71 delete __pDataControlManagerInstance;
75 _DataControlManager::GetInstance(void)
77 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
79 if (__pDataControlManagerInstance == null)
82 pthread_once(&onceBlock, InitSingleton);
83 result r = GetLastResult();
86 onceBlock = PTHREAD_ONCE_INIT;
87 SysPropagate(NID_APP, r);
91 return __pDataControlManagerInstance;
95 _DataControlManager::GetRequestCount(void) const
97 return __pDataControlRequestList->GetCount();
101 _DataControlManager::AddRequestInfo(Integer* pReqId, _DataControlRequestInfo* pReqInfo)
103 //SysLog(NID_APP, "DataControl request list count: %d", __pDataControlRequestList->GetCount());
104 return __pDataControlRequestList->Add(pReqId, pReqInfo);
107 _DataControlRequestInfo*
108 _DataControlManager::GetRequestInfo(Integer& reqId)
110 result r = E_SUCCESS;
112 Object* pObj = __pDataControlRequestList->GetValue(reqId);
113 SysTryReturn(NID_APP, pObj != null, null, GetLastResult(), "[%s] Propagating to caller...", GetErrorMessage(GetLastResult()));
115 _DataControlRequestInfo* pReqInfo = dynamic_cast< _DataControlRequestInfo* >(pObj);
116 SysTryReturn(NID_APP, pReqInfo != null, null, r, "[E_SYSTEM] invalid request info");
122 _DataControlManager::RemoveRequestInfo(Integer& reqId)
124 __pDataControlRequestList->Remove(reqId);
128 _DataControlManager::RemoveAllRequests(void)
130 __pDataControlRequestList->RemoveAll();
134 _DataControlManager::GetUniqueId(void)
137 //__sync_fetch_and_add(&__uniqueId, 1);
138 g_atomic_int_inc(&__uniqueId);