ipc2: added ipc_endpoint
This commit is contained in:
@@ -87,6 +87,7 @@
|
|||||||
msgrequest.c
|
msgrequest.c
|
||||||
ipc_server.c
|
ipc_server.c
|
||||||
ipc_client.c
|
ipc_client.c
|
||||||
|
ipc_endpoint.c
|
||||||
tty_endpoint.c
|
tty_endpoint.c
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
|
|||||||
133
aqhome/ipc2/ipc_endpoint.c
Normal file
133
aqhome/ipc2/ipc_endpoint.c
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
|
*
|
||||||
|
* The license for this file can be found in the file COPYING which you
|
||||||
|
* should have received along with this file.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "./ipc_endpoint.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_IpcEndpoint_ExchangeConnectMsg(AQH_OBJECT *ipcEndpoint,
|
||||||
|
uint16_t connectMsgCode,
|
||||||
|
uint16_t resultMsgCode,
|
||||||
|
const char *clientId,
|
||||||
|
const char *userId,
|
||||||
|
const char *passw,
|
||||||
|
uint32_t flags,
|
||||||
|
int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *msgOut;
|
||||||
|
uint32_t msgId;
|
||||||
|
|
||||||
|
msgId=AQH_Endpoint_GetNextMessageId(ipcEndpoint);
|
||||||
|
msgOut=AQH_IpcdMessageConnect_new(connectMsgCode, msgId, 0, clientId, userId, passw, flags);
|
||||||
|
AQH_Endpoint_AddMsgOut(ipcEndpoint, msgOut);
|
||||||
|
|
||||||
|
return AQH_IpcEndpoint_WaitForResultMsg(ipcEndpoint, resultMsgCode, msgId, timeoutInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_IpcEndpoint_WaitForResultMsg(AQH_OBJECT *ipcEndpoint, uint16_t resultMsgCode, uint32_t refMsgId, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
for (;;) {
|
||||||
|
AQH_MESSAGE *msgIn;
|
||||||
|
|
||||||
|
msgIn=AQH_IpcEndpoint_WaitForResponseMsg(ipcEndpoint, refMsgId, timeoutInSeconds);
|
||||||
|
if (msgIn) {
|
||||||
|
GWEN_TAG16_LIST *tagList;
|
||||||
|
|
||||||
|
tagList=AQH_IpcMessageTag16_ParsePayload(msgIn, 0);
|
||||||
|
if (tagList) {
|
||||||
|
int code;
|
||||||
|
|
||||||
|
code=AQH_IpcMessage_GetCode(msgIn);
|
||||||
|
if (code==resultMsgCode) {
|
||||||
|
int result;
|
||||||
|
|
||||||
|
result=AQH_IpcMessageResult_GetResult(tagList);
|
||||||
|
GWEN_Tag16_List_free(tagList);
|
||||||
|
AQH_Message_free(msgIn);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_ERROR(NULL, "Unexpected message received (%x)", code);
|
||||||
|
}
|
||||||
|
GWEN_Tag16_List_free(tagList);
|
||||||
|
}
|
||||||
|
AQH_Message_free(msgIn);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_ERROR(NULL, "No matching msg received");
|
||||||
|
return GWEN_ERROR_TIMEOUT;
|
||||||
|
}
|
||||||
|
} /* for */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_MESSAGE *AQH_IpcEndpoint_WaitForResponseMsg(AQH_OBJECT *ipcEndpoint, uint32_t refMsgId, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
time_t startTime;
|
||||||
|
|
||||||
|
startTime=time(NULL);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
AQH_MESSAGE *msg;
|
||||||
|
time_t now;
|
||||||
|
|
||||||
|
AQH_EventLoop_Run(AQH_Object_GetEventLoop(ipcEndpoint), 500);
|
||||||
|
msg=AQH_Endpoint_GetNextMsgIn(ipcEndpoint);
|
||||||
|
if (msg) {
|
||||||
|
if (refMsgId==0 || refMsgId==AQH_IpcMessage_GetRefMsgId(msg))
|
||||||
|
return msg;
|
||||||
|
else {
|
||||||
|
uint16_t code;
|
||||||
|
|
||||||
|
code=AQH_IpcMessage_GetCode(msg);
|
||||||
|
DBG_ERROR(NULL, "Received unexpected message %d (%x), ignoring", code, code);
|
||||||
|
AQH_Message_free(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
now=time(NULL);
|
||||||
|
if (now-startTime>timeoutInSeconds) {
|
||||||
|
DBG_INFO(NULL, "Timeout");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQH_IpcEndpoint_SendResponseResultToEndpoint(AQH_OBJECT *ep,
|
||||||
|
uint8_t protoId, uint8_t protoVer,uint16_t code,
|
||||||
|
uint32_t refMsgId, int result)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *msg;
|
||||||
|
|
||||||
|
msg=AQH_IpcMessageResult_new(protoId, protoVer, code, AQH_Endpoint_GetNextMessageId(ep), refMsgId, result, NULL);
|
||||||
|
AQH_Endpoint_AddMsgOut(ep, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
34
aqhome/ipc2/ipc_endpoint.h
Normal file
34
aqhome/ipc2/ipc_endpoint.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
|
*
|
||||||
|
* The license for this file can be found in the file COPYING which you
|
||||||
|
* should have received along with this file.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef AQH_IPC_ENDPOINT_H
|
||||||
|
#define AQH_IPC_ENDPOINT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <aqhome/ipc2/endpoint.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQHOME_API int AQH_IpcEndpoint_ExchangeConnectMsg(AQH_OBJECT *ipcEndpoint,
|
||||||
|
uint16_t connectMsgCode,
|
||||||
|
uint16_t resultMsgCode,
|
||||||
|
const char *clientId,
|
||||||
|
const char *userId,
|
||||||
|
const char *passw,
|
||||||
|
uint32_t flags,
|
||||||
|
int timeoutInSeconds);
|
||||||
|
AQHOME_API int AQH_IpcEndpoint_WaitForResultMsg(AQH_OBJECT *ipcEndpoint, uint16_t resultMsgCode, uint32_t refMsgId, int timeoutInSeconds);
|
||||||
|
AQHOME_API AQH_MESSAGE *AQH_IpcEndpoint_WaitForResponseMsg(AQH_OBJECT *ipcEndpoint, uint32_t refMsgId, int timeoutInSeconds);
|
||||||
|
AQHOME_API void AQH_IpcEndpoint_SendResponseResultToEndpoint(AQH_OBJECT *ep,
|
||||||
|
uint8_t protoId, uint8_t protoVer,uint16_t code,
|
||||||
|
uint32_t refMsgId, int result);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
Reference in New Issue
Block a user