[FIX] wrong pack size of system memory total/used
[platform/core/system/swap-manager.git] / daemon / daemon.h
1 /*
2  *  DA manager
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  * Cherepanov Vitaliy <v.cherepanov@samsung.com>
12  * Nikita Kalyazin    <n.kalyazin@samsung.com>
13  *
14  * Licensed under the Apache License, Version 2.0 (the "License");
15  * you may not use this file except in compliance with the License.
16  * You may obtain a copy of the License at
17  *
18  * http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing, software
21  * distributed under the License is distributed on an "AS IS" BASIS,
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  * See the License for the specific language governing permissions and
24  * limitations under the License.
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  * - Samsung RnD Institute Russia
29  *
30  */
31
32
33 #ifndef _DAEMON_H_
34 #define _DAEMON_H_
35
36 #include <stdint.h>             // for uint64_t, int64_t
37 #include <pthread.h>    // for pthread_mutex_t
38
39 #include "da_protocol.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45
46 #define PROTOCOL_VERSION                        "2.1"
47
48 #define RUN_APP_LOADER
49
50 #define MAX_TARGET_COUNT                        8
51 #define DA_MSG_MAX                                      4096
52 #define RECV_BUF_MAX                            4104    // = sizeof(msg_t)
53
54 #define MAX_DEVICE                              10
55 #define MAX_FILENAME                    128
56
57 #define INPUT_ID_TOUCH                  0
58 #define INPUT_ID_KEY                    1
59 #define STR_TOUCH                               "TOUCH"
60 #define STR_KEY                                 "KEY"
61 #define INPUT_ID_STR_KEY                "ID_INPUT_KEY=1"
62 #define INPUT_ID_STR_TOUCH              "ID_INPUT_TOUCHSCREEN=1"
63 #define INPUT_ID_STR_KEYBOARD   "ID_INPUT_KEYBOARD=1"
64 #define INPUT_ID_STR_TABLET             "ID_INPUT_TABLET=1"
65
66
67 /*
68 enum ErrorCode
69 {
70         ERR_LOCKFILE_CREATE_FAILED = -101,
71         ERR_ALREADY_RUNNING = -102,
72         ERR_INITIALIZE_SYSTEM_INFO_FAILED = -103,
73         ERR_HOST_SERVER_SOCKET_CREATE_FAILED = -104,
74         ERR_TARGET_SERVER_SOCKET_CREATE_FAILED = -105,
75         ERR_SIGNAL_MASK_SETTING_FAILED = -106,
76         ERR_WRONG_MESSAGE_FORMAT = -201,
77         ERR_WRONG_MESSAGE_TYPE = -202,
78         ERR_WRONG_MESSAGE_DATA = -203,
79         ERR_CANNOT_START_PROFILING = -204,
80         ERR_WRONG_PROTOCOL_VERSION = -205
81 };*/
82
83 enum TargetMessageType
84 {
85         MSG_DEVICE = 1,
86         MSG_TIME = 2,
87         MSG_SAMPLE = 3,
88         MSG_RESOURCE = 4,
89         MSG_LOG = 5,
90         MSG_IMAGE = 6,
91         MSG_TERMINATE = 7,
92         MSG_PID = 8,
93         MSG_MSG = 9,
94         MSG_ALLOC = 10,
95         MSG_ERROR = 11
96 };
97 #define IS_PROBE_MSG(type) (((type) & 0x0100) == 0x0100)
98
99 enum HostMessageType
100 {
101         MSG_HOST_BEGIN = 100,
102         MSG_START = 100,
103         MSG_STOP = 101,
104         MSG_PAUSE = 102,
105         MSG_OPTION = 103,
106         MSG_ISALIVE = 104,
107         MSG_ALIVE = 105,
108         MSG_BATT_START = 106,
109         MSG_BATT_STOP = 107,
110         MSG_RECORD = 801,
111         MSG_REPLAY = 802,
112         MSG_OK = 901,
113         MSG_NOTOK = 902,
114         MSG_VERSION = 999,
115         MSG_HOST_END = 999
116 };
117
118 enum DaOptions
119 {
120         OPT_CPUMEM              =       0x00000001,
121         OPT_FUNC                =       0x00000002,
122         OPT_ALLOC               =       0x00000004,
123         OPT_FILE                =       0x00000008,
124         OPT_THREAD              =       0x00000010,
125         OPT_UI                  =       0x00000020,
126         OPT_SNAPSHOT    =       0x00000040,
127         OPT_EVENT               =       0x00000080,
128         OPT_RECORD              =       0x00000100
129 };
130
131 enum DAState
132 {
133         DAS_NONE = 0,
134         DAS_START_BEGIN = 1,
135         DAS_TARGET_ARM_START = 1,
136         DAS_TARGET_X86_START = 2,
137         DAS_EMUL_ARM_START = 3,
138         DAS_EMUL_X86_START = 4,
139         DAS_TARGET_ARM_BATT_START = 5,
140         DAS_TARGET_X86_BATT_START = 6,
141         DAS_EMUL_ARM_BATT_START = 7,
142         DAS_EMUL_X86_BATT_START = 8,
143         DAS_START_END = 8,
144         DAS_STOP = 9,
145         DAS_TERMINATE = 10
146 };
147
148
149 #ifndef likely
150 #define likely(x)       __builtin_expect((x), 1)
151 #define unlikely(x)     __builtin_expect((x), 0)
152 #endif
153
154 #define EVENT_STOP              0x00000001
155 #define EVENT_PID               0x00000002
156 #define EVENT_ERROR             0x00000004
157
158 typedef struct
159 {
160         unsigned int    type;
161         unsigned int    length;
162         char                    data[DA_MSG_MAX];
163 } msg_target_t;
164
165 typedef struct
166 {
167         int                                     control_socket;
168         int                                     data_socket;
169         pthread_mutex_t         data_socket_mutex;
170 } __da_host_info;
171
172 typedef struct
173 {
174         int64_t                 allocmem;               // written only by recv thread
175         pid_t                           pid;                    // written only by recv thread
176         int                             socket;                 // written only by main thread
177         pthread_t               recv_thread;    // written only by main thread
178         int                             event_fd;               // for thread communication (from recv thread to main thread)
179         int                             initial_log;    // written only by main thread
180 } __da_target_info;
181
182 typedef struct
183 {
184         int brightness;
185         int voltage;
186         int procmeminfo;
187         FILE *video;
188         FILE *audio_status;
189         FILE *procstat;
190         FILE *networkstat;
191         FILE *diskstats;
192 } __file_descriptors;
193
194 typedef struct
195 {
196         int host_server_socket;
197         int target_server_socket;
198         int target_count;
199         unsigned int config_flag;
200         int app_launch_timerfd;
201         int connect_timeout_timerfd;
202         pthread_t sampling_thread;
203         pthread_t replay_thread;
204         pthread_t transfer_thread;
205         int buf_fd;
206         int user_ev_fd;
207         int efd;
208         __da_host_info host;
209         __da_target_info target[MAX_TARGET_COUNT];
210         __file_descriptors fd;
211         char appPath[128]; // application executable path
212 } __da_manager;
213
214
215 typedef struct _input_dev
216 {
217         int fd;
218         char fileName[MAX_FILENAME];
219 } input_dev;
220
221 extern input_dev g_key_dev[MAX_DEVICE];
222 extern input_dev g_touch_dev[MAX_DEVICE];
223
224 extern __da_manager manager;
225
226 void initialize_log();
227 int daemonLoop();
228 long long get_total_alloc_size();
229 void unlink_portfile(void);
230
231 int makeRecvThread(int index);
232 int samplingStart();
233 int samplingStop();
234
235
236
237
238 // TODO maybe need move to other file
239 int start_profiling();
240 void stop_profiling();
241 int reconfigure();
242 int sendACKCodeToHost(enum HostMessageType resp, int msgcode);
243 void terminate_all();
244 void _device_write(input_dev *dev, struct input_event* in_ev);
245
246
247 #ifdef __cplusplus
248 }
249 #endif
250
251 #endif // _DAEMON_H_