[FIX] cherry-pick a1a779f6e7dda81b331db36bb07068dd73022041 (#8:6) + merge
[platform/core/system/swap-probe.git] / include / dahelper.h
1 /*
2  *  DA probe
3  *
4  * Copyright (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  * 
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 ENABLE_INTERNAL_MALLOC          0x0001
60 #define ENABLE_SNAPSHOT                         0x0002
61
62 #define LOG(FORMAT, ...)                                        \
63         do {                                                                    \
64                 char buf[128];                                          \
65                 sprintf(buf, FORMAT, __VA_ARGS__);      \
66                 PRINTMSG(buf);                                          \
67         } while(0)                                                              \
68
69 #define SCREENSHOT_LOCK()                                                                               \
70         do {                                                                                                            \
71                 int old;                                                                                                \
72                 LOG("screenshot_lock : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
73                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
74                 old = gTraceInfo.screenshot.state;                                              \
75                 gTraceInfo.screenshot.state = -1;                                               \
76                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
77                 if(old > 0) {                                                                                   \
78                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
79                                 captureScreen();                                                                \
80                 }                                                                                                               \
81         } while(0)
82
83 #define SCREENSHOT_UNLOCK()                                                                             \
84         do {                                                                                                            \
85                 LOG("screenshot_unlock : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
86                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
87                 gTraceInfo.screenshot.state = 1;                                                \
88                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
89         } while(0)
90
91 #define SCREENSHOT_SET()                                                                                \
92         do {                                                                                                            \
93                 int old;                                                                                                \
94                 LOG("screenshot_set : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
95                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
96                 old = gTraceInfo.screenshot.state;                                              \
97                 if(gTraceInfo.screenshot.state >= 0)                                    \
98                         gTraceInfo.screenshot.state = 1;                                        \
99                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
100                 if(old == 2) {                                                                                  \
101                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
102                                 captureScreen();                                                                \
103                 }                                                                                                               \
104         } while(0)
105
106 #define SCREENSHOT_UNSET()                                                                              \
107         do {                                                                                                            \
108                 LOG("screenshot_unset : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
109                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
110                 if(gTraceInfo.screenshot.state >= 0)                                    \
111                         gTraceInfo.screenshot.state = 0;                                        \
112                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
113         } while(0)
114
115 #define SCREENSHOT_DONE()                                                                               \
116         do {                                                                                                            \
117                 int old;                                                                                                \
118                 LOG("screenshot_done : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
119                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
120                 old = gTraceInfo.screenshot.state;                                              \
121                 if(gTraceInfo.screenshot.state == 1)                                    \
122                         gTraceInfo.screenshot.state = 2;                                        \
123                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
124                 if(old == 1) {                                                                                  \
125                         activateCaptureTimer();                                                         \
126                 }                                                                                                               \
127         } while(0)
128
129 #define SCREENSHOT_TIMEOUT()                                                                    \
130         do {                                                                                                            \
131                 int old;                                                                                                \
132                 LOG("screenshot_timeout : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
133                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
134                 old = gTraceInfo.screenshot.state;                                              \
135                 if(gTraceInfo.screenshot.state == 2)                                    \
136                         gTraceInfo.screenshot.state = 0;                                        \
137                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
138                 if(old == 2) {                                                                                  \
139                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
140                                 captureScreen();                                                                \
141                 }                                                                                                               \
142         } while(0)
143
144 #define NUM_ORIGINAL_LIBRARY    9
145
146 typedef enum
147 {
148         LIBC = 0,
149         LIBPTHREAD = 1,
150         LIBELEMENTARY = 2,
151         LIBOSP_UIFW = 3,
152         LIBOSP_APPFW = 4,
153         LIBOSP_WEB = 5,
154         LIBECORE_INPUT_EVAS = 6,
155         LIBDAEMON = 7,
156         LIBCAPI_APPFW_APPLICATION = 8
157 } ORIGINAL_LIBRARY;
158
159 extern char *lib_string[NUM_ORIGINAL_LIBRARY];
160 extern void *lib_handle[NUM_ORIGINAL_LIBRARY];
161
162 // type definition for global variable
163 typedef struct
164 {
165         int eventIndex;
166         pthread_mutex_t eventMutex;
167 } __indexInfo;
168
169 typedef struct
170 {
171         int daemonSock;
172         pthread_mutex_t sockMutex;
173 } __socketInfo;
174
175 typedef struct
176 {
177         char appName[128];
178         unsigned int startTime;
179 } __appInfo;
180
181 typedef struct
182 {
183         int state;
184         pthread_mutex_t ssMutex;
185 } __screenshotInfo;
186
187 typedef struct
188 {
189         void* map_start;
190         void* map_end;
191 } __mapInfo;
192
193 typedef struct
194 {
195         __indexInfo                     index;
196         __socketInfo            socket;
197         __appInfo                       app;
198         __screenshotInfo        screenshot;
199         __mapInfo                       exec_map;
200         int                                     stateTouch;
201         int                                     init_complete;
202         int                                     custom_chart_callback_count;
203         unsigned long           optionflag;
204 } __traceInfo;
205
206 extern __traceInfo gTraceInfo;
207
208 int get_map_address(void* symbol, void** map_start, void** map_end);
209 char** da_backtrace_symbols (void* const* array, int size);
210 char** cached_backtrace_symbols (void* const* array, int size);
211
212 // profil turned on
213 int __profil(int mode);
214
215 //wchar_t* -> char*
216 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
217
218 // screen capture functions
219 int initialize_screencapture();
220 int finalize_screencapture();
221 int captureScreen();
222 int activateCaptureTimer();
223 void _cb_render_post(void* data, Evas* e, void* eventinfo);
224
225 // event related functions
226 int initialize_event();
227 int finalize_event();
228 int getOrientation();
229 void orientationEnabled();
230 void on_orientation_changed(int angle, bool capi);
231
232 int remove_indir(const char* dirname);
233
234 // query functions
235 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
236
237 #ifdef __cplusplus
238 }
239 #endif
240
241 #endif  // _DAHELPER_H_