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