Merge "Change the way to conver Mbs to Wcs and vice versa" into tizen_2.1
[platform/framework/native/appfw.git] / src / app / FAppAppResource.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 /**
19  * @file        FAppAppResource.cpp
20  * @brief       This is the implementation for the AppResource class.
21  */
22
23 #include <FBaseResult.h>
24 #include <FBaseSysLog.h>
25 #include <FAppAppResource.h>
26
27 #include <FSec_AccessController.h>
28 #include "FApp_AppResourceImpl.h"
29 #include "FApp_AppInfo.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace App
36 {
37
38 AppResource::AppResource(void)
39         : __pAppResourceImpl(null)
40 {
41 }
42
43
44 AppResource::~AppResource(void)
45 {
46         delete __pAppResourceImpl;
47 }
48
49 result
50 AppResource::GetString(const String& resourceId, String& loadedString) const
51 {
52         SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
53         return __pAppResourceImpl->GetString(resourceId, loadedString);
54 }
55
56
57 Bitmap*
58 AppResource::GetBitmapN(const String& imgFilePath, BitmapPixelFormat pixelFormat) const
59 {
60         SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
61         return __pAppResourceImpl->GetBitmapN(imgFilePath, pixelFormat);
62 }
63
64
65 Bitmap*
66 AppResource::GetBitmapN(const String& imgFilePath) const
67 {
68         SysAssertf(__pAppResourceImpl != null, "Not yet constructed. Construct() should be called before use.");
69         return __pAppResourceImpl->GetBitmapN(imgFilePath);
70 }
71
72
73 AppResource*
74 AppResource::GetInstance(void)
75 {
76         static AppResource* pSelfAppResource = null;
77         if (pSelfAppResource == null)
78         {
79                 pSelfAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_DEFAULT);
80         }
81
82 //      ClearLastResult();      // as this method does not register any exception.
83         return pSelfAppResource;
84 }
85
86 AppResource*
87 AppResource::LoadAppResource(const Tizen::Base::String& resourcePath)
88 {
89         SysTryReturn(NID_APP, !resourcePath.IsEmpty(), null, E_INVALID_ARG, "Resource path is empty");
90
91         AppResource* pAppResource = _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_LIBRARY_NAME, resourcePath);
92         if (GetLastResult() == E_DATA_NOT_FOUND)
93         {
94                 SetLastResult(E_FILE_NOT_FOUND);
95         }
96
97         return pAppResource;
98 }
99
100 AppResource*
101 AppResource::GetInstanceByAppId(const AppId& appId)
102 {
103         result r = E_SUCCESS;
104
105         r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
106         SysTryReturn(NID_APP, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
107
108         SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_APP_NOT_INSTALLED, "Invalid app id");
109
110         String packageId;
111         r = appId.SubString(0, 10, packageId);
112         SysTryReturn(NID_APP, !IsFailed(r), null,
113                         E_APP_NOT_INSTALLED, "[%s] Failed to get the package info", GetErrorMessage(E_APP_NOT_INSTALLED));
114         return _AppResourceImpl::GetInstanceN(APP_RESOURCE_BY_APP_ID, packageId);
115 }
116
117 result
118 AppResource::ReleaseInstanceByAppId(const AppId& appId)
119 {
120         result r = E_SUCCESS;
121
122         r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
123         SysTryReturnResult(NID_APP, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
124
125         if (appId == _AppInfo::GetApplicationId() || appId == _AppInfo::GetPackageId())
126         {
127                 SysLog(NID_APP, "Ignoring key[%ls] with current instance", appId.GetPointer());
128                 return E_SUCCESS;
129         }
130
131         String packageId;
132         r = appId.SubString(0, 10, packageId);
133         SysTryReturn(NID_APP, !IsFailed(r), null,
134                         E_OBJ_NOT_FOUND, "[%s] Failed to get the package info", GetErrorMessage(E_OBJ_NOT_FOUND));
135         return _AppResourceImpl::ReleaseInstance(packageId);
136 }
137
138 } } // Tizen::App