Merge "Fix DataSet for exception case" into tizen_2.1
[platform/framework/native/appfw.git] / src / app / FApp_DataControlManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FApp_DataControlManager.cpp
20  * @brief       This is the implementation for the _DataControlManager class.
21  */
22
23 #include <new>
24 #include <cstdlib>
25 #include <pthread.h>
26 #include <typeinfo>
27
28 #include <FBaseInteger.h>
29 #include <FBaseSysLog.h>
30
31 #include "FApp_DataControlManager.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35
36 namespace Tizen { namespace App
37 {
38
39 _DataControlManager* _DataControlManager::__pDataControlManagerInstance = null;
40
41 _DataControlManager::_DataControlManager(void)
42         : __pDataControlRequestList(null)
43 {
44         __pDataControlRequestList = new (std::nothrow) HashMap(SingleObjectDeleter);
45         SysTryReturnVoidResult(NID_APP, __pDataControlRequestList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
46
47         __pDataControlRequestList->Construct();
48 }
49
50 _DataControlManager::~_DataControlManager(void)
51 {
52         delete __pDataControlRequestList;
53 }
54
55 void
56 _DataControlManager::InitSingleton(void)
57 {
58         _DataControlManager* pInst = new (std::nothrow) _DataControlManager();
59         SysTryReturnVoidResult(NID_APP, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
60
61         __pDataControlManagerInstance = pInst;
62                 
63         std::atexit(DestroySingleton);
64         return;
65 }
66
67 void
68 _DataControlManager::DestroySingleton(void)
69 {
70         delete __pDataControlManagerInstance;
71 }
72
73 _DataControlManager*
74 _DataControlManager::GetInstance(void)
75 {
76         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
77         
78         if (__pDataControlManagerInstance == null)
79         {
80                 ClearLastResult();
81                 pthread_once(&onceBlock, InitSingleton);
82                 result r = GetLastResult();
83                 if (IsFailed(r))
84                 {
85                         onceBlock = PTHREAD_ONCE_INIT;
86                         SysPropagate(NID_APP, r);
87                 }
88         }
89
90         return __pDataControlManagerInstance;
91 }
92
93 result
94 _DataControlManager::AddRequestInfo(Integer* pReqId, _DataControlRequestInfo* pReqInfo)
95 {
96         //SysLog(NID_APP, "DataControl request list count: %d", __pDataControlRequestList->GetCount());
97         return __pDataControlRequestList->Add(pReqId, pReqInfo);
98 }
99
100 _DataControlRequestInfo*
101 _DataControlManager::GetRequestInfo(Integer& reqId) 
102 {
103         result r = E_SUCCESS;
104
105         Object* pObj = __pDataControlRequestList->GetValue(reqId);
106         SysTryReturn(NID_APP, pObj != null, null, GetLastResult(), "[%s] Propagating to caller...", GetErrorMessage(GetLastResult()));
107
108         _DataControlRequestInfo* pReqInfo = dynamic_cast< _DataControlRequestInfo* >(pObj);
109         SysTryReturn(NID_APP, pReqInfo != null, null, r, "[E_SYSTEM] invalid request info");
110
111         return pReqInfo;
112 }
113
114 void
115 _DataControlManager::RemoveRequestInfo(Integer& reqId)
116 {
117         __pDataControlRequestList->Remove(reqId);
118 }
119
120 }} // Tizen::App
121