[FIX] include paths (capi-system-runtime-info)
[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 extern int app_efl_main_flg;
46
47 #define MAX_PATH_LENGTH         256
48 #define MAX_STACK_DEPTH         128
49 #define TRIM_STACK_DEPTH        2
50
51 /*
52 #define WIN_RENDER_POST 0
53 #define CONTROLBAR_RENDER_POST 1
54 #define NAVIFRAME_RENDER_POST 2
55 #define PAGER_RENDER_POST 3
56 #define RENDER_POST_COUNT 4
57
58 #define SNAPSHOT_WAIT_TIME_MAX 10000
59 */
60
61 #define ENABLE_INTERNAL_MALLOC          0x0001
62 #define ENABLE_SNAPSHOT                         0x0002
63
64 #define LOG(FORMAT, ...)                                        \
65         do {                                                                    \
66                 char buf[128];                                          \
67                 sprintf(buf, FORMAT, __VA_ARGS__);      \
68                 PRINTMSG(buf);                                          \
69         } while(0)                                                              \
70
71 #define SCREENSHOT_LOCK()                                                                               \
72         do {                                                                                                            \
73                 int old;                                                                                                \
74                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
75                 old = gTraceInfo.screenshot.state;                                              \
76                 gTraceInfo.screenshot.state = -1;                                               \
77                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
78                 if(old > 0) {                                                                                   \
79                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
80                                 captureScreen();                                                                \
81                 }                                                                                                               \
82         } while(0)
83
84 #define SCREENSHOT_UNLOCK()                                                                             \
85         do {                                                                                                            \
86                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
87                 if(gTraceInfo.screenshot.state < 0)                                             \
88                         gTraceInfo.screenshot.state = 1;                                        \
89                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
90         } while(0)
91
92 #define SCREENSHOT_SET()                                                                                \
93         do {                                                                                                            \
94                 int old;                                                                                                \
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                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
109                 if(gTraceInfo.screenshot.state >= 0)                                    \
110                         gTraceInfo.screenshot.state = 0;                                        \
111                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
112         } while(0)
113
114 #define SCREENSHOT_DONE()                                                                               \
115         do {                                                                                                            \
116                 int old;                                                                                                \
117                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
118                 old = gTraceInfo.screenshot.state;                                              \
119                 if(gTraceInfo.screenshot.state == 1)                                    \
120                         gTraceInfo.screenshot.state = 2;                                        \
121                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
122                 if(old == 1) {                                                                                  \
123                         activateCaptureTimer();                                                         \
124                 }                                                                                                               \
125         } while(0)
126
127 #define SCREENSHOT_TIMEOUT()                                                                    \
128         do {                                                                                                            \
129                 int old;                                                                                                \
130                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
131                 old = gTraceInfo.screenshot.state;                                              \
132                 if(gTraceInfo.screenshot.state == 2)                                    \
133                         gTraceInfo.screenshot.state = 0;                                        \
134                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
135                 if(old == 2) {                                                                                  \
136                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
137                                 captureScreen();                                                                \
138                 }                                                                                                               \
139         } while(0)
140
141 #define NUM_ORIGINAL_LIBRARY    9
142
143 typedef enum
144 {
145         LIBC = 0,
146         LIBPTHREAD = 1,
147         LIBELEMENTARY = 2,
148         LIBECORE_INPUT_EVAS = 3,
149         LIBDAEMON = 4,
150         LIBCAPI_APPFW_APPLICATION = 5,
151         LIBGLES20 = 6,
152         LIBEGL = 7,
153         LIBSELF = 8
154 } ORIGINAL_LIBRARY;
155
156 extern const char *lib_string[NUM_ORIGINAL_LIBRARY];
157 extern void *lib_handle[NUM_ORIGINAL_LIBRARY];
158
159 // type definition for global variable
160 typedef struct
161 {
162         int eventIndex;
163         pthread_mutex_t eventMutex;
164 } __indexInfo;
165
166 typedef struct
167 {
168         int daemonSock;
169         pthread_mutex_t sockMutex;
170 } __socketInfo;
171
172 typedef struct
173 {
174         char appName[128];
175         uint64_t startTime;
176 } __appInfo;
177
178 typedef struct
179 {
180         int state;
181         pthread_mutex_t ssMutex;
182 } __screenshotInfo;
183
184 typedef struct
185 {
186         void* map_start;
187         void* map_end;
188 } __mapInfo;
189
190 typedef struct
191 {
192         __indexInfo                     index;
193         __socketInfo            socket;
194         __appInfo                       app;
195         __screenshotInfo        screenshot;
196         __mapInfo                       exec_map;
197         int                                     stateTouch;
198         int                                     init_complete;
199         int                                     custom_chart_callback_count;
200         uint64_t                optionflag;
201 } __traceInfo;
202
203 extern __traceInfo gTraceInfo;
204
205 int get_map_address(void* symbol, void** map_start, void** map_end);
206 char** da_backtrace_symbols (void* const* array, int size);
207 char** cached_backtrace_symbols (void* const* array, int size);
208
209 /* real malloc function pointer */
210 extern void *(*real_malloc)(size_t);
211
212 /* pid/tid values */
213 pid_t _getpid();
214 pid_t _gettid();
215 extern void reset_pid_tid();
216
217 // profil turned on
218 int __profil(int mode);
219
220 //wchar_t* -> char*
221 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
222 char *absolutize_filepath(const char *fname, char *buf, size_t bufsiz);
223
224 /* returns the real absolute file path (resolves symlinks) */
225 char *real_abs_path(int fd, char *buffer, size_t bufsiz);
226
227 // screen capture functions
228 int initialize_screencapture();
229 int finalize_screencapture();
230 int captureScreen();
231 int activateCaptureTimer();
232 void _cb_render_post(void* data, Evas* e, void* eventinfo);
233
234 // event related functions
235 int initialize_event();
236 int finalize_event();
237 int getOrientation();
238 void on_orientation_changed(int angle, bool capi);
239
240 int remove_indir(const char* dirname);
241
242 // query functions
243 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
244
245 #ifdef __cplusplus
246 }
247 #endif
248
249 #endif  // _DAHELPER_H_