aqhome: use new type GWEN_ConnectableMsgEndpoint.
This allows for reconnect of endpoints if necessary.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "aqhome/msg/endpoint_node.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
|
||||
#include <gwenhywfar/endpoint_connectable.h>
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
@@ -40,13 +41,12 @@ GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY)
|
||||
|
||||
|
||||
|
||||
static int _getReadFd(GWEN_MSG_ENDPOINT *ep);
|
||||
static int _getWriteFd(GWEN_MSG_ENDPOINT *ep);
|
||||
static int _handleReadable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *emgr);
|
||||
static int _handleWritable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *emgr);
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
|
||||
static int _connect(GWEN_MSG_ENDPOINT *ep);
|
||||
static int _startMsg(GWEN_MSG_ENDPOINT *ep);
|
||||
static int _endMsg(GWEN_MSG_ENDPOINT *ep);
|
||||
static int _isLineBusy(GWEN_MSG_ENDPOINT *ep);
|
||||
@@ -64,19 +64,23 @@ GWEN_MSG_ENDPOINT *AQH_TtyNodeEndpoint_new(const char *devicePath, int groupId)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
AQH_MSG_ENDPOINT_TTY *xep;
|
||||
int fd;
|
||||
// int fd;
|
||||
|
||||
ep=AQH_NodeEndpoint_new(AQH_MSG_ENDPOINT_TTY_NAME, groupId);
|
||||
|
||||
GWEN_ConnectableMsgEndpoint_Extend(ep);
|
||||
GWEN_ConnectableMsgEndpoint_SetReconnectWaitTime(ep, 5);
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_TTY, xep);
|
||||
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep, xep, _freeData);
|
||||
|
||||
GWEN_MsgEndpoint_SetHandleReadableFn(ep, _handleReadable);
|
||||
GWEN_MsgEndpoint_SetHandleWritableFn(ep, _handleWritable);
|
||||
GWEN_MsgEndpoint_SetGetReadFdFn(ep, _getReadFd);
|
||||
GWEN_MsgEndpoint_SetGetWriteFdFn(ep, _getWriteFd);
|
||||
GWEN_ConnectableMsgEndpoint_SetConnectFn(ep, _connect);
|
||||
|
||||
xep->deviceName=strdup(devicePath);
|
||||
|
||||
#if 0
|
||||
fd=_openDevice(ep);
|
||||
if (fd<0) {
|
||||
DBG_INFO(NULL, "here (%d)", fd);
|
||||
@@ -85,6 +89,7 @@ GWEN_MSG_ENDPOINT *AQH_TtyNodeEndpoint_new(const char *devicePath, int groupId)
|
||||
}
|
||||
GWEN_MsgEndpoint_SetFd(ep, fd);
|
||||
_attnHigh(ep);
|
||||
#endif
|
||||
|
||||
return ep;
|
||||
}
|
||||
@@ -101,16 +106,31 @@ void _freeData(void *bp, void *p)
|
||||
|
||||
|
||||
|
||||
int _getReadFd(GWEN_MSG_ENDPOINT *ep)
|
||||
int _connect(GWEN_MSG_ENDPOINT *ep)
|
||||
{
|
||||
return GWEN_MsgEndpoint_GetFd(ep);
|
||||
}
|
||||
AQH_MSG_ENDPOINT_TTY *xep;
|
||||
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
|
||||
if (xep) {
|
||||
int state;
|
||||
|
||||
state=GWEN_ConnectableMsgEndpoint_GetState(ep);
|
||||
if (state<GWEN_MSG_ENDPOINT_CONN_STATE_CONNECTED) {
|
||||
int fd;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Opening device %s", xep->deviceName);
|
||||
fd=_openDevice(ep);
|
||||
if (fd<0) {
|
||||
DBG_INFO(NULL, "here (%d)", fd);
|
||||
return fd;
|
||||
}
|
||||
GWEN_MsgEndpoint_SetFd(ep, fd);
|
||||
_attnHigh(ep);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _getWriteFd(GWEN_MSG_ENDPOINT *ep)
|
||||
{
|
||||
return GWEN_MsgEndpoint_HaveMessageToSend(ep)?GWEN_MsgEndpoint_GetFd(ep):GWEN_ERROR_NO_DATA;
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user