adapted to latest changes in gwen (msgio API v2 becomes v1).

This commit is contained in:
Martin Preuss
2023-07-12 19:30:53 +02:00
parent 7a4edb6854
commit 0fd58567fe
37 changed files with 956 additions and 956 deletions

View File

@@ -143,7 +143,7 @@ int main(int argc, char **argv)
int _serve(GWEN_DB_NODE *dbArgs)
{
const char *pidFile;
GWEN_MSG_ENDPOINT2 *epTcp;
GWEN_MSG_ENDPOINT *epTcp;
ITEM_LIST *itemList;
int rv;
int timeout;
@@ -186,7 +186,7 @@ int _serve(GWEN_DB_NODE *dbArgs)
rv=AqHomeMqttLog_MqttConnect(epTcp);
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
Item_List_free(itemList);
return rv;
}
@@ -194,7 +194,7 @@ int _serve(GWEN_DB_NODE *dbArgs)
rv=AqHomeMqttLog_Subscribe(epTcp, "#");
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
Item_List_free(itemList);
return rv;
}
@@ -203,14 +203,14 @@ int _serve(GWEN_DB_NODE *dbArgs)
while(!stopService) {
DBG_DEBUG(NULL, "Next loop");
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
if (GWEN_MsgEndpoint2_GetState(epTcp)!=GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
if (GWEN_MsgEndpoint_GetState(epTcp)!=GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
DBG_INFO(NULL, "Not connected...");
}
else {
GWEN_MSG *msg;
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
if (msg) {
#ifdef FULL_DEBUG
DBG_ERROR(NULL, "Received this message:");
@@ -267,7 +267,7 @@ int _serve(GWEN_DB_NODE *dbArgs)
if (pidFile && *pidFile)
remove(pidFile);
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
Item_List_free(itemList);
return 0;
}

View File

@@ -15,7 +15,7 @@
#include <aqhome/api.h>
#include <aqhome/aqhome.h>
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include <aqhome/mqtt/msg_mqtt_connect.h>
#include <aqhome/mqtt/msg_mqtt_connack.h>
#include <aqhome/mqtt/msg_mqtt_publish.h>
@@ -44,7 +44,7 @@
* ------------------------------------------------------------------------------------------------
*/
static GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT2 *epTcp, uint8_t expectedPacketType, int timeoutInSeconds);
static GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT *epTcp, uint8_t expectedPacketType, int timeoutInSeconds);
@@ -53,7 +53,7 @@ static GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT2 *epTcp, uint8_t expectedPacketT
* ------------------------------------------------------------------------------------------------
*/
GWEN_MSG_ENDPOINT2 *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs)
GWEN_MSG_ENDPOINT *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs)
{
const char *mqttAddress;
int mqttPort;
@@ -68,17 +68,17 @@ GWEN_MSG_ENDPOINT2 *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs)
mqttKeepAlive=GWEN_DB_GetIntValue(dbArgs, "mqttKeepAlive", 0, 600);
if (mqttAddress && *mqttAddress && mqttPort) {
GWEN_MSG_ENDPOINT2 *epMqtt;
GWEN_MSG_ENDPOINT *epMqtt;
DBG_INFO(AQH_LOGDOMAIN, "Connecting to %s (port %d)", mqttAddress, mqttPort);
epMqtt=AQH_MqttClientEndpoint2_new(mqttClientId, mqttAddress, mqttPort, NULL, 0);
epMqtt=AQH_MqttClientEndpoint_new(mqttClientId, mqttAddress, mqttPort, NULL, 0);
if (epMqtt==NULL) {
DBG_ERROR(AQH_LOGDOMAIN, "Error creating endpoint TCP");
return NULL;
}
if (mqttTopicPrefix && *mqttTopicPrefix)
AQH_MqttClientEndpoint2_SetTopicPrefix(epMqtt, mqttTopicPrefix);
AQH_MqttClientEndpoint2_SetKeepAliveTime(epMqtt, mqttKeepAlive);
AQH_MqttClientEndpoint_SetTopicPrefix(epMqtt, mqttTopicPrefix);
AQH_MqttClientEndpoint_SetKeepAliveTime(epMqtt, mqttKeepAlive);
return epMqtt;
}
@@ -88,41 +88,41 @@ GWEN_MSG_ENDPOINT2 *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs)
int AqHomeMqttLog_MqttConnect(GWEN_MSG_ENDPOINT2 *epTcp)
int AqHomeMqttLog_MqttConnect(GWEN_MSG_ENDPOINT *epTcp)
{
if (GWEN_MsgEndpoint2_GetState(epTcp)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
if (GWEN_MsgEndpoint_GetState(epTcp)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
int rv;
rv=AQH_MqttClientEndpoint2_StartConnect(epTcp);
rv=AQH_MqttClientEndpoint_StartConnect(epTcp);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_ERROR(NULL, "Error starting to connect (%d)", rv);
return rv;
}
}
while(GWEN_MsgEndpoint2_GetState(epTcp)!=GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
while(GWEN_MsgEndpoint_GetState(epTcp)!=GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
DBG_DEBUG(NULL, "Next loop");
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
}
return 0;
}
int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT2 *epTcp, const char *topicFilter)
int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT *epTcp, const char *topicFilter)
{
uint16_t pckId;
GWEN_MSG *msgOut;
GWEN_MSG *msgIn;
DBG_INFO(NULL, "Sending SUBSCRIBE %s", topicFilter);
pckId=AQH_MqttClientEndpoint2_GetNextPacketId(epTcp);
pckId=AQH_MqttClientEndpoint_GetNextPacketId(epTcp);
msgOut=GWEN_SubscribeMqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBSCRIBE, pckId, topicFilter, 0);
if (msgOut==NULL) {
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_INTERNAL;
}
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
DBG_INFO(NULL, "Waiting for response");
msgIn=_awaitPacket(epTcp, AQH_MQTTMSG_MSGTYPE_SUBACK, AQHOME_MQTTLOG_DEFAULT_CMDTIMEOUT);
@@ -141,7 +141,7 @@ int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT2 *epTcp, const char *topicFilter)
int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT2 *epTcp)
int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT *epTcp)
{
GWEN_MSG *msgOut;
@@ -151,14 +151,14 @@ int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT2 *epTcp)
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_INTERNAL;
}
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
return 0;
}
GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT2 *epTcp, uint8_t expectedPacketType, int timeoutInSeconds)
GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT *epTcp, uint8_t expectedPacketType, int timeoutInSeconds)
{
time_t startTime;
@@ -168,8 +168,8 @@ GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT2 *epTcp, uint8_t expectedPacketType, in
GWEN_MSG *msg;
time_t now;
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
if (msg) {
if ((AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0)==(expectedPacketType & 0xf0)) {
return msg;

View File

@@ -10,16 +10,16 @@
#define AQHOME_TOOL_MQTT_H
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include <gwenhywfar/db.h>
GWEN_MSG_ENDPOINT2 *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs);
int AqHomeMqttLog_MqttConnect(GWEN_MSG_ENDPOINT2 *epTcp);
int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT2 *epTcp, const char *topicFilter);
int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT2 *epTcp);
GWEN_MSG_ENDPOINT *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs);
int AqHomeMqttLog_MqttConnect(GWEN_MSG_ENDPOINT *epTcp);
int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT *epTcp, const char *topicFilter);
int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT *epTcp);

View File

@@ -13,7 +13,7 @@
#include "./flash.h"
#include "./utils.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_setaccmsggrps.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/msg/msg_node.h"
@@ -47,28 +47,28 @@ static int _doFlash(GWEN_DB_NODE *dbArgs);
static AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename);
static int _rebootNode(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds);
static int _performFlashProcedure(GWEN_MSG_ENDPOINT2 *epTcp,
static int _rebootNode(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds);
static int _performFlashProcedure(GWEN_MSG_ENDPOINT *epTcp,
unsigned int uid,
const AQH_FLASHRECORD_LIST *flashRecordList,
int pageSize,
int timeoutInSeconds);
static int _flashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds);
static int _flashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds);
static GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT2 *epTcp,
static GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT *epTcp,
unsigned int uid, int timeoutInSeconds);
static int _sendRebootRequest(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid);
static int _sendFlashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid);
static int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds);
static int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds);
static int _sendFlashRecord(GWEN_MSG_ENDPOINT2 *epTcp,
static int _sendRebootRequest(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid);
static int _sendFlashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid);
static int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
static int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
static int _sendFlashRecord(GWEN_MSG_ENDPOINT *epTcp,
const AQH_FLASHRECORD *flashRecord,
uint16_t pageSize,
int timeoutInSeconds);
static int _sendFlashEnd(GWEN_MSG_ENDPOINT2 *epTcp, int reason);
static int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason);
@@ -185,7 +185,7 @@ int AQH_Tool_Flash(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
int _doFlash(GWEN_DB_NODE *dbArgs)
{
GWEN_MSG_ENDPOINT2 *epTcp;
GWEN_MSG_ENDPOINT *epTcp;
int rv;
int timeoutInSeconds;
int doReboot;
@@ -222,7 +222,7 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
rv=Utils_SendAcceptedMsgGroups(epTcp, AQH_MSG_TYPEGROUP_FLASH);
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
return 3;
}
@@ -231,7 +231,7 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
rv=_rebootNode(epTcp, uid, timeoutInSeconds);
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
return 3;
}
fprintf(stdout, "Reboot in progress\n");
@@ -242,7 +242,7 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
msg=_waitForFlashReadyMessageForUid(epTcp, uid, timeoutInSeconds);
if (msg==NULL) {
DBG_INFO(NULL, "No FLASH_READY message received.");
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
return 3;
}
DBG_INFO(NULL, "FLASH_READY message received");
@@ -255,14 +255,14 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
if (rv<0) {
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
AQH_FlashRecord_List_free(flashRecordList);
return 4;
}
}
AQH_FlashRecord_List_free(flashRecordList);
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
return 0;
}
@@ -293,7 +293,7 @@ AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename)
int _rebootNode(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds)
int _rebootNode(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds)
{
int rv;
@@ -316,7 +316,7 @@ int _rebootNode(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSecond
int _performFlashProcedure(GWEN_MSG_ENDPOINT2 *epTcp,
int _performFlashProcedure(GWEN_MSG_ENDPOINT *epTcp,
unsigned int uid,
const AQH_FLASHRECORD_LIST *flashRecordList,
int pageSize,
@@ -361,7 +361,7 @@ int _performFlashProcedure(GWEN_MSG_ENDPOINT2 *epTcp,
int _flashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds)
int _flashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds)
{
int rv;
int i;
@@ -399,7 +399,7 @@ int _flashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSecond
GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds)
GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds)
{
int i;
@@ -428,7 +428,7 @@ GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT2 *epTcp, unsigned in
int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds)
int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
{
GWEN_MSG *msg;
@@ -443,7 +443,7 @@ int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSecond
int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds)
int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
{
GWEN_MSG *msg;
int responseCode;
@@ -460,7 +460,7 @@ int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds
int _sendRebootRequest(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid)
int _sendRebootRequest(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
{
GWEN_MSG *msgNode;
GWEN_MSG *msgOut;
@@ -472,14 +472,14 @@ int _sendRebootRequest(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid)
}
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
GWEN_Msg_free(msgNode);
return 0;
}
int _sendFlashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid)
int _sendFlashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
{
GWEN_MSG *msgNode;
GWEN_MSG *msgOut;
@@ -491,14 +491,14 @@ int _sendFlashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid)
}
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
GWEN_Msg_free(msgNode);
return 0;
}
int _sendFlashEnd(GWEN_MSG_ENDPOINT2 *epTcp, int reason)
int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason)
{
GWEN_MSG *msgNode;
GWEN_MSG *msgOut;
@@ -510,14 +510,14 @@ int _sendFlashEnd(GWEN_MSG_ENDPOINT2 *epTcp, int reason)
}
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
GWEN_Msg_free(msgNode);
return 0;
}
int _sendFlashRecord(GWEN_MSG_ENDPOINT2 *epTcp,
int _sendFlashRecord(GWEN_MSG_ENDPOINT *epTcp,
const AQH_FLASHRECORD *flashRecord,
uint16_t pageSize,
int timeoutInSeconds)
@@ -556,7 +556,7 @@ int _sendFlashRecord(GWEN_MSG_ENDPOINT2 *epTcp,
}
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
GWEN_Msg_free(msgNode);
rv=_waitForFlashResponseMessage(epTcp, timeoutInSeconds);

View File

@@ -13,7 +13,7 @@
#include "./getdevices.h"
#include "./utils.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_getdevices_req.h"
#include "aqhome/ipc/msg_ipc_getdevices_rsp.h"
#include "aqhome/ipc/msg_ipc_error.h"
@@ -34,7 +34,7 @@
static int _doGetDevices(GWEN_DB_NODE *dbArgs);
static int _sendGetDevices(GWEN_MSG_ENDPOINT2 *epTcp);
static int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp);
@@ -118,7 +118,7 @@ int AQH_Tool_GetDevices(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
int _doGetDevices(GWEN_DB_NODE *dbArgs)
{
GWEN_MSG_ENDPOINT2 *epTcp;
GWEN_MSG_ENDPOINT *epTcp;
int rv;
int timeoutInSeconds;
@@ -149,7 +149,7 @@ int _doGetDevices(GWEN_DB_NODE *dbArgs)
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_GETDEVICES_RSP, timeoutInSeconds);
if (msg==NULL) {
DBG_INFO(NULL, "No GET_DEVICE response received.");
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
return 2;
}
code=GWEN_IpcMsg_GetCode(msg);
@@ -196,13 +196,13 @@ int _doGetDevices(GWEN_DB_NODE *dbArgs)
}
}
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
return 0;
}
int _sendGetDevices(GWEN_MSG_ENDPOINT2 *epTcp)
int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp)
{
GWEN_MSG *msgOut;
@@ -211,7 +211,7 @@ int _sendGetDevices(GWEN_MSG_ENDPOINT2 *epTcp)
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_GENERIC;
}
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
return 0;
}

View File

@@ -16,7 +16,7 @@
#include "aqhome/ipc/msg_ipc_setaccmsggrps.h"
#include "aqhome/ipc/msg_ipc_ping.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/msg/msg_node.h"
#include <gwenhywfar/args.h>
@@ -34,7 +34,7 @@
static int _doPing(GWEN_DB_NODE *dbArgs);
static int _sendPing(GWEN_MSG_ENDPOINT2 *epTcp, int nodeAddr);
static int _sendPing(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr);
@@ -129,7 +129,7 @@ int AQH_Tool_Ping(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
int _doPing(GWEN_DB_NODE *dbArgs)
{
GWEN_MSG_ENDPOINT2 *epTcp;
GWEN_MSG_ENDPOINT *epTcp;
int rv;
int nodeAddr;
int timeoutInSeconds;
@@ -165,13 +165,13 @@ int _doPing(GWEN_DB_NODE *dbArgs)
}
fprintf(stdout, "PONG response received\n");
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
return 0;
}
int _sendPing(GWEN_MSG_ENDPOINT2 *epTcp, int nodeAddr)
int _sendPing(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr)
{
GWEN_MSG *msgOut;
@@ -180,7 +180,7 @@ int _sendPing(GWEN_MSG_ENDPOINT2 *epTcp, int nodeAddr)
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_GENERIC;
}
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
return 0;
}

View File

@@ -13,11 +13,11 @@
#include "./utils.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_setaccmsggrps.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include <gwenhywfar/endpoint2_tcpc.h>
#include <gwenhywfar/endpoint_tcpc.h>
#include <gwenhywfar/debug.h>
#include <time.h>
@@ -26,9 +26,9 @@
GWEN_MSG_ENDPOINT2 *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs)
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs)
{
GWEN_MSG_ENDPOINT2 *epTcp;
GWEN_MSG_ENDPOINT *epTcp;
const char *tcpAddress;
int tcpPort;
int rv;
@@ -37,15 +37,15 @@ GWEN_MSG_ENDPOINT2 *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs)
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, 45454);
DBG_INFO(NULL, "Setup tcp client endpoint to %s:%d", tcpAddress, tcpPort);
epTcp=AQH_IpcEndpoint2_CreateIpcTcpClient(tcpAddress, tcpPort, "aqhome-tool-IPC", 0);
epTcp=AQH_IpcEndpoint_CreateIpcTcpClient(tcpAddress, tcpPort, "aqhome-tool-IPC", 0);
if (epTcp==NULL) {
DBG_ERROR(NULL, "Error creating endpoint TCPc");
return NULL;
}
rv=GWEN_TcpcEndpoint2_StartConnect(epTcp);
rv=GWEN_TcpcEndpoint_StartConnect(epTcp);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_ERROR(NULL, "Error connecting (%d)", rv);
GWEN_MsgEndpoint2_free(epTcp);
GWEN_MsgEndpoint_free(epTcp);
return NULL;
}
@@ -54,7 +54,7 @@ GWEN_MSG_ENDPOINT2 *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs)
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT2 *epTcp,
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp,
int msgCode,
int nodeAddr,
int timeoutInSeconds)
@@ -67,8 +67,8 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT2 *epTcp,
GWEN_MSG *msg;
time_t now;
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
if (msg) {
if (GWEN_IpcMsg_GetCode(msg)==AQH_MSGTYPE_IPC_FORWARD) {
GWEN_MSG *nodeMsg;
@@ -103,7 +103,7 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT2 *epTcp,
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT2 *epTcp,
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp,
int msgCode,
int timeoutInSeconds)
{
@@ -115,8 +115,8 @@ GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT2 *epTcp,
GWEN_MSG *msg;
time_t now;
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
if (msg) {
uint16_t code;
@@ -143,16 +143,16 @@ GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT2 *epTcp,
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds)
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
{
time_t startTime;
startTime=time(NULL);
while(GWEN_MsgEndpoint2_HaveMessageToSend(epTcp)) {
while(GWEN_MsgEndpoint_HaveMessageToSend(epTcp)) {
time_t now;
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
now=time(NULL);
if (now-startTime>timeoutInSeconds) {
DBG_INFO(NULL, "Timeout");
@@ -165,7 +165,7 @@ int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds)
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *epTcp, uint32_t groups)
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups)
{
GWEN_MSG *msgOut;
@@ -174,7 +174,7 @@ int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *epTcp, uint32_t groups)
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_GENERIC;
}
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
return 0;
}

View File

@@ -11,24 +11,24 @@
#include <gwenhywfar/db.h>
#include <gwenhywfar/endpoint2.h>
#include <gwenhywfar/endpoint.h>
GWEN_MSG_ENDPOINT2 *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs);
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs);
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT2 *epTcp,
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp,
int msgCode,
int nodeAddr,
int timeoutInSeconds);
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT2 *epTcp,
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp,
int msgCode,
int timeoutInSeconds);
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds);
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *epTcp, uint32_t groups);
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups);
#endif

View File

@@ -14,9 +14,9 @@
#include "./tty_log.h"
#include "./tty_write.h"
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/debug.h>
@@ -51,7 +51,7 @@ AQHOMED *AqHomed_new(void)
AQHOMED *aqh;
GWEN_NEW_OBJECT(AQHOMED, aqh);
aqh->rootEndpoint=GWEN_MsgEndpoint2_new("root", 0);
aqh->rootEndpoint=GWEN_MsgEndpoint_new("root", 0);
aqh->nodeDb=AQH_NodeDb_new();
return aqh;
@@ -62,7 +62,7 @@ AQHOMED *AqHomed_new(void)
void AqHomed_free(AQHOMED *aqh)
{
if (aqh) {
GWEN_MsgEndpoint2_free(aqh->rootEndpoint);
GWEN_MsgEndpoint_free(aqh->rootEndpoint);
aqh->rootEndpoint=NULL;
aqh->ttyEndpoint=NULL;
aqh->ipcdEndpoint=NULL;
@@ -82,21 +82,21 @@ void AqHomed_free(AQHOMED *aqh)
GWEN_MSG_ENDPOINT2 *AqHomed_GetTtyEndpoint(const AQHOMED *aqh)
GWEN_MSG_ENDPOINT *AqHomed_GetTtyEndpoint(const AQHOMED *aqh)
{
return aqh?aqh->ttyEndpoint:NULL;
}
GWEN_MSG_ENDPOINT2 *AqHomed_GetIpcdEndpoint(const AQHOMED *aqh)
GWEN_MSG_ENDPOINT *AqHomed_GetIpcdEndpoint(const AQHOMED *aqh)
{
return aqh?aqh->ipcdEndpoint:NULL;
}
GWEN_MSG_ENDPOINT2 *AqHomed_GetMqttEndpoint(const AQHOMED *aqh)
GWEN_MSG_ENDPOINT *AqHomed_GetMqttEndpoint(const AQHOMED *aqh)
{
return aqh?aqh->mqttEndpoint:NULL;
}

View File

@@ -10,7 +10,7 @@
#define AQHOMED_H
#include <gwenhywfar/endpoint2.h>
#include <gwenhywfar/endpoint.h>
#include <gwenhywfar/db.h>
@@ -24,9 +24,9 @@ typedef struct AQHOMED AQHOMED;
AQHOMED *AqHomed_new(void);
void AqHomed_free(AQHOMED *aqh);
GWEN_MSG_ENDPOINT2 *AqHomed_GetTtyEndpoint(const AQHOMED *aqh);
GWEN_MSG_ENDPOINT2 *AqHomed_GetIpcdEndpoint(const AQHOMED *aqh);
GWEN_MSG_ENDPOINT2 *AqHomed_GetMqttEndpoint(const AQHOMED *aqh);
GWEN_MSG_ENDPOINT *AqHomed_GetTtyEndpoint(const AQHOMED *aqh);
GWEN_MSG_ENDPOINT *AqHomed_GetIpcdEndpoint(const AQHOMED *aqh);
GWEN_MSG_ENDPOINT *AqHomed_GetMqttEndpoint(const AQHOMED *aqh);
GWEN_DB_NODE *AqHomed_GetDbArgs(const AQHOMED *aqh);

View File

@@ -28,11 +28,11 @@
struct AQHOMED {
GWEN_MSG_ENDPOINT2 *rootEndpoint;
GWEN_MSG_ENDPOINT *rootEndpoint;
GWEN_MSG_ENDPOINT2 *ttyEndpoint;
GWEN_MSG_ENDPOINT2 *ipcdEndpoint;
GWEN_MSG_ENDPOINT2 *mqttEndpoint;
GWEN_MSG_ENDPOINT *ttyEndpoint;
GWEN_MSG_ENDPOINT *ipcdEndpoint;
GWEN_MSG_ENDPOINT *mqttEndpoint;
AQH_NODE_DB *nodeDb;

View File

@@ -28,7 +28,7 @@
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endpoint2_tcpd.h>
#include <gwenhywfar/endpoint_tcpd.h>
#include <gwenhywfar/timestamp.h>

View File

@@ -17,7 +17,7 @@
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endpoint2_tcpd.h>
#include <gwenhywfar/endpoint_tcpd.h>
#include <unistd.h>
@@ -39,7 +39,7 @@
* ------------------------------------------------------------------------------------------------
*/
static void _disconnectTree(GWEN_MSG_ENDPOINT2 *ep);
static void _disconnectTree(GWEN_MSG_ENDPOINT *ep);
@@ -53,7 +53,7 @@ void AqHomed_Fini(AQHOMED *aqh)
if (aqh) {
if (aqh->rootEndpoint) {
_disconnectTree(aqh->rootEndpoint);
GWEN_MsgEndpoint2_Disconnect(aqh->rootEndpoint);
GWEN_MsgEndpoint_Disconnect(aqh->rootEndpoint);
}
aqh->rootEndpoint=NULL;
aqh->ttyEndpoint=NULL;
@@ -67,17 +67,17 @@ void AqHomed_Fini(AQHOMED *aqh)
void _disconnectTree(GWEN_MSG_ENDPOINT2 *ep)
void _disconnectTree(GWEN_MSG_ENDPOINT *ep)
{
GWEN_MSG_ENDPOINT2 *epChild;
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
while(epChild) {
_disconnectTree(epChild);
epChild=GWEN_MsgEndpoint2_Tree2_GetNext(epChild);
epChild=GWEN_MsgEndpoint_Tree2_GetNext(epChild);
} /* while */
GWEN_MsgEndpoint2_Disconnect(ep);
GWEN_MsgEndpoint_Disconnect(ep);
}

View File

@@ -16,14 +16,14 @@
#include "./tty_log.h"
#include "./tty_write.h"
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endpoint2_tcpd.h>
#include <gwenhywfar/endpoint_tcpd.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
@@ -59,7 +59,7 @@
static int _setupTty(AQHOMED *aqh, GWEN_DB_NODE *dbArgs);
static void _setupIpc(AQHOMED *aqh, GWEN_DB_NODE *dbArgs);
static GWEN_MSG_ENDPOINT2 *_acceptIpcFn(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKET *sk, const GWEN_INETADDRESS *addr, void *data);
static GWEN_MSG_ENDPOINT *_acceptIpcFn(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKET *sk, const GWEN_INETADDRESS *addr, void *data);
static void _setupMqtt(AQHOMED *aqh, GWEN_DB_NODE *dbArgs);
static void _setupLog(AQHOMED *aqh, GWEN_DB_NODE *dbArgs);
static void _setupWriter(AQHOMED *aqh, GWEN_DB_NODE *dbArgs);
@@ -125,14 +125,14 @@ int _setupTty(AQHOMED *aqh, GWEN_DB_NODE *dbArgs)
devicePath=GWEN_DB_GetCharValue(dbArgs, "device", 0, AQHOMED_DEFAULT_DEVICE);
if (devicePath && *devicePath) {
GWEN_MSG_ENDPOINT2 *epTty;
GWEN_MSG_ENDPOINT *epTty;
epTty=AQH_TtyEndpoint2_new(devicePath, AQHOME_ENDPOINTGROUP_NODE);
epTty=AQH_TtyEndpoint_new(devicePath, AQHOME_ENDPOINTGROUP_NODE);
if (epTty==NULL) {
DBG_ERROR(NULL, "Error creating endpoint TTY");
return GWEN_ERROR_GENERIC;
}
GWEN_MsgEndpoint2_Tree2_AddChild(aqh->rootEndpoint, epTty);
GWEN_MsgEndpoint_Tree2_AddChild(aqh->rootEndpoint, epTty);
aqh->ttyEndpoint=epTty;
}
else {
@@ -154,12 +154,12 @@ void _setupIpc(AQHOMED *aqh, GWEN_DB_NODE *dbArgs)
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, AQHOMED_DEFAULT_IPC_PORT);
if (tcpAddress && *tcpAddress && tcpPort) {
GWEN_MSG_ENDPOINT2 *ep;
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_TcpdEndpoint2_new(tcpAddress, tcpPort, NULL, AQHOME_ENDPOINTGROUP_IPC);
GWEN_TcpdEndpoint2_SetAcceptFn(ep, _acceptIpcFn, aqh);
ep=GWEN_TcpdEndpoint_new(tcpAddress, tcpPort, NULL, AQHOME_ENDPOINTGROUP_IPC);
GWEN_TcpdEndpoint_SetAcceptFn(ep, _acceptIpcFn, aqh);
GWEN_MsgEndpoint2_Tree2_AddChild(aqh->rootEndpoint, ep);
GWEN_MsgEndpoint_Tree2_AddChild(aqh->rootEndpoint, ep);
aqh->ipcdEndpoint=ep;
}
}
@@ -181,18 +181,18 @@ void _setupMqtt(AQHOMED *aqh, GWEN_DB_NODE *dbArgs)
mqttKeepAlive=GWEN_DB_GetIntValue(dbArgs, "mqttKeepAlive", 0, AQHOMED_DEFAULT_MQTT_KEEPALIVE);
if (mqttAddress && *mqttAddress && mqttPort) {
GWEN_MSG_ENDPOINT2 *ep;
GWEN_MSG_ENDPOINT *ep;
int rv;
ep=AQH_MqttClientEndpoint2_new(mqttClientId, mqttAddress, mqttPort, NULL, AQHOME_ENDPOINTGROUP_MQTT);
ep=AQH_MqttClientEndpoint_new(mqttClientId, mqttAddress, mqttPort, NULL, AQHOME_ENDPOINTGROUP_MQTT);
AqHomed_SetMqttTopicPrefix(aqh, mqttTopicPrefix);
AQH_MqttClientEndpoint2_SetTopicPrefix(ep, mqttTopicPrefix);
AQH_MqttClientEndpoint2_SetKeepAliveTime(ep, mqttKeepAlive);
AQH_MqttClientEndpoint_SetTopicPrefix(ep, mqttTopicPrefix);
AQH_MqttClientEndpoint_SetKeepAliveTime(ep, mqttKeepAlive);
GWEN_MsgEndpoint2_Tree2_AddChild(aqh->rootEndpoint, ep);
GWEN_MsgEndpoint_Tree2_AddChild(aqh->rootEndpoint, ep);
aqh->mqttEndpoint=ep;
rv=AQH_MqttClientEndpoint2_StartConnect(ep);
rv=AQH_MqttClientEndpoint_StartConnect(ep);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_ERROR(NULL, "Error connecting to MQTT server %s:%d (%d), will retry later", mqttAddress, mqttPort, rv);
}
@@ -201,17 +201,17 @@ void _setupMqtt(AQHOMED *aqh, GWEN_DB_NODE *dbArgs)
GWEN_MSG_ENDPOINT2 *_acceptIpcFn(GWEN_MSG_ENDPOINT2 *ep,
GWEN_SOCKET *sk,
const GWEN_INETADDRESS *addr,
GWEN_UNUSED void *data)
GWEN_MSG_ENDPOINT *_acceptIpcFn(GWEN_MSG_ENDPOINT *ep,
GWEN_SOCKET *sk,
const GWEN_INETADDRESS *addr,
GWEN_UNUSED void *data)
{
/* AQHOMED *aqh;
*
* aqh=(AQHOMED*) data;
*/
DBG_INFO(NULL, "Incoming IPC connection");
return AQH_IpcEndpoint2_CreateIpcTcpServiceForSocket(sk, NULL, AQHOME_ENDPOINTGROUP_IPC);
return AQH_IpcEndpoint_CreateIpcTcpServiceForSocket(sk, NULL, AQHOME_ENDPOINTGROUP_IPC);
}

View File

@@ -19,18 +19,18 @@
#include "./tty_write.h"
#include "./db.h"
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/msg/msg_value2.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/ipc/msg_ipc_value.h"
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endpoint2_tcpd.h>
#include <gwenhywfar/endpoint_tcpd.h>
@@ -60,7 +60,7 @@
void AqHomed_Loop(AQHOMED *aqh, int timeoutInMsecs)
{
if (aqh) {
GWEN_MsgEndpoint2_ChildrenIoLoop(aqh->rootEndpoint, timeoutInMsecs);
GWEN_MsgEndpoint_ChildrenIoLoop(aqh->rootEndpoint, timeoutInMsecs);
AqHomed_ReadAndHandleTtyMessages(aqh);
AqHomed_ReadAndHandleIpcMessages(aqh);

View File

@@ -17,11 +17,11 @@
#include "./tty_write.h"
#include "./db.h"
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/msg/msg_value2.h"
#include "aqhome/msg/msg_ping.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/ipc/msg_ipc_value.h"
@@ -33,7 +33,7 @@
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endpoint2_tcpd.h>
#include <gwenhywfar/endpoint_tcpd.h>
@@ -52,12 +52,12 @@
* ------------------------------------------------------------------------------------------------
*/
static void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep);
static void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg);
void _handleIpcMsgPing(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg);
void _handleIpcMsgSetAccMsgGrps(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg);
void _handleIpcMsgForward(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg);
void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg);
static void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep);
static void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
void _handleIpcMsgPing(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
void _handleIpcMsgSetAccMsgGrps(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
void _handleIpcMsgForward(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
@@ -70,23 +70,23 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN
void AqHomed_ReadAndHandleIpcMessages(AQHOMED *aqh)
{
if (aqh->ipcdEndpoint) {
GWEN_MSG_ENDPOINT2 *ep;
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_MsgEndpoint2_Tree2_GetFirstChild(aqh->ipcdEndpoint);
ep=GWEN_MsgEndpoint_Tree2_GetFirstChild(aqh->ipcdEndpoint);
while(ep) {
_handleIpcEndpoint(aqh, ep);
ep=GWEN_MsgEndpoint2_Tree2_GetNext(ep);
ep=GWEN_MsgEndpoint_Tree2_GetNext(ep);
}
}
}
void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep)
void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep)
{
GWEN_MSG *msg;
while( (msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(ep)) ) {
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) {
_handleIpcMsg(aqh, ep, msg);
GWEN_Msg_free(msg);
}
@@ -94,7 +94,7 @@ void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep)
void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg)
void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
{
uint16_t code;
@@ -112,46 +112,46 @@ void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg)
void _handleIpcMsgPing(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg)
void _handleIpcMsgPing(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
{
if (aqh->ttyEndpoint && GWEN_MsgEndpoint2_GetState(aqh->ttyEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
if (aqh->ttyEndpoint && GWEN_MsgEndpoint_GetState(aqh->ttyEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
GWEN_MSG *msgOut;
DBG_ERROR(AQH_LOGDOMAIN, "Received IPC PING message");
msgOut=AQH_PingMsg_new(aqh->nodeAddress, AQH_PingIpcMsg_GetDestAddr(msg), AQH_MSG_TYPE_PING);
GWEN_MsgEndpoint2_AddSendMessage(aqh->ttyEndpoint, msgOut);
GWEN_MsgEndpoint_AddSendMessage(aqh->ttyEndpoint, msgOut);
}
}
void _handleIpcMsgSetAccMsgGrps(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg)
void _handleIpcMsgSetAccMsgGrps(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
{
uint32_t groups;
DBG_ERROR(AQH_LOGDOMAIN, "Received IPC SET_ACCEPTED_MSG_GROUPS message");
groups=AQH_SetAcceptedMsgGroupsIpcMsg_GetMsgGroups(msg);
AQH_IpcEndpoint2_SetAcceptedMsgGroups(ep, groups);
AQH_IpcEndpoint_SetAcceptedMsgGroups(ep, groups);
// TODO: send response?
}
void _handleIpcMsgForward(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg)
void _handleIpcMsgForward(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
{
if (aqh->ttyEndpoint && GWEN_MsgEndpoint2_GetState(aqh->ttyEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
if (aqh->ttyEndpoint && GWEN_MsgEndpoint_GetState(aqh->ttyEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
GWEN_MSG *msgOut;
DBG_ERROR(AQH_LOGDOMAIN, "Received IPC FORWARD message");
msgOut=AQH_ForwardIpcMsg_GetCopyOfNodeMsg(msg);
if (msgOut)
GWEN_MsgEndpoint2_AddSendMessage(aqh->ttyEndpoint, msgOut);
GWEN_MsgEndpoint_AddSendMessage(aqh->ttyEndpoint, msgOut);
}
}
void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *msg)
void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
{
AQH_NODE_INFO_LIST *nodeInfoList;
@@ -168,7 +168,7 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN
niNext=AQH_NodeInfo_List_Next(ni);
DBG_INFO(AQH_LOGDOMAIN, "Sending response for node %02x (%08x)", AQH_NodeInfo_GetBusAddress(ni), AQH_NodeInfo_GetUid(ni));
msgOut=AQH_GetDevicesResponseIpcMsg_new(AQH_MSGTYPE_IPC_GETDEVICES_RSP, niNext?0:AQH_MSGIPC_GETDEVICES_RSP_FLAGS_LAST, ni);
GWEN_MsgEndpoint2_AddSendMessage(ep, msgOut);
GWEN_MsgEndpoint_AddSendMessage(ep, msgOut);
ni=niNext;
}
}
@@ -177,7 +177,7 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT2 *ep, const GWEN
DBG_INFO(AQH_LOGDOMAIN, "No nodes");
msgOut=AQH_ErrorIpcMsg_new(AQH_MSGTYPE_IPC_ERROR, AQH_MSG_IPC_ERROR_NODATA);
GWEN_MsgEndpoint2_AddSendMessage(ep, msgOut);
GWEN_MsgEndpoint_AddSendMessage(ep, msgOut);
}
}

View File

@@ -19,18 +19,18 @@
#include "./tty_write.h"
#include "./db.h"
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/msg/msg_value2.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/ipc/msg_ipc_value.h"
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endpoint2_tcpd.h>
#include <gwenhywfar/endpoint_tcpd.h>
@@ -63,7 +63,7 @@ void AqHomed_ReadAndHandleTtyMessages(AQHOMED *aqh)
{
GWEN_MSG *msg;
while( (msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(aqh->ttyEndpoint)) ) {
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(aqh->ttyEndpoint)) ) {
_handleTtyMsg(aqh, msg);
GWEN_Msg_free(msg);
}

View File

@@ -17,18 +17,18 @@
#include "./tty_write.h"
#include "./db.h"
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/msg/msg_value2.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/ipc/msg_ipc_value.h"
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endpoint2_tcpd.h>
#include <gwenhywfar/endpoint_tcpd.h>
@@ -47,8 +47,8 @@
* ------------------------------------------------------------------------------------------------
*/
static void _forwardValue2MsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg);
static void _forwardAnyMsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg);
static void _forwardValue2MsgToIpc(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *nodeMsg);
static void _forwardAnyMsgToIpc(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *nodeMsg);
@@ -63,11 +63,11 @@ void AqHomed_ForwardTtyMsgToIpcClients(AQHOMED *aqh, const GWEN_MSG *msg)
msgGroup=AQH_NodeMsg_GetMsgGroup(AQH_NodeMsg_GetMsgType(msg));
if (msgGroup) {
GWEN_MSG_ENDPOINT2 *ep;
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_MsgEndpoint2_Tree2_GetFirstChild(aqh->ipcdEndpoint);
ep=GWEN_MsgEndpoint_Tree2_GetFirstChild(aqh->ipcdEndpoint);
while(ep) {
if (msgGroup & AQH_IpcEndpoint2_GetAcceptedMsgGroups(ep)) {
if (msgGroup & AQH_IpcEndpoint_GetAcceptedMsgGroups(ep)) {
DBG_INFO(NULL, "Endpoint accepts msg group %d", msgGroup);
switch(AQH_NodeMsg_GetMsgType(msg)) {
case AQH_MSG_TYPE_VALUE2:
@@ -79,7 +79,7 @@ void AqHomed_ForwardTtyMsgToIpcClients(AQHOMED *aqh, const GWEN_MSG *msg)
}
}
ep=GWEN_MsgEndpoint2_Tree2_GetNext(ep);
ep=GWEN_MsgEndpoint_Tree2_GetNext(ep);
}
}
else {
@@ -89,7 +89,7 @@ void AqHomed_ForwardTtyMsgToIpcClients(AQHOMED *aqh, const GWEN_MSG *msg)
void _forwardValue2MsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg)
void _forwardValue2MsgToIpc(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *nodeMsg)
{
GWEN_MSG *ipcMsg;
@@ -99,17 +99,17 @@ void _forwardValue2MsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg)
AQH_Value2Msg_GetValueType(nodeMsg),
AQH_Value2Msg_GetValueNom(nodeMsg),
AQH_Value2Msg_GetValueDenom(nodeMsg));
GWEN_MsgEndpoint2_AddSendMessage(ep, ipcMsg);
GWEN_MsgEndpoint_AddSendMessage(ep, ipcMsg);
}
void _forwardAnyMsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg)
void _forwardAnyMsgToIpc(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *nodeMsg)
{
GWEN_MSG *ipcMsg;
ipcMsg=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(nodeMsg), GWEN_Msg_GetBytesInBuffer(nodeMsg));
GWEN_MsgEndpoint2_AddSendMessage(ep, ipcMsg);
GWEN_MsgEndpoint_AddSendMessage(ep, ipcMsg);
}

View File

@@ -17,21 +17,21 @@
#include "./tty_write.h"
#include "./db.h"
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/msg/msg_value2.h"
#include "aqhome/msg/msg_sendstats.h"
#include "aqhome/msg/msg_recvstats.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/ipc/msg_ipc_value.h"
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include "aqhome/mqtt/msg_mqtt_publish.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endpoint2_tcpd.h>
#include <gwenhywfar/endpoint_tcpd.h>
@@ -69,7 +69,7 @@ static void _publishString(AQHOMED *aqh, uint32_t uid, int valueId, const char *
void AqHomed_ForwardTtyMsgToMqttServer(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
{
if (GWEN_MsgEndpoint2_GetState(aqh->mqttEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
if (GWEN_MsgEndpoint_GetState(aqh->mqttEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
DBG_DEBUG(AQH_LOGDOMAIN, "Processing output message");
switch(AQH_NodeMsg_GetMsgType(nodeMsg)) {
case AQH_MSG_TYPE_VALUE2:
@@ -207,7 +207,7 @@ void _publishString(AQHOMED *aqh, uint32_t uid, int valueId, const char *valuePa
pubMsg=AQH_PublishMqttMsg_new(0, 0, GWEN_Buffer_GetStart(bufTopic), (const uint8_t*) v, strlen(v));
if (pubMsg) {
DBG_INFO(AQH_LOGDOMAIN, "MQTT PUBLISH %s: %s", GWEN_Buffer_GetStart(bufTopic), v);
GWEN_MsgEndpoint2_AddSendMessage(aqh->mqttEndpoint, pubMsg);
GWEN_MsgEndpoint_AddSendMessage(aqh->mqttEndpoint, pubMsg);
}
GWEN_Buffer_free(bufTopic);
}

View File

@@ -45,7 +45,7 @@
<headers dist="true" install="$(pkgincludedir)/ipc" >
endpoint2_ipc.h
endpoint_ipc.h
msg_ipc.h
msg_ipc_forward.h
msg_ipc_value.h
@@ -58,14 +58,14 @@
<headers dist="true" >
endpoint2_ipc_p.h
endpoint_ipc_p.h
</headers>
<sources>
$(local/typefiles)
endpoint2_ipc.c
endpoint_ipc.c
msg_ipc.c
msg_ipc_forward.c
msg_ipc_value.c

View File

@@ -1,139 +0,0 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 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 "aqhome/ipc/endpoint2_ipc_p.h"
#include <gwenhywfar/endpoint2_ipc.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_ENDPOINT2_IPC_NAME "ipc"
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT2_IPC)
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
void AQH_IpcEndpoint2_Extend(GWEN_MSG_ENDPOINT2 *ep)
{
AQH_ENDPOINT2_IPC *xep;
GWEN_NEW_OBJECT(AQH_ENDPOINT2_IPC, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep, xep, _freeData);
}
void _freeData(void *bp, void *p)
{
AQH_ENDPOINT2_IPC *xep;
xep=(AQH_ENDPOINT2_IPC*) p;
GWEN_FREE_OBJECT(xep);
}
uint32_t AQH_IpcEndpoint2_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT2 *ep)
{
if (ep) {
AQH_ENDPOINT2_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep);
if (xep) {
return xep->acceptedMsgGroups;
}
}
return 0;
}
void AQH_IpcEndpoint2_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i)
{
if (ep) {
AQH_ENDPOINT2_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep);
if (xep)
xep->acceptedMsgGroups=i;
}
}
void AQH_IpcEndpoint2_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i)
{
if (ep) {
AQH_ENDPOINT2_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep);
if (xep)
xep->acceptedMsgGroups|=i;
}
}
void AQH_IpcEndpoint2_SubAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i)
{
if (ep) {
AQH_ENDPOINT2_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep);
if (xep)
xep->acceptedMsgGroups&=~i;
}
}
GWEN_MSG_ENDPOINT2 *AQH_IpcEndpoint2_CreateIpcTcpClient(const char *host, int port, const char *name, int groupId)
{
GWEN_MSG_ENDPOINT2 *ep;
ep=GWEN_IpcEndpoint2_CreateIpcTcpClient(host, port, name?name:AQH_MSG_ENDPOINT2_IPC_NAME, groupId);
AQH_IpcEndpoint2_Extend(ep);
return ep;
}
GWEN_MSG_ENDPOINT2 *AQH_IpcEndpoint2_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, const char *name, int groupId)
{
GWEN_MSG_ENDPOINT2 *ep;
ep=GWEN_IpcEndpoint2_CreateIpcTcpServiceForSocket(sk, name?name:AQH_MSG_ENDPOINT2_IPC_NAME, groupId);
AQH_IpcEndpoint2_Extend(ep);
return ep;
}

View File

@@ -1,31 +0,0 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 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_ENDPOINT2_IPC_H
#define AQH_ENDPOINT2_IPC_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint2.h>
AQHOME_API void AQH_IpcEndpoint2_Extend(GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API GWEN_MSG_ENDPOINT2 *AQH_IpcEndpoint2_CreateIpcTcpClient(const char *host, int port, const char *name, int groupId);
AQHOME_API GWEN_MSG_ENDPOINT2 *AQH_IpcEndpoint2_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, const char *name, int groupId);
AQHOME_API uint32_t AQH_IpcEndpoint2_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API void AQH_IpcEndpoint2_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i);
AQHOME_API void AQH_IpcEndpoint2_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i);
AQHOME_API void AQH_IpcEndpoint2_SubAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i);
#endif

139
aqhome/ipc/endpoint_ipc.c Normal file
View File

@@ -0,0 +1,139 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 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 "aqhome/ipc/endpoint_ipc_p.h"
#include <gwenhywfar/endpoint_ipc.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_ENDPOINT_IPC_NAME "ipc"
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC)
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
void AQH_IpcEndpoint_Extend(GWEN_MSG_ENDPOINT *ep)
{
AQH_ENDPOINT_IPC *xep;
GWEN_NEW_OBJECT(AQH_ENDPOINT_IPC, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep, xep, _freeData);
}
void _freeData(void *bp, void *p)
{
AQH_ENDPOINT_IPC *xep;
xep=(AQH_ENDPOINT_IPC*) p;
GWEN_FREE_OBJECT(xep);
}
uint32_t AQH_IpcEndpoint_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
AQH_ENDPOINT_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep);
if (xep) {
return xep->acceptedMsgGroups;
}
}
return 0;
}
void AQH_IpcEndpoint_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i)
{
if (ep) {
AQH_ENDPOINT_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep);
if (xep)
xep->acceptedMsgGroups=i;
}
}
void AQH_IpcEndpoint_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i)
{
if (ep) {
AQH_ENDPOINT_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep);
if (xep)
xep->acceptedMsgGroups|=i;
}
}
void AQH_IpcEndpoint_SubAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i)
{
if (ep) {
AQH_ENDPOINT_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep);
if (xep)
xep->acceptedMsgGroups&=~i;
}
}
GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpClient(const char *host, int port, const char *name, int groupId)
{
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_IpcEndpoint_CreateIpcTcpClient(host, port, name?name:AQH_MSG_ENDPOINT_IPC_NAME, groupId);
AQH_IpcEndpoint_Extend(ep);
return ep;
}
GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, const char *name, int groupId)
{
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_IpcEndpoint_CreateIpcTcpServiceForSocket(sk, name?name:AQH_MSG_ENDPOINT_IPC_NAME, groupId);
AQH_IpcEndpoint_Extend(ep);
return ep;
}

31
aqhome/ipc/endpoint_ipc.h Normal file
View File

@@ -0,0 +1,31 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 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_ENDPOINT_IPC_H
#define AQH_ENDPOINT_IPC_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint.h>
AQHOME_API void AQH_IpcEndpoint_Extend(GWEN_MSG_ENDPOINT *ep);
AQHOME_API GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpClient(const char *host, int port, const char *name, int groupId);
AQHOME_API GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, const char *name, int groupId);
AQHOME_API uint32_t AQH_IpcEndpoint_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_IpcEndpoint_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i);
AQHOME_API void AQH_IpcEndpoint_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i);
AQHOME_API void AQH_IpcEndpoint_SubAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i);
#endif

View File

@@ -6,19 +6,19 @@
* should have received along with this file.
****************************************************************************/
#ifndef AQH_ENDPOINT2_IPC_P_H
#define AQH_ENDPOINT2_IPC_P_H
#ifndef AQH_ENDPOINT_IPC_P_H
#define AQH_ENDPOINT_IPC_P_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint2.h>
#include <gwenhywfar/endpoint.h>
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/endpoint_ipc.h"
typedef struct AQH_ENDPOINT2_IPC AQH_ENDPOINT2_IPC;
struct AQH_ENDPOINT2_IPC {
typedef struct AQH_ENDPOINT_IPC AQH_ENDPOINT_IPC;
struct AQH_ENDPOINT_IPC {
uint32_t acceptedMsgGroups;
};

View File

@@ -7,7 +7,7 @@
#include "aqhome/ipc/msg_ipc_ping.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/ipc/msg_ipc_setaccmsggrps.h"
#include "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include "aqhome/mqtt/msg_mqtt_connect.h"
#include "aqhome/mqtt/msg_mqtt_connack.h"
#include "aqhome/mqtt/msg_mqtt_publish.h"
@@ -28,8 +28,8 @@
#include <time.h>
static int _mqttConnect2(GWEN_MSG_ENDPOINT2 *epClient);
static GWEN_MSG *_awaitPacket2(GWEN_MSG_ENDPOINT2 *epClient, uint8_t expectedPacketType);
static int _mqttConnect2(GWEN_MSG_ENDPOINT *epClient);
static GWEN_MSG *_awaitPacket2(GWEN_MSG_ENDPOINT *epClient, uint8_t expectedPacketType);
@@ -104,18 +104,18 @@ GWEN_MSG *createPingMsg(uint8_t destAddr, uint8_t srcAddr)
int testMqttConnection2()
{
GWEN_MSG_ENDPOINT2 *epClient;
GWEN_MSG_ENDPOINT *epClient;
int loop;
AQH_Init();
epClient=AQH_MqttClientEndpoint2_new("TESTCLIENT1234", "127.0.0.1", 1883, NULL, 1);
epClient=AQH_MqttClientEndpoint_new("TESTCLIENT1234", "127.0.0.1", 1883, NULL, 1);
for (loop=0;; loop++) {
DBG_INFO(GWEN_LOGDOMAIN, "Loop %d:", loop);
GWEN_MsgEndpoint2_IoLoop(epClient, 2000); /* 2000 ms */
GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */
if (GWEN_MsgEndpoint2_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
if (GWEN_MsgEndpoint_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
DBG_INFO(AQH_LOGDOMAIN, "Connected.");
break;
}
@@ -127,7 +127,7 @@ int testMqttConnection2()
int testMqttSubscribe2(int argc, char **argv)
{
GWEN_MSG_ENDPOINT2 *epClient;
GWEN_MSG_ENDPOINT *epClient;
int rv;
GWEN_MSG *msgOut;
GWEN_MSG *msgIn;
@@ -140,14 +140,14 @@ int testMqttSubscribe2(int argc, char **argv)
host=argv[1];
DBG_ERROR(AQH_LOGDOMAIN, "Connecting to %s (%s)", host, argv[1]);
epClient=AQH_MqttClientEndpoint2_new("TESTCLIENT1234", host, 1883, NULL, 1);
epClient=AQH_MqttClientEndpoint_new("TESTCLIENT1234", host, 1883, NULL, 1);
rv=_mqttConnect2(epClient);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return 2;
}
pckId=AQH_MqttClientEndpoint2_GetNextPacketId(epClient);
pckId=AQH_MqttClientEndpoint_GetNextPacketId(epClient);
//msgOut=AQH_PublishMqttMsg_new(AQH_MQTTMSG_FLAGS_QOS1, 1, "test/subject1", (const uint8_t*) "29.9", 4);
//msgOut=GWEN_SubscribeMqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBSCRIBE, pckId, "aqhome/#", 0);
msgOut=GWEN_SubscribeMqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBSCRIBE, pckId, "#", 0);
@@ -155,7 +155,7 @@ int testMqttSubscribe2(int argc, char **argv)
DBG_ERROR(NULL, "Error creating message");
return 2;
}
GWEN_MsgEndpoint2_AddSendMessage(epClient, msgOut);
GWEN_MsgEndpoint_AddSendMessage(epClient, msgOut);
msgIn=_awaitPacket2(epClient, AQH_MQTTMSG_MSGTYPE_SUBACK);
if (msgIn) {
@@ -171,8 +171,8 @@ int testMqttSubscribe2(int argc, char **argv)
for (;;) {
GWEN_MSG *msg;
GWEN_MsgEndpoint2_IoLoop(epClient, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epClient);
GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epClient);
if (msg) {
if ((AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0)==(AQH_MQTTMSG_MSGTYPE_PUBLISH & 0xf0)) {
GWEN_BUFFER *buf;
@@ -196,19 +196,19 @@ int testMqttSubscribe2(int argc, char **argv)
int _mqttConnect2(GWEN_MSG_ENDPOINT2 *epClient)
int _mqttConnect2(GWEN_MSG_ENDPOINT *epClient)
{
int loop;
for (loop=0;; loop++) {
DBG_INFO(GWEN_LOGDOMAIN, "Loop %d:", loop);
GWEN_MsgEndpoint2_IoLoop(epClient, 2000); /* 2000 ms */
GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */
if (GWEN_MsgEndpoint2_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
if (GWEN_MsgEndpoint_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
DBG_INFO(AQH_LOGDOMAIN, "Connected.");
break;
}
else if (GWEN_MsgEndpoint2_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
else if (GWEN_MsgEndpoint_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_INFO(AQH_LOGDOMAIN, "Disconnected.");
return GWEN_ERROR_IO;
}
@@ -219,15 +219,15 @@ int _mqttConnect2(GWEN_MSG_ENDPOINT2 *epClient)
GWEN_MSG *_awaitPacket2(GWEN_MSG_ENDPOINT2 *epClient, uint8_t expectedPacketType)
GWEN_MSG *_awaitPacket2(GWEN_MSG_ENDPOINT *epClient, uint8_t expectedPacketType)
{
fprintf(stdout, "Waiting for response\n");
for (;;) {
GWEN_MSG *msg;
DBG_DEBUG(AQH_LOGDOMAIN, "Next loop");
GWEN_MsgEndpoint2_IoLoop(epClient, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epClient);
GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epClient);
if (msg) {
if ((AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0)==(expectedPacketType & 0xf0)) {
return msg;

View File

@@ -45,8 +45,8 @@
<headers dist="true" install="$(pkgincludedir)/ipc" >
endpoint2_mqtt.h
endpoint2_mqttc.h
endpoint_mqtt.h
endpoint_mqttc.h
msg_mqtt.h
msg_mqtt_connect.h
msg_mqtt_connack.h
@@ -58,15 +58,15 @@
<headers dist="true" >
endpoint2_mqtt_p.h
endpoint_mqtt_p.h
</headers>
<sources>
$(local/typefiles)
endpoint2_mqtt.c
endpoint2_mqttc.c
endpoint_mqtt.c
endpoint_mqttc.c
msg_mqtt.c
msg_mqtt_connect.c
msg_mqtt_connack.c

View File

@@ -1,392 +0,0 @@
/****************************************************************************
* This file is part of the project Gwenhywfar.
* Gwenhywfar (c) by 2023 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 "aqhome/mqtt/endpoint2_mqttc.h"
#include "aqhome/mqtt/endpoint2_mqtt.h"
#include "aqhome/mqtt/msg_mqtt_connect.h"
#include "aqhome/mqtt/msg_mqtt_connack.h"
#include "aqhome/mqtt/msg_mqtt_publish.h"
#include <gwenhywfar/endpoint2_tcpc.h>
#include <gwenhywfar/endpoint2_msgio.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/inherit.h>
#define AQH_ENDPOINT2_MQTT_NAME "mqtt-client"
#define AQH_ENDPOINT2_MQTTC_RECONNECT_TIME 5
#define AQH_ENDPOINT2_MQTTC_CONNECT_TIMEOUT 10
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _addSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet);
static void _checkSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static int _startConnect(GWEN_MSG_ENDPOINT2 *ep);
static void _moveMessagesBetweenLists(GWEN_MSG_LIST *srcList, GWEN_MSG_LIST *dstList);
static void _addSocketsWhenUnconnected(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static void _addSocketsWhenConnecting(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static void _addSocketsWhenConnected(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static void _checkSocketsWhenConnecting(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static void _checkSocketsWhenConnected(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
GWEN_MSG_ENDPOINT2 *AQH_MqttClientEndpoint2_new(const char *clientId,
const char *host, int port,
const char *name, int groupId)
{
GWEN_MSG_ENDPOINT2 *ep;
GWEN_MSG_ENDPOINT2 *epChild;
ep=GWEN_MsgEndpoint2_new(name?name:AQH_ENDPOINT2_MQTT_NAME, groupId);
GWEN_MsgEndpoint2_SetAddSocketsFn(ep, _addSockets);
GWEN_MsgEndpoint2_SetCheckSocketsFn(ep, _checkSockets);
epChild=GWEN_TcpcEndpoint2_new(host, port, NULL, groupId);
GWEN_MsgIoEndpoint2_Extend(epChild);
AQH_MqttEndpoint2_Extend(epChild);
AQH_MqttEndpoint2_SetClientId(epChild, clientId);
GWEN_MsgEndpoint2_Tree2_AddChild(ep, epChild);
return ep;
}
int AQH_MqttClientEndpoint2_StartConnect(GWEN_MSG_ENDPOINT2 *ep)
{
if (ep) {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
int rv;
/* connect, set state */
rv=_startConnect(ep);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_INFO(AQH_LOGDOMAIN, "Endpoint %s: Error connecting (%d)", GWEN_MsgEndpoint2_GetName(ep), rv);
GWEN_MsgEndpoint2_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING);
}
else {
DBG_INFO(AQH_LOGDOMAIN, "Endpoint %s: Connecting.", GWEN_MsgEndpoint2_GetName(ep));
GWEN_MsgEndpoint2_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING);
}
return rv;
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Endpoint %s: Not unconnected", GWEN_MsgEndpoint2_GetName(ep));
}
}
else {
DBG_ERROR(GWEN_LOGDOMAIN, "No endpoint");
}
return GWEN_ERROR_GENERIC;
}
uint16_t AQH_MqttClientEndpoint2_GetKeepAliveTime(const GWEN_MSG_ENDPOINT2 *ep)
{
if (ep) {
GWEN_MSG_ENDPOINT2 *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
if (epChild)
return AQH_MqttEndpoint2_GetKeepAliveTime(epChild);
}
return 0;
}
void AQH_MqttClientEndpoint2_SetKeepAliveTime(GWEN_MSG_ENDPOINT2 *ep, uint16_t i)
{
if (ep) {
GWEN_MSG_ENDPOINT2 *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
if (epChild) {
AQH_MqttEndpoint2_SetKeepAliveTime(epChild, i);
}
}
}
uint16_t AQH_MqttClientEndpoint2_GetNextPacketId(const GWEN_MSG_ENDPOINT2 *ep)
{
if (ep) {
GWEN_MSG_ENDPOINT2 *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
if (epChild) {
return AQH_MqttEndpoint2_GetNextPacketId(epChild);
}
}
return 0;
}
const char *AQH_MqttClientEndpoint2_GetTopicPrefix(const GWEN_MSG_ENDPOINT2 *ep)
{
if (ep) {
GWEN_MSG_ENDPOINT2 *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
if (epChild)
return AQH_MqttEndpoint2_GetTopicPrefix(epChild);
}
return NULL;
}
void AQH_MqttClientEndpoint2_SetTopicPrefix(GWEN_MSG_ENDPOINT2 *ep, const char *s)
{
if (ep) {
GWEN_MSG_ENDPOINT2 *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
if (epChild)
AQH_MqttEndpoint2_SetTopicPrefix(epChild, s);
}
}
void _addSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
if (ep) {
GWEN_MSG_ENDPOINT2 *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
if (epChild) {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED)
_addSocketsWhenUnconnected(ep, epChild, readSet, writeSet, xSet);
else {
if (GWEN_MsgEndpoint2_GetState(epChild)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcp layer, disconnecting");
GWEN_MsgEndpoint2_Disconnect(epChild);
GWEN_MsgEndpoint2_Disconnect(ep);
}
else {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTING)
_addSocketsWhenConnecting(ep, epChild, readSet, writeSet, xSet);
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED)
_addSocketsWhenConnected(ep, epChild, readSet, writeSet, xSet);
}
}
} /* if (epChild) */
} /* if (ep) */
}
void _checkSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
DBG_DEBUG(AQH_LOGDOMAIN, "Checking sockets in state %d", GWEN_MsgEndpoint2_GetState(ep));
if (ep) {
GWEN_MSG_ENDPOINT2 *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
if (epChild) {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
/* nothing to do here */
} /* if GWEN_MSG_ENDPOINT_STATE_UNCONNECTED */
else {
if (GWEN_MsgEndpoint2_GetState(epChild)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcp layer, disconnecting");
GWEN_MsgEndpoint2_Disconnect(epChild);
GWEN_MsgEndpoint2_Disconnect(ep);
}
else {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTING)
_checkSocketsWhenConnecting(ep, epChild, readSet, writeSet, xSet);
else if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED)
_checkSocketsWhenConnected(ep, epChild, readSet, writeSet, xSet);
}
}
}
}
}
void _addSocketsWhenUnconnected(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
time_t now;
now=time(NULL);
if ((now-GWEN_MsgEndpoint2_GetTimeOfLastStateChange(ep))>=AQH_ENDPOINT2_MQTTC_RECONNECT_TIME) {
int rv;
/* (re)connect, set state */
DBG_INFO(AQH_LOGDOMAIN, "Starting to (re-)connect");
rv=AQH_MqttClientEndpoint2_StartConnect(ep);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
}
}
}
void _addSocketsWhenConnecting(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
time_t now;
now=time(NULL);
if ((now-GWEN_MsgEndpoint2_GetTimeOfLastStateChange(ep))>=AQH_ENDPOINT2_MQTTC_CONNECT_TIMEOUT ||
GWEN_MsgEndpoint2_GetState(epChild)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_ERROR(AQH_LOGDOMAIN, "Timeout on connect");
GWEN_MsgEndpoint2_Disconnect(epChild);
GWEN_MsgEndpoint2_Disconnect(ep);
}
else
GWEN_MsgEndpoint2_AddSockets(epChild, readSet, writeSet, xSet);
}
void _addSocketsWhenConnected(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
if (GWEN_MsgEndpoint2_GetState(epChild)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcp layer, disconnecting");
GWEN_MsgEndpoint2_Disconnect(epChild);
GWEN_MsgEndpoint2_Disconnect(ep);
}
else {
/* move to-send messages to child */
_moveMessagesBetweenLists(GWEN_MsgEndpoint2_GetSendMessageList(ep), GWEN_MsgEndpoint2_GetSendMessageList(epChild));
GWEN_MsgEndpoint2_AddSockets(epChild, readSet, writeSet, xSet);
}
}
void _checkSocketsWhenConnecting(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
GWEN_MSG *msg;
GWEN_MsgEndpoint2_CheckSockets(epChild, readSet, writeSet, xSet); /* let base layer work */
msg=GWEN_MsgEndpoint2_GetFirstReceivedMessage(epChild);
while(msg) {
GWEN_MSG *msgNext;
uint8_t msgType;
msgNext=GWEN_Msg_List_Next(msg);
msgType=AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0;
if (msgType==AQH_MQTTMSG_MSGTYPE_CONNACK) {
int code;
GWEN_Msg_List_Del(msg); /* remove from list */
code=AQH_ConnAckMqttMsg_GetResultCode(msg);
if (code==AQH_MQTTMSG_CONNACK_RESULT_ACCEPTED) {
DBG_INFO(AQH_LOGDOMAIN, "Positive CONNACK response, connected");
GWEN_MsgEndpoint2_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Negative CONNACK response (%d)", code);
GWEN_MsgEndpoint2_Disconnect(epChild);
GWEN_MsgEndpoint2_Disconnect(ep);
}
GWEN_Msg_free(msg);
break;
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Ignoring response (%d)", msgType);
}
msg=msgNext;
} /* while */
}
void _checkSocketsWhenConnected(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG_ENDPOINT2 *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
_moveMessagesBetweenLists(GWEN_MsgEndpoint2_GetSendMessageList(ep), GWEN_MsgEndpoint2_GetSendMessageList(epChild));
GWEN_MsgEndpoint2_CheckSockets(epChild, readSet, writeSet, xSet);
_moveMessagesBetweenLists(GWEN_MsgEndpoint2_GetReceivedMessageList(epChild), GWEN_MsgEndpoint2_GetReceivedMessageList(ep));
}
int _startConnect(GWEN_MSG_ENDPOINT2 *ep)
{
GWEN_MSG_ENDPOINT2 *epChild;
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
if (epChild) {
int rv;
GWEN_MSG *msg;
rv=GWEN_TcpcEndpoint2_StartConnect(epChild);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_INFO(AQH_LOGDOMAIN, "Error starting to connect child layer (%d)", rv);
return rv;
}
msg=AQH_MqttEndpoint2_CreateMsgConnect(epChild);
if (msg) {
GWEN_MsgEndpoint2_AddSendMessage(epChild, msg);
GWEN_MsgEndpoint2_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING);
return rv; /* result from GWEN_TcpcEndpoint2_StartConnect() above */
}
}
return GWEN_ERROR_GENERIC;
}
void _moveMessagesBetweenLists(GWEN_MSG_LIST *srcList, GWEN_MSG_LIST *dstList)
{
GWEN_MSG *msg;
while( (msg=GWEN_Msg_List_First(srcList)) ) {
GWEN_Msg_List_Del(msg);
GWEN_Msg_List_Add(msg, dstList);
}
}

View File

@@ -10,21 +10,21 @@
# include <config.h>
#endif
#include "aqhome/mqtt/endpoint2_mqtt_p.h"
#include "aqhome/mqtt/endpoint_mqtt_p.h"
#include "aqhome/mqtt/msg_mqtt_connect.h"
#include "aqhome/mqtt/msg_mqtt_publish.h"
#include <gwenhywfar/endpoint2_msgio.h>
#include <gwenhywfar/endpoint_msgio.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/inherit.h>
#define AQH_ENDPOINT2_MQTT_DEFAULT_KEEPALIVE 600
#define AQH_ENDPOINT_MQTT_DEFAULT_KEEPALIVE 600
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT2_MQTT)
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT)
@@ -35,7 +35,7 @@ GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT2_MQTT)
*/
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
static int _getBytesNeededForMessage(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg);
static int _getBytesNeededForMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
static int _calcAndSetPayloadSizeAndOffset(GWEN_MSG *msg);
@@ -46,16 +46,16 @@ static int _calcAndSetPayloadSizeAndOffset(GWEN_MSG *msg);
*/
void AQH_MqttEndpoint2_Extend(GWEN_MSG_ENDPOINT2 *ep)
void AQH_MqttEndpoint_Extend(GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
GWEN_NEW_OBJECT(AQH_ENDPOINT2_MQTT, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep, xep, _freeData);
xep->keepAliveTime=AQH_ENDPOINT2_MQTT_DEFAULT_KEEPALIVE;
GWEN_NEW_OBJECT(AQH_ENDPOINT_MQTT, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep, xep, _freeData);
xep->keepAliveTime=AQH_ENDPOINT_MQTT_DEFAULT_KEEPALIVE;
GWEN_MsgIoEndpoint2_SetGetNeededBytesFn(ep, _getBytesNeededForMessage);
GWEN_MsgIoEndpoint_SetGetNeededBytesFn(ep, _getBytesNeededForMessage);
}
}
@@ -63,9 +63,9 @@ void AQH_MqttEndpoint2_Extend(GWEN_MSG_ENDPOINT2 *ep)
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
{
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=(AQH_ENDPOINT2_MQTT*) p;
xep=(AQH_ENDPOINT_MQTT*) p;
free(xep->clientId);
free(xep->topicPrefix);
GWEN_FREE_OBJECT(xep);
@@ -73,12 +73,12 @@ void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
const char *AQH_MqttEndpoint2_GetClientId(const GWEN_MSG_ENDPOINT2 *ep)
const char *AQH_MqttEndpoint_GetClientId(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
return xep->clientId;
}
@@ -88,12 +88,12 @@ const char *AQH_MqttEndpoint2_GetClientId(const GWEN_MSG_ENDPOINT2 *ep)
void AQH_MqttEndpoint2_SetClientId(GWEN_MSG_ENDPOINT2 *ep, const char *s)
void AQH_MqttEndpoint_SetClientId(GWEN_MSG_ENDPOINT *ep, const char *s)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
free(xep->clientId);
xep->clientId=s?strdup(s):NULL;
@@ -103,12 +103,12 @@ void AQH_MqttEndpoint2_SetClientId(GWEN_MSG_ENDPOINT2 *ep, const char *s)
const char *AQH_MqttEndpoint2_GetTopicPrefix(const GWEN_MSG_ENDPOINT2 *ep)
const char *AQH_MqttEndpoint_GetTopicPrefix(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
return xep->topicPrefix;
}
@@ -118,12 +118,12 @@ const char *AQH_MqttEndpoint2_GetTopicPrefix(const GWEN_MSG_ENDPOINT2 *ep)
void AQH_MqttEndpoint2_SetTopicPrefix(GWEN_MSG_ENDPOINT2 *ep, const char *s)
void AQH_MqttEndpoint_SetTopicPrefix(GWEN_MSG_ENDPOINT *ep, const char *s)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
free(xep->topicPrefix);
xep->topicPrefix=s?strdup(s):NULL;
@@ -133,12 +133,12 @@ void AQH_MqttEndpoint2_SetTopicPrefix(GWEN_MSG_ENDPOINT2 *ep, const char *s)
uint16_t AQH_MqttEndpoint2_GetNextPacketId(const GWEN_MSG_ENDPOINT2 *ep)
uint16_t AQH_MqttEndpoint_GetNextPacketId(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
return ++(xep->lastPacketId);
}
@@ -148,12 +148,12 @@ uint16_t AQH_MqttEndpoint2_GetNextPacketId(const GWEN_MSG_ENDPOINT2 *ep)
uint16_t AQH_MqttEndpoint2_GetKeepAliveTime(const GWEN_MSG_ENDPOINT2 *ep)
uint16_t AQH_MqttEndpoint_GetKeepAliveTime(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
return xep->keepAliveTime;
}
@@ -163,12 +163,12 @@ uint16_t AQH_MqttEndpoint2_GetKeepAliveTime(const GWEN_MSG_ENDPOINT2 *ep)
void AQH_MqttEndpoint2_SetKeepAliveTime(GWEN_MSG_ENDPOINT2 *ep, uint16_t i)
void AQH_MqttEndpoint_SetKeepAliveTime(GWEN_MSG_ENDPOINT *ep, uint16_t i)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
xep->keepAliveTime=i;
}
@@ -177,7 +177,7 @@ void AQH_MqttEndpoint2_SetKeepAliveTime(GWEN_MSG_ENDPOINT2 *ep, uint16_t i)
int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg)
int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg)
{
uint32_t bytesInMsg;
@@ -239,13 +239,13 @@ int _calcAndSetPayloadSizeAndOffset(GWEN_MSG *msg)
GWEN_MSG *AQH_MqttEndpoint2_CreateMsgConnect(GWEN_MSG_ENDPOINT2 *ep)
GWEN_MSG *AQH_MqttEndpoint_CreateMsgConnect(GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
DBG_INFO(AQH_LOGDOMAIN, "Sending connect msg");
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
return GWEN_ConnectMqttMsg_new("MQTT", 4, 0, xep->keepAliveTime, xep->clientId, NULL, NULL);
}
@@ -255,38 +255,38 @@ GWEN_MSG *AQH_MqttEndpoint2_CreateMsgConnect(GWEN_MSG_ENDPOINT2 *ep)
GWEN_MSG *AQH_MqttEndpoint2_CreateMsgPublishDouble(GWEN_MSG_ENDPOINT2 *ep, uint32_t uid, int valueId, const char *valuePath, double v)
GWEN_MSG *AQH_MqttEndpoint_CreateMsgPublishDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v)
{
char numBuf[16];
snprintf(numBuf, sizeof(numBuf)-1, "%f", v);
numBuf[sizeof(numBuf)-1]=0;
return AQH_MqttEndpoint2_CreateMsgPublishString(ep, uid, valueId, valuePath, numBuf);
return AQH_MqttEndpoint_CreateMsgPublishString(ep, uid, valueId, valuePath, numBuf);
}
GWEN_MSG *AQH_MqttEndpoint2_CreateMsgPublishInt(GWEN_MSG_ENDPOINT2 *ep, uint32_t uid, int valueId, const char *valuePath, int v)
GWEN_MSG *AQH_MqttEndpoint_CreateMsgPublishInt(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, int v)
{
char numBuf[16];
snprintf(numBuf, sizeof(numBuf)-1, "%d", v);
numBuf[sizeof(numBuf)-1]=0;
return AQH_MqttEndpoint2_CreateMsgPublishString(ep, uid, valueId, valuePath, numBuf);
return AQH_MqttEndpoint_CreateMsgPublishString(ep, uid, valueId, valuePath, numBuf);
}
GWEN_MSG *AQH_MqttEndpoint2_CreateMsgPublishString(GWEN_MSG_ENDPOINT2 *ep,
GWEN_MSG *AQH_MqttEndpoint_CreateMsgPublishString(GWEN_MSG_ENDPOINT *ep,
uint32_t uid,
int valueId,
const char *valuePath,
const char *v)
{
if (ep) {
AQH_ENDPOINT2_MQTT *xep;
AQH_ENDPOINT_MQTT *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_MQTT, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep);
if (xep) {
GWEN_BUFFER *bufTopic;
GWEN_MSG *pubMsg;

View File

@@ -6,13 +6,13 @@
* should have received along with this file.
****************************************************************************/
#ifndef AQH_ENDPOINT2_MQTT_H
#define AQH_ENDPOINT2_MQTT_H
#ifndef AQH_ENDPOINT_MQTT_H
#define AQH_ENDPOINT_MQTT_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint2.h>
#include <gwenhywfar/endpoint.h>
#ifdef __cplusplus
@@ -21,37 +21,37 @@ extern "C" {
/**
* Extends the given endpoint to support MQTT messages. It expects the function GWEN_MsgIoEndpoint2_Extend() to have been called
* Extends the given endpoint to support MQTT messages. It expects the function GWEN_MsgIoEndpoint_Extend() to have been called
* beforehand.
*/
AQHOME_API void AQH_MqttEndpoint2_Extend(GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API void AQH_MqttEndpoint_Extend(GWEN_MSG_ENDPOINT *ep);
AQHOME_API const char *AQH_MqttEndpoint2_GetClientId(const GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API void AQH_MqttEndpoint2_SetClientId(GWEN_MSG_ENDPOINT2 *ep, const char *s);
AQHOME_API const char *AQH_MqttEndpoint_GetClientId(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_MqttEndpoint_SetClientId(GWEN_MSG_ENDPOINT *ep, const char *s);
AQHOME_API const char *AQH_MqttEndpoint2_GetTopicPrefix(const GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API void AQH_MqttEndpoint2_SetTopicPrefix(GWEN_MSG_ENDPOINT2 *ep, const char *s);
AQHOME_API const char *AQH_MqttEndpoint_GetTopicPrefix(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_MqttEndpoint_SetTopicPrefix(GWEN_MSG_ENDPOINT *ep, const char *s);
AQHOME_API uint16_t AQH_MqttEndpoint2_GetNextPacketId(const GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API uint16_t AQH_MqttEndpoint_GetNextPacketId(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API uint16_t AQH_MqttEndpoint2_GetKeepAliveTime(const GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API void AQH_MqttEndpoint2_SetKeepAliveTime(GWEN_MSG_ENDPOINT2 *ep, uint16_t i);
AQHOME_API uint16_t AQH_MqttEndpoint_GetKeepAliveTime(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_MqttEndpoint_SetKeepAliveTime(GWEN_MSG_ENDPOINT *ep, uint16_t i);
AQHOME_API GWEN_MSG *AQH_MqttEndpoint2_CreateMsgConnect(GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API GWEN_MSG *AQH_MqttEndpoint2_CreateMsgPublishString(GWEN_MSG_ENDPOINT2 *ep,
AQHOME_API GWEN_MSG *AQH_MqttEndpoint_CreateMsgConnect(GWEN_MSG_ENDPOINT *ep);
AQHOME_API GWEN_MSG *AQH_MqttEndpoint_CreateMsgPublishString(GWEN_MSG_ENDPOINT *ep,
uint32_t uid,
int valueId,
const char *valuePath,
const char *v);
AQHOME_API GWEN_MSG *AQH_MqttEndpoint2_CreateMsgPublishDouble(GWEN_MSG_ENDPOINT2 *ep,
AQHOME_API GWEN_MSG *AQH_MqttEndpoint_CreateMsgPublishDouble(GWEN_MSG_ENDPOINT *ep,
uint32_t uid,
int valueId,
const char *valuePath,
double v);
AQHOME_API GWEN_MSG *AQH_MqttEndpoint2_CreateMsgPublishInt(GWEN_MSG_ENDPOINT2 *ep,
AQHOME_API GWEN_MSG *AQH_MqttEndpoint_CreateMsgPublishInt(GWEN_MSG_ENDPOINT *ep,
uint32_t uid,
int valueId,
const char *valuePath,

View File

@@ -6,16 +6,16 @@
* should have received along with this file.
****************************************************************************/
#ifndef AQH_ENDPOINT2_MQTT_P_H
#define AQH_ENDPOINT2_MQTT_P_H
#ifndef AQH_ENDPOINT_MQTT_P_H
#define AQH_ENDPOINT_MQTT_P_H
#include "aqhome/mqtt/endpoint2_mqtt.h"
#include "aqhome/mqtt/endpoint_mqtt.h"
typedef struct AQH_ENDPOINT2_MQTT AQH_ENDPOINT2_MQTT;
struct AQH_ENDPOINT2_MQTT {
typedef struct AQH_ENDPOINT_MQTT AQH_ENDPOINT_MQTT;
struct AQH_ENDPOINT_MQTT {
char *clientId;
char *topicPrefix;
uint16_t lastPacketId;

View File

@@ -0,0 +1,392 @@
/****************************************************************************
* This file is part of the project Gwenhywfar.
* Gwenhywfar (c) by 2023 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 "aqhome/mqtt/endpoint_mqttc.h"
#include "aqhome/mqtt/endpoint_mqtt.h"
#include "aqhome/mqtt/msg_mqtt_connect.h"
#include "aqhome/mqtt/msg_mqtt_connack.h"
#include "aqhome/mqtt/msg_mqtt_publish.h"
#include <gwenhywfar/endpoint_tcpc.h>
#include <gwenhywfar/endpoint_msgio.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/inherit.h>
#define AQH_ENDPOINT2_MQTT_NAME "mqtt-client"
#define AQH_ENDPOINT2_MQTTC_RECONNECT_TIME 5
#define AQH_ENDPOINT2_MQTTC_CONNECT_TIMEOUT 10
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet);
static void _checkSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static int _startConnect(GWEN_MSG_ENDPOINT *ep);
static void _moveMessagesBetweenLists(GWEN_MSG_LIST *srcList, GWEN_MSG_LIST *dstList);
static void _addSocketsWhenUnconnected(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static void _addSocketsWhenConnecting(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static void _addSocketsWhenConnected(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static void _checkSocketsWhenConnecting(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
static void _checkSocketsWhenConnected(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
GWEN_MSG_ENDPOINT *AQH_MqttClientEndpoint_new(const char *clientId,
const char *host, int port,
const char *name, int groupId)
{
GWEN_MSG_ENDPOINT *ep;
GWEN_MSG_ENDPOINT *epChild;
ep=GWEN_MsgEndpoint_new(name?name:AQH_ENDPOINT2_MQTT_NAME, groupId);
GWEN_MsgEndpoint_SetAddSocketsFn(ep, _addSockets);
GWEN_MsgEndpoint_SetCheckSocketsFn(ep, _checkSockets);
epChild=GWEN_TcpcEndpoint_new(host, port, NULL, groupId);
GWEN_MsgIoEndpoint_Extend(epChild);
AQH_MqttEndpoint_Extend(epChild);
AQH_MqttEndpoint_SetClientId(epChild, clientId);
GWEN_MsgEndpoint_Tree2_AddChild(ep, epChild);
return ep;
}
int AQH_MqttClientEndpoint_StartConnect(GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
int rv;
/* connect, set state */
rv=_startConnect(ep);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_INFO(AQH_LOGDOMAIN, "Endpoint %s: Error connecting (%d)", GWEN_MsgEndpoint_GetName(ep), rv);
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING);
}
else {
DBG_INFO(AQH_LOGDOMAIN, "Endpoint %s: Connecting.", GWEN_MsgEndpoint_GetName(ep));
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING);
}
return rv;
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Endpoint %s: Not unconnected", GWEN_MsgEndpoint_GetName(ep));
}
}
else {
DBG_ERROR(GWEN_LOGDOMAIN, "No endpoint");
}
return GWEN_ERROR_GENERIC;
}
uint16_t AQH_MqttClientEndpoint_GetKeepAliveTime(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
if (epChild)
return AQH_MqttEndpoint_GetKeepAliveTime(epChild);
}
return 0;
}
void AQH_MqttClientEndpoint_SetKeepAliveTime(GWEN_MSG_ENDPOINT *ep, uint16_t i)
{
if (ep) {
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
if (epChild) {
AQH_MqttEndpoint_SetKeepAliveTime(epChild, i);
}
}
}
uint16_t AQH_MqttClientEndpoint_GetNextPacketId(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
if (epChild) {
return AQH_MqttEndpoint_GetNextPacketId(epChild);
}
}
return 0;
}
const char *AQH_MqttClientEndpoint_GetTopicPrefix(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
if (epChild)
return AQH_MqttEndpoint_GetTopicPrefix(epChild);
}
return NULL;
}
void AQH_MqttClientEndpoint_SetTopicPrefix(GWEN_MSG_ENDPOINT *ep, const char *s)
{
if (ep) {
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
if (epChild)
AQH_MqttEndpoint_SetTopicPrefix(epChild, s);
}
}
void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
if (ep) {
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
if (epChild) {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED)
_addSocketsWhenUnconnected(ep, epChild, readSet, writeSet, xSet);
else {
if (GWEN_MsgEndpoint_GetState(epChild)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcp layer, disconnecting");
GWEN_MsgEndpoint_Disconnect(epChild);
GWEN_MsgEndpoint_Disconnect(ep);
}
else {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTING)
_addSocketsWhenConnecting(ep, epChild, readSet, writeSet, xSet);
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED)
_addSocketsWhenConnected(ep, epChild, readSet, writeSet, xSet);
}
}
} /* if (epChild) */
} /* if (ep) */
}
void _checkSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
DBG_DEBUG(AQH_LOGDOMAIN, "Checking sockets in state %d", GWEN_MsgEndpoint_GetState(ep));
if (ep) {
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
if (epChild) {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
/* nothing to do here */
} /* if GWEN_MSG_ENDPOINT_STATE_UNCONNECTED */
else {
if (GWEN_MsgEndpoint_GetState(epChild)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcp layer, disconnecting");
GWEN_MsgEndpoint_Disconnect(epChild);
GWEN_MsgEndpoint_Disconnect(ep);
}
else {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTING)
_checkSocketsWhenConnecting(ep, epChild, readSet, writeSet, xSet);
else if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED)
_checkSocketsWhenConnected(ep, epChild, readSet, writeSet, xSet);
}
}
}
}
}
void _addSocketsWhenUnconnected(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
time_t now;
now=time(NULL);
if ((now-GWEN_MsgEndpoint_GetTimeOfLastStateChange(ep))>=AQH_ENDPOINT2_MQTTC_RECONNECT_TIME) {
int rv;
/* (re)connect, set state */
DBG_INFO(AQH_LOGDOMAIN, "Starting to (re-)connect");
rv=AQH_MqttClientEndpoint_StartConnect(ep);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
}
}
}
void _addSocketsWhenConnecting(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
time_t now;
now=time(NULL);
if ((now-GWEN_MsgEndpoint_GetTimeOfLastStateChange(ep))>=AQH_ENDPOINT2_MQTTC_CONNECT_TIMEOUT ||
GWEN_MsgEndpoint_GetState(epChild)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_ERROR(AQH_LOGDOMAIN, "Timeout on connect");
GWEN_MsgEndpoint_Disconnect(epChild);
GWEN_MsgEndpoint_Disconnect(ep);
}
else
GWEN_MsgEndpoint_AddSockets(epChild, readSet, writeSet, xSet);
}
void _addSocketsWhenConnected(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
if (GWEN_MsgEndpoint_GetState(epChild)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcp layer, disconnecting");
GWEN_MsgEndpoint_Disconnect(epChild);
GWEN_MsgEndpoint_Disconnect(ep);
}
else {
/* move to-send messages to child */
_moveMessagesBetweenLists(GWEN_MsgEndpoint_GetSendMessageList(ep), GWEN_MsgEndpoint_GetSendMessageList(epChild));
GWEN_MsgEndpoint_AddSockets(epChild, readSet, writeSet, xSet);
}
}
void _checkSocketsWhenConnecting(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
GWEN_MSG *msg;
GWEN_MsgEndpoint_CheckSockets(epChild, readSet, writeSet, xSet); /* let base layer work */
msg=GWEN_MsgEndpoint_GetFirstReceivedMessage(epChild);
while(msg) {
GWEN_MSG *msgNext;
uint8_t msgType;
msgNext=GWEN_Msg_List_Next(msg);
msgType=AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0;
if (msgType==AQH_MQTTMSG_MSGTYPE_CONNACK) {
int code;
GWEN_Msg_List_Del(msg); /* remove from list */
code=AQH_ConnAckMqttMsg_GetResultCode(msg);
if (code==AQH_MQTTMSG_CONNACK_RESULT_ACCEPTED) {
DBG_INFO(AQH_LOGDOMAIN, "Positive CONNACK response, connected");
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Negative CONNACK response (%d)", code);
GWEN_MsgEndpoint_Disconnect(epChild);
GWEN_MsgEndpoint_Disconnect(ep);
}
GWEN_Msg_free(msg);
break;
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Ignoring response (%d)", msgType);
}
msg=msgNext;
} /* while */
}
void _checkSocketsWhenConnected(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
{
_moveMessagesBetweenLists(GWEN_MsgEndpoint_GetSendMessageList(ep), GWEN_MsgEndpoint_GetSendMessageList(epChild));
GWEN_MsgEndpoint_CheckSockets(epChild, readSet, writeSet, xSet);
_moveMessagesBetweenLists(GWEN_MsgEndpoint_GetReceivedMessageList(epChild), GWEN_MsgEndpoint_GetReceivedMessageList(ep));
}
int _startConnect(GWEN_MSG_ENDPOINT *ep)
{
GWEN_MSG_ENDPOINT *epChild;
epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep);
if (epChild) {
int rv;
GWEN_MSG *msg;
rv=GWEN_TcpcEndpoint_StartConnect(epChild);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_INFO(AQH_LOGDOMAIN, "Error starting to connect child layer (%d)", rv);
return rv;
}
msg=AQH_MqttEndpoint_CreateMsgConnect(epChild);
if (msg) {
GWEN_MsgEndpoint_AddSendMessage(epChild, msg);
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING);
return rv; /* result from GWEN_TcpcEndpoint_StartConnect() above */
}
}
return GWEN_ERROR_GENERIC;
}
void _moveMessagesBetweenLists(GWEN_MSG_LIST *srcList, GWEN_MSG_LIST *dstList)
{
GWEN_MSG *msg;
while( (msg=GWEN_Msg_List_First(srcList)) ) {
GWEN_Msg_List_Del(msg);
GWEN_Msg_List_Add(msg, dstList);
}
}

View File

@@ -12,7 +12,7 @@
#include <aqhome/api.h>
#include <gwenhywfar/endpoint2.h>
#include <gwenhywfar/endpoint.h>
#ifdef __cplusplus
@@ -22,20 +22,20 @@ extern "C" {
/**
*/
AQHOME_API GWEN_MSG_ENDPOINT2 *AQH_MqttClientEndpoint2_new(const char *clientId,
AQHOME_API GWEN_MSG_ENDPOINT *AQH_MqttClientEndpoint_new(const char *clientId,
const char *host, int port,
const char *name, int groupId);
AQHOME_API uint16_t AQH_MqttClientEndpoint2_GetKeepAliveTime(const GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API void AQH_MqttClientEndpoint2_SetKeepAliveTime(GWEN_MSG_ENDPOINT2 *ep, uint16_t i);
AQHOME_API uint16_t AQH_MqttClientEndpoint_GetKeepAliveTime(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_MqttClientEndpoint_SetKeepAliveTime(GWEN_MSG_ENDPOINT *ep, uint16_t i);
AQHOME_API uint16_t AQH_MqttClientEndpoint2_GetNextPacketId(const GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API uint16_t AQH_MqttClientEndpoint_GetNextPacketId(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API const char *AQH_MqttClientEndpoint2_GetTopicPrefix(const GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API void AQH_MqttClientEndpoint2_SetTopicPrefix(GWEN_MSG_ENDPOINT2 *ep, const char *s);
AQHOME_API const char *AQH_MqttClientEndpoint_GetTopicPrefix(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_MqttClientEndpoint_SetTopicPrefix(GWEN_MSG_ENDPOINT *ep, const char *s);
AQHOME_API int AQH_MqttClientEndpoint2_StartConnect(GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API int AQH_MqttClientEndpoint_StartConnect(GWEN_MSG_ENDPOINT *ep);

View File

@@ -45,7 +45,7 @@
<headers dist="true" install="$(pkgincludedir)/msg" >
endpoint2_tty.h
endpoint_tty.h
msg_node.h
msg_ping.h
msg_pong.h
@@ -70,14 +70,14 @@
<headers dist="true" >
endpoint2_tty_p.h
endpoint_tty_p.h
</headers>
<sources>
$(local/typefiles)
endpoint2_tty.c
endpoint_tty.c
msg_node.c
msg_ping.c
msg_pong.c

View File

@@ -11,14 +11,14 @@
#endif
#include "aqhome/msg/endpoint2_tty_p.h"
#include "aqhome/msg/endpoint_tty_p.h"
#include "aqhome/msg/msg_node.h"
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#include <gwenhywfar/endpoint2_msgio.h>
#include <gwenhywfar/endpoint_msgio.h>
#include <fcntl.h>
#include <termios.h>
@@ -28,13 +28,13 @@
#define AQH_MSG_ENDPOINT2_TTY_BAUDRATE B19200
#define AQH_MSG_ENDPOINT2_TTY_BYTE_MICROSECS 520
#define GWEN_ENDPOINT2_TTY_RECONNECT_TIME 10
#define AQH_MSG_ENDPOINT_TTY_BAUDRATE B19200
#define AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS 520
#define GWEN_ENDPOINT_TTY_RECONNECT_TIME 10
GWEN_INHERIT(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY)
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY)
@@ -46,20 +46,20 @@ GWEN_INHERIT(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY)
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
/* virtual fn for GWEN_MSG_ENDPOINT2 */
static void _addSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
/* virtual fn for GWEN_MSG_ENDPOINT */
static void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
/* virtual fns for GWEN_MSG_ENDPOINT2_MSGIO */
static int _getBytesNeededForMessage(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg);
static int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg);
static void _endMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg);
/* virtual fns for GWEN_MSG_ENDPOINT_MSGIO */
static int _getBytesNeededForMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
static int _startMsg(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
static void _endMsg(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
/* private fns */
static int _getSocketFd(GWEN_MSG_ENDPOINT2 *ep);
static int _openDevice(GWEN_MSG_ENDPOINT2 *ep);
static int _attnLow(GWEN_MSG_ENDPOINT2 *ep);
static int _attnHigh(GWEN_MSG_ENDPOINT2 *ep);
static int _isAttnLow(GWEN_MSG_ENDPOINT2 *ep);
static int _getSocketFd(GWEN_MSG_ENDPOINT *ep);
static int _openDevice(GWEN_MSG_ENDPOINT *ep);
static int _attnLow(GWEN_MSG_ENDPOINT *ep);
static int _attnHigh(GWEN_MSG_ENDPOINT *ep);
static int _isAttnLow(GWEN_MSG_ENDPOINT *ep);
@@ -69,26 +69,26 @@ static int _isAttnLow(GWEN_MSG_ENDPOINT2 *ep);
*/
GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint2_new(const char *devicePath, int groupId)
GWEN_MSG_ENDPOINT *AQH_TtyEndpoint_new(const char *devicePath, int groupId)
{
GWEN_MSG_ENDPOINT2 *ep;
AQH_MSG_ENDPOINT2_TTY *xep;
GWEN_MSG_ENDPOINT *ep;
AQH_MSG_ENDPOINT_TTY *xep;
ep=GWEN_MsgEndpoint2_new(AQH_MSG_ENDPOINT2_TTY_NAME, groupId);
GWEN_MsgEndpoint2_SetDefaultMessageSize(ep, AQH_MAXMSGSIZE);
ep=GWEN_MsgEndpoint_new(AQH_MSG_ENDPOINT_TTY_NAME, groupId);
GWEN_MsgEndpoint_SetDefaultMessageSize(ep, AQH_MAXMSGSIZE);
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT2_TTY, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep, xep, _freeData);
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_TTY, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep, xep, _freeData);
xep->deviceName=strdup(devicePath);
GWEN_MsgEndpoint2_SetAddSocketsFn(ep, _addSockets);
GWEN_MsgEndpoint_SetAddSocketsFn(ep, _addSockets);
/* extend with msg handling code */
GWEN_MsgIoEndpoint2_Extend(ep);
GWEN_MsgIoEndpoint2_SetGetNeededBytesFn(ep, _getBytesNeededForMessage);
GWEN_MsgIoEndpoint2_SetSendMsgStartFn(ep, _startMsg);
GWEN_MsgIoEndpoint2_SetSendMsgFinishFn(ep, _endMsg);
GWEN_MsgIoEndpoint_Extend(ep);
GWEN_MsgIoEndpoint_SetGetNeededBytesFn(ep, _getBytesNeededForMessage);
GWEN_MsgIoEndpoint_SetSendMsgStartFn(ep, _startMsg);
GWEN_MsgIoEndpoint_SetSendMsgFinishFn(ep, _endMsg);
return ep;
}
@@ -97,48 +97,48 @@ GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint2_new(const char *devicePath, int groupId)
void _freeData(void *bp, void *p)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
xep=(AQH_MSG_ENDPOINT2_TTY*) p;
xep=(AQH_MSG_ENDPOINT_TTY*) p;
free(xep->deviceName);
GWEN_FREE_OBJECT(xep);
}
void _addSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet)
void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet)
{
if (ep) {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
time_t now;
now=time(NULL);
if ((now-GWEN_MsgEndpoint2_GetTimeOfLastStateChange(ep))>=GWEN_ENDPOINT2_TTY_RECONNECT_TIME) {
if ((now-GWEN_MsgEndpoint_GetTimeOfLastStateChange(ep))>=GWEN_ENDPOINT_TTY_RECONNECT_TIME) {
int rv;
/* (re)connect, set state */
DBG_INFO(AQH_LOGDOMAIN, "Starting to (re-)connect");
rv=GWEN_TtyEndpoint2_Connect(ep);
rv=AQH_TtyEndpoint_Connect(ep);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
}
}
}
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
GWEN_SocketSet_AddSocket(readSet, GWEN_MsgEndpoint2_GetSocket(ep));
if (GWEN_MsgEndpoint2_HaveMessageToSend(ep))
GWEN_SocketSet_AddSocket(writeSet, GWEN_MsgEndpoint2_GetSocket(ep));
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
GWEN_SocketSet_AddSocket(readSet, GWEN_MsgEndpoint_GetSocket(ep));
if (GWEN_MsgEndpoint_HaveMessageToSend(ep))
GWEN_SocketSet_AddSocket(writeSet, GWEN_MsgEndpoint_GetSocket(ep));
}
} /* if (ep) */
}
int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep)
int AQH_TtyEndpoint_Connect(GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
int fd;
DBG_INFO(AQH_LOGDOMAIN, "Connecting TTY device");
@@ -151,15 +151,15 @@ int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep)
GWEN_SOCKET *sk;
sk=GWEN_Socket_fromFile(fd);
GWEN_MsgEndpoint2_SetSocket(ep, sk);
GWEN_MsgEndpoint2_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
GWEN_MsgEndpoint2_DiscardInput(ep);
GWEN_MsgEndpoint_SetSocket(ep, sk);
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
GWEN_MsgEndpoint_DiscardInput(ep);
_attnHigh(ep);
return 0;
}
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Endpoint %s: Not unconnected", GWEN_MsgEndpoint2_GetName(ep));
DBG_ERROR(AQH_LOGDOMAIN, "Endpoint %s: Not unconnected", GWEN_MsgEndpoint_GetName(ep));
return GWEN_ERROR_INVALID;
}
}
@@ -168,12 +168,12 @@ int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep)
int _getSocketFd(GWEN_MSG_ENDPOINT2 *ep)
int _getSocketFd(GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
GWEN_SOCKET *sk;
sk=GWEN_MsgEndpoint2_GetSocket(ep);
sk=GWEN_MsgEndpoint_GetSocket(ep);
if (sk) {
return GWEN_Socket_GetSocketInt(sk);
}
@@ -183,14 +183,14 @@ int _getSocketFd(GWEN_MSG_ENDPOINT2 *ep)
int _openDevice(GWEN_MSG_ENDPOINT2 *ep)
int _openDevice(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
int fd;
struct termios options;
int rv;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
DBG_INFO(AQH_LOGDOMAIN, "Opening device %s", xep->deviceName);
fd=open(xep->deviceName, O_NOCTTY | O_NDELAY | O_RDWR);
@@ -214,12 +214,12 @@ int _openDevice(GWEN_MSG_ENDPOINT2 *ep)
options.c_cc[VTIME]=0; /* read timeout in deciseconds */
options.c_cc[VMIN]=0; /* no minimum number of receive bytes */
rv=cfsetispeed(&options, AQH_MSG_ENDPOINT2_TTY_BAUDRATE);
rv=cfsetispeed(&options, AQH_MSG_ENDPOINT_TTY_BAUDRATE);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on cfsetispeed(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
rv=cfsetospeed(&options, AQH_MSG_ENDPOINT2_TTY_BAUDRATE);
rv=cfsetospeed(&options, AQH_MSG_ENDPOINT_TTY_BAUDRATE);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on cfsetospeed(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
@@ -242,12 +242,12 @@ int _openDevice(GWEN_MSG_ENDPOINT2 *ep)
int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
int _startMsg(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG *msg)
{
if (ep) {
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
if (xep->intendedAttnState==1) {
int rv;
@@ -259,7 +259,7 @@ int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
}
if (rv>0) {
DBG_INFO(AQH_LOGDOMAIN, "Line busy");
usleep(AQH_MSG_ENDPOINT2_TTY_BYTE_MICROSECS);
usleep(AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS);
return GWEN_ERROR_TIMEOUT;
}
@@ -268,7 +268,7 @@ int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
usleep(AQH_MSG_ENDPOINT2_TTY_BYTE_MICROSECS/5);
usleep(AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS/5);
}
}
return 0;
@@ -276,7 +276,7 @@ int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
void _endMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
void _endMsg(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG *msg)
{
/* TODO: flush before releasing ATTN */
_attnHigh(ep);
@@ -284,7 +284,7 @@ void _endMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg)
int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg)
{
uint32_t bytesInMsg;
@@ -309,14 +309,14 @@ int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg)
int _attnLow(GWEN_MSG_ENDPOINT2 *ep)
int _attnLow(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=_getSocketFd(ep);
if (fd<0) {
@@ -340,14 +340,14 @@ int _attnLow(GWEN_MSG_ENDPOINT2 *ep)
int _attnHigh(GWEN_MSG_ENDPOINT2 *ep)
int _attnHigh(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=_getSocketFd(ep);
if (fd<0) {
@@ -373,14 +373,14 @@ int _attnHigh(GWEN_MSG_ENDPOINT2 *ep)
int _isAttnLow(GWEN_MSG_ENDPOINT2 *ep)
int _isAttnLow(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=_getSocketFd(ep);
if (fd<0) {

View File

@@ -6,21 +6,21 @@
* should have received along with this file.
****************************************************************************/
#ifndef AQH_MSGENDPOINT2_TTY_H
#define AQH_MSGENDPOINT2_TTY_H
#ifndef AQH_MSGENDPOINT_TTY_H
#define AQH_MSGENDPOINT_TTY_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint2.h>
#include <gwenhywfar/endpoint.h>
#define AQH_MSG_ENDPOINT2_TTY_NAME "tty"
#define AQH_MSG_ENDPOINT_TTY_NAME "tty"
AQHOME_API GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint2_new(const char *devicePath, int groupId);
AQHOME_API GWEN_MSG_ENDPOINT *AQH_TtyEndpoint_new(const char *devicePath, int groupId);
AQHOME_API int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API int AQH_TtyEndpoint_Connect(GWEN_MSG_ENDPOINT *ep);
#endif

View File

@@ -6,22 +6,22 @@
* should have received along with this file.
****************************************************************************/
#ifndef AQH_MSGENDPOINT2_TTY_P_H
#define AQH_MSGENDPOINT2_TTY_P_H
#ifndef AQH_MSGENDPOINT_TTY_P_H
#define AQH_MSGENDPOINT_TTY_P_H
#include <aqhome/api.h>
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/msg/endpoint_tty.h"
#include <termios.h>
typedef struct AQH_MSG_ENDPOINT2_TTY AQH_MSG_ENDPOINT2_TTY;
struct AQH_MSG_ENDPOINT2_TTY {
typedef struct AQH_MSG_ENDPOINT_TTY AQH_MSG_ENDPOINT_TTY;
struct AQH_MSG_ENDPOINT_TTY {
char *deviceName;
struct termios previousOptions;
int intendedAttnState;