sync with tizen_2.0
[platform/framework/native/appfw.git] / src / app / FAppApp.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        FAppApp.cpp
20  * @brief       This is the implementation for the App class.
21  */
22
23 #include <FAppApp.h>
24 #include <FAppAppResource.h>
25 #include <FAppAppRegistry.h>
26 #include <FBaseResult.h>
27 #include <FBaseCol.h>
28
29 #include <FBaseSysLog.h>
30 #include "FApp_AppInfo.h"
31 #include "FApp_AppImpl.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35
36 namespace Tizen { namespace App
37 {
38
39 App::App(void)
40 {
41         __pAppImpl = new (std::nothrow) _AppImpl(this);
42         SysAssertf(__pAppImpl != null, "Allocating memory for App instance failed.");
43         SysTryReturnVoidResult(NID_APP, __pAppImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
44 }
45
46 App::~App(void)
47 {
48         delete __pAppImpl;
49 }
50
51 AppRegistry*
52 App::GetAppRegistry(void) const
53 {
54         return AppRegistry::GetInstance();
55 }
56
57 AppResource*
58 App::GetAppResource(void) const
59 {
60         return AppResource::GetInstance();
61 }
62
63 IList*
64 App::GetAppArgumentListN(void) const
65 {
66         SysAssertf(__pAppImpl != null, "Getting App instance failed.");
67
68         return __pAppImpl->GetAppArgumentListN();
69 }
70
71 AppState
72 App::GetAppState(void) const
73 {
74         return _AppInfo::GetAppState();
75 }
76
77 String
78 App::GetAppName(void) const
79 {
80         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
81         {
82                 return _AppInfo::GetAppName();
83         }
84         else
85         {
86                 return _AppInfo::GetAppExecutableName();
87         }
88 }
89
90 String
91 App::GetAppDisplayName(void) const
92 {
93         return _AppInfo::GetAppName();
94 }
95
96 String
97 App::GetAppVersion(void) const
98 {
99         return _AppInfo::GetAppVersion();
100 }
101
102 AppId
103 App::GetAppId(void) const
104 {
105         return _AppInfo::GetApplicationId();
106 }
107
108 String
109 App::GetAppRootPath(void) const
110 {
111         return _AppInfo::GetAppRootPath();
112 }
113
114 String
115 App::GetAppDataPath(void) const
116 {
117         static String appDataPath(_AppInfo::GetAppRootPath() + L"data/");
118         return appDataPath;
119 }
120
121 String
122 App::GetAppResourcePath(void) const
123 {
124         static String appResPath(_AppInfo::GetAppRootPath() + L"res/");
125         return appResPath;
126 }
127
128 result
129 App::Terminate(void)
130 {
131         SysTryReturnResult(NID_APP, __pAppImpl != null, E_INVALID_STATE, "Getting App instance failed.");
132
133         return __pAppImpl->Terminate();
134 }
135
136 bool
137 App::OnAppInitialized(void)
138 {
139         return true;
140 }
141
142 bool
143 App::OnAppWillTerminate(void)
144 {
145         return true;
146 }
147
148 void
149 App::OnLowMemory(void)
150 {
151
152 }
153
154 void
155 App::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel)
156 {
157
158 }
159
160 result
161 App::SendUserEvent(RequestId requestId, const IList* pArgs)
162 {
163         SysAssertf(__pAppImpl != null, "Getting App instance failed.");
164
165         return __pAppImpl->SendUserEvent(requestId, pArgs);
166 }
167
168 void
169 App::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
170 {
171         if (pArgs != null)
172         {
173                 pArgs->RemoveAll(true);
174                 delete pArgs;
175         }
176 }
177
178 App*
179 App::GetInstance(void)
180 {
181         _AppImpl* pAppImpl = _AppImpl::GetInstance();
182
183         if (pAppImpl != null)
184         {
185                 return pAppImpl->GetAppInstance();
186         }
187
188         return null;
189 }
190
191 }} //Tizen::App
192