gwenhywfar 5.14.1
msg_ipc.c
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the project Gwenhywfar.
3 * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
4 *
5 * The license for this file can be found in the file COPYING which you
6 * should have received along with this file.
7 ****************************************************************************/
8
9#ifdef HAVE_CONFIG_H
10# include <config.h>
11#endif
12
13/*#define DISABLE_DEBUGLOG*/
14
15
16#include "msgio/msg_p.h"
17#include "msgio/msg_ipc.h"
18
19
20
21
22GWEN_MSG *GWEN_IpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
23 uint32_t msgId, uint32_t refMsgId,
24 uint32_t payloadLen, const uint8_t *payload)
25{
26 GWEN_MSG *msg;
27 uint32_t len;
28
29 len=GWEN_MSGIPC_OFFS_PAYLOAD+payloadLen;
30 msg=GWEN_Msg_new(len);
31 if (msg==NULL)
32 return NULL;
33
34 msg->maxSize=len;
35
36 GWEN_Msg_AddUint32(msg, len);
37 GWEN_Msg_AddUint8(msg, protoId);
38 GWEN_Msg_AddUint8(msg, protoVer);
39 GWEN_Msg_AddUint16(msg, code);
40 GWEN_Msg_AddUint32(msg, msgId);
41 GWEN_Msg_AddUint32(msg, refMsgId);
42
43 if (payloadLen && payload)
44 GWEN_Msg_AddBytes(msg, payload, payloadLen);
45 return msg;
46}
47
48
49
51{
52 if (msg) {
53 GWEN_Msg_WriteUint32At(msg, GWEN_MSGIPC_OFFS_SIZE, msg->bytesInBuffer);
54 }
55}
56
57
59{
60 if (msg && msg->bytesInBuffer>4) {
61 uint32_t len;
62
64 if (len>msg->maxSize)
65 return -1;
66 else if (msg->bytesInBuffer>=len)
67 return 1;
68 }
69 return 0;
70}
71
72
73
74uint32_t GWEN_IpcMsg_GetMsgSize(const GWEN_MSG *msg)
75{
77}
78
79
80
82{
84}
85
86
87
92
93
94
95uint16_t GWEN_IpcMsg_GetCode(const GWEN_MSG *msg)
96{
98}
99
100
101
102uint32_t GWEN_IpcMsg_GetMsgId(const GWEN_MSG *msg)
103{
105}
106
107
108
110{
112}
113
114
115
116
117
118
119
#define NULL
Definition binreloc.c:300
uint8_t GWEN_Msg_GetUint8At(const GWEN_MSG *msg, int offs, uint8_t defaultValue)
Definition msg.c:631
int GWEN_Msg_AddBytes(GWEN_MSG *msg, const uint8_t *bufferPtr, uint32_t bufferLen)
Definition msg.c:193
uint16_t GWEN_Msg_GetUint16At(const GWEN_MSG *msg, int offs, uint16_t defaultValue)
Definition msg.c:617
int GWEN_Msg_WriteUint32At(GWEN_MSG *msg, uint32_t pos, uint32_t v)
Definition msg.c:236
int GWEN_Msg_AddUint8(GWEN_MSG *msg, uint8_t v)
Definition msg.c:383
int GWEN_Msg_AddUint32(GWEN_MSG *msg, uint32_t v)
Definition msg.c:341
uint32_t GWEN_Msg_GetUint32At(const GWEN_MSG *msg, int offs, uint32_t defaultValue)
Definition msg.c:603
GWEN_MSG * GWEN_Msg_new(uint32_t bufferSize)
Definition msg.c:37
int GWEN_Msg_AddUint16(GWEN_MSG *msg, uint16_t v)
Definition msg.c:362
struct GWEN_MSG GWEN_MSG
Definition msg.h:24
uint32_t GWEN_IpcMsg_GetRefMsgId(const GWEN_MSG *msg)
Definition msg_ipc.c:109
uint8_t GWEN_IpcMsg_GetProtoVersion(const GWEN_MSG *msg)
Definition msg_ipc.c:88
uint8_t GWEN_IpcMsg_GetProtoId(const GWEN_MSG *msg)
Definition msg_ipc.c:81
void GWEN_IpcMsg_AdjustMsgSize(GWEN_MSG *msg)
Definition msg_ipc.c:50
uint32_t GWEN_IpcMsg_GetMsgId(const GWEN_MSG *msg)
Definition msg_ipc.c:102
int GWEN_IpcMsg_IsMsgComplete(const GWEN_MSG *msg)
Definition msg_ipc.c:58
uint32_t GWEN_IpcMsg_GetMsgSize(const GWEN_MSG *msg)
Definition msg_ipc.c:74
uint16_t GWEN_IpcMsg_GetCode(const GWEN_MSG *msg)
Definition msg_ipc.c:95
GWEN_MSG * GWEN_IpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t payloadLen, const uint8_t *payload)
Definition msg_ipc.c:22
#define GWEN_MSGIPC_OFFS_CODE
Definition msg_ipc.h:20
#define GWEN_MSGIPC_OFFS_PROTOVER
Definition msg_ipc.h:19
#define GWEN_MSGIPC_OFFS_SIZE
Definition msg_ipc.h:17
#define GWEN_MSGIPC_OFFS_REFID
Definition msg_ipc.h:22
#define GWEN_MSGIPC_OFFS_PROTOID
Definition msg_ipc.h:18
#define GWEN_MSGIPC_OFFS_ID
Definition msg_ipc.h:21
#define GWEN_MSGIPC_OFFS_PAYLOAD
Definition msg_ipc.h:23