-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcommline.c
81 lines (71 loc) · 1.58 KB
/
commline.c
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
/*
* Copyright (C) 2017 Rahul Jadhav <[email protected]>
*
* This file is subject to the terms and conditions of the GNU
* General Public License v2. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup commline
* @{
*
* @file
* @brief Exported interfaces for commline
*
* @author Rahul Jadhav <[email protected]>
*
* @}
*/
#define _COMMLINE_C_
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <commline.h>
#include <errno.h>
#ifdef USE_UNIX_SOCKETS
#include <cl_usock.h>
#else
#include <cl_msgq.h>
#endif
int cl_init(const long my_mtype, const uint8_t flags)
{
return CL_INIT(my_mtype, flags);
}
int cl_bind(const long my_mtype)
{
#ifdef USE_UNIX_SOCKETS
return CL_INIT(my_mtype, 0);
#else
return SUCCESS;
#endif
}
void cl_cleanup(void)
{
CL_CLEANUP();
}
int cl_sendto_q(const long mtype, msg_buf_t *mbuf, uint16_t len)
{
if (!mbuf || !len) {
ERROR("sendto invalid parameters passed buf:%p, buflen:%d\n", mbuf, len);
return FAILURE;
}
return CL_SENDTO(mtype, mbuf, len);
}
int cl_recvfrom_q(const long mtype, msg_buf_t *mbuf, uint16_t len, uint16_t flags)
{
if (!mbuf || !len) {
ERROR("invalid parameters passed buf:%p, buflen:%d\n", mbuf, len);
return FAILURE;
}
memset(mbuf, 0, sizeof(msg_buf_t));
return CL_RECVFROM(mtype, mbuf, len, flags);
}
int cl_get_descriptor(const long mtype)
{
#ifdef USE_UNIX_SOCKETS
return CL_GET_DESCRIPTOR(mtype);
#else
ERROR("Get descriptor not supported for used IPC\n");
return FAILURE;
#endif
}