Revert "Fix intApp TC failure"
[platform/framework/native/appfw.git] / src / app / FApp_AppSettingImpl.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 /**
18  * @file        FApp_AppResourceImpl.cpp
19  * @brief       This is the implementation file of the _AppResourceImpl class.
20  */
21
22 #include <memory>
23 #include <unistd.h>
24 #include <libxml/tree.h>
25 #include <unique_ptr.h>
26 #include <FAppApp.h>
27 #include <FBaseString.h>
28 #include <FBaseBoolean.h>
29 #include <FBaseInteger.h>
30 #include <FBaseUtilStringUtil.h>
31 #include <FBaseSysLog.h>
32 #include <FIoFile.h>
33 #include <FIoDirectory.h>
34 #include <FAppPkgPackageInfo.h>
35 #include <FAppPkgPackageManager.h>
36 #include <FAppIAppSettingEventListener.h>
37 #include "FApp_AppSettingImpl.h"
38 #include "FApp_AppInfo.h"
39 #include "FAppPkg_PackageManagerImpl.h"
40 #include "FAppPkg_PackageInfoImpl.h"
41
42
43 using namespace Tizen::App::Package;
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46 using namespace Tizen::Io;
47 using namespace Tizen::App;
48
49
50 namespace Tizen { namespace App
51 {
52
53 const int APP_ID_LENTH = 10;
54 const int MAX_LOCAL_BUFSIZE = 128;
55 const char* DBUS_PATH = "/setting/dbus_handler";
56 const char* DBUS_SIGNAL_INTERFACE = "org.tizen.setting.signal";
57 static const wchar_t DBUS_SIGNAL_PREFIX[] = L"Update_";
58
59 static const wchar_t RESOUCE_FILE_PATH[] = L"setting/";
60 static const wchar_t RESOUCE_FILE_NAME[] = L"setting";
61 static const wchar_t RESOUCE_FILE_EXT[] = L".xml";
62
63 static _AppSettingImpl* pAppSettingImplInstance = null;
64
65 _AppSettingImpl::_MutiInstanceManager _AppSettingImpl::__appIdMultiInstanceMgr; // static member
66 DBusConnection* pDBusConnection = null;
67
68 class _CleanUpDBus
69 {
70 public:
71         ~_CleanUpDBus()
72         {
73                 if (pDBusConnection)
74                 {
75                         dbus_connection_close(pDBusConnection);
76                         pDBusConnection = null;
77                 }
78         }
79 };
80 static _CleanUpDBus cleanUpDBus;
81
82 _AppSettingImpl::_MutiInstanceManager::_MutiInstanceManager(void)
83 {
84         __stringToInstanceMap.Construct();
85 }
86
87 _AppSettingImpl::_MutiInstanceManager::~_MutiInstanceManager(void)
88 {
89         __stringToInstanceMap.RemoveAll(true);          // Remove instance on exit.
90 }
91
92 AppSetting*
93 _AppSettingImpl::_MutiInstanceManager::GetInstance(const String& version)
94 {
95         result r = E_SUCCESS;
96         AppSetting* pAppSettingInstance = null;
97         String* pKeyStr = null;
98
99         AppSetting* pAppSetting = static_cast<AppSetting*>( __stringToInstanceMap.GetValue(version));
100         if (pAppSetting)
101         {
102                 return pAppSetting;
103         }
104
105         // Common creation part
106         std::unique_ptr<_AppSettingImpl> pAppSettingImpl(new (std::nothrow) _AppSettingImpl());
107         SysTryReturn(NID_APP, pAppSettingImpl != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
108                                  GetErrorMessage(E_OUT_OF_MEMORY));
109
110         // Get current application context AppId
111         App* pApp = App::GetInstance();
112         String appId;
113         SysTryCatch(NID_APP, pApp != null, , E_SYSTEM, "[%s] A system error has been occurred. App::GetInstance() failed",
114                                 GetErrorMessage(E_SYSTEM));
115         appId = pApp->GetAppId();
116
117         r = pAppSettingImpl->Construct(appId, version);
118         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
119
120         pAppSettingInstance = _AppSettingImpl::CreateAppSetting();
121         SysTryCatch(NID_APP, pAppSettingInstance != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
122                                 GetErrorMessage(E_OUT_OF_MEMORY));
123         _AppSettingImpl::SetImplInstance(*pAppSettingInstance, *pAppSettingImpl.release());
124
125         pKeyStr = new (std::nothrow) String(version);
126         SysTryCatch(NID_APP, pKeyStr != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
127
128         r = __stringToInstanceMap.Add(*pKeyStr, *pAppSettingInstance);
129         SysTryCatch(NID_APP, r != E_OUT_OF_MEMORY, , r, "[%s] Memory allocation failed.", GetErrorMessage(r));
130         SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
131
132         return pAppSettingInstance;
133
134 CATCH:
135         delete pAppSettingInstance;
136         return null;
137 }
138
139 AppSetting*
140 _AppSettingImpl::_MutiInstanceManager::GetInstanceByAppId(const AppId& appId)
141 {
142         result r = E_SUCCESS;
143         AppSetting* pAppSettingInstance = null;
144         String* pKeyStr = null;
145
146         // Convert AppId to package type id.
147         String packageId;
148         appId.SubString(0, APP_ID_LENTH, packageId);
149
150         AppSetting* pAppSetting = static_cast<AppSetting*>( __stringToInstanceMap.GetValue(packageId));
151         if (pAppSetting)
152         {
153                 return pAppSetting;
154         }
155
156         _PackageManagerImpl* pPkgMgrImpl = _PackageManagerImpl::GetInstance();
157         SysTryReturn(NID_APP, pPkgMgrImpl != null, null, E_SYSTEM,
158                                  "[%s] A system error has been occurred. failed to get _PackageMaangerImpl.", GetErrorMessage(E_SYSTEM));
159
160         std::unique_ptr<PackageInfo> pPackageInfo(pPkgMgrImpl->GetPackageInfoN(packageId));     // !E_SUCCESS for DB fail and query fail
161         SysTryReturn(NID_APP, pPackageInfo != null, null, E_APP_NOT_INSTALLED, "[%s] Propagating.", GetErrorMessage(E_APP_NOT_INSTALLED));
162
163         const _PackageInfoImpl* pPkgInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
164         SysTryReturn(NID_APP, pPkgInfoImpl != null, null, E_SYSTEM,
165                                  "[%s] A system error has been occurred. failed to get _PackageInfoImpl.", GetErrorMessage(E_SYSTEM));
166
167         String rootPath = pPkgInfoImpl->GetAppRootPath();
168         rootPath += L"/";
169
170         // Common creation part
171         std::unique_ptr<_AppSettingImpl> pAppSettingImpl(new (std::nothrow) _AppSettingImpl());
172         SysTryReturn(NID_APP, pAppSettingImpl != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
173                                  GetErrorMessage(E_OUT_OF_MEMORY));
174
175         r = pAppSettingImpl->ConstructByAppPath(packageId, rootPath);
176         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
177
178         pAppSettingInstance = _AppSettingImpl::CreateAppSetting();
179         SysTryCatch(NID_APP, pAppSettingInstance != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
180                                 GetErrorMessage(E_OUT_OF_MEMORY));
181         _AppSettingImpl::SetImplInstance(*pAppSettingInstance, *pAppSettingImpl.release());
182
183         pKeyStr = new (std::nothrow) String(packageId);
184         SysTryCatch(NID_APP, pKeyStr != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
185
186         r = __stringToInstanceMap.Add(*pKeyStr, *pAppSettingInstance);
187         SysTryCatch(NID_APP, r != E_OUT_OF_MEMORY, , r, "[%s] Memory allocation failed.", GetErrorMessage(r));
188         SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
189
190         return pAppSettingInstance;
191
192 CATCH:
193         delete pAppSettingInstance;
194         return null;
195 }
196
197 result
198 _AppSettingImpl::_MutiInstanceManager::ReleaseInstanceByAppId(const AppId& appId)
199 {
200         // Convert AppId to package type id.
201         String packageId;
202         appId.SubString(0, APP_ID_LENTH, packageId);
203
204         AppSetting* pAppSetting = static_cast<AppSetting*>(__stringToInstanceMap.GetValue(packageId));
205         if (pAppSetting)
206         {
207                 if (pDBusConnection)
208                 {
209                         _AppSettingImpl* pThisAppSettingImpl = _AppSettingImpl::GetInstance(*pAppSetting);
210                         dbus_connection_remove_filter(pDBusConnection, HandleDBusMessage, pThisAppSettingImpl);
211                 }
212                 __stringToInstanceMap.Remove(packageId, true);  // Delete item instance and remove item from __stringToInstanceMap
213                 return E_SUCCESS;
214         }
215         else
216         {
217                 return E_OBJ_NOT_FOUND;
218         }
219 }
220
221 result
222 _AppSettingImpl::_MutiInstanceManager::ReleaseOtherAppInstances(void)
223 {
224         if (pDBusConnection)
225         {       // Iterate all element and remove correspond dbus filter
226                 std::unique_ptr<IMapEnumerator> pEnum(__stringToInstanceMap.GetMapEnumeratorN());
227                 if (pEnum.get())
228                 {
229                         while (pEnum->MoveNext() == E_SUCCESS)
230                         {
231                                 AppSetting* pAppSetting = null;
232                                 pAppSetting = static_cast<AppSetting*>(pEnum->GetValue());
233                                 _AppSettingImpl* pThisAppSettingImpl = _AppSettingImpl::GetInstance(*pAppSetting);
234                                 dbus_connection_remove_filter(pDBusConnection, HandleDBusMessage, pThisAppSettingImpl);
235                         }
236                 }
237         }
238         __stringToInstanceMap.RemoveAll(true);
239         return E_SUCCESS;
240 }
241
242 class _SettingItem
243         : public Object
244 {
245 public:
246         _SettingItem(Object* pItemValue, int min, int max, xmlNodePtr pItemXmlNode)
247                 : __pValue(pItemValue)
248                 , __min(min)
249                 , __max(max)
250                 , __pXmlNode(pItemXmlNode)
251         {}
252         ~_SettingItem(void)
253         {
254                 delete __pValue;
255         }
256         Object* GetValue(void)
257         {
258                 return __pValue;
259         }
260         const Object* GetValue(void) const
261         {
262                 return __pValue;
263         }
264         int GetMin(void)
265         {
266                 return __min;
267         }
268         int GetMax(void)
269         {
270                 return __max;
271         }
272         xmlNodePtr GetXmlNode(void)
273         {
274                 return __pXmlNode;
275         }
276 private:
277         _SettingItem(void);
278         _SettingItem(const _SettingItem& rhs);
279         _SettingItem& operator =(const _SettingItem& rhs);
280 private:
281         Object* __pValue;
282         int __min;
283         int __max;
284         xmlNodePtr __pXmlNode;
285 };
286
287 class _ReverseStringComparer
288         : public Tizen::Base::Collection::IComparer
289 {
290 public:
291         _ReverseStringComparer(void) {};
292         virtual ~_ReverseStringComparer(void) {};
293         virtual result Compare(const Tizen::Base::Object& obj1, const Tizen::Base::Object& obj2, int& cmp) const
294         {
295                 const String& objString1 = static_cast<const String&>(obj1);
296                 const String& objString2 = static_cast<const String&>(obj2);
297                 cmp = objString2.CompareTo(objString1); // reverse
298                 return E_SUCCESS;
299         }
300 };
301
302 _AppSettingImpl::_AppSettingImpl(void)
303         : __oldVersionInstance(false)
304         , __pEventListener(null)
305         , __pDoc(null)
306 {
307
308 }
309
310 _AppSettingImpl::~_AppSettingImpl(void)
311 {
312         if (__pDoc)
313         {
314                 xmlFreeDoc(__pDoc);
315                 __pDoc = null;
316         }
317         __settingContainer.RemoveAll(true);
318 }
319
320 _AppSettingImpl*
321 _AppSettingImpl::GetInstance(void)
322 {
323         ClearLastResult();
324         result r = E_SUCCESS;
325
326         if (pAppSettingImplInstance == null)
327         {
328                 pAppSettingImplInstance = new (std::nothrow) _AppSettingImpl();
329                 SysTryReturn(NID_APP, pAppSettingImplInstance != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
330                                          GetErrorMessage(E_OUT_OF_MEMORY));
331
332                 // Get current application context AppId
333                 App* pApp = App::GetInstance();
334                 SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] A system error has been occurred. App::GetInstance() failed",
335                                         GetErrorMessage(E_SYSTEM));
336                 String appId;
337                 appId = pApp->GetAppId();
338                 r = pAppSettingImplInstance->Construct(appId);
339                 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
340         }
341         return pAppSettingImplInstance;
342
343 CATCH:
344         delete pAppSettingImplInstance;
345         pAppSettingImplInstance = null;
346         return null;
347 }
348
349 AppSetting*
350 _AppSettingImpl::GetInstance(const Tizen::Base::String& version)
351 {
352         ClearLastResult();
353         //result r = E_SUCCESS;
354
355         static _MutiInstanceManager multiInstanceManager;
356         AppSetting* pVersionAppSetting = multiInstanceManager.GetInstance(version);
357         SysTryReturn(NID_APP, pVersionAppSetting != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
358                                  GetErrorMessage(E_OUT_OF_MEMORY));
359
360         return pVersionAppSetting;
361 }
362
363 AppSetting*
364 _AppSettingImpl::GetInstanceByAppId(const AppId& appId)
365 {
366         ClearLastResult();
367
368         AppSetting* pAppSettingByAppId = __appIdMultiInstanceMgr.GetInstanceByAppId(appId);
369         return pAppSettingByAppId;
370 }
371
372 result
373 _AppSettingImpl::ReleaseInstanceByAppId(const AppId& appId)
374 {
375         return __appIdMultiInstanceMgr.ReleaseInstanceByAppId(appId);
376 }
377
378 result
379 _AppSettingImpl::ReleaseOtherAppInstances(void)
380 {
381         return __appIdMultiInstanceMgr.ReleaseOtherAppInstances();
382 }
383
384 Tizen::Base::Collection::IList*
385 _AppSettingImpl::GetAppSettingVersionListN(void)
386 {
387         result r = E_SUCCESS;
388         ArrayList* pVersionList = new (std::nothrow) ArrayList;
389         SysTryReturn(NID_APP, pVersionList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
390                                  GetErrorMessage(E_OUT_OF_MEMORY));
391         r = pVersionList->Construct();
392         SysTryReturn(NID_APP, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
393                                  GetErrorMessage(E_OUT_OF_MEMORY));
394
395         // Iterate file and add to list
396         String dirPath = _AppInfo::GetAppRootPath() + RESOUCE_FILE_PATH;
397         Directory dir;
398         r = dir.Construct(dirPath);
399         SysTryReturn(NID_APP, !IsFailed(r), null, E_SYSTEM, "[%s] A system error has been occurred. Directory construction failed.",
400                                  GetErrorMessage(E_SYSTEM));
401
402         std::unique_ptr<DirEnumerator> pDirEnum(dir.ReadN());
403         SysTryReturn(NID_APP, pDirEnum != null, null, E_SYSTEM,
404                                  "[%s] A system error has been occurred. Directory enumerator getting failed.", GetErrorMessage(E_SYSTEM));
405
406         String settingName(RESOUCE_FILE_NAME);
407         String settingExt(RESOUCE_FILE_EXT);
408         while (pDirEnum->MoveNext() == E_SUCCESS)
409         {
410                 DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
411                 if (!dirEntry.IsDirectory())
412                 {
413                         String fullName = dirEntry.GetName();
414                         // Check name and extension to getting valid one
415                         String name;
416                         String ext;
417                         const int extLength = settingExt.GetLength();
418                         const int posStart = settingName.GetLength();
419                         const int posEnd = fullName.GetLength() - extLength;
420                         if (posStart >= posEnd)
421                         {
422                                 continue;
423                         }
424                         fullName.SubString(0, posStart, name);
425                         fullName.SubString(posEnd, ext);
426                         if ((name == settingName) && (ext == settingExt))
427                         {
428                                 String version;
429                                 if (E_SUCCESS == fullName.SubString(posStart, posEnd-posStart, version))
430                                 {
431                                         String* pVersionStr = new (std::nothrow) String(version);
432                                         SysTryReturn(NID_APP, pVersionStr != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
433                                                                  GetErrorMessage(E_OUT_OF_MEMORY));
434                                         pVersionList->Add(*pVersionStr);
435                                 }
436                         }
437                 }
438         }
439
440         if (pVersionList->GetCount())
441         {
442                 static _ReverseStringComparer strComparator;
443                 pVersionList->Sort(strComparator);
444                 pVersionList->RemoveAt(0);      // remove latest version from list.
445         }
446
447         return pVersionList;
448 }
449
450 result
451 _AppSettingImpl::GetValue(const Tizen::Base::String& id, bool& value) const
452 {
453         const Object* pObject = __settingContainer.GetValue(id);
454         SysTryReturnResult(NID_APP, pObject != null, E_OBJ_NOT_FOUND, "Specified id is not found in the application setting");
455         const _SettingItem* pItem = dynamic_cast<const _SettingItem*>(pObject);
456         SysTryReturnResult(NID_APP, pItem != null, E_TYPE_MISMATCH, "Type mismatch for instance of id.");
457         const Boolean* pBoolean = dynamic_cast<const Boolean*>(pItem->GetValue());
458         SysTryReturnResult(NID_APP, pBoolean != null, E_TYPE_MISMATCH, "Type mismatch between requested type bool and object type.");
459         value = pBoolean->ToBool();
460
461         return E_SUCCESS;
462 }
463
464 result
465 _AppSettingImpl::GetValue(const Tizen::Base::String& id, int& value) const
466 {
467         const Object* pObject = __settingContainer.GetValue(id);
468         SysTryReturnResult(NID_APP, pObject != null, E_OBJ_NOT_FOUND, "Specified id is not found in the application setting");
469         const _SettingItem* pItem = dynamic_cast<const _SettingItem*>(pObject);
470         SysTryReturnResult(NID_APP, pItem != null, E_TYPE_MISMATCH, "Type mismatch for instance of id.");
471         const Integer* pInteger = dynamic_cast<const Integer*>(pItem->GetValue());
472         SysTryReturnResult(NID_APP, pInteger != null, E_TYPE_MISMATCH, "Type mismatch between requested type int and object type.");
473         value = pInteger->ToInt();
474
475         return E_SUCCESS;
476 }
477
478 result
479 _AppSettingImpl::GetValue(const Tizen::Base::String& id, Tizen::Base::String& value) const
480 {
481         const Object* pObject = __settingContainer.GetValue(id);
482         SysTryReturnResult(NID_APP, pObject != null, E_OBJ_NOT_FOUND, "Specified id is not found in the application setting");
483         const _SettingItem* pItem = dynamic_cast<const _SettingItem*>(pObject);
484         SysTryReturnResult(NID_APP, pItem != null, E_TYPE_MISMATCH, "Type mismatch for instance of id.");
485         const String* pString = dynamic_cast<const String*>(pItem->GetValue());
486         SysTryReturnResult(NID_APP, pString != null, E_TYPE_MISMATCH, "Type mismatch between requested type String and object type.");
487         value = *pString;
488
489         return E_SUCCESS;
490 }
491
492 result
493 _AppSettingImpl::SetValue(const Tizen::Base::String& id, bool value, bool save)
494 {
495         Object* pObject = __settingContainer.GetValue(id);
496         SysTryReturnResult(NID_APP, pObject != null, E_OBJ_NOT_FOUND, "Specified id is not found in the application setting");
497         _SettingItem* pItem = dynamic_cast<_SettingItem*>(pObject);
498         SysTryReturnResult(NID_APP, pItem != null, E_TYPE_MISMATCH, "Type mismatch for instance of id.");
499         Boolean* pBoolean = dynamic_cast<Boolean*>(pItem->GetValue());
500         SysTryReturnResult(NID_APP, pBoolean != null, E_TYPE_MISMATCH, "Type mismatch between requested type bool and object type.");
501         *pBoolean = value;
502
503         static const String strTrue(L"true");
504         static const String strFalse(L"false");
505         const String& strValue = value ? strTrue : strFalse;
506         UpdateProperty(pItem->GetXmlNode(), strValue);
507         if (save)
508         {
509                 Save();
510                 static const String strIntTrue(L"1");
511                 static const String strIntFalse(L"0");
512                 SendMessage(id, value ? strIntTrue : strIntFalse, true);
513         }
514         if (__pEventListener)
515         {
516                 __pEventListener->OnAppSettingChanged(id);
517         }
518
519         return E_SUCCESS;
520 }
521
522 result
523 _AppSettingImpl::SetValue(const Tizen::Base::String& id, int value, bool save)
524 {
525         Object* pObject = __settingContainer.GetValue(id);
526         SysTryReturnResult(NID_APP, pObject != null, E_OBJ_NOT_FOUND, "Specified id is not found in the application setting");
527         _SettingItem* pItem = dynamic_cast<_SettingItem*>(pObject);
528         SysTryReturnResult(NID_APP, pItem != null, E_TYPE_MISMATCH, "Type mismatch for instance of id.");
529         Integer* pInteger = dynamic_cast<Integer*>(pItem->GetValue());
530         SysTryReturnResult(NID_APP, pInteger != null, E_TYPE_MISMATCH, "Type mismatch between requested type int and object type.");
531
532         SysTryReturnResult(NID_APP, (pItem->GetMin() <= value), E_OUT_OF_RANGE, "value(%d) is less than minimum range(%d).",
533                                            value, pItem->GetMin());
534         SysTryReturnResult(NID_APP, (pItem->GetMax() >= value), E_OUT_OF_RANGE, "value(%d) is greater than maximum range(%d).",
535                                            value, pItem->GetMax());
536         *pInteger = value;
537
538         String strValue = pInteger->ToString();
539         UpdateProperty(pItem->GetXmlNode(), strValue);
540         if (save)
541         {
542                 Save();
543                 SendMessage(id, strValue, true);
544         }
545         if (__pEventListener)
546         {
547                 __pEventListener->OnAppSettingChanged(id);
548         }
549
550         return E_SUCCESS;
551 }
552
553 result
554 _AppSettingImpl::SetValue(const Tizen::Base::String& id, const Tizen::Base::String& value, bool save)
555 {
556         Object* pObject = __settingContainer.GetValue(id);
557         SysTryReturnResult(NID_APP, pObject != null, E_OBJ_NOT_FOUND, "Specified id is not found in the application setting");
558         _SettingItem* pItem = dynamic_cast<_SettingItem*>(pObject);
559         SysTryReturnResult(NID_APP, pItem != null, E_TYPE_MISMATCH, "Type mismatch for instance of id.");
560         String* pString = dynamic_cast<String*>(pItem->GetValue());
561         SysTryReturnResult(NID_APP, pString != null, E_TYPE_MISMATCH, "Type mismatch between requested type String and object type.");
562
563         SysTryReturnResult(NID_APP, pItem->GetMin() <= value.GetLength(), E_OUT_OF_RANGE,
564                                            "value length(%d) less than minimum length(%d).", value.GetLength(), pItem->GetMin());
565         SysTryReturnResult(NID_APP, pItem->GetMax() >= value.GetLength(), E_OUT_OF_RANGE,
566                                            "value length(%d) greater than maximum range(%d).", value.GetLength(), pItem->GetMax());
567         *pString = value;
568
569         UpdateProperty(pItem->GetXmlNode(), *pString);
570         if (save)
571         {
572                 Save();
573                 SendMessage(id, *pString, false);
574         }
575         if (__pEventListener)
576         {
577                 __pEventListener->OnAppSettingChanged(id);
578         }
579
580         return E_SUCCESS;
581 }
582
583 result
584 _AppSettingImpl::SetAppSettingEventListener(IAppSettingEventListener* pListener)
585 {
586         __pEventListener = pListener;
587         return E_SUCCESS;
588 }
589
590 _AppSettingImpl*
591 _AppSettingImpl::GetInstance(AppSetting& appSetting)
592 {
593         return appSetting.__pAppSettingImpl;
594 }
595
596 const _AppSettingImpl*
597 _AppSettingImpl::GetInstance(const AppSetting& appSetting)
598 {
599         return appSetting.__pAppSettingImpl;
600 }
601
602 result
603 _AppSettingImpl::Construct(const AppId& correspondAppId, const String& version)
604 {
605         result r = E_SUCCESS;
606         if (version.GetLength() > 0)
607         {
608                 __oldVersionInstance = true;
609         }
610         correspondAppId.SubString(0, APP_ID_LENTH, __correspondAppId);  // Use 10 char id value.
611
612         __filePath = _AppInfo::GetAppRootPath() + RESOUCE_FILE_PATH;
613         __filePath += RESOUCE_FILE_NAME;
614         if (version.GetLength())
615         {
616                 __filePath += version;
617         }
618         __filePath += RESOUCE_FILE_EXT;
619
620         r = __settingContainer.Construct();
621         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
622         if (!__oldVersionInstance)
623         {
624                 SysTryReturnResult(NID_APP, InitializeDBus(), E_SYSTEM, "A system error has been occurred. DBus initialization failed.");
625         }
626         r = Load();
627         SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "A system error has been occurred. Loading procedure failed.");
628         return r;
629 }
630
631 result
632 _AppSettingImpl::ConstructByAppPath(const AppId& correspondAppId, const Tizen::Base::String& appRootPath)
633 {
634         result r = E_SUCCESS;
635         SysTryReturn(NID_APP, !appRootPath.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG,
636                                  "[%s] Invalid argument is used. appRootPath length is 0.", GetErrorMessage(E_INVALID_ARG));
637
638         correspondAppId.SubString(0, APP_ID_LENTH, __correspondAppId);  // Use 10 char id value.
639         __filePath = appRootPath + RESOUCE_FILE_PATH;
640         __filePath += RESOUCE_FILE_NAME;
641         __filePath += RESOUCE_FILE_EXT;
642
643         r = __settingContainer.Construct();
644         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
645         SysTryReturnResult(NID_APP, InitializeDBus(), E_SYSTEM, "A system error has been occurred. DBus initialization failed.");
646         r = Load();
647         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
648
649         return r;
650 }
651
652 result
653 _AppSettingImpl::Load(void)
654 {
655         SysTryReturnResult(NID_APP, File::IsFileExist(__filePath), E_OBJ_NOT_FOUND,
656                                            "The instance of specified AppId does not have setting information. %ls", __filePath.GetPointer());
657
658         result r = E_SUCCESS;
659         std::unique_ptr<ByteBuffer> pfilePath(Tizen::Base::Utility::StringUtil::StringToUtf8N(__filePath));
660         SysTryReturnResult(NID_APP, pfilePath != null, E_OUT_OF_MEMORY, "Memory allocation failed. File path conversion failed.");
661
662         __pDoc = xmlParseFile(reinterpret_cast<const char*>(pfilePath->GetPointer()));
663         SysTryReturnResult(NID_APP, __pDoc != null, E_SYSTEM,
664                                            "A system error has been occurred. Can not parse xml file: %ls", __filePath.GetPointer());
665
666         xmlNodePtr rootNodePtr = xmlDocGetRootElement(__pDoc);
667         SysTryReturnResult(NID_APP, rootNodePtr != null, E_SYSTEM, "A system error has been occurred. Can not find root node");
668
669         VisitNode(rootNodePtr);
670
671         return r;
672 }
673
674 result
675 _AppSettingImpl::Save(void)
676 {
677         static const int XML_SAVE_FAILED = -1;
678         static const int XML_SAVE_FORMAT = 1;
679
680         SysTryReturnResult(NID_APP, __pDoc != null, E_SYSTEM,
681                                            "A system error has been occurred. XML Document not valid so can not save it.");
682         std::unique_ptr<ByteBuffer> pfilePath(Tizen::Base::Utility::StringUtil::StringToUtf8N(__filePath));
683         SysTryReturnResult(NID_APP, pfilePath != null, E_OUT_OF_MEMORY, "Memory allocation failed. File path conversion failed.");
684
685         int result = xmlSaveFormatFile(reinterpret_cast<const char*>(pfilePath->GetPointer()), __pDoc, XML_SAVE_FORMAT);
686         SysTryReturnResult(NID_APP, result != XML_SAVE_FAILED, E_SYSTEM, "A system error has been occurred. Document saving failed.");
687
688         return E_SUCCESS;
689 }
690
691 void
692 _AppSettingImpl::VisitNode(xmlNodePtr pCurrentNode)
693 {
694         for (xmlNodePtr nodePtr = pCurrentNode; nodePtr != null; nodePtr = nodePtr->next)       // Visit sibling node
695         {
696                 // Check node name and add to collection.
697                 if (nodePtr->type == XML_ELEMENT_NODE)
698                 {
699                         CheckNodeNameAndAddToCollection(nodePtr);
700                 }
701                 // Visit child node
702                 VisitNode(nodePtr->children);
703         }
704 }
705
706 void
707 _AppSettingImpl::CheckNodeNameAndAddToCollection(xmlNodePtr pNode)
708 {
709         static const char* pPropId = "id";
710         static const char* pPropValue = "value";
711
712         // 1. Get type (bool, integer, string, expandlist)
713         _ElementType detectedType = GetElementType(pNode);
714
715         // Make item and add to collection.
716         if (detectedType != ELEMENT_INVALID)
717         {
718                 // 2. Get "id"
719                 xmlChar* pId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropId));
720                 if (pId)
721                 {
722                         int min = 0;
723                         int max = 255;
724
725                         std::unique_ptr<String> pStrId(new (std::nothrow) String(reinterpret_cast<char*>(pId)));
726                         SysTryReturnVoidResult(NID_APP, pStrId, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
727                                                                    GetErrorMessage(E_OUT_OF_MEMORY));
728
729                         xmlFree(pId);
730
731                         if (pStrId)
732                         {       // 3. Get min(length), max(length) value
733                                 if ((detectedType == ELEMENT_INTEGER) || (detectedType == ELEMENT_STRING))
734                                 {
735                                         GetMinMaxValue(pNode, detectedType, min, max);
736                                 }
737                                 // 4. Get "value"
738                                 String strValue;
739                                 bool validValue = false;
740                                 xmlChar* pValue = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropValue));
741                                 if (pValue)
742                                 {
743                                         strValue = String(reinterpret_cast<char*>(pValue));
744                                         xmlFree(pValue);
745                                         pValue = null;
746                                         validValue = true;
747                                 }
748                                 // 5. Create value object from value
749                                 Object* pValueObject = GetValueObjectN(detectedType, strValue, validValue);
750                                 if (pValueObject)
751                                 {
752                                         _SettingItem* pSettingItem = new (std::nothrow) _SettingItem(pValueObject, min, max, pNode);
753                                         SysTryReturnVoidResult(NID_APP, pSettingItem, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
754                                                                                    GetErrorMessage(E_OUT_OF_MEMORY));
755                                         if (pSettingItem)
756                                         {       // 6. Add item to container
757                                                 SysLog(NID_APP, "AppSetting item adding: ID=%ls min=%d max=%d Value=%ls",
758                                                                         pStrId->GetPointer(), min, max, strValue.GetPointer());
759                                                 __settingContainer.Add(*pStrId.release(), *pSettingItem);
760                                         }
761                                         else
762                                         {
763                                                 SysLog(NID_APP, "Failed create new _SettingItem");
764                                         }
765                                 }
766                         } // pStrId
767                 } // pId
768         } // ELEMET_INVALID
769 }
770
771 _ElementType
772 _AppSettingImpl::GetElementType(xmlNodePtr pNode)
773 {
774         const xmlChar* pElementBool = reinterpret_cast<const xmlChar*>("bool");
775         const xmlChar* pElementInteger = reinterpret_cast<const xmlChar*>("integer");
776         const xmlChar* pElementString = reinterpret_cast<const xmlChar*>("string");
777         const xmlChar* pElementExpandlist = reinterpret_cast<const xmlChar*>("expandlist");
778
779         _ElementType type = ELEMENT_INVALID;
780         if (xmlStrcmp(pNode->name, pElementBool) == 0)
781         {
782                 type = ELEMENT_BOOL;
783         }
784         else
785         if (xmlStrcmp(pNode->name, pElementInteger) == 0)
786         {
787                 type = ELEMENT_INTEGER;
788         }
789         else
790         if (xmlStrcmp(pNode->name, pElementString) == 0)
791         {
792                 type = ELEMENT_STRING;
793         }
794         else
795         if (xmlStrcmp(pNode->name, pElementExpandlist) == 0)
796         {
797                 type = ELEMENT_EXPANDLIST;
798         }
799
800         return type;
801 }
802
803 void
804 _AppSettingImpl::GetMinMaxValue(xmlNodePtr pNode, _ElementType type, int& min, int& max)
805 {
806         const xmlChar* pPropMin = reinterpret_cast<const xmlChar*>("min");
807         const xmlChar* pPropMax = reinterpret_cast<const xmlChar*>("max");
808         const xmlChar* pPropMinLength = reinterpret_cast<const xmlChar*>("minlength");
809         const xmlChar* pPropMaxLength = reinterpret_cast<const xmlChar*>("maxlength");
810
811         if (type == ELEMENT_INTEGER)
812         {
813                 xmlChar* pStrMin = xmlGetProp(pNode, pPropMin);
814                 if (pStrMin)
815                 {
816                         Integer::Parse(reinterpret_cast<char*>(pStrMin), min);
817                         xmlFree(pStrMin);
818                 }
819                 else
820                 {
821                         SysLog(NID_APP, "Failed to get 'min' value.");
822                 }
823
824                 xmlChar* pStrMax = xmlGetProp(pNode, pPropMax);
825                 if (pStrMax)
826                 {
827                         Integer::Parse(reinterpret_cast<char*>(pStrMax), max);
828                         xmlFree(pStrMax);
829                 }
830                 else
831                 {
832                         SysLog(NID_APP, "Failed to get 'max' value.");
833                 }
834         }
835         else
836         if (type == ELEMENT_STRING)
837         {
838                 xmlChar* pStrMin = xmlGetProp(pNode, pPropMinLength);
839                 if (pStrMin)
840                 {
841                         Integer::Parse(reinterpret_cast<char*>(pStrMin), min);
842                         xmlFree(pStrMin);
843                 }
844                 else
845                 {
846                         SysLog(NID_APP, "Failed to get 'minlength' value.");
847                 }
848
849                 xmlChar* pStrMax = xmlGetProp(pNode, pPropMaxLength);
850                 if (pStrMax)
851                 {
852                         Integer::Parse(reinterpret_cast<char*>(pStrMax), max);
853                         xmlFree(pStrMax);
854                 }
855                 else
856                 {
857                         SysLog(NID_APP, "Failed to get 'maxlength' value.");
858                 }
859         }
860         else
861         {
862                 SysLog(NID_APP, "Invalid element type.");
863         }
864 }
865
866 Object*
867 _AppSettingImpl::GetValueObjectN(_ElementType type, String& strValue, bool validValue)
868 {
869         const String strTrue(L"true");
870         Object* pValueObject = null;
871
872         switch (type)
873         {
874         case ELEMENT_BOOL:
875                 {
876                         bool valueBool = false;
877                         if (validValue)
878                         {
879                                 if (strValue == strTrue)
880                                 {
881                                         valueBool = true;
882                                 }
883                         }
884                         pValueObject = new (std::nothrow) Boolean(valueBool);
885                         SysTryReturn(NID_APP, pValueObject != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
886                                                  GetErrorMessage(E_OUT_OF_MEMORY));
887                 }
888                 break;
889
890         case ELEMENT_INTEGER:
891                 {
892                         int valueInteger = 0;
893                         if (validValue)
894                         {
895                                 Integer::Parse(strValue, valueInteger);
896                         }
897                         pValueObject = new (std::nothrow) Integer(valueInteger);
898                         SysTryReturn(NID_APP, pValueObject != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
899                                                  GetErrorMessage(E_OUT_OF_MEMORY));
900                 }
901                 break;
902
903         case ELEMENT_STRING:
904         case ELEMENT_EXPANDLIST:
905                 {
906                         String* pStringObject = new (std::nothrow) String;
907                         SysTryReturn(NID_APP, pStringObject != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
908                                                  GetErrorMessage(E_OUT_OF_MEMORY));
909                         if (pStringObject && validValue)
910                         {
911                                 *pStringObject = strValue;
912                         }
913                         pValueObject = pStringObject;
914                 }
915                 break;
916
917         case ELEMENT_INVALID:
918                 // It already validate by caller;
919                 SysLog(NID_APP, "Invalid element type.");
920                 break;
921         }
922
923         return pValueObject;
924 }
925
926 bool
927 _AppSettingImpl::UpdateProperty(xmlNodePtr pNode, const String& value)
928 {
929         const xmlChar* pPropValue = reinterpret_cast<const xmlChar*>("value");
930
931         if (value.IsEmpty())
932         {
933                 const xmlChar* pZeroLength = reinterpret_cast<const xmlChar*>("");
934                 xmlAttrPtr attrPtr = xmlSetProp(pNode, pPropValue, pZeroLength);
935                 if (attrPtr)
936                 {
937                         return true;
938                 }
939         }
940         else
941         {
942                 std::unique_ptr<ByteBuffer> pBuf(Tizen::Base::Utility::StringUtil::StringToUtf8N(value));
943                 if (pBuf)
944                 {
945                         xmlAttrPtr attrPtr = xmlSetProp(pNode, pPropValue, reinterpret_cast<const xmlChar*>(pBuf->GetPointer()));
946                         if (attrPtr)
947                         {
948                                 return true;
949                         }
950                 }
951                 else
952                 {
953                         SysLog(NID_APP, "StringToUtf8N is failed.");
954                 }
955         }
956         return false;
957 }
958
959 bool
960 _AppSettingImpl::InitializeDBus(void)
961 {
962         DBusError error;
963         dbus_error_init(&error);
964
965         if (pDBusConnection == null)
966         {
967                 char rule[MAX_LOCAL_BUFSIZE];
968                 pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
969                 if (pDBusConnection == null)
970                 {
971                         SysLog(NID_APP, "Fail to connect to the D-BUS daemon: %s", error.message);
972                         dbus_error_free(&error);
973                         return false;
974                 }
975                 dbus_connection_setup_with_g_main(pDBusConnection, null);
976
977                 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
978                 dbus_bus_add_match(pDBusConnection, rule, &error);
979                 if (dbus_error_is_set(&error))
980                 {
981                         SysLog(NID_APP, "Fail to add match : %s", error.message);
982                         dbus_error_free(&error);
983                         return false;
984                 }
985         }
986
987         // this value is vary by AppSetting instance for proper handling.
988         // Should be explicit remove filter on ReleaseInstanceByAppId.
989         if (dbus_connection_add_filter(pDBusConnection, HandleDBusMessage, this, NULL) == FALSE)
990         {
991                 SysLog(NID_APP, "Fail to add filter : %s", error.message);
992                 dbus_error_free(&error);
993                 return false;
994         }
995         return true;
996 }
997
998 DBusHandlerResult
999 _AppSettingImpl::HandleDBusMessage(DBusConnection* connection, DBusMessage* message, void* user_data)
1000 {
1001         int my_pid = getpid();
1002         int sender_pid = 0;
1003         char* pId = NULL;
1004         char* pValue = NULL;
1005
1006         DBusError error;
1007         dbus_error_init(&error);
1008
1009         _AppSettingImpl* pAppSettingImpl = static_cast<_AppSettingImpl*>(user_data);
1010         SysTryLogReturn(NID_APP, pAppSettingImpl != null, DBUS_HANDLER_RESULT_HANDLED,
1011                                         "Not valid pAppSettingImpl from user_data");
1012         String signalString(DBUS_SIGNAL_PREFIX);
1013         signalString += pAppSettingImpl->__correspondAppId;
1014         std::unique_ptr<ByteBuffer> pBufferSignal(Tizen::Base::Utility::StringUtil::StringToUtf8N(signalString));
1015         SysTryLogReturn(NID_APP, pBufferSignal != null, DBUS_HANDLER_RESULT_HANDLED, "pBufferSignal is not valid");
1016         const char* pCharBufferSignal = reinterpret_cast<const char*>(pBufferSignal->GetPointer());
1017
1018         if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, pCharBufferSignal))
1019         {
1020                 if (dbus_message_get_args(message, &error,
1021                                                                   DBUS_TYPE_UINT32, &sender_pid,
1022                                                                   DBUS_TYPE_STRING, &pId,
1023                                                                   DBUS_TYPE_STRING, &pValue,
1024                                                                   DBUS_TYPE_INVALID) == FALSE)
1025                 {
1026                         SysLog(NID_APP, "Fail to get data : %s", error.message);
1027                         dbus_error_free(&error);
1028                         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1029                 }
1030
1031                 if (sender_pid != 0 && my_pid != sender_pid)
1032                 {
1033                         pAppSettingImpl->SetValueFromDBusData(pId, pValue);
1034                 }
1035                 return DBUS_HANDLER_RESULT_HANDLED;
1036         }
1037         else
1038         {
1039                 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1040         }
1041 }
1042
1043 void
1044 _AppSettingImpl::SetValueFromDBusData(const char* pId, const char* pValue)
1045 {
1046         const String delimiter(L"|");
1047         String strId;
1048         String strValue;
1049         int indexOfDelimiter = 0;
1050
1051         // Native Setting module send the key as "id|title" so need to get id part before the '|' character.
1052         // Value is "INT|value" for check box and slider Or "STRING|value" so need to get right side value string.
1053         String strOrg(pId);
1054         strOrg.Trim();
1055         result r = strOrg.IndexOf(delimiter, 0, indexOfDelimiter);
1056         SysTryReturnVoidResult(NID_APP, !IsFailed(r), r, "[%s] Propagating. Bus data parsing failed", GetErrorMessage(r));
1057         strOrg.SubString(0, indexOfDelimiter, strId);   // Get left string of '|'
1058
1059         strOrg = pValue;
1060         strOrg.Trim();
1061         r = strOrg.IndexOf(delimiter, 0, indexOfDelimiter);
1062         SysTryReturnVoidResult(NID_APP, !IsFailed(r), r, "[%s] Propagating. Bus data parsing failed", GetErrorMessage(r));
1063         strOrg.SubString(indexOfDelimiter+1, strValue); // Get right string of '|'
1064
1065         const Object* pObject = __settingContainer.GetValue(strId);
1066         if (pObject)
1067         {
1068                 const _SettingItem* pItem = dynamic_cast<const _SettingItem*>(pObject);
1069                 SysTryReturnVoidResult(NID_APP, pItem != null, E_SYSTEM, "[%s] A system error has been occurred. Casting failed to item.",
1070                                                            GetErrorMessage(E_SYSTEM));
1071                 const Boolean* pBoolean = dynamic_cast<const Boolean*>(pItem->GetValue());
1072                 if (pBoolean)
1073                 {
1074                         static const String strFalse(L"0");
1075                         bool valueBool = true;
1076
1077                         if (strValue == strFalse)
1078                         {
1079                                 valueBool = false;
1080                         }
1081                         SetValue(strId, valueBool, false);
1082                         return;
1083                 }
1084                 const Integer* pInteger = dynamic_cast<const Integer*>(pItem->GetValue());
1085                 if (pInteger)
1086                 {
1087                         int valueInteger = 0;
1088                         Integer::Parse(strValue, valueInteger);
1089                         SetValue(strId, valueInteger, false);
1090                         return;
1091                 }
1092                 const String* pString = dynamic_cast<const String*>(pItem->GetValue());
1093                 if (pString)
1094                 {
1095                         SetValue(strId, strValue, false);
1096                         return;
1097                 }
1098                 SysSecureLog(NID_APP, "Failed determine value type for id= %s", pId);
1099         }
1100         else
1101         {
1102                 SysSecureLog(NID_APP, "Failed find value for id= %s", pId);
1103         }
1104 }
1105
1106 bool
1107 _AppSettingImpl::SendMessage(const String& id, const String& value, bool intType)
1108 {
1109         if (__oldVersionInstance)
1110         {
1111                 return true;    // NOP for old version instance.
1112         }
1113
1114         if (!pDBusConnection)
1115         {
1116                 SysLog(NID_APP, "DBus connection invalid");
1117                 return false;
1118         }
1119
1120         bool result = true;
1121         const String strRightOfId(L"|N/A");
1122         const String strLeftOfValueIntType(L"INT|");
1123         const String strLeftOfValueStrType(L"STRING|");
1124
1125         String strId = id + strRightOfId;
1126         String strValue;
1127         if (intType)
1128         {
1129                 strValue = strLeftOfValueIntType;
1130         }
1131         else
1132         {
1133                 strValue = strLeftOfValueStrType;
1134         }
1135         strValue += value;
1136         String signalString(DBUS_SIGNAL_PREFIX);
1137         signalString += __correspondAppId;
1138
1139         std::unique_ptr<ByteBuffer> pBufferId(Tizen::Base::Utility::StringUtil::StringToUtf8N(strId));
1140         std::unique_ptr<ByteBuffer> pBufferValue(Tizen::Base::Utility::StringUtil::StringToUtf8N(strValue));
1141         std::unique_ptr<ByteBuffer> pBufferSignal(Tizen::Base::Utility::StringUtil::StringToUtf8N(signalString));
1142         if (pBufferId && pBufferValue && pBufferSignal)
1143         {
1144                 int sender_pid = getpid();
1145                 const char* pCharBufferId = reinterpret_cast<const char*>(pBufferId->GetPointer());
1146                 const char* pCharBufferValue = reinterpret_cast<const char*>(pBufferValue->GetPointer());
1147                 const char* pCharBufferSignal = reinterpret_cast<const char*>(pBufferSignal->GetPointer());
1148
1149                 DBusMessage* pMessageWihtAppId = dbus_message_new_signal(DBUS_PATH, DBUS_SIGNAL_INTERFACE, pCharBufferSignal);
1150                 if (dbus_message_append_args(pMessageWihtAppId,
1151                                                                          DBUS_TYPE_UINT32, &sender_pid,
1152                                                                          DBUS_TYPE_STRING, &pCharBufferId,
1153                                                                          DBUS_TYPE_STRING, &pCharBufferValue,
1154                                                                          DBUS_TYPE_INVALID) == FALSE)
1155                 {
1156                         SysLog(NID_APP, "DBus connection invalid");
1157                         result = false;
1158                 }
1159
1160                 if (dbus_connection_send(pDBusConnection, pMessageWihtAppId, NULL) == FALSE)
1161                 {
1162                         SysLog(NID_APP, "Fail to send message");
1163                         result = false;
1164                 }
1165
1166                 dbus_connection_flush(pDBusConnection);
1167                 dbus_message_unref(pMessageWihtAppId);
1168         }
1169         else
1170         {
1171                 SysLog(NID_APP, "System error: memory full ?");
1172         }
1173
1174         return result;
1175 }
1176
1177 AppSetting*
1178 _AppSettingImpl::CreateAppSetting(void)
1179 {
1180         AppSetting* pAppSetting = new (std::nothrow) AppSetting;
1181         SysTryReturn(NID_APP, pAppSetting != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
1182                                  GetErrorMessage(E_OUT_OF_MEMORY));
1183
1184         return pAppSetting;
1185 }
1186
1187 void
1188 _AppSettingImpl::SetImplInstance(AppSetting& appSetting, _AppSettingImpl& impl)
1189 {
1190         appSetting.__pAppSettingImpl = &impl;
1191 }
1192
1193 } } // Tizen::App