sync with master
[framework/osp/common-service.git] / src / CommonService.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 #include <FBaseSysLog.h>
19 #include "CommonService.h"
20 #include "FApp_PackageManagerStub.h"
21 #include "FUi_UiManagerStub.h"
22
23 using namespace std;
24 using namespace Tizen::App;
25 using namespace Tizen::Base;
26 using namespace Tizen::System;
27 using namespace Tizen::Ui;
28
29 CommonService::CommonService(void)
30         : __pPackageManagerStub(null)
31 {
32         
33 }
34
35 CommonService::~CommonService(void)
36 {
37         delete __pPackageManagerStub;
38 }
39
40 ServiceApp*
41 CommonService::CreateInstance(void)
42 {
43         // Create the instance through the constructor.
44         return new CommonService();
45 }
46
47 bool
48 CommonService::OnAppInitializing(AppRegistry& appRegistry)
49 {
50         // TODO:
51         // Initialize App specific data.
52         // The App's permanent data and context can be obtained from the appRegistry.
53         //
54         // If this method is successful, return true; otherwise, return false.
55         // If this method returns false, the App will be terminated.
56
57         // TODO: Add your initialization code here
58
59         return true;
60 }
61
62 bool
63 CommonService::OnAppInitialized(void)
64 {
65         InitializeServices();
66         
67         return true;
68 }
69
70 bool
71 CommonService::OnAppWillTerminate(void)
72 {
73         // TODO:
74         // Comment.
75
76         return true;
77 }
78
79 bool
80 CommonService::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
81 {
82         // TODO:
83         // Deallocate resources allocated by this App for termination.
84         // The App's permanent data and context can be saved via appRegistry.
85
86         // TODO: Add your termination code here
87
88         return true;
89 }
90
91 void
92 CommonService::OnLowMemory(void)
93 {
94         // TODO:
95         // Free unused resources or close the App.
96 }
97
98 void
99 CommonService::OnBatteryLevelChanged(BatteryLevel batteryLevel)
100 {
101         // TODO:
102         // Handle any changes in battery level here.
103         // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
104 }
105
106 void
107 CommonService::InitializeServices(void)
108 {
109         __pPackageManagerStub = new (std::nothrow) _PackageManagerStub();
110         SysAssert(__pPackageManagerStub != null);
111
112         result r = __pPackageManagerStub->Construct();
113         SysAssert(!IsFailed(r));        
114
115         unique_ptr<_UiManagerStub> pUiManagerStub(new (std::nothrow) _UiManagerStub());
116         SysTryReturnVoidResult(NID_UI, pUiManagerStub, E_OUT_OF_MEMORY, "Memory is insufficient.");
117
118         r = pUiManagerStub->Construct();
119         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "Propagating.");
120
121         __pUiManagerStub = move(pUiManagerStub);
122 }