change Copyright headers, change line endings to Unix format
[platform/core/system/swap-probe.git] / include / dahelper.h
1 /*
2  *  DA probe
3  *
4  * Copyright (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 #ifndef _DAHELPER_H_
32 #define _DAHELPER_H_
33
34 #include <stdbool.h>
35 #include <pthread.h>                    // for pthread_mutex_t
36
37 #include <Evas.h>
38
39 #include "daprobe.h"
40
41 #ifdef __cplusplus
42 extern "C"{
43 #endif
44
45 #define MAX_PATH_LENGTH         256
46 #define MAX_STACK_DEPTH         128
47 #define TRIM_STACK_DEPTH        2
48
49 /*
50 #define WIN_RENDER_POST 0
51 #define CONTROLBAR_RENDER_POST 1
52 #define NAVIFRAME_RENDER_POST 2
53 #define PAGER_RENDER_POST 3
54 #define RENDER_POST_COUNT 4
55
56 #define SNAPSHOT_WAIT_TIME_MAX 10000
57 */
58
59 #define TS_NONE                                         0x00000000
60 #define TS_PROBE                                        0x00000001
61 #define TS_INIT                                         0x00000002
62 #define TS_FINIT                                        0x00000004
63 #define TS_ENTER_PROBE_BLOCK            0x00000008
64 #define TS_SET_PROBE_POINT                      0x00000010
65 #define TS_PRINT_LOG                            0x00000020
66 #define TS_PRINT_SAMPLE_LOG                     0x00000040
67 #define TS_APPEND_TYPE_LOG                      0x00000080
68 #define TS_BACKTRACE                            0x00000100
69 #define TS_HASHFUNC                                     0x00000200
70 #define TS_PROFIL_THREAD                        0x00000400
71 #define TS_PROFIL_COUNT                         0x00000800
72 #define TS_DETECT_TOUCH                         0x00001000
73 #define TS_REGIST_SCREEN_CHANGE         0x00002000
74 #define TS_POSSIBLE_CAPTURE                     0x00004000
75 #define TS_RECV_THREAD                          0x00008000
76 #define TS_CUSTOM_CHART_THREAD          0x00010000
77 #define TRACE_STATE_SET(value)          ((gSTrace) |= (value))
78 #define TRACE_STATE_UNSET(value)        ((gSTrace) &= (~value))
79
80 #define ENABLE_INTERNAL_MALLOC          0x0001
81 #define ENABLE_SNAPSHOT                         0x0002
82
83 #define SCREENSHOT_LOCK()                                                                               \
84         do {                                                                                                            \
85                 int old;                                                                                                \
86                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
87                 old = gTraceInfo.screenshot.state;                                              \
88                 gTraceInfo.screenshot.state = -1;                                               \
89                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
90                 if(old > 0) {                                                                                   \
91                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
92                                 captureScreen();                                                                \
93                 }                                                                                                               \
94         } while(0)
95
96 #define SCREENSHOT_UNLOCK()                                                                             \
97         do {                                                                                                            \
98                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
99                 gTraceInfo.screenshot.state = 1;                                                \
100                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
101         } while(0)
102
103 #define SCREENSHOT_SET()                                                                                \
104         do {                                                                                                            \
105                 int old;                                                                                                \
106                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
107                 old = gTraceInfo.screenshot.state;                                              \
108                 if(gTraceInfo.screenshot.state >= 0)                                    \
109                         gTraceInfo.screenshot.state = 1;                                        \
110                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
111                 if(old == 2) {                                                                                  \
112                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
113                                 captureScreen();                                                                \
114                 }                                                                                                               \
115         } while(0)
116
117 #define SCREENSHOT_UNSET()                                                                              \
118         do {                                                                                                            \
119                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
120                 if(gTraceInfo.screenshot.state >= 0)                                    \
121                         gTraceInfo.screenshot.state = 0;                                        \
122                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
123         } while(0)
124
125 #define SCREENSHOT_DONE()                                                                               \
126         do {                                                                                                            \
127                 int old;                                                                                                \
128                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
129                 old = gTraceInfo.screenshot.state;                                              \
130                 if(gTraceInfo.screenshot.state == 1) {                                  \
131                         gTraceInfo.screenshot.state = 2;                                        \
132                 } else if(gTraceInfo.screenshot.state == 2) {                   \
133                         gTraceInfo.screenshot.state = 0;                                        \
134                 } else {                                                                                                \
135                 }                                                                                                               \
136                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
137                 if(old == 1) {                                                                                  \
138                         activateCaptureTimer();                                                         \
139                 } else if(old == 2) {                                                                   \
140                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
141                                 captureScreen();                                                                \
142                 }                                                                                                               \
143         } while(0)
144
145 #define NUM_ORIGINAL_LIBRARY    9
146
147 typedef enum
148 {
149         LIBC = 0,
150         LIBPTHREAD = 1,
151         LIBELEMENTARY = 2,
152         LIBOSP_UIFW = 3,
153         LIBOSP_APPFW = 4,
154         LIBOSP_WEB = 5,
155         LIBECORE_INPUT_EVAS = 6,
156         LIBDAEMON = 7,
157         LIBCAPI_APPFW_APPLICATION = 8
158 } ORIGINAL_LIBRARY;
159
160 extern char *lib_string[NUM_ORIGINAL_LIBRARY];
161 extern void *lib_handle[NUM_ORIGINAL_LIBRARY];
162
163 // type definition for global variable
164 typedef struct
165 {
166         int eventIndex;
167         pthread_mutex_t eventMutex;
168 } __indexInfo;
169
170 typedef struct
171 {
172         int daemonSock;
173         pthread_mutex_t sockMutex;
174 } __socketInfo;
175
176 typedef struct
177 {
178         char appName[128];
179         unsigned int startTime;
180 } __appInfo;
181
182 typedef struct
183 {
184         int state;
185         pthread_mutex_t ssMutex;
186 } __screenshotInfo;
187
188 typedef struct
189 {
190         void* map_start;
191         void* map_end;
192 } __mapInfo;
193
194 typedef struct
195 {
196         __indexInfo                     index;
197         __socketInfo            socket;
198         __appInfo                       app;
199         __screenshotInfo        screenshot;
200         __mapInfo                       exec_map;
201         int                                     stateTouch;
202         int                                     init_complete;
203         int                                     custom_chart_callback_count;
204         unsigned long           optionflag;
205 } __traceInfo;
206
207 extern __thread unsigned long   gSTrace;
208 extern __traceInfo gTraceInfo;
209
210 int get_map_address(void* symbol, void** map_start, void** map_end);
211 char** da_backtrace_symbols (void* const* array, int size);
212 char** cached_backtrace_symbols (void* const* array, int size);
213
214 // profil turned on
215 int __profil(int mode);
216
217 //wchar_t* -> char*
218 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
219
220 // screen capture functions
221 int initialize_screencapture();
222 int finalize_screencapture();
223 int captureScreen();
224 int activateCaptureTimer();
225 void _cb_render_post(void* data, Evas* e, void* eventinfo);
226
227 // event related functions
228 int initialize_event();
229 int finalize_event();
230 int getOrientation();
231 void orientationEnabled();
232 void on_orientation_changed(int angle, bool capi);
233
234 int remove_indir(const char* dirname);
235
236 // query functions
237 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
238
239 #ifdef __cplusplus
240 }
241 #endif
242
243 #endif  // _DAHELPER_H_