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;
43 using namespace Tizen::System;
45 const wchar_t USE_UI_KEY[] = L"UseUi";
46 const wchar_t USE_UI_VAL_TRUE[] = L"True";
48 static const RequestId HANDLER_REQUEST_ALARMID = 2;
50 namespace Tizen { namespace App
53 static const wchar_t* ALARM_PLUGIN_LIBRARY_PATH = L"/opt/apps/aospd00043/lib/libosp-cond-alarm.so";
54 typedef void (*OnAlarmForLaunch)(int alarmId);
56 _ServiceAppImpl* _ServiceAppImpl::__pServiceAppImpl = null;
59 _ServiceAppImpl::_ServiceAppImpl(ServiceApp* pServiceApp)
60 : __pAppImpl(_AppImpl::GetInstance())
61 , __pServiceApp(pServiceApp)
63 __pServiceAppImpl = this;
64 SysTryReturnVoidResult(NID_APP, __pAppImpl, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
68 _ServiceAppImpl::~_ServiceAppImpl(void)
70 __pServiceAppImpl = null;
75 _ServiceAppImpl::OnCreate(void)
77 SysLog(NID_APP, "Platform creation event.");
79 _AppInfo::SetAppState(INITIALIZING);
86 _ServiceAppImpl::OnService(service_s* service, bool initial)
88 SysLog(NID_APP, "Service requested.");
89 char* pOperation = NULL;
90 int errVal = service_get_operation(service, &pOperation);
93 if ( (errVal == SERVICE_ERROR_NONE) && (!strcmp(pOperation, "osp.appsvc.operation.ALARM")) )
95 char* pAlarmId = NULL;
97 errVal = service_get_extra_data(service, SERVICE_DATA_ALARM_ID, &pAlarmId);
98 if (errVal == SERVICE_ERROR_NONE)
100 int alarmId = atoi(pAlarmId);
102 SysLog(NID_SYS, "Start to load external lib");
104 OnAlarmForLaunch pOnAlarmForLaunch = null;
105 r = lib.Construct(ALARM_PLUGIN_LIBRARY_PATH);
109 SysLog(NID_SYS, "Open alarm condition library");
110 pOnAlarmForLaunch = (OnAlarmForLaunch)lib.GetProcAddress(L"OnAlarmForLaunch");
111 if(pOnAlarmForLaunch != null)
113 SysLog(NID_SYS, "Function is found");
114 pOnAlarmForLaunch(alarmId);
115 SysLog(NID_SYS, "Requested to check current alarm id to AlarmConditionHandler %d", alarmId);
119 SysLog(NID_SYS, "Fail to find alarm function");
124 SysLog(NID_SYS, "Fail to open alarm condition library");
141 _ServiceAppImpl::OnTerminate(void)
143 SysLog(NID_APP, "Termination event 0x%x state", _AppInfo::GetAppState());
145 if (_AppInfo::GetAppState() == TERMINATED)
150 _AppInfo::SetAppState(TERMINATING);
152 if (OnServiceAppImplTerminating(__pAppImpl->IsForcedTermination()) != true)
154 SysLog(NID_APP, "[E_SYSTEM] The Termination of application failed.");
157 _AppInfo::SetAppState(TERMINATED);
162 _ServiceAppImpl::OnResume(void)
164 SysLog(NID_APP, "System resume event on 0x%x state", _AppInfo::GetAppState());
169 _ServiceAppImpl::OnPause(void)
171 SysLog(NID_APP, "System pause event on 0x%x state", _AppInfo::GetAppState());
176 _ServiceAppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation)
178 SysLog(NID_APP, "System device orientation changed event on 0x%x state", _AppInfo::GetAppState());
183 _ServiceAppImpl::OnWindowHandleRequest(void)
189 _ServiceAppImpl::GetInstance(void)
191 return __pServiceAppImpl;
196 _ServiceAppImpl::GetServiceAppInstance(void)
198 return __pServiceApp;
202 _ServiceAppImpl::OnAppInitializing(void)
204 const String& packageId = _AppInfo::GetPackageId();
205 const String& exeName = _AppInfo::GetAppExecutableName();
207 HashMapT<String, _AppFeatureInfoImpl*>* pInfo = _PackageManagerImpl::GetInstance()->GetPackageAppFeatureMapN(packageId, exeName);
211 _AppFeatureInfoImpl* pFeature = null;
213 result r = pInfo->GetValue(USE_UI_KEY, pFeature);
217 const String& val = pFeature->GetValue();
218 if (val == USE_UI_VAL_TRUE)
220 SysLog(NID_APP, "Using remote ui on service application.");
222 _LibraryImpl& lib = _AppManagerImpl::GetInstance()->GetUiLibraryImpl();
223 result (*pInit)(void) = null;
225 pInit = reinterpret_cast<result (*)()>(lib.GetProcAddress(L"InitializeUiFramework"));
229 SysLog(NID_APP, "[%s] UI initialized.", GetErrorMessage(r));
234 _DeleteCollectionMapValue<String, _AppFeatureInfoImpl>(*pInfo);
238 SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
239 return __pServiceApp->OnAppInitializing(*(AppRegistry::GetInstance()));
243 _ServiceAppImpl::OnAppInitialized(void)
245 SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
246 return __pServiceApp->OnAppInitialized();
250 _ServiceAppImpl::OnServiceAppImplTerminating(bool forcedTermination)
252 SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
253 return __pServiceApp->OnAppTerminating(*(AppRegistry::GetInstance()), forcedTermination);