[Title] apply runtime config and new protocol
[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                                         0x0000
60 #define TS_PROBE                                        0x0001
61 #define TS_INIT                                         0x0002
62 #define TS_FINIT                                        0x0004
63 #define TS_ENTER_PROBE_BLOCK            0x0008
64 #define TS_SET_PROBE_POINT                      0x0010
65 #define TS_PRINT_LOG                            0x0020
66 #define TS_PRINT_SAMPLE_LOG                     0x0040
67 #define TS_APPEND_TYPE_LOG                      0x0080
68 #define TS_BACKTRACE                            0x0100
69 #define TS_HASHFUNC                                     0x0200
70 #define TS_PROFIL_THREAD                        0x0400
71 #define TS_PROFIL_COUNT                         0x0800
72 #define TS_DETECT_TOUCH                         0x1000
73 #define TS_REGIST_SCREEN_CHANGE         0x2000
74 #define TS_POSSIBLE_CAPTURE                     0x4000
75 #define TRACE_STATE_SET(value)          ((gSTrace) |= (value))
76 #define TRACE_STATE_UNSET(value)        ((gSTrace) &= (~value))
77
78 #define ENABLE_INTERNAL_MALLOC          0x0001
79 #define ENABLE_SNAPSHOT                         0x0002
80
81 #define SCREENSHOT_LOCK()                                                                               \
82         do {                                                                                                            \
83                 int old;                                                                                                \
84                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
85                 old = gTraceInfo.screenshot.state;                                              \
86                 gTraceInfo.screenshot.state = -1;                                               \
87                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
88                 if(old > 0) {                                                                                   \
89                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
90                                 captureScreen();                                                                \
91                 }                                                                                                               \
92         } while(0)
93
94 #define SCREENSHOT_UNLOCK()                                                                             \
95         do {                                                                                                            \
96                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
97                 gTraceInfo.screenshot.state = 1;                                                \
98                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
99         } while(0)
100
101 #define SCREENSHOT_SET()                                                                                \
102         do {                                                                                                            \
103                 int old;                                                                                                \
104                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
105                 old = gTraceInfo.screenshot.state;                                              \
106                 if(gTraceInfo.screenshot.state >= 0)                                    \
107                         gTraceInfo.screenshot.state = 1;                                        \
108                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
109                 if(old == 2) {                                                                                  \
110                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
111                                 captureScreen();                                                                \
112                 }                                                                                                               \
113         } while(0)
114
115 #define SCREENSHOT_UNSET()                                                                              \
116         do {                                                                                                            \
117                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
118                 if(gTraceInfo.screenshot.state >= 0)                                    \
119                         gTraceInfo.screenshot.state = 0;                                        \
120                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
121         } while(0)
122
123 #define SCREENSHOT_DONE()                                                                               \
124         do {                                                                                                            \
125                 int old;                                                                                                \
126                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
127                 old = gTraceInfo.screenshot.state;                                              \
128                 if(gTraceInfo.screenshot.state == 1) {                                  \
129                         gTraceInfo.screenshot.state = 2;                                        \
130                 } else if(gTraceInfo.screenshot.state == 2) {                   \
131                         gTraceInfo.screenshot.state = 0;                                        \
132                 } else {                                                                                                \
133                 }                                                                                                               \
134                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
135                 if(old == 1) {                                                                                  \
136                         activateCaptureTimer();                                                         \
137                 } else if(old == 2) {                                                                   \
138                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
139                                 captureScreen();                                                                \
140                 }                                                                                                               \
141         } while(0)
142
143 // type definition for global variable
144 typedef struct
145 {
146         int eventIndex;
147         pthread_mutex_t eventMutex;
148 } __indexInfo;
149
150 typedef struct
151 {
152         int daemonSock;
153         pthread_mutex_t sockMutex;
154 } __socketInfo;
155
156 typedef struct
157 {
158         char appName[128];
159         unsigned int startTime;
160 } __appInfo;
161
162 typedef struct
163 {
164         int state;
165         pthread_mutex_t ssMutex;
166 } __screenshotInfo;
167
168 typedef struct
169 {
170         void* map_start;
171         void* map_end;
172 } __mapInfo;
173
174 typedef struct
175 {
176         __indexInfo                     index;
177         __socketInfo            socket;
178         __appInfo                       app;
179         __screenshotInfo        screenshot;
180         __mapInfo                       exec_map;
181         int                                     stateTouch;
182         int                                     init_complete;
183         int                                     custom_chart_callback_count;
184         unsigned long           optionflag;
185 } __traceInfo;
186
187 extern __thread unsigned long   gSTrace;
188 extern __traceInfo gTraceInfo;
189
190 char** da_backtrace_symbols (void* const* array, int size);
191 char** cached_backtrace_symbols (void* const* array, int size);
192
193 // profil turned on
194 int __profil(int mode);
195
196 //wchar_t* -> char*
197 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
198
199 // screen capture functions
200 int initialize_screencapture();
201 int finalize_screencapture();
202 int captureScreen();
203 int activateCaptureTimer();
204 void _cb_render_post(void* data, Evas* e, void* eventinfo);
205
206 // event related functions
207 int initialize_event();
208 int finalize_event();
209 int getOrientation();
210 void orientationEnabled();
211 void on_orientation_changed(int angle, bool capi);
212
213 int remove_indir(const char* dirname);
214
215 // query functions
216 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
217
218 #ifdef __cplusplus
219 }
220 #endif
221
222 #endif  // _DAHELPER_H_