[FIX] dastout license
[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 SCREENSHOT_LOCK()                                                                               \
65         do {                                                                                                            \
66                 int old;                                                                                                \
67                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
68                 old = gTraceInfo.screenshot.state;                                              \
69                 gTraceInfo.screenshot.state = -1;                                               \
70                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
71                 if(old > 0) {                                                                                   \
72                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
73                                 captureScreen();                                                                \
74                 }                                                                                                               \
75         } while(0)
76
77 #define SCREENSHOT_UNLOCK()                                                                             \
78         do {                                                                                                            \
79                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
80                 if(gTraceInfo.screenshot.state < 0)                                             \
81                         gTraceInfo.screenshot.state = 1;                                        \
82                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
83         } while(0)
84
85 #define SCREENSHOT_SET()                                                                                \
86         do {                                                                                                            \
87                 int old;                                                                                                \
88                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
89                 old = gTraceInfo.screenshot.state;                                              \
90                 if(gTraceInfo.screenshot.state >= 0)                                    \
91                         gTraceInfo.screenshot.state = 1;                                        \
92                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
93                 if(old == 2) {                                                                                  \
94                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
95                                 captureScreen();                                                                \
96                 }                                                                                                               \
97         } while(0)
98
99 #define SCREENSHOT_UNSET()                                                                              \
100         do {                                                                                                            \
101                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
102                 if(gTraceInfo.screenshot.state >= 0)                                    \
103                         gTraceInfo.screenshot.state = 0;                                        \
104                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
105         } while(0)
106
107 #define SCREENSHOT_DONE()                                                                               \
108         do {                                                                                                            \
109                 int old;                                                                                                \
110                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
111                 old = gTraceInfo.screenshot.state;                                              \
112                 if(gTraceInfo.screenshot.state == 1)                                    \
113                         gTraceInfo.screenshot.state = 2;                                        \
114                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
115                 if(old == 1) {                                                                                  \
116                         activateCaptureTimer();                                                         \
117                 }                                                                                                               \
118         } while(0)
119
120 #define SCREENSHOT_TIMEOUT()                                                                    \
121         do {                                                                                                            \
122                 int old;                                                                                                \
123                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
124                 old = gTraceInfo.screenshot.state;                                              \
125                 if(gTraceInfo.screenshot.state == 2)                                    \
126                         gTraceInfo.screenshot.state = 1;                                        \
127                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
128                 if(old == 2) {                                                                                  \
129                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
130                                 captureScreen();                                                                \
131                 }                                                                                                               \
132         } while(0)
133
134 #define NUM_ORIGINAL_LIBRARY    9
135
136 typedef enum
137 {
138         LIB_NO = -1,
139         LIBC = 0,
140         LIBPTHREAD = 1,
141         LIBELEMENTARY = 2,
142         LIBECORE_INPUT_EVAS = 3,
143         LIBDAEMON = 4,
144         LIBCAPI_APPFW_APPLICATION = 5,
145         LIBGLES20 = 6,
146         LIBEGL = 7,
147         LIBSELF = 8
148 } ORIGINAL_LIBRARY;
149
150 extern const char *lib_string[NUM_ORIGINAL_LIBRARY];
151 extern void *lib_handle[NUM_ORIGINAL_LIBRARY];
152
153 // type definition for global variable
154 typedef struct
155 {
156         int eventIndex;
157         pthread_mutex_t eventMutex;
158 } __indexInfo;
159
160 typedef struct
161 {
162         int daemonSock;
163         pthread_mutex_t sockMutex;
164 } __socketInfo;
165
166 typedef struct
167 {
168         char appName[128];
169         uint64_t startTime;
170 } __appInfo;
171
172 typedef struct
173 {
174         int state;
175         pthread_mutex_t ssMutex;
176 } __screenshotInfo;
177
178 typedef struct
179 {
180         void* map_start;
181         void* map_end;
182 } __mapInfo;
183
184 typedef struct
185 {
186         __indexInfo                     index;
187         __socketInfo            socket;
188         __appInfo                       app;
189         __screenshotInfo        screenshot;
190         __mapInfo                       exec_map;
191         int                                     stateTouch;
192         int                                     init_complete;
193         int                                     custom_chart_callback_count;
194         uint64_t                optionflag;
195 } __traceInfo;
196
197 extern __traceInfo gTraceInfo;
198
199 int get_map_address(void* symbol, void** map_start, void** map_end);
200 char** da_backtrace_symbols (void* const* array, int size);
201 char** cached_backtrace_symbols (void* const* array, int size);
202
203 /* pid/tid values */
204 pid_t _getpid();
205 pid_t _gettid();
206 extern void reset_pid_tid();
207
208 // profil turned on
209 int __profil(int mode);
210
211 //wchar_t* -> char*
212 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
213 char *absolutize_filepath(const char *fname, char *buf, size_t bufsiz);
214
215 /* returns the real absolute file path (resolves symlinks) */
216 char *real_abs_path(int fd, char *buffer, size_t bufsiz);
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 on_orientation_changed(int angle, bool capi);
230
231 int remove_indir(const char* dirname);
232
233 // query functions
234 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
235
236 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif  // _DAHELPER_H_