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_ServiceAppImpl.cpp
20 * @brief This is the implementation for the _ServiceAppImpl class.
24 #include <linux/limits.h>
26 #include <FAppAppRegistry.h>
27 #include <FBaseErrors.h>
28 #include <FBaseSysLog.h>
30 #include <FBaseRt_LibraryImpl.h>
32 #include "FApp_AppInfo.h"
33 #include "FApp_AppImpl.h"
34 #include "FApp_ServiceAppImpl.h"
35 #include "FAppPkg_PackageManagerImpl.h"
36 #include "FApp_AppManagerImpl.h"
37 #include "FApp_TemplateUtil.h"
39 using namespace Tizen::App::Package;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Base::Runtime;
44 const wchar_t USE_UI_KEY[] = L"UseUi";
45 const wchar_t USE_UI_VAL_TRUE[] = L"True";
47 static const RequestId HANDLER_REQUEST_ALARMID = 2;
49 namespace Tizen { namespace App
52 _ServiceAppImpl* _ServiceAppImpl::__pServiceAppImpl = null;
55 _ServiceAppImpl::_ServiceAppImpl(ServiceApp* pServiceApp)
56 : __pAppImpl(_AppImpl::GetInstance())
57 , __pServiceApp(pServiceApp)
59 __pServiceAppImpl = this;
60 SysTryReturnVoidResult(NID_APP, __pAppImpl, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
64 _ServiceAppImpl::~_ServiceAppImpl(void)
66 __pServiceAppImpl = null;
71 _ServiceAppImpl::OnCreate(void)
73 SysLog(NID_APP, "Platform creation event.");
75 _AppInfo::SetAppState(INITIALIZING);
82 _ServiceAppImpl::OnService(service_s* service, bool initial)
84 SysLog(NID_APP, "Service requested.");
85 char* pOperation = NULL;
86 int errVal = service_get_operation(service, &pOperation);
88 if ( (errVal == SERVICE_ERROR_NONE) && (!strcmp(pOperation, "osp.appsvc.operation.ALARM")) )
90 char* pAlarmId = NULL;
93 errVal = service_get_extra_data(service, SERVICE_DATA_ALARM_ID, &pAlarmId);
94 if (errVal == SERVICE_ERROR_NONE)
96 //int alarmId = atoi(pAlarmId);
98 String* pAlarmStr = new (std::nothrow) String(pAlarmId);
100 alarmArg.Add(*pAlarmStr);
101 __pServiceApp->OnUserEventReceivedN(HANDLER_REQUEST_ALARMID, &alarmArg);
117 _ServiceAppImpl::OnTerminate(void)
119 SysLog(NID_APP, "Termination event 0x%x state", _AppInfo::GetAppState());
121 if (_AppInfo::GetAppState() == TERMINATED)
126 _AppInfo::SetAppState(TERMINATING);
128 if (OnServiceAppImplTerminating(__pAppImpl->IsForcedTermination()) != true)
130 SysLog(NID_APP, "[E_SYSTEM] The Termination of application failed.");
133 _AppInfo::SetAppState(TERMINATED);
138 _ServiceAppImpl::OnResume(void)
140 SysLog(NID_APP, "System resume event on 0x%x state", _AppInfo::GetAppState());
145 _ServiceAppImpl::OnPause(void)
147 SysLog(NID_APP, "System pause event on 0x%x state", _AppInfo::GetAppState());
152 _ServiceAppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation)
154 SysLog(NID_APP, "System device orientation changed event on 0x%x state", _AppInfo::GetAppState());
159 _ServiceAppImpl::OnWindowHandleRequest(void)
165 _ServiceAppImpl::GetInstance(void)
167 return __pServiceAppImpl;
172 _ServiceAppImpl::GetServiceAppInstance(void)
174 return __pServiceApp;
178 _ServiceAppImpl::OnAppInitializing(void)
180 const String& packageId = _AppInfo::GetPackageId();
181 const String& exeName = _AppInfo::GetAppExecutableName();
183 HashMapT<String, _AppFeatureInfoImpl*>* pInfo = _PackageManagerImpl::GetInstance()->GetPackageAppFeatureMapN(packageId, exeName);
187 _AppFeatureInfoImpl* pFeature = null;
189 result r = pInfo->GetValue(USE_UI_KEY, pFeature);
193 const String& val = pFeature->GetValue();
194 if (val == USE_UI_VAL_TRUE)
196 SysLog(NID_APP, "Using remote ui on service application.");
198 _LibraryImpl& lib = _AppManagerImpl::GetInstance()->GetUiLibraryImpl();
199 result (*pInit)(void) = null;
201 pInit = reinterpret_cast<result (*)()>(lib.GetProcAddress(L"InitializeUiFramework"));
205 SysLog(NID_APP, "[%s] UI initialized.", GetErrorMessage(r));
210 _DeleteCollectionMapValue<String, _AppFeatureInfoImpl>(*pInfo);
214 SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
215 return __pServiceApp->OnAppInitializing(*(AppRegistry::GetInstance()));
219 _ServiceAppImpl::OnAppInitialized(void)
221 SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
222 return __pServiceApp->OnAppInitialized();
226 _ServiceAppImpl::OnServiceAppImplTerminating(bool forcedTermination)
228 SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
229 return __pServiceApp->OnAppTerminating(*(AppRegistry::GetInstance()), forcedTermination);