2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FApp_AppResourceImpl.cpp
20 * @brief This is the implementation for the _AppResourceImpl class.
23 #include <FBaseObject.h>
24 #include <FBaseString.h>
25 #include <FBaseResult.h>
26 #include <FBaseSysLog.h>
27 #include <FAppAppResource.h>
29 #include <FBaseRt_LibraryImpl.h>
31 #include "FApp_AppResourceImpl.h"
32 #include "FApp_AppResourceString.h"
33 #include "FApp_AppManagerImpl.h"
34 #include "FApp_IAppResourceBitmap.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Io;
39 using namespace Tizen::Locales;
40 using namespace Tizen::System;
42 using namespace Tizen::Graphics;
44 namespace Tizen { namespace App
47 #define BITMAP_PIXEL_FORMAT_INVALID (BITMAP_PIXEL_FORMAT_MIN)
49 static _IAppResourceBitmap*(* p_Create_AppResourceBitmapInstanceN)(void) = null;
50 static _IAppResourceBitmap*(* p_Create_AppResourceBitmapInstanceByAppIdN)(const String& appId) = null;
52 _AppResourceImpl::_AppResourceImpl(void)
53 : __pAppResource(null)
54 , __p_AppResourceString(null)
55 , __p_IAppResourceBitmap(null)
62 _AppResourceImpl::Construct(const Locale& locale)
69 _AppResourceImpl::Construct(void)
75 _AppResourceImpl::Construct(const AppId& appId)
78 if (__p_AppResourceString == null)
80 __p_AppResourceString = new (std::nothrow) _AppResourceString();
81 SysTryReturnResult(NID_APP, __p_AppResourceString != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]Failed to create String resource");
83 r = __p_AppResourceString->Construct(appId);
84 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to construct String resource", GetErrorMessage(r));
87 if (p_Create_AppResourceBitmapInstanceByAppIdN == null)
89 _LibraryImpl& lib = _AppManagerImpl::GetInstance()->GetUiLibraryImpl();
90 p_Create_AppResourceBitmapInstanceByAppIdN = reinterpret_cast<_IAppResourceBitmap*(*)(const String& appId)>(lib.GetProcAddress(L"_Create_IAppResourceBitmapInstanceByAppIdN"));
91 SysTryCatch(NID_APP, p_Create_AppResourceBitmapInstanceByAppIdN != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to get Bitmap resource [%s].", GetErrorMessage(GetLastResult()));
94 if (__p_IAppResourceBitmap == null)
96 __p_IAppResourceBitmap = p_Create_AppResourceBitmapInstanceByAppIdN(appId);
97 SysTryCatch(NID_APP, __p_IAppResourceBitmap != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to get Bitmap resource.");
104 delete __p_AppResourceString;
105 __p_AppResourceString = null;
110 _AppResourceImpl::~_AppResourceImpl(void)
112 delete __p_AppResourceString;
113 delete __p_IAppResourceBitmap;
118 _AppResourceImpl::GetString(const String& resourceId, String& loadedString)
120 result r = E_SUCCESS;
122 if ((__isByAppId == false) && (__p_AppResourceString == null))
124 __p_AppResourceString = new (std::nothrow) _AppResourceString();
125 SysTryReturnResult(NID_APP, __p_AppResourceString != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]Not enough memory.");
127 r = __p_AppResourceString->Construct();
128 SysTryCatch(NID_APP, !IsFailed(r), , r = E_SYSTEM, "[E_SYSTEM] Failed to get String resource.");
131 r = __p_AppResourceString->GetString(resourceId, loadedString);
139 _AppResourceImpl::GetBitmapN(const String& imgFilePath, BitmapPixelFormat pixelFormat)
141 if (__isByAppId == false)
143 if (p_Create_AppResourceBitmapInstanceN == null)
145 _LibraryImpl& lib = _AppManagerImpl::GetInstance()->GetUiLibraryImpl();
146 p_Create_AppResourceBitmapInstanceN = reinterpret_cast<_IAppResourceBitmap*(*)(void)>(lib.GetProcAddress(L"_Create_IAppResourceBitmapInstanceN"));
147 SysTryCatch(NID_APP, p_Create_AppResourceBitmapInstanceN != null, , E_SYSTEM, "[E_SYSTEM] Failed to get Bitmap resource [%s].", GetErrorMessage(GetLastResult()));
150 if (__p_IAppResourceBitmap == null)
152 __p_IAppResourceBitmap = p_Create_AppResourceBitmapInstanceN();
153 SysTryCatch(NID_APP, __p_IAppResourceBitmap != null, , E_SYSTEM, "[E_SYSTEM] Failed to get Bitmap resource.");
157 return __p_IAppResourceBitmap->GetBitmapN(imgFilePath, pixelFormat);
165 _AppResourceImpl::GetBitmapN(const String& imgFilePath)
167 return GetBitmapN(imgFilePath, BITMAP_PIXEL_FORMAT_INVALID);
172 _AppResourceImpl::GetAppResource(void)
174 return __pAppResource;
178 _AppResourceImpl::GetInstance(void)
180 // return __pAppResource->__pAppResourceImpl;
181 return AppResource::GetInstance()->__pAppResourceImpl;
185 _AppResourceImpl::Reinitialize(void)
187 if (__p_AppResourceString != null)
190 __p_AppResourceString->Initialize();
192 AppResource::Reinitialize();
196 _AppResourceImpl::Reinitialize(const AppId& appId)
198 __p_AppResourceString->Initialize(appId);