-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibconn.h
More file actions
100 lines (91 loc) · 3.69 KB
/
libconn.h
File metadata and controls
100 lines (91 loc) · 3.69 KB
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
/*************************************************************************
>
> File Name: libconn.h
>
> Author: Michel Sumyan
>
> Created Time: 2017/10/05
>
*************************************************************************/
#ifndef __LIBCONN__H__
#define __LIBCONN__H__
#define CONN_OK 0
#define CONN_ERR -1
#define CONN_ERR_SERVER_SOCKET -2
#define CONN_ERR_SERVER_BIND -3
#define CONN_ERR_SERVER_LISTEN -4
#define CONN_ERR_SERVER_ACCEPT -5
#define CONN_ERR_CLIENT_CONNECT -10
#define CONN_ERR_CLIENT_BIND -11
#define CONN_ERR_CLIENT_SEND -12
#define CONN_ERR_CLIENT_SELECT -13
#define CONN_ERR_CLIENT_RECV -14
/*
***************************************************************
***************************************************************
** SERVER PART
***************************************************************
***************************************************************
*/
/*
* Callback function to process message
* - cmd : contains the received command (including null char for debug request)
* - lenCmd : contains the received command length (including null char for debug request)
* - out : contains the pointer to store the response buffer address
* this buffer must be maloc by callback then freed by conn library
* Return:
* - 0 if OK and nothing to answer
* - the output buffer len if > 0
* - errcode if < 0
* Note:
* - output buffer is freed only if not NULL and return > 0
*/
typedef int (*connProcessFunc)(const char *cmd, int lenCmd, char **out);
/*
* Server loop request - No return
* Manage requests from client
* callback to manage requests must returns an alloc buffer into **out if not NULL
* this buffer wll be free by lib
* - sockName: server socket path (full path)
* - func: callback function to be called when receiving command
* - maxCmdLen: max length of received command to be processed by func
* No return - infinite loop
*/
extern void conn_server_loop_request(const char *sockName, connProcessFunc func, int maxCmdLen);
/*
***************************************************************
***************************************************************
** CLIENT PART
***************************************************************
***************************************************************
*/
/*
* Send cmd request to socket and get response id resp != NULL and maxResp != 0
* Command & Response are uint8_t bytes
* - sockName: server socket path (full path)
* - sockId: NULL or client socket prefix (ex: "led.", default is "conn.")
* - cmd: input cmd
* - lenCmd: input cmd length
* - resp: output buffer
* - maxResp: max output buffer len
* - timeout: timeout for response
* Return:
* if OK: return 0 or response length
* if NOK: return errcode < 0
*/
extern int conn_client_request(const char *sockName, const char *sockId, const char *cmd, int lenCmd, char *resp, int maxResp, int timeout);
/*
* Send debug request to socket and get response id resp != NULL and maxResp != 0
* Command & Response are strings null terminated
* - sockName: server socket path (full path)
* - cmd: input cmd (NULL terminated)
* - lenCmd: input cmd length
* - resp: output buffer
* - maxResp: max output buffer len including ending NULL char
* - timeout: timeout for response
* Return:
* if OK: return 0 or response length
* if NOK: return errcode < 0
*/
extern int conn_client_debug_request(const char *sockName, const char *sockId, const char *cmd, char *resp, int maxResp, int timeout);
#endif