86007b0ce00efe36fd99a978f72c6d4ed638018b
[platform/core/system/swap-probe.git] / probe_tizenapi / tizen_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 "tizen_probe.h"
42
43 #include "binproto.h"
44
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Collection;
47
48 namespace Tizen { namespace App
49 {
50
51 //class _IAppImpl
52 //{
53 //      virtual void OnDeviceOrientationChanged(app_device_orientation_e orientation) = 0;
54 //};
55
56 class _AppImpl
57 {
58         static void OnTerminate(void* user_data);
59 //      static void OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data);
60 };
61
62 class _UiAppImpl
63 //      : public Tizen::Base::Object
64 //      , public _IAppImpl
65 {
66         void OnBackground(void);
67         void OnForeground(void);
68 //      virtual void OnDeviceOrientationChanged(app_device_orientation_e orientation);
69 };
70
71 class _AppInfo
72 {
73         static void SetAppState(AppState appstate);
74 };
75
76 result UiApp::Execute(UiAppInstanceFactory pUiAppFactory,
77                 const IList* pArguments)
78 {
79         typedef result (*methodType)(UiAppInstanceFactory pFactory, const IList* pArgs);
80         static methodType uiapp_executep;
81         probeInfo_t     probeInfo;
82         unsigned long __attribute__((unused)) ret;
83
84         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App5UiApp7ExecuteEPFPS1_vEPKNS_4Base10Collection5IListE,
85                 LIBOSP_UIFW, uiapp_executep);
86
87         probeBlockStart();
88         if(gTraceInfo.exec_map.map_start == NULL)
89         {
90                 get_map_address(CALLER_ADDRESS, &(gTraceInfo.exec_map.map_start),
91                                                 &(gTraceInfo.exec_map.map_end));
92         }
93         setProbePoint(&probeInfo);
94         probeBlockEnd();
95
96         ret = uiapp_executep(pUiAppFactory, pArguments);
97
98         probeBlockStart();
99
100         PREPARE_LOCAL_BUF();
101         PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
102                           API_ID_result_UiApp__Execute_UiAppInstanceFactory_pUiAppFactory__const_IList__pArguments_,
103                           "pp", (uint64_t)(pUiAppFactory),
104                           voidp_to_uint64(pArguments));
105         PACK_COMMON_END('x', ret, 0, 0);
106         FLUSH_LOCAL_BUF();
107
108         probeBlockEnd();
109
110         return ret;
111 }
112
113 void _AppImpl::OnTerminate(void* user_data)
114 {
115         typedef void (*methodType)(void*);
116         static methodType appimpl_onterminatep;
117         probeInfo_t     probeInfo;
118
119         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppImpl11OnTerminateEPv, LIBOSP_APPFW, appimpl_onterminatep);
120
121         probeBlockStart();
122         setProbePoint(&probeInfo);
123
124         PREPARE_LOCAL_BUF();
125         PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
126                           API_ID_void__AppImpl__OnTerminate_void__user_data_,
127                           "p", voidp_to_uint64(user_data));
128         PACK_COMMON_END('v', 0, 0, 0);
129         FLUSH_LOCAL_BUF();
130
131         probeBlockEnd();
132
133         appimpl_onterminatep(user_data);
134 }
135 /*
136 void _AppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data)
137 {
138         typedef void (*methodType)(app_device_orientation_e, void*);
139         static methodType appimpl_ondeviceorientationchangedp;
140
141         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppImpl26OnDeviceOrientationChangedE24app_device_orientation_ePv,
142                         LIBOSP_APPFW, appimpl_ondeviceorientationchangedp);
143
144         probeBlockStart();
145         on_orientation_changed((int)orientation, false);
146         probeBlockEnd();
147
148         appimpl_ondeviceorientationchangedp(orientation, user_data);
149 }
150 */
151 void _AppInfo::SetAppState(AppState appState)
152 {
153         typedef void (*methodType)(AppState appstate);
154         static methodType appinfo_setappstatep;
155         probeInfo_t     probeInfo;
156
157         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppInfo11SetAppStateENS0_8AppStateE, LIBOSP_APPFW, appinfo_setappstatep);
158
159         probeBlockStart();
160         if(appState == RUNNING)
161         {
162                 setProbePoint(&probeInfo);
163
164                 PREPARE_LOCAL_BUF();
165                 PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
166                                   API_ID_void__AppInfo__SetAppState_AppState_appState_,
167                                   "x", (uint64_t)(appState));
168                 PACK_COMMON_END('v', 0, 0, 0);
169                 FLUSH_LOCAL_BUF();
170         }
171         probeBlockEnd();
172
173         appinfo_setappstatep(appState);
174 }
175
176 void _UiAppImpl::OnBackground(void)
177 {
178         typedef void (_UiAppImpl::*methodType)(void);
179         static methodType uiappimpl_onbackgroundp;
180         probeInfo_t     probeInfo;
181
182         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App10_UiAppImpl12OnBackgroundEv, LIBOSP_UIFW, uiappimpl_onbackgroundp);
183
184         probeBlockStart();
185         SCREENSHOT_LOCK();
186         setProbePoint(&probeInfo);
187
188         PREPARE_LOCAL_BUF();
189         PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
190                           API_ID_void__UiAppImpl__OnBackground_void_,
191                           "", 0);
192         PACK_COMMON_END('v', 0, 0, 0);
193         FLUSH_LOCAL_BUF();
194
195         probeBlockEnd();
196
197         (this->*uiappimpl_onbackgroundp)();
198 }
199
200 void _UiAppImpl::OnForeground(void)
201 {
202         typedef void (_UiAppImpl::*methodType)(void);
203         static methodType uiappimpl_onforegroundp;
204         probeInfo_t     probeInfo;
205
206         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App10_UiAppImpl12OnForegroundEv, LIBOSP_UIFW, uiappimpl_onforegroundp);
207
208         probeBlockStart();
209         setProbePoint(&probeInfo);
210
211         PREPARE_LOCAL_BUF();
212         PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE,
213                           API_ID_void__UiAppImpl__OnForeground_void_,
214                           "", 0);
215         PACK_COMMON_END('v', 0, 0, 0);
216         FLUSH_LOCAL_BUF();
217
218         SCREENSHOT_UNLOCK();
219 //      SCREENSHOT_DONE();
220         probeBlockEnd();
221
222         (this->*uiappimpl_onforegroundp)();
223 }
224
225 /*
226 void _UiAppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation)
227 {
228         typedef void (*methodType)(_UiAppImpl* th, app_device_orientation_e orientation);
229         static methodType uiappimpl_ondeviceorientationchangedp;
230
231         GET_REAL_FUNC_TIZEN(_ZThn4_N5Tizen3App10_UiAppImpl26OnDeviceOrientationChangedE24app_device_orientation_e,
232                         LIBOSP_UIFW, uiappimpl_ondeviceorientationchangedp);
233
234         probeBlockStart();
235         on_orientation_changed((int)orientation, false);
236         probeBlockEnd();
237
238         uiappimpl_ondeviceorientationchangedp(static_cast<_UiAppImpl*>(dynamic_cast<_IAppImpl*>(this)), orientation);
239 }
240 */
241 } }     // end of namespace