aqhome-nodes: use request functions from aqhome/ipc.

This commit is contained in:
Martin Preuss
2024-10-01 22:04:42 +02:00
parent 6f5da8ee6c
commit 21d47b8b7f
7 changed files with 9 additions and 183 deletions

View File

@@ -49,8 +49,6 @@
tty_log.h
devicesread.h
devicesdump.h
requests.h
n_setdata.h
r_setdata.h
</headers>
@@ -70,8 +68,6 @@
tty_log.c
devicesread.c
devicesdump.c
requests.c
n_setdata.c
r_setdata.c
</sources>

View File

@@ -18,7 +18,6 @@
#include "./aqhomed_p.h"
#include "./tty_log.h"
#include "./db.h"
#include "./requests.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/msg/msg_node.h"
@@ -26,6 +25,7 @@
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/nodes/msg_ipc_forward.h"
#include "aqhome/ipc/nodes/msg_ipc_value.h"
#include "aqhome/ipc/requests.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
@@ -65,8 +65,8 @@ void AqHomed_Loop(AQHOMED *aqh, int timeoutInMsecs)
AqHomed_ReadAndHandleIpcMessages(aqh);
AqHomed_ReadAndHandleBrokerMessages(aqh);
AqHomeNodes_Requests_CheckTimeouts(aqh);
AqHomeNodes_Requests_Cleanup(aqh);
AQH_Requests_CheckTimeouts(aqh->requestTree);
AQH_Requests_Cleanup(aqh->requestTree);
#if 0
DBG_ERROR(NULL, "Messages in TTY queue: %d in, %d out",

View File

@@ -16,7 +16,6 @@
#include "./b_setdata.h"
#include "./tty_log.h"
#include "./db.h"
#include "./requests.h"
#include "./r_setdata.h"
#include "aqhome/msg/endpoint_tty.h"
@@ -26,6 +25,7 @@
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_result.h"
#include "aqhome/ipc/data/ipc_data.h"
#include "aqhome/ipc/requests.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
@@ -69,7 +69,7 @@ void AqHomed_ReadAndHandleBrokerMessages(AQHOMED *aqh)
code=GWEN_IpcMsg_GetCode(msg);
DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC packet %d (%x)", (int) code, code);
if (AqHomeNodes_Requests_HandleIpcMsg(aqh, epTcp, msg)!=GWEN_MSG_REQUEST_RESULT_HANDLED)
if (AQH_Requests_HandleIpcMsg(aqh->requestTree, epTcp, msg)!=GWEN_MSG_REQUEST_RESULT_HANDLED)
_handleIpcMsg(aqh, epTcp, msg);
GWEN_Msg_free(msg);
}

View File

@@ -15,7 +15,6 @@
#include "./aqhomed_p.h"
#include "./tty_log.h"
#include "./db.h"
#include "./requests.h"
#include "./r_setdata.h"
#include "aqhome/msg/endpoint_tty.h"
@@ -33,6 +32,7 @@
#include "aqhome/ipc/data/ipc_data.h"
#include "aqhome/ipc/data/msg_data_set.h"
#include "aqhome/ipc/msg_ipc_result.h"
#include "aqhome/ipc/requests.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
@@ -93,7 +93,7 @@ void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep)
GWEN_MSG *msg;
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) {
if (AqHomeNodes_Requests_HandleIpcMsg(aqh, ep, msg)!=GWEN_MSG_REQUEST_RESULT_HANDLED)
if (AQH_Requests_HandleIpcMsg(aqh->requestTree, ep, msg)!=GWEN_MSG_REQUEST_RESULT_HANDLED)
_handleIpcMsg(aqh, ep, msg);
GWEN_Msg_free(msg);
}

View File

@@ -17,7 +17,6 @@
#include "./aqhomed_p.h"
#include "./tty_log.h"
#include "./db.h"
#include "./requests.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/msg/msg_node.h"
@@ -25,6 +24,7 @@
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/nodes/msg_ipc_forward.h"
#include "aqhome/ipc/nodes/msg_ipc_value.h"
#include "aqhome/ipc/requests.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
@@ -64,7 +64,7 @@ void AqHomed_ReadAndHandleTtyMessages(AQHOMED *aqh)
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(aqh->ttyEndpoint)) ) {
_handleTtyMsg(aqh, msg);
AqHomeNodes_Requests_HandleTtyMsg(aqh, aqh->ttyEndpoint, msg);
AQH_Requests_HandleTtyMsg(aqh->requestTree, aqh->ttyEndpoint, msg);
GWEN_Msg_free(msg);
}
}

View File

@@ -1,140 +0,0 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 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 "./requests.h"
#include "./aqhomed_p.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/data/ipc_data.h"
#include <gwenhywfar/request.h>
#include <gwenhywfar/debug.h>
static void _freeFinishedRequests(GWEN_MSG_REQUEST *rq);
void AqHomeNodes_Requests_CheckTimeouts(AQHOMED *aqh)
{
if (aqh && aqh->requestTree) {
GWEN_MSG_REQUEST *rq;
GWEN_TIMESTAMP *now;
now=GWEN_Timestamp_NowInLocalTime();
rq=GWEN_MsgRequest_Tree2_GetFirstChild(aqh->requestTree);
while(rq) {
const GWEN_TIMESTAMP *ts;
ts=GWEN_MsgRequest_GetExpiresAt(rq);
if (GWEN_Timestamp_Compare(now, ts)>=0) {
/* timeout */
DBG_INFO(NULL, "Request timed out, aborting");
GWEN_MsgRequest_Abort(rq);
}
rq=GWEN_MsgRequest_Tree2_GetBelow(rq);
}
GWEN_Timestamp_free(now);
}
}
void AqHomeNodes_Requests_Cleanup(AQHOMED *aqh)
{
if (aqh && aqh->requestTree) {
GWEN_MSG_REQUEST *rq;
rq=GWEN_MsgRequest_Tree2_GetFirstChild(aqh->requestTree);
while(rq) {
GWEN_MSG_REQUEST *nextSubRq;
nextSubRq=GWEN_MsgRequest_Tree2_GetNext(rq);
_freeFinishedRequests(rq);
rq=nextSubRq;
}
}
}
int AqHomeNodes_Requests_HandleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg)
{
if (aqh && aqh->requestTree) {
uint32_t refMsgId;
refMsgId=GWEN_IpcMsg_GetRefMsgId(recvdMsg);
if (refMsgId) {
GWEN_MSG_REQUEST *rq;
rq=GWEN_MsgRequest_Tree2_GetFirstChild(aqh->requestTree);
while(rq) {
if (srcEp==GWEN_MsgRequest_GetEndpoint(rq) && refMsgId==GWEN_MsgRequest_GetRequestMsgId(rq)) {
if (GWEN_MsgRequest_HandleResponse(rq, recvdMsg)==GWEN_MSG_REQUEST_RESULT_HANDLED)
return GWEN_MSG_REQUEST_RESULT_HANDLED;
}
rq=GWEN_MsgRequest_Tree2_GetBelow(rq);
}
}
else {
DBG_INFO(NULL, "Message has no reference msg id, not a response");
}
}
return GWEN_MSG_REQUEST_RESULT_NOT_HANDLED;
}
int AqHomeNodes_Requests_HandleTtyMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg)
{
if (aqh && aqh->requestTree) {
GWEN_MSG_REQUEST *rq;
rq=GWEN_MsgRequest_Tree2_GetFirstChild(aqh->requestTree);
while(rq) {
if (srcEp==GWEN_MsgRequest_GetEndpoint(rq)) {
if (GWEN_MsgRequest_HandleResponse(rq, recvdMsg)==GWEN_MSG_REQUEST_RESULT_HANDLED)
return GWEN_MSG_REQUEST_RESULT_HANDLED;
}
rq=GWEN_MsgRequest_Tree2_GetBelow(rq);
}
}
return GWEN_MSG_REQUEST_RESULT_NOT_HANDLED;
}
void _freeFinishedRequests(GWEN_MSG_REQUEST *rq)
{
GWEN_MSG_REQUEST *subRq;
subRq=GWEN_MsgRequest_Tree2_GetFirstChild(rq);
while(subRq) {
GWEN_MSG_REQUEST *nextSubRq;
nextSubRq=GWEN_MsgRequest_Tree2_GetNext(subRq);
_freeFinishedRequests(subRq);
subRq=nextSubRq;
}
if (GWEN_MsgRequest_GetState(rq)==GWEN_MSG_REQUEST_STATE_DONE) {
DBG_ERROR(NULL, "Deleting request");
GWEN_MsgRequest_free(rq);
}
}

View File

@@ -1,30 +0,0 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 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 AQHOMED_REQUESTS_H
#define AQHOMED_REQUESTS_H
#include "./aqhomed.h"
#include <gwenhywfar/request.h>
void AqHomeNodes_Requests_CheckTimeouts(AQHOMED *aqh);
void AqHomeNodes_Requests_Cleanup(AQHOMED *aqh);
int AqHomeNodes_Requests_HandleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg);
int AqHomeNodes_Requests_HandleTtyMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg);
#endif