summaryrefslogtreecommitdiff
path: root/src/include/dzl_internal_types.h
blob: d9eff5daea8bef18894089784999fd95cf8c000d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/**
 * @file        dzl_internal_types.h
 * @brief       Definition for debugging and internal struct and enum

 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
 * This software is the confidential and proprietary information
 * of Samsung Electronics, Inc. ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Samsung.
 */

#ifndef __DZL_INTERNAL_TYPES_H__
#define __DZL_INTERNAL_TYPES_H__

#include <string.h>

#if defined(GBS_BUILD)
#include <dlog.h>
#endif

#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

#ifdef LOG_TAG
#undef LOG_TAG
#endif

#define LOG_TAG "docker-launcher"

#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

#if defined(GBS_BUILD)
//#if !defined(_D)
#define _D(fmt, arg...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s[%d]\t " #fmt "\n", __FILENAME__, __FUNCTION__, __LINE__, ##arg)
//#endif

#if !defined(_W)
#define _W(fmt, arg...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s[%d]\t " #fmt "\n", __FILENAME__, __FUNCTION__ , __LINE__, ##arg)
#endif

#if !defined(_E)
#define _E(fmt, arg...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s[%d]\t " #fmt "\n", __FILENAME__, __FUNCTION__ , __LINE__, ##arg)
#endif
#else							// DGBS_BUILD

#define RST		"\033[0m"
#define RED		"\033[0;31m"
#define IRED	"\033[1;91m"

#define _D(fmt, ...)	printf(RST "%s: %s[%d]\t " #fmt "\n", __FILENAME__, __FUNCTION__ , __LINE__, ##__VA_ARGS__)
#define _W(fmt, ...)	printf(RED "%s: %s[%d]\t " #fmt RST "\n", __FILENAME__, __FUNCTION__ , __LINE__, ##__VA_ARGS__)
#define _E(fmt, ...)	printf(IRED "%s: %s[%d]\t " #fmt RST "\n", __FILENAME__, __FUNCTION__ , __LINE__, ##__VA_ARGS__)

#endif							// DGBS_BUILD

#define STATEMACHINE_QID		0x00000001
#define DOCKER_INTERFACE_QID 0x00000002

/**
 * @brief  This enum contains docker status
 *
 * The docker_status_e indicates what is status of docker interface
 *
 */
typedef enum {
	DOCKER_STATUS_NO_ERROR = 0,			/**< Successful */
	DOCKER_STATUS_STARTED,				/**< docker daemon Started */
	DOCKER_STATUS_ENGINE_FAIL,			/**< docker engine error */
	DOCKER_STATUS_ENGINE_API_FAIL,		/**< docker engine api error */
	DOCKER_STATUS_SERVICE_FAIL,			/**< service start error */
	DOCKER_STATUS_INVALID_PARAM,		/**< parameter invalid */
	DOCKER_STATUS_NETWORK_BRIDGE_FAIL,	/**< network bridge error */
	DOCKER_STATUS_INIT_FAIL,			/**< docker engine init fail */
	DOCKER_STATUS_UNKNOWN,				/**< unknown error */
	DOCKER_STATUS_MAX
} docker_status_e;

/**
 * @brief  This enum contains container status
 *
 * The container_status_e indicates what is status of container
 *
 */
typedef enum {
	CONTAINER_STATUS_UNKNOWN = 0,	/**< unknown status */
	CONTAINER_STATUS_CREATED,		/**< container status is created */
	CONTAINER_STATUS_RUNNING,		/**< container status is running */
	CONTAINER_STATUS_STOP,			/**< container status is stopped */
	CONTAINER_STATUS_EXITED,		/**< container status is exited */
	CONTAINER_STATUS_REMOVED,		/**< container is removed */
} container_status_e;

/**
 * @struct docker_control_info_s
 * @brief  This struct contains docker control parameters
 *
 * The docker_control_info_s struct encapsulate *path and *opt_cmd in the one data
 *
 */
typedef struct {
	char *path;
	char *opt_cmd;
} docker_control_info_s;

/**
 * @struct mount_info_s
 * @brief  This struct contains mount information
 *
 * The mount_info_s struct encapsulate read_only, *source, and *target in the one data
 *
 */
typedef struct {
	int read_only;
	char *source;
	char *target;
} mount_info_s;

/**
 * @struct container_create_info_s
 * @brief  This struct contains creation parameters for container
 *
 * The container_create_info_s struct encapsulate name, image, entry_cmd, volume, port, net_mode, privileged, environment and enable in the one data
 *
 */
typedef struct {
	char *name;			/**< container name */
	char *image;		/**< image name */
	char *entry_cmd;	/**< container initialization argument */
	char *port;			/**< published port info */
	char *volume;		/**< volume mount info count */
	char *net_mode;		/**< host mode or bridge mode */
	int privileged;		/**< run as privileged mode */
	int enable;			/**< enable launching */
	char *environment;	/**< container environment */
} container_create_info_s;

/**
 * @struct image_load_info_s
 * @brief  This struct load parameters for pre-installed image
 *
 * The image_load_info_s struct encapsulate name, image in the one data
 *
 */
typedef struct {
	char *name;			/**< tar archive name */
	char *image_repo;	/**< image repo */
} image_load_info_s;

/**
 * @struct dzl_dockerctl_Task
 * @brief  This struct contains task information
 *
 * The dzl_dockerctl_Task struct encapsulate id and status in the one data
 *
 */
typedef struct {
	char id[256];
	char status[256];
} dzl_dockerctl_Task;

/**
 * @struct dzl_dockerctl_TasksInfo
 * @brief  This struct contains count and point of dzl_dockerctl_Task
 *
 * The dzl_dockerctl_TasksInfo struct encapsulate count and *pstTasks in the one data
 *
 */
typedef struct {
	int count;
	dzl_dockerctl_Task *pstTasks;
} dzl_dockerctl_TasksInfo;

/**
 * @struct dzl_dockerctl_NetworksInfo
 * @brief  This struct contains name and id and gatewayflag
 */
typedef struct {
	char name[256];
	char id[256];
	int gatewayflag;
} dzl_dockerctl_NetworksInfo;

/**
 * @struct dzl_dockerctl_Service
 * @brief  This struct contains service information
 *
 * The dzl_dockerctl_Service struct encapsulate id, name and imageName in the one data
 *
 */
typedef struct {
	char id[256];
	char name[256];
	char imageName[256];
} dzl_dockerctl_Service;

/**
 * @struct dzl_dockerctl_ServicesInfo
 * @brief  This struct contains count and point of dzl_dockerctl_Service
 *
 * The dzl_dockerctl_ServicesInfo struct encapsulate count and *pstServices in the one data
 *
 */
typedef struct {
	int count;
	dzl_dockerctl_Service *pstServices;
} dzl_dockerctl_ServicesInfo;

/**
 * @struct dzl_dockerctl_serviceinfo_s
 * @brief  This struct contains service info to reuse in dockerform
 *
 * The dzl_dockerctl_serviceinfo_s struct encapsulate spec_config, id and version in the one data
 *
 */
typedef struct {
	char *spec_config;
	char *id;
	int version;
} dzl_dockerctl_serviceinfo_s;

/**
 * @brief  This enum contains monitor type
 *
 * The status_monitor_type_e indicates what is the type of status
 *
 */
typedef enum {
	SM_TYPE_DOCKER_STATUS = 0,	/**< docker-engine status changed */
	SM_TYPE_CONTAINER_STATUS,	/**< container status chagned */
	SM_TYPE_CHECK_STATUS,		/**< check SM state */
	SM_TYPE_END,
} status_monitor_type_e;

/**
 * @struct sm_containers_list_s
 * @brief  This struct contains count and containers information maximum MAX_CONTAINER_NUM
 *
 * The sm_containers_list_s struct encapsulate count and container in the one data
 *
 */
typedef struct {
	int count;					/**< the counts of containers info */
	struct {
		char *container_name;	/**< Container name from service */
		container_status_e status;	/**< Container Status :  */
	} container[MAX_CONTAINER_NUM];	/**< Max Count constraint */
} sm_containers_list_s;

/**
 * @struct sm_msgq_buf_s
 * @brief  This struct message information in dzl
 *
 * The sm_msgq_buf_s struct encapsulate mytpe, sm_type, docker_status and container_info in the one data
 *
 */
typedef struct {
	long mtype;		/**< message type */
	status_monitor_type_e sm_type;	/**< event type */
	docker_status_e docker_status;	/**< docker daemon status */
	struct {
		char *container_name;					/**< container name from callback event */
		container_status_e container_status;	/**< status of container_name */
	} container_info;
} sm_msgq_buf_s;


typedef enum {
	SA_START_LAUNCHER_SVC = 0,		/**< start launcher service */
	SA_RESTART_DOCKERD,				/**< restart docker engine */
	SA_STOP_DOCKERD,				/**< stop docker engine */
	SA_CMD_UNKNOWN
} sa_interface_cmd_e;

/**
 * @brief  This type is definition of status monitor callback
 *
 * The status_monitor_cb includes status, param1 and param2 in the one data
 *
 */
typedef void (*status_monitor_cb) (status_monitor_type_e status, void *param1, void *param2);
/**
 * @brief  This type is definition of event callback
 *
 * The docker_event_cb includes data,size, nmemb and buffer in the one data
 *
 */
typedef size_t(*docker_event_cb) (char *data, size_t size, size_t nmemb, void *buffer);

#endif							/* __DZL_INTERNAL_TYPES_H__ */