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