Initialize Tizen 2.3
[framework/system/dynamic-analysis-probe.git] / probe_tizenapi / tizen_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 <Ecore.h>
33 #include <FApp.h>
34 #include <FBase.h>
35
36 #include "daprobe.h"
37 #include "dahelper.h"
38 #include "probeinfo.h"
39 #include "tizen_probe.h"
40
41 extern "C"
42 {
43 Ecore_Event_Handler* register_orientation_event_listener();
44 void unregister_orientation_event_listener(Ecore_Event_Handler* handler);
45 }
46
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49
50 #define LIFECYCLE_PROBE_BLOCK(FUNCNAME)                                 \
51         setProbePoint(&probeInfo);                                                      \
52         INIT_LOG;                                                                                       \
53         APPEND_LOG_BASIC_NAME(LC_LIFECYCLE, FUNCNAME);          \
54         APPEND_LOG_COMMON_NONE(CALLER_ADDRESS);                         \
55         printLog(&log, MSG_LOG)
56
57 namespace Tizen { namespace App
58 {
59
60 //class _IAppImpl
61 //{
62 //      virtual void OnDeviceOrientationChanged(app_device_orientation_e orientation) = 0;
63 //};
64
65 class _AppImpl
66 {
67         static void OnTerminate(void* user_data);
68 //      static void OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data);
69 };
70
71 class _UiAppImpl 
72 //      : public Tizen::Base::Object
73 //      , public _IAppImpl
74 {
75         void OnBackground(void);
76         void OnForeground(void);
77 //      virtual void OnDeviceOrientationChanged(app_device_orientation_e orientation);
78 };
79
80 class _AppInfo
81 {
82         static void SetAppState(AppState appstate);
83 };
84
85 result UiApp::Execute(UiAppInstanceFactory pUiAppFactory,
86                 const IList* pArguments)
87 {
88         typedef result (*methodType)(UiAppInstanceFactory pFactory, const IList* pArgs);
89         static methodType uiapp_executep;
90         DECLARE_COMMON_VARIABLE;
91         Ecore_Event_Handler* handler;
92         result ret;
93
94         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App5UiApp7ExecuteEPFPS1_vEPKNS_4Base10Collection5IListE,
95                 LIBOSP_UIFW, uiapp_executep);
96
97         probeBlockStart();
98         handler = register_orientation_event_listener();
99         if(gTraceInfo.exec_map.map_start == NULL)
100         {
101                 get_map_address(CALLER_ADDRESS, &(gTraceInfo.exec_map.map_start),
102                                                 &(gTraceInfo.exec_map.map_end));
103         }
104         LIFECYCLE_PROBE_BLOCK("INITIALIZING");
105         probeBlockEnd();
106
107         ret = uiapp_executep(pUiAppFactory, pArguments);
108
109         probeBlockStart();
110         unregister_orientation_event_listener(handler);
111         probeBlockEnd();
112
113         return ret;
114 }
115
116 void _AppImpl::OnTerminate(void* user_data)
117 {
118         typedef void (*methodType)(void*);
119         static methodType appimpl_onterminatep;
120         DECLARE_COMMON_VARIABLE;
121         
122         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppImpl11OnTerminateEPv, LIBOSP_APPFW, appimpl_onterminatep);
123
124         probeBlockStart();
125         LIFECYCLE_PROBE_BLOCK("TERMINATING");
126         probeBlockEnd();
127
128         appimpl_onterminatep(user_data);
129 }
130 /*
131 void _AppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data)
132 {
133         typedef void (*methodType)(app_device_orientation_e, void*);
134         static methodType appimpl_ondeviceorientationchangedp;
135         
136         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppImpl26OnDeviceOrientationChangedE24app_device_orientation_ePv,
137                         LIBOSP_APPFW, appimpl_ondeviceorientationchangedp);
138
139         probeBlockStart();
140         on_orientation_changed((int)orientation, false);
141         probeBlockEnd();
142
143         appimpl_ondeviceorientationchangedp(orientation, user_data);
144 }
145 */
146 void _AppInfo::SetAppState(AppState appState)
147 {
148         typedef void (*methodType)(AppState appstate);
149         static methodType appinfo_setappstatep;
150         DECLARE_COMMON_VARIABLE;
151         
152         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppInfo11SetAppStateENS0_8AppStateE, LIBOSP_APPFW, appinfo_setappstatep);
153
154         probeBlockStart();
155         if(appState == RUNNING)
156         {
157                 LIFECYCLE_PROBE_BLOCK("RUNNING");
158         }
159         probeBlockEnd();
160
161         appinfo_setappstatep(appState);
162 }
163
164 void _UiAppImpl::OnBackground(void)
165 {
166         typedef void (_UiAppImpl::*methodType)(void);
167         static methodType uiappimpl_onbackgroundp;
168         DECLARE_COMMON_VARIABLE;
169         
170         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App10_UiAppImpl12OnBackgroundEv, LIBOSP_UIFW, uiappimpl_onbackgroundp);
171
172         probeBlockStart();
173         SCREENSHOT_LOCK();
174         LIFECYCLE_PROBE_BLOCK("PAUSING");
175         probeBlockEnd();
176
177         (this->*uiappimpl_onbackgroundp)();
178 }
179
180 void _UiAppImpl::OnForeground(void)
181 {
182         typedef void (_UiAppImpl::*methodType)(void);
183         static methodType uiappimpl_onforegroundp;
184         DECLARE_COMMON_VARIABLE;
185         
186         GET_REAL_FUNC_TIZEN(_ZN5Tizen3App10_UiAppImpl12OnForegroundEv, LIBOSP_UIFW, uiappimpl_onforegroundp);
187
188         probeBlockStart();
189         LIFECYCLE_PROBE_BLOCK("RUNNING");
190         SCREENSHOT_UNLOCK();
191 //      SCREENSHOT_DONE();
192         probeBlockEnd();
193
194         (this->*uiappimpl_onforegroundp)();
195 }
196
197 /*
198 void _UiAppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation)
199 {
200         typedef void (*methodType)(_UiAppImpl* th, app_device_orientation_e orientation);
201         static methodType uiappimpl_ondeviceorientationchangedp;
202         
203         GET_REAL_FUNC_TIZEN(_ZThn4_N5Tizen3App10_UiAppImpl26OnDeviceOrientationChangedE24app_device_orientation_e,
204                         LIBOSP_UIFW, uiappimpl_ondeviceorientationchangedp);
205
206         probeBlockStart();
207         on_orientation_changed((int)orientation, false);
208         probeBlockEnd();
209
210         uiappimpl_ondeviceorientationchangedp(static_cast<_UiAppImpl*>(dynamic_cast<_IAppImpl*>(this)), orientation);
211 }
212 */
213 } }     // end of namespace
214