sync with tizen_2.0
[platform/framework/native/appfw.git] / src / app / FAppAppSetting.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 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  * @file        FAppAppSetting.h
19  * @brief       This is the implementation file for the %AppSetting class.
20  *
21  */
22
23 #include <cstdlib>
24 #include <new>
25 #include <pthread.h>
26 #include <FAppAppSetting.h>
27 #include <FBaseSysLog.h>
28 #include "FApp_AppSettingImpl.h"
29
30 using namespace Tizen::Base::Collection;
31
32 namespace Tizen { namespace App
33 {
34
35 AppSetting* AppSetting::__pAppSettingInstance = null;
36
37 AppSetting::AppSetting(void)
38         : __pAppSettingImpl(null)
39 {
40
41 }
42
43 AppSetting::~AppSetting(void)
44 {
45         delete __pAppSettingImpl;
46 }
47
48 AppSetting*
49 AppSetting::GetInstance(void)
50 {
51         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
52
53         if (!__pAppSettingInstance)
54         {
55                 ClearLastResult();
56                 pthread_once(&onceBlock, InitSingleton);
57                 result r = GetLastResult();
58                 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
59
60                 __pAppSettingInstance->__pAppSettingImpl = _AppSettingImpl::GetInstance();
61                 SysTryCatch(NID_APP, __pAppSettingInstance->__pAppSettingImpl != null, , E_OUT_OF_MEMORY,
62                                         "[%s] Memory allocation failed.");
63         }
64
65         return __pAppSettingInstance;
66
67 CATCH:
68         delete __pAppSettingInstance;
69         __pAppSettingInstance = null;
70         onceBlock = PTHREAD_ONCE_INIT;
71         return null;
72 }
73
74 AppSetting*
75 AppSetting::GetInstance(const Tizen::Base::String& version)
76 {
77         return _AppSettingImpl::GetInstance(version);
78 }
79
80 AppSetting*
81 AppSetting::GetInstanceByAppId(const AppId& appId)
82 {
83         //TODO: Add privilege checking code
84         return _AppSettingImpl::GetInstanceByAppId(appId);
85 }
86
87 result
88 AppSetting::ReleaseInstanceByAppId(const AppId& appId)
89 {
90         return _AppSettingImpl::ReleaseInstanceByAppId(appId);
91 }
92
93 Tizen::Base::Collection::IList*
94 AppSetting::GetAppSettingVersionListN(void)
95 {
96         return _AppSettingImpl::GetAppSettingVersionListN();
97 }
98
99 result
100 AppSetting::GetValue(const Tizen::Base::String& id, bool& value) const
101 {
102         return __pAppSettingImpl->GetValue(id, value);
103 }
104
105 result
106 AppSetting::GetValue(const Tizen::Base::String& id, int& value) const
107 {
108         return __pAppSettingImpl->GetValue(id, value);
109 }
110
111 result
112 AppSetting::GetValue(const Tizen::Base::String& id, Tizen::Base::String& value) const
113 {
114         return __pAppSettingImpl->GetValue(id, value);
115 }
116
117 result
118 AppSetting::SetValue(const Tizen::Base::String& id, bool value)
119 {
120         return __pAppSettingImpl->SetValue(id, value);
121 }
122
123 result
124 AppSetting::SetValue(const Tizen::Base::String& id, int value)
125 {
126         return __pAppSettingImpl->SetValue(id, value);
127 }
128
129 result
130 AppSetting::SetValue(const Tizen::Base::String& id, const Tizen::Base::String& value)
131 {
132         return __pAppSettingImpl->SetValue(id, value);
133 }
134
135 result
136 AppSetting::SetAppSettingEventListener(IAppSettingEventListener* pListener)
137 {
138         return __pAppSettingImpl->SetAppSettingEventListener(pListener);
139 }
140
141 void
142 AppSetting::InitSingleton(void)
143 {
144         AppSetting* pInst = new (std::nothrow) AppSetting();
145         SysTryReturnVoidResult(NID_UI_SCENES, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
146                                                    GetErrorMessage(E_OUT_OF_MEMORY));
147
148         __pAppSettingInstance = pInst;
149         std::atexit(DestroySingleton);
150 }
151
152 void
153 AppSetting::DestroySingleton(void)
154 {
155         delete __pAppSettingInstance;
156 }
157
158
159 } } // Tizen::App