31e6ee8af00268343974da09f9ced14d8f24b727
[platform/core/system/swap-probe.git] / probe_badaapi / bada_lifecycle.cpp
1 /*
2  *  DA probe
3  *
4  * Copyright (File::*c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  * Anastasia Lyupa <a.lyupa@samsung.com>
12  *
13  * This library is free software; you can redistribute it and/or modify it under
14  * the terms of the GNU Lesser General Public License as published by the
15  * Free Software Foundation; either version 2.1 of the License, or (at your option)
16  * any later version.
17  *
18  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21  * License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this library; if not, write to the Free Software Foundation, Inc., 51
25  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26  *
27  * Contributors:
28  * - S-Core Co., Ltd
29  * - Samsung RnD Institute Russia
30  *
31  */
32
33 #include <app.h>
34 #include <Ecore.h>
35 #include <FApp.h>
36 #include <FBase.h>
37
38 #include "daprobe.h"
39 #include "dahelper.h"
40 #include "probeinfo.h"
41 #include "osp_probe.h"
42
43 #include "binproto.h"
44 extern "C"
45 {
46 Ecore_Event_Handler* register_orientation_event_listener();
47 void unregister_orientation_event_listener(Ecore_Event_Handler* handler);
48 }
49
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52
53 namespace Tizen { namespace App
54 {
55
56 //class _IAppImpl
57 //{
58 //      virtual void OnDeviceOrientationChanged(app_device_orientation_e orientation) = 0;
59 //};
60
61 class _AppImpl
62 {
63         static void OnTerminate(void* user_data);
64 //      static void OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data);
65 };
66
67 class _UiAppImpl
68 //      : public Tizen::Base::Object
69 //      , public _IAppImpl
70 {
71         void OnBackground(void);
72         void OnForeground(void);
73 //      virtual void OnDeviceOrientationChanged(app_device_orientation_e orientation);
74 };
75
76 class _AppInfo
77 {
78         static void SetAppState(AppState appstate);
79 };
80
81 result UiApp::Execute(UiAppInstanceFactory pUiAppFactory,
82                 const IList* pArguments)
83 {
84         typedef result (*methodType)(UiAppInstanceFactory pFactory, const IList* pArgs);
85         static methodType uiapp_executep;
86         DECLARE_VARIABLE_STANDARD;
87         Ecore_Event_Handler* handler;
88
89         GET_REAL_FUNC_OSP(_ZN5Tizen3App5UiApp7ExecuteEPFPS1_vEPKNS_4Base10Collection5IListE,
90                 LIBOSP_UIFW, uiapp_executep);
91
92         probeBlockStart();
93         handler = register_orientation_event_listener();
94         if(gTraceInfo.exec_map.map_start == NULL)
95         {
96                 get_map_address(CALLER_ADDRESS, &(gTraceInfo.exec_map.map_start),
97                                                 &(gTraceInfo.exec_map.map_end));
98         }
99         setProbePoint(&probeInfo);
100         probeBlockEnd();
101
102         ret = uiapp_executep(pUiAppFactory, pArguments);
103
104         probeBlockStart();
105
106         PREPARE_LOCAL_BUF();
107         PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
108                           API_ID_result_UiApp__Execute_UiAppInstanceFactory_pUiAppFactory__const_IList__pArguments_,
109                           "pp", pUiAppFactory, pArguments);
110         PACK_COMMON_END(ret, 0, 0);
111         FLUSH_LOCAL_BUF();
112
113         unregister_orientation_event_listener(handler);
114         probeBlockEnd();
115
116         return ret;
117 }
118
119 void _AppImpl::OnTerminate(void* user_data)
120 {
121         typedef void (*methodType)(void*);
122         static methodType appimpl_onterminatep;
123         probeInfo_t     probeInfo;
124
125         GET_REAL_FUNC_OSP(_ZN5Tizen3App8_AppImpl11OnTerminateEPv, LIBOSP_APPFW, appimpl_onterminatep);
126
127         probeBlockStart();
128         setProbePoint(&probeInfo);
129
130         PREPARE_LOCAL_BUF();
131         PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
132                           API_ID_void__AppImpl__OnTerminate_void__user_data_,
133                           "p", user_data);
134         PACK_COMMON_END(0, 0, 0);
135         FLUSH_LOCAL_BUF();
136
137         probeBlockEnd();
138
139         appimpl_onterminatep(user_data);
140 }
141 /*
142 void _AppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data)
143 {
144         typedef void (*methodType)(app_device_orientation_e, void*);
145         static methodType appimpl_ondeviceorientationchangedp;
146
147         GET_REAL_FUNC_OSP(_ZN5Tizen3App8_AppImpl26OnDeviceOrientationChangedE24app_device_orientation_ePv,
148                         LIBOSP_APPFW, appimpl_ondeviceorientationchangedp);
149
150         probeBlockStart();
151         on_orientation_changed((int)orientation, false);
152         probeBlockEnd();
153
154         appimpl_ondeviceorientationchangedp(orientation, user_data);
155 }
156 */
157 void _AppInfo::SetAppState(AppState appState)
158 {
159         typedef void (*methodType)(AppState appstate);
160         static methodType appinfo_setappstatep;
161         probeInfo_t     probeInfo;
162
163         GET_REAL_FUNC_OSP(_ZN5Tizen3App8_AppInfo11SetAppStateENS0_8AppStateE, LIBOSP_APPFW, appinfo_setappstatep);
164
165         probeBlockStart();
166         if(appState == RUNNING)
167         {
168                 setProbePoint(&probeInfo);
169
170                 PREPARE_LOCAL_BUF();
171                 PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
172                                   API_ID_void__AppInfo__SetAppState_AppState_appState_,
173                                   "p", appState);
174                 PACK_COMMON_END(0, 0, 0);
175                 FLUSH_LOCAL_BUF();
176         }
177         probeBlockEnd();
178
179         appinfo_setappstatep(appState);
180 }
181
182 void _UiAppImpl::OnBackground(void)
183 {
184         typedef void (_UiAppImpl::*methodType)(void);
185         static methodType uiappimpl_onbackgroundp;
186         probeInfo_t     probeInfo;
187
188         GET_REAL_FUNC_OSP(_ZN5Tizen3App10_UiAppImpl12OnBackgroundEv, LIBOSP_UIFW, uiappimpl_onbackgroundp);
189
190         probeBlockStart();
191         SCREENSHOT_LOCK();
192         setProbePoint(&probeInfo);
193
194         PREPARE_LOCAL_BUF();
195         PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
196                           API_ID_void__UiAppImpl__OnBackground_void_,
197                           "", 0);
198         PACK_COMMON_END(0, 0, 0);
199         FLUSH_LOCAL_BUF();
200
201         probeBlockEnd();
202
203         (this->*uiappimpl_onbackgroundp)();
204 }
205
206 void _UiAppImpl::OnForeground(void)
207 {
208         typedef void (_UiAppImpl::*methodType)(void);
209         static methodType uiappimpl_onforegroundp;
210         probeInfo_t     probeInfo;
211
212         GET_REAL_FUNC_OSP(_ZN5Tizen3App10_UiAppImpl12OnForegroundEv, LIBOSP_UIFW, uiappimpl_onforegroundp);
213
214         probeBlockStart();
215         setProbePoint(&probeInfo);
216
217         PREPARE_LOCAL_BUF();
218         PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
219                           API_ID_void__UiAppImpl__OnForeground_void_,
220                           "", 0);
221         PACK_COMMON_END(0, 0, 0);
222         FLUSH_LOCAL_BUF();
223
224         SCREENSHOT_UNLOCK();
225 //      SCREENSHOT_DONE();
226         probeBlockEnd();
227
228         (this->*uiappimpl_onforegroundp)();
229 }
230
231 /*
232 void _UiAppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation)
233 {
234         typedef void (*methodType)(_UiAppImpl* th, app_device_orientation_e orientation);
235         static methodType uiappimpl_ondeviceorientationchangedp;
236
237         GET_REAL_FUNC_OSP(_ZThn4_N5Tizen3App10_UiAppImpl26OnDeviceOrientationChangedE24app_device_orientation_e,
238                         LIBOSP_UIFW, uiappimpl_ondeviceorientationchangedp);
239
240         probeBlockStart();
241         on_orientation_changed((int)orientation, false);
242         probeBlockEnd();
243
244         uiappimpl_ondeviceorientationchangedp(static_cast<_UiAppImpl*>(dynamic_cast<_IAppImpl*>(this)), orientation);
245 }
246 */
247 } }     // end of namespace