added generic IPC result message.

This commit is contained in:
Martin Preuss
2023-08-13 17:56:00 +02:00
parent 64938b9cb0
commit 290967a7c5
6 changed files with 31 additions and 24 deletions

View File

@@ -16,7 +16,7 @@
#include "aqhome/ipc/endpoint_ipc.h" #include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/nodes/msg_ipc_getdevices_req.h" #include "aqhome/ipc/nodes/msg_ipc_getdevices_req.h"
#include "aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h" #include "aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h"
#include "aqhome/ipc/nodes/msg_ipc_error.h" #include "aqhome/ipc/msg_ipc_result.h"
#include "aqhome/msg/msg_node.h" #include "aqhome/msg/msg_node.h"
#include <gwenhywfar/args.h> #include <gwenhywfar/args.h>
@@ -154,7 +154,7 @@ int _doGetDevices(GWEN_DB_NODE *dbArgs)
} }
code=GWEN_IpcMsg_GetCode(msg); code=GWEN_IpcMsg_GetCode(msg);
if (code==AQH_MSGTYPE_IPC_NODES_ERROR) { if (code==AQH_MSGTYPE_IPC_NODES_ERROR) {
fprintf(stdout, "No device list (%d)\n", AQH_ErrorIpcMsg_GetErrorCode(msg)); fprintf(stdout, "No device list (%d)\n", AQH_ResultIpcMsg_GetResultCode(msg));
GWEN_Msg_free(msg); GWEN_Msg_free(msg);
break; break;
} }

View File

@@ -28,7 +28,7 @@
#include "aqhome/ipc/nodes/msg_ipc_ping.h" #include "aqhome/ipc/nodes/msg_ipc_ping.h"
#include "aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h" #include "aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h"
#include "aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h" #include "aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h"
#include "aqhome/ipc/nodes/msg_ipc_error.h" #include "aqhome/ipc/msg_ipc_result.h"
#include <gwenhywfar/gwenhywfar.h> #include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h> #include <gwenhywfar/args.h>
@@ -176,7 +176,7 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_
GWEN_MSG *msgOut; GWEN_MSG *msgOut;
DBG_INFO(AQH_LOGDOMAIN, "No nodes"); DBG_INFO(AQH_LOGDOMAIN, "No nodes");
msgOut=AQH_ErrorIpcMsg_new(AQH_MSGTYPE_IPC_NODES_ERROR, AQH_MSG_IPC_ERROR_NODATA); msgOut=AQH_ResultIpcMsg_new(AQH_MSGTYPE_IPC_NODES_ERROR, AQH_MSG_IPC_ERROR_NODATA);
GWEN_MsgEndpoint_AddSendMessage(ep, msgOut); GWEN_MsgEndpoint_AddSendMessage(ep, msgOut);
} }
} }

View File

@@ -46,6 +46,7 @@
<headers dist="true" install="$(pkgincludedir)/ipc" > <headers dist="true" install="$(pkgincludedir)/ipc" >
endpoint_ipc.h endpoint_ipc.h
msg_ipc_result.h
</headers> </headers>
@@ -58,6 +59,7 @@
$(local/typefiles) $(local/typefiles)
endpoint_ipc.c endpoint_ipc.c
msg_ipc_result.c
</sources> </sources>
@@ -67,10 +69,12 @@
<useTargets> <useTargets>
aqhipcnodes aqhipcnodes
aqhipcdata
</useTargets> </useTargets>
<subdirs> <subdirs>
nodes nodes
data
</subdirs> </subdirs>

View File

@@ -10,7 +10,7 @@
# include <config.h> # include <config.h>
#endif #endif
#include <aqhome/ipc/nodes/msg_ipc_error.h> #include <aqhome/ipc/msg_ipc_result.h>
#include <gwenhywfar/msg.h> #include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h> #include <gwenhywfar/buffer.h>
@@ -23,46 +23,47 @@
#include <gwenhywfar/msg_ipc.h> #include <gwenhywfar/msg_ipc.h>
#define AQH_MSGIPC_ERROR_OFFS_ERRORCODE 0 /* 2 bytes */
#define AQH_MSGIPC_ERROR_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_ERROR_OFFS_ERRORCODE+2) #define AQH_MSGIPC_RESULT_OFFS_RESULTCODE 0 /* 2 bytes */
#define AQH_MSGIPC_RESULT_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+2)
GWEN_MSG *AQH_ErrorIpcMsg_new(uint16_t code, uint16_t errorCode) GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint16_t errorCode)
{ {
GWEN_MSG *msg; GWEN_MSG *msg;
uint8_t *ptr; uint8_t *ptr;
msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, AQH_MSGIPC_ERROR_MINSIZE, NULL); msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_RESULT_ID, AQH_IPC_PROTOCOL_RESULT_VERSION, code, AQH_MSGIPC_RESULT_MINSIZE, NULL);
ptr=GWEN_Msg_GetBuffer(msg); ptr=GWEN_Msg_GetBuffer(msg);
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_ERROR_OFFS_ERRORCODE+0]=errorCode & 0xff; ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+0]=errorCode & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_ERROR_OFFS_ERRORCODE+1]=errorCode & 0xff; ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+1]=errorCode & 0xff;
return msg; return msg;
} }
uint16_t AQH_ErrorIpcMsg_GetErrorCode(const GWEN_MSG *msg) uint16_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg)
{ {
return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_ERROR_OFFS_ERRORCODE, 0); return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE, 0);
} }
void AQH_ErrorIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) void AQH_ResultIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{ {
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_ERROR_MINSIZE) { if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_RESULT_MINSIZE) {
GWEN_Buffer_AppendArgs(dbuf, GWEN_Buffer_AppendArgs(dbuf,
"ERROR (code=%d, proto=%d, proto version=%d, error=%d)\n", "ERROR (code=%d, proto=%d, proto version=%d, error=%d)\n",
GWEN_IpcMsg_GetCode(msg), GWEN_IpcMsg_GetCode(msg),
GWEN_IpcMsg_GetProtoId(msg), GWEN_IpcMsg_GetProtoId(msg),
GWEN_IpcMsg_GetProtoVersion(msg), GWEN_IpcMsg_GetProtoVersion(msg),
AQH_ErrorIpcMsg_GetErrorCode(msg)); AQH_ResultIpcMsg_GetResultCode(msg));
} }
} }

View File

@@ -6,8 +6,8 @@
* should have received along with this file. * should have received along with this file.
****************************************************************************/ ****************************************************************************/
#ifndef AQH_MSG_IPC_ERROR_H #ifndef AQH_MSG_IPC_RESULT_H
#define AQH_MSG_IPC_ERROR_H #define AQH_MSG_IPC_RESULT_H
#include <aqhome/api.h> #include <aqhome/api.h>
@@ -18,13 +18,17 @@
#include <gwenhywfar/buffer.h> #include <gwenhywfar/buffer.h>
#define AQH_MSG_IPC_ERROR_OK 0 #define AQH_IPC_PROTOCOL_RESULT_ID 0
#define AQH_IPC_PROTOCOL_RESULT_VERSION 1
#define AQH_MSG_IPC_SUCCESS 0
#define AQH_MSG_IPC_ERROR_NODATA 1 #define AQH_MSG_IPC_ERROR_NODATA 1
AQHOME_API GWEN_MSG *AQH_ErrorIpcMsg_new(uint16_t code, uint16_t errorCode); AQHOME_API GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint16_t errorCode);
AQHOME_API uint16_t AQH_ErrorIpcMsg_GetErrorCode(const GWEN_MSG *msg); AQHOME_API uint16_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg);
AQHOME_API void AQH_ErrorIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); AQHOME_API void AQH_ResultIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif #endif

View File

@@ -49,7 +49,6 @@
msg_ipc_forward.h msg_ipc_forward.h
msg_ipc_value.h msg_ipc_value.h
msg_ipc_ping.h msg_ipc_ping.h
msg_ipc_error.h
msg_ipc_setaccmsggrps.h msg_ipc_setaccmsggrps.h
msg_ipc_getdevices_req.h msg_ipc_getdevices_req.h
msg_ipc_getdevices_rsp.h msg_ipc_getdevices_rsp.h
@@ -68,7 +67,6 @@
msg_ipc_forward.c msg_ipc_forward.c
msg_ipc_value.c msg_ipc_value.c
msg_ipc_ping.c msg_ipc_ping.c
msg_ipc_error.c
msg_ipc_setaccmsggrps.c msg_ipc_setaccmsggrps.c
msg_ipc_getdevices_req.c msg_ipc_getdevices_req.c
msg_ipc_getdevices_rsp.c msg_ipc_getdevices_rsp.c