Merge "Change the way to conver Mbs to Wcs and vice versa" into tizen_2.1
[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 String
129 App::GetAppSharedPath(void) const
130 {
131         static String appSharedPath(_AppInfo::GetAppRootPath() + L"shared/");
132         return appSharedPath;
133 }
134
135 result
136 App::Terminate(void)
137 {
138         SysTryReturnResult(NID_APP, __pAppImpl != null, E_INVALID_STATE, "Getting App instance failed.");
139
140         return __pAppImpl->Terminate();
141 }
142
143 bool
144 App::OnAppInitialized(void)
145 {
146         return true;
147 }
148
149 bool
150 App::OnAppWillTerminate(void)
151 {
152         return true;
153 }
154
155 void
156 App::OnLowMemory(void)
157 {
158
159 }
160
161 void
162 App::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel)
163 {
164
165 }
166
167 result
168 App::SendUserEvent(RequestId requestId, const IList* pArgs)
169 {
170         SysAssertf(__pAppImpl != null, "Getting App instance failed.");
171
172         return __pAppImpl->SendUserEvent(requestId, pArgs);
173 }
174
175 void
176 App::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
177 {
178         if (pArgs != null)
179         {
180                 pArgs->RemoveAll(true);
181                 delete pArgs;
182         }
183 }
184
185 App*
186 App::GetInstance(void)
187 {
188         _AppImpl* pAppImpl = _AppImpl::GetInstance();
189
190         if (pAppImpl != null)
191         {
192                 return pAppImpl->GetAppInstance();
193         }
194
195         return null;
196 }
197
198 }} //Tizen::App
199