Sync with tizen_2.2.1 appfw spec
[platform/framework/native/appfw.git] / src / app / FAppApp.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FAppApp.cpp
19  * @brief       This is the implementation for the App class.
20  */
21
22 #include <FAppApp.h>
23 #include <FAppAppResource.h>
24 #include <FAppAppRegistry.h>
25 #include <FBaseResult.h>
26 #include <FBaseCol.h>
27
28 #include <FBaseSysLog.h>
29 #include "FApp_AppInfo.h"
30 #include "FApp_AppImpl.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34
35 namespace Tizen { namespace App
36 {
37
38 App::App(void)
39 {
40         __pAppImpl = new (std::nothrow) _AppImpl(this);
41         SysAssertf(__pAppImpl != null, "Allocating memory for App instance failed.");
42         SysTryReturnVoidResult(NID_APP, __pAppImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
43 }
44
45 App::~App(void)
46 {
47         delete __pAppImpl;
48 }
49
50 AppRegistry*
51 App::GetAppRegistry(void) const
52 {
53         return AppRegistry::GetInstance();
54 }
55
56 AppResource*
57 App::GetAppResource(void) const
58 {
59         return AppResource::GetInstance();
60 }
61
62 IList*
63 App::GetAppArgumentListN(void) const
64 {
65         SysAssertf(__pAppImpl != null, "Getting App instance failed.");
66
67         return __pAppImpl->GetAppArgumentListN();
68 }
69
70 AppState
71 App::GetAppState(void) const
72 {
73         return _AppInfo::GetAppState();
74 }
75
76 String
77 App::GetAppName(void) const
78 {
79         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
80         {
81                 return _AppInfo::GetAppName();
82         }
83         else
84         {
85                 return _AppInfo::GetAppExecutableName();
86         }
87 }
88
89 String
90 App::GetAppDisplayName(void) const
91 {
92         return _AppInfo::GetAppName();
93 }
94
95 String
96 App::GetAppVersion(void) const
97 {
98         return _AppInfo::GetAppVersion();
99 }
100
101 AppId
102 App::GetAppId(void) const
103 {
104         return _AppInfo::GetApplicationId();
105 }
106
107 String
108 App::GetAppRootPath(void) const
109 {
110         return _AppInfo::GetAppRootPath();
111 }
112
113 String
114 App::GetAppDataPath(void) const
115 {
116         static String appDataPath(_AppInfo::GetAppRootPath() + L"data/");
117         return appDataPath;
118 }
119
120 String
121 App::GetAppResourcePath(void) const
122 {
123         static String appResPath(_AppInfo::GetAppRootPath() + L"res/");
124         return appResPath;
125 }
126
127 String
128 App::GetAppSharedPath(void) const
129 {
130         static String appSharedPath(_AppInfo::GetAppRootPath() + L"shared/");
131         return appSharedPath;
132 }
133
134 result
135 App::Terminate(void)
136 {
137         SysTryReturnResult(NID_APP, __pAppImpl != null, E_INVALID_STATE, "Getting App instance failed.");
138
139         return __pAppImpl->Terminate();
140 }
141
142 bool
143 App::OnAppInitialized(void)
144 {
145         return true;
146 }
147
148 bool
149 App::OnAppWillTerminate(void)
150 {
151         return true;
152 }
153
154 void
155 App::OnLowMemory(void)
156 {
157
158 }
159
160 void
161 App::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel)
162 {
163
164 }
165
166 result
167 App::SendUserEvent(RequestId requestId, const IList* pArgs)
168 {
169         SysAssertf(__pAppImpl != null, "Getting App instance failed.");
170
171         return __pAppImpl->SendUserEvent(requestId, pArgs, true);
172 }
173
174 void
175 App::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
176 {
177         if (pArgs != null)
178         {
179                 pArgs->RemoveAll(true);
180                 delete pArgs;
181         }
182 }
183
184 App*
185 App::GetInstance(void)
186 {
187         _AppImpl* pAppImpl = _AppImpl::GetInstance();
188
189         if (pAppImpl != null)
190         {
191                 return pAppImpl->GetAppInstance();
192         }
193
194         return null;
195 }
196
197 }} //Tizen::App
198