222 lines
4.3 KiB
C
222 lines
4.3 KiB
C
/****************************************************************************
|
|
* 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 "./aqhomed_p.h"
|
|
#include "./tty_log.h"
|
|
|
|
#include "aqhome/msg/endpoint_tty.h"
|
|
#include "aqhome/ipc/endpoint_ipc.h"
|
|
|
|
#include <gwenhywfar/gwenhywfar.h>
|
|
#include <gwenhywfar/debug.h>
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* defines
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#define I18N(msg) msg
|
|
#define I18S(msg) msg
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* forward declarations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* implementations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
AQHOMED *AqHomed_new(void)
|
|
{
|
|
AQHOMED *aqh;
|
|
|
|
GWEN_NEW_OBJECT(AQHOMED, aqh);
|
|
aqh->rootEndpoint=GWEN_MsgEndpoint_new("root", 0);
|
|
aqh->nodeDb=AQH_NodeDb_new();
|
|
aqh->requestTree=GWEN_MsgRequest_new();
|
|
|
|
return aqh;
|
|
}
|
|
|
|
|
|
|
|
void AqHomed_free(AQHOMED *aqh)
|
|
{
|
|
if (aqh) {
|
|
GWEN_MsgRequest_free(aqh->requestTree);
|
|
GWEN_MsgEndpoint_free(aqh->rootEndpoint);
|
|
aqh->rootEndpoint=NULL;
|
|
aqh->ttyEndpoint=NULL;
|
|
aqh->ipcdEndpoint=NULL;
|
|
aqh->brokerEndpoint=NULL;
|
|
GWEN_DB_Group_free(aqh->dbArgs);
|
|
AQH_NodeDb_free(aqh->nodeDb);
|
|
aqh->dbArgs=NULL;
|
|
free(aqh->logFile);
|
|
free(aqh->pidFile);
|
|
free(aqh->dbFile);
|
|
|
|
GWEN_FREE_OBJECT(aqh);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG_ENDPOINT *AqHomed_GetTtyEndpoint(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->ttyEndpoint:NULL;
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG_ENDPOINT *AqHomed_GetIpcdEndpoint(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->ipcdEndpoint:NULL;
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG_ENDPOINT *AqHomed_GetBrokerEndpoint(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->brokerEndpoint:NULL;
|
|
}
|
|
|
|
|
|
|
|
GWEN_DB_NODE *AqHomed_GetDbArgs(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->dbArgs:NULL;
|
|
}
|
|
|
|
|
|
|
|
const char *AqHomed_GetLogFile(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->logFile:NULL;
|
|
}
|
|
|
|
|
|
|
|
void AqHomed_SetLogFile(AQHOMED *aqh, const char *s)
|
|
{
|
|
if (aqh) {
|
|
free(aqh->logFile);
|
|
aqh->logFile=s?strdup(s):NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const char *AqHomed_GetPidFile(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->pidFile:NULL;
|
|
}
|
|
|
|
|
|
|
|
void AqHomed_SetPidFile(AQHOMED *aqh, const char *s)
|
|
{
|
|
if (aqh) {
|
|
free(aqh->pidFile);
|
|
aqh->pidFile=s?strdup(s):NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const char *AqHomed_GetDbFile(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->dbFile:NULL;
|
|
}
|
|
|
|
|
|
|
|
void AqHomed_SetDbFile(AQHOMED *aqh, const char *s)
|
|
{
|
|
if (aqh) {
|
|
free(aqh->dbFile);
|
|
aqh->dbFile=s?strdup(s):NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int AqHomed_GetTimeout(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->timeout:0;
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG_REQUEST *AqHomed_GetRequestTree(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->requestTree:NULL;
|
|
}
|
|
|
|
|
|
|
|
void AqHomed_AddRequestToTree(AQHOMED *aqh, GWEN_MSG_REQUEST *rq)
|
|
{
|
|
if (aqh && rq)
|
|
GWEN_MsgRequest_Tree2_AddChild(aqh->requestTree, rq);
|
|
}
|
|
|
|
|
|
|
|
const AQHNODE_DEVICE_LIST *AqHomed_GetDeviceDefList(const AQHOMED *aqh)
|
|
{
|
|
return aqh?aqh->deviceDefList:NULL;
|
|
}
|
|
|
|
|
|
|
|
const AQHNODE_DEVICE *AqHomed_FindDeviceDef(const AQHOMED *aqh, uint32_t manufacturer, uint16_t deviceType, uint16_t deviceVersion)
|
|
{
|
|
if (aqh && aqh->deviceDefList) {
|
|
const AQHNODE_DEVICE *device;
|
|
|
|
device=AQHNODE_Device_List_First(aqh->deviceDefList);
|
|
while(device) {
|
|
if (AQHNODE_Device_GetManufacturer(device)==manufacturer &&
|
|
AQHNODE_Device_GetDeviceType(device)==deviceType &&
|
|
AQHNODE_Device_GetDeviceVersion(device)==(deviceVersion & 0xff00))
|
|
return device;
|
|
device=AQHNODE_Device_List_Next(device);
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
const AQHNODE_DEVICE *AqHomed_GetDeviceDefByName(const AQHOMED *aqh, const char *name)
|
|
{
|
|
if (aqh && aqh->deviceDefList && name)
|
|
return AQHNODE_Device_List_GetByName(aqh->deviceDefList, name);
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
|
|
|