aqhome-react: finish new network reading code, improved debugging helper code.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
@@ -91,12 +92,19 @@ int AQHomeReact_ReadUnitNetFiles(AQHOME_REACT *aqh)
|
||||
|
||||
AQHREACT_UNIT *AQHomeReact_FindAndReadDataDirNetwork(AQHOME_REACT *aqh, const char *networkName)
|
||||
{
|
||||
if (aqh && networkName) {
|
||||
AQHREACT_UNIT *unit;
|
||||
GWEN_BUFFER *bufFilename;
|
||||
GWEN_BUFFER *bufPath;
|
||||
const char *s;
|
||||
|
||||
bufFilename=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GWEN_Buffer_AppendArgs(bufFilename, "aqhome/react/networks/%s.xml", networkName);
|
||||
GWEN_Buffer_AppendString(bufFilename, "aqhome/react/networks/");
|
||||
s=networkName;
|
||||
while(*s)
|
||||
GWEN_Buffer_AppendByte(bufFilename, tolower((unsigned char) *(s++)));
|
||||
GWEN_Buffer_AppendString(bufFilename, ".xml");
|
||||
|
||||
bufPath=AQH_FindPathOfDataFile(GWEN_Buffer_GetStart(bufFilename));
|
||||
if (bufPath==NULL) {
|
||||
DBG_ERROR(NULL, "Network file \"%s\" not found in data folders", GWEN_Buffer_GetStart(bufFilename));
|
||||
@@ -114,6 +122,8 @@ AQHREACT_UNIT *AQHomeReact_FindAndReadDataDirNetwork(AQHOME_REACT *aqh, const ch
|
||||
|
||||
GWEN_Buffer_free(bufPath);
|
||||
return unit;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ AQHREACT_LINK *AQHREACT_Link_new()
|
||||
|
||||
GWEN_NEW_OBJECT(AQHREACT_LINK, lnk);
|
||||
GWEN_LIST_INIT(AQHREACT_LINK, lnk);
|
||||
lnk->targetInputSlotIdForUnit=-1;
|
||||
|
||||
return lnk;
|
||||
}
|
||||
@@ -36,45 +35,12 @@ void AQHREACT_Link_free(AQHREACT_LINK *lnk)
|
||||
{
|
||||
if (lnk) {
|
||||
GWEN_LIST_FINI(AQHREACT_LINK, lnk);
|
||||
free(lnk->targetUnitId);
|
||||
GWEN_FREE_OBJECT(lnk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *AQHREACT_Link_GetTargetUnitId(const AQHREACT_LINK *lnk)
|
||||
{
|
||||
return lnk?lnk->targetUnitId:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQHREACT_Link_SetTargetUnitId(AQHREACT_LINK *lnk, const char *s)
|
||||
{
|
||||
if (lnk) {
|
||||
free(lnk->targetUnitId);
|
||||
lnk->targetUnitId=s?strdup(s):NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQHREACT_Link_GetTargetInputSlotIdForUnit(const AQHREACT_LINK *lnk)
|
||||
{
|
||||
return lnk?lnk->targetInputSlotIdForUnit:-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQHREACT_Link_SetTargetInputSlotIdForUnit(AQHREACT_LINK *lnk, int i)
|
||||
{
|
||||
if (lnk)
|
||||
lnk->targetInputSlotIdForUnit=i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQHREACT_UNIT *AQHREACT_Link_GetTargetUnit(const AQHREACT_LINK *lnk)
|
||||
{
|
||||
return lnk?lnk->targetUnit:NULL;
|
||||
@@ -108,12 +74,19 @@ void AQHREACT_Link_SetTargetPort(AQHREACT_LINK *lnk, AQHREACT_PORT *port)
|
||||
void AQHREACT_Link_Dump(const AQHREACT_LINK *lnk, GWEN_BUFFER *buf, int indent)
|
||||
{
|
||||
if (lnk && buf) {
|
||||
const char *unitName;
|
||||
const char *unitId;
|
||||
const char *portName;
|
||||
|
||||
unitName=(lnk->targetUnit)?AQHREACT_Unit_GetName(lnk->targetUnit):NULL;
|
||||
unitId=(lnk->targetUnit)?AQHREACT_Unit_GetId(lnk->targetUnit):NULL;
|
||||
portName=(lnk->targetPort)?AQHREACT_Port_GetName(lnk->targetPort):NULL;
|
||||
if (indent)
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
|
||||
GWEN_Buffer_AppendArgs(buf, "target unit id: %s (%s), target slot id: %d\n",
|
||||
(lnk->targetUnitId)?(lnk->targetUnitId):"<empty>",
|
||||
(lnk->targetUnit)?"set":"not set",
|
||||
lnk->targetInputSlotIdForUnit);
|
||||
GWEN_Buffer_AppendArgs(buf, "- target unit id: %s (%s), target slot name: %s\n",
|
||||
unitId?unitId:"<no id>",
|
||||
unitName?unitName:"<no name>",
|
||||
portName?portName:"<no port>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,6 @@ AQHREACT_LINK *AQHREACT_Link_new();
|
||||
void AQHREACT_Link_free(AQHREACT_LINK *lnk);
|
||||
|
||||
|
||||
const char *AQHREACT_Link_GetTargetUnitId(const AQHREACT_LINK *lnk);
|
||||
void AQHREACT_Link_SetTargetUnitId(AQHREACT_LINK *lnk, const char *s);
|
||||
|
||||
int AQHREACT_Link_GetTargetInputSlotIdForUnit(const AQHREACT_LINK *lnk);
|
||||
void AQHREACT_Link_SetTargetInputSlotIdForUnit(AQHREACT_LINK *lnk, int i);
|
||||
|
||||
AQHREACT_UNIT *AQHREACT_Link_GetTargetUnit(const AQHREACT_LINK *lnk);
|
||||
void AQHREACT_Link_SetTargetUnit(AQHREACT_LINK *lnk, AQHREACT_UNIT *unit);
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
struct AQHREACT_LINK {
|
||||
GWEN_LIST_ELEMENT(AQHREACT_LINK)
|
||||
|
||||
char *targetUnitId;
|
||||
int targetInputSlotIdForUnit;
|
||||
|
||||
AQHREACT_UNIT *targetUnit;
|
||||
AQHREACT_PORT *targetPort;
|
||||
};
|
||||
|
||||
@@ -259,10 +259,10 @@ void AQHREACT_Param_Dump(const AQHREACT_PARAM *param, GWEN_BUFFER *buf, int inde
|
||||
|
||||
switch(param->dataType) {
|
||||
case AQHREACT_DATAOBJECTTYPE_DOUBLE:
|
||||
GWEN_Buffer_AppendArgs(buf, "%s = %f [DOUBLE]\n", (param->name)?(param->name):"<unnamed>", param->doubleValue);
|
||||
GWEN_Buffer_AppendArgs(buf, "- %s = %f [DOUBLE]\n", (param->name)?(param->name):"<unnamed>", param->doubleValue);
|
||||
break;
|
||||
case AQHREACT_DATAOBJECTTYPE_STRING:
|
||||
GWEN_Buffer_AppendArgs(buf, "%s = %s [STRING]\n", (param->name)?(param->name):"<unnamed>", param->stringValue);
|
||||
GWEN_Buffer_AppendArgs(buf, "- %s = %s [STRING]\n", (param->name)?(param->name):"<unnamed>", param->stringValue);
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR(NULL, "Unhandled data type %d", param->dataType);
|
||||
|
||||
@@ -263,21 +263,12 @@ void AQHREACT_Port_Dump(const AQHREACT_PORT *port, GWEN_BUFFER *buf, int indent)
|
||||
if (port && buf) {
|
||||
if (indent)
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
|
||||
GWEN_Buffer_AppendArgs(buf, "name........: %s\n", (port->name)?(port->name):"<empty>");
|
||||
|
||||
if (indent)
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
|
||||
GWEN_Buffer_AppendArgs(buf, "description.: %s\n", (port->description)?(port->description):"<empty>");
|
||||
|
||||
if (indent)
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
|
||||
GWEN_Buffer_AppendArgs(buf, "data type...: %s\n", AQHREACT_DataObjectType_toString(port->dataType));
|
||||
|
||||
if (indent)
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
|
||||
GWEN_Buffer_AppendArgs(buf, "flags.......: %08x\n", port->flags);
|
||||
|
||||
AQHREACT_Link_List_Dump(port->linkList, buf, indent, "Link List:");
|
||||
GWEN_Buffer_AppendArgs(buf, "- \"%s\" (%s, %08x)\n",
|
||||
(port->name)?(port->name):"<no name>",
|
||||
AQHREACT_DataObjectType_toString(port->dataType),
|
||||
port->flags);
|
||||
if (port->linkList && AQHREACT_Link_List_GetCount(port->linkList))
|
||||
AQHREACT_Link_List_Dump(port->linkList, buf, indent+2, "Link List:");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,9 +285,7 @@ void AQHREACT_Port_List_Dump(const AQHREACT_PORT_LIST *portList, GWEN_BUFFER *bu
|
||||
|
||||
port=AQHREACT_Port_List_First(portList);
|
||||
while(port) {
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent+2);
|
||||
GWEN_Buffer_AppendString(buf, "Port:\n");
|
||||
AQHREACT_Port_Dump(port, buf, indent+4);
|
||||
AQHREACT_Port_Dump(port, buf, indent+2);
|
||||
port=AQHREACT_Port_List_Next(port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,6 +442,20 @@ AQHREACT_UNIT_PROCESS_FN AQHREACT_Unit_SetProcessFn(AQHREACT_UNIT *unit, AQHREAC
|
||||
|
||||
|
||||
|
||||
AQHREACT_UNIT_DUMP_FN AQHREACT_Unit_SetDumpFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_DUMP_FN f)
|
||||
{
|
||||
if (unit) {
|
||||
AQHREACT_UNIT_DUMP_FN oldFn;
|
||||
|
||||
oldFn=unit->dumpFn;
|
||||
unit->dumpFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQHREACT_Unit_OutputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
if (unit && port) {
|
||||
@@ -589,7 +603,7 @@ void AQHREACT_Unit_Dump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent)
|
||||
|
||||
if (indent)
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
|
||||
GWEN_Buffer_AppendArgs(buf, "name.......: %s\n", (unit->name)?(unit->name):"<empty>");
|
||||
GWEN_Buffer_AppendArgs(buf, "type.......: %s\n", (unit->name)?(unit->name):"<empty>");
|
||||
|
||||
if (indent)
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
|
||||
@@ -599,9 +613,15 @@ void AQHREACT_Unit_Dump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent)
|
||||
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
|
||||
GWEN_Buffer_AppendArgs(buf, "flags......: %08x\n", unit->flags);
|
||||
|
||||
if (unit->paramList && AQHREACT_Param_List_GetCount(unit->paramList))
|
||||
AQHREACT_Param_List_Dump(unit->paramList, buf, indent, "Unit Parameter List:");
|
||||
if (unit->inputPortList && AQHREACT_Port_List_GetCount(unit->inputPortList))
|
||||
AQHREACT_Port_List_Dump(unit->inputPortList, buf, indent, "Input Port List:");
|
||||
if (unit->outputPortList && AQHREACT_Port_List_GetCount(unit->outputPortList))
|
||||
AQHREACT_Port_List_Dump(unit->outputPortList, buf, indent, "Output Port List:");
|
||||
|
||||
if (unit->dumpFn)
|
||||
unit->dumpFn(unit, buf, indent+2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ typedef void (*AQHREACT_UNIT_INPUTDATA_FN)(AQHREACT_UNIT *unit, AQHREACT_PORT *p
|
||||
typedef void (*AQHREACT_UNIT_OUTPUTDATA_FN)(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
typedef AQHREACT_PARAM* (*AQHREACT_UNIT_GETPARAMBYNAME_FN)(const AQHREACT_UNIT *unit, const char *paramName);
|
||||
typedef int (*AQHREACT_UNIT_PROCESS_FN)(AQHREACT_UNIT *unit);
|
||||
typedef void (*AQHREACT_UNIT_DUMP_FN)(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent);
|
||||
|
||||
|
||||
|
||||
@@ -107,6 +108,7 @@ AQHREACT_UNIT_INPUTDATA_FN AQHREACT_Unit_SetInputDataFn(AQHREACT_UNIT *unit, AQH
|
||||
AQHREACT_UNIT_OUTPUTDATA_FN AQHREACT_Unit_SetOutputDataFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_OUTPUTDATA_FN f);
|
||||
AQHREACT_UNIT_GETPARAMBYNAME_FN AQHREACT_Unit_SetGetParamByNameFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_GETPARAMBYNAME_FN f);
|
||||
AQHREACT_UNIT_PROCESS_FN AQHREACT_Unit_SetProcessFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_PROCESS_FN f);
|
||||
AQHREACT_UNIT_DUMP_FN AQHREACT_Unit_SetDumpFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_DUMP_FN f);
|
||||
|
||||
|
||||
AQHREACT_UNIT *AQHREACT_Unit_List_GetById(const AQHREACT_UNIT_LIST *unitList, const char *id);
|
||||
|
||||
@@ -36,6 +36,7 @@ struct AQHREACT_UNIT {
|
||||
AQHREACT_UNIT_OUTPUTDATA_FN outputDataFn;
|
||||
AQHREACT_UNIT_GETPARAMBYNAME_FN getParamByNameFn;
|
||||
AQHREACT_UNIT_PROCESS_FN processFn;
|
||||
AQHREACT_UNIT_DUMP_FN dumpFn;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static AQHREACT_PARAM *_cbGetParamByName(const AQHREACT_UNIT *unit, const char *paramName);
|
||||
static int _cbProcess(AQHREACT_UNIT *unit);
|
||||
static void _cbDump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent);
|
||||
|
||||
static void _readProxyFromXml(GWEN_XMLNODE *xmlNode,
|
||||
MODULE_PROXY_DESCR_LIST *proxyDescrList,
|
||||
@@ -155,6 +156,7 @@ AQHREACT_UNIT *AqHomeReact_UnitModule_new(AQHOME_REACT *aqh)
|
||||
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||
AQHREACT_Unit_SetGetParamByNameFn(unit, _cbGetParamByName);
|
||||
AQHREACT_Unit_SetProcessFn(unit, _cbProcess);
|
||||
AQHREACT_Unit_SetDumpFn(unit, _cbDump);
|
||||
|
||||
return unit;
|
||||
}
|
||||
@@ -243,13 +245,18 @@ AQHREACT_PARAM *_cbGetParamByName(const AQHREACT_UNIT *unit, const char *paramNa
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
|
||||
DBG_INFO(NULL, "Looking for param \"%s\" in proxy descr of module \"%s\"", paramName, AQHREACT_Unit_GetName(unit));
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
if (xunit) {
|
||||
const MODULE_PROXY_DESCR *pd;
|
||||
|
||||
pd=ModuleProxyDescr_List_FindByName(xunit->paramProxyList, paramName);
|
||||
if (pd)
|
||||
AQHREACT_Unit_GetParamByName(pd->targetObjectPtr, pd->targetName);
|
||||
if (pd) {
|
||||
DBG_INFO(NULL, "Found proxydescr for param (-> %s:%s)",
|
||||
(pd->targetObjectPtr)?AQHREACT_Unit_GetName(pd->targetObjectPtr):"<no unit>",
|
||||
(pd->targetName)?(pd->targetName):"<no param>");
|
||||
return AQHREACT_Unit_GetParamByName(pd->targetObjectPtr, pd->targetName);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -282,6 +289,17 @@ int _cbProcess(AQHREACT_UNIT *unit)
|
||||
|
||||
|
||||
|
||||
void _cbDump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
if (xunit)
|
||||
AQHREACT_Unit_List_Dump(xunit->unitList, buf, indent, "Sub Units:");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _readProxyFromXml(GWEN_XMLNODE *xmlNode,
|
||||
MODULE_PROXY_DESCR_LIST *proxyDescrList,
|
||||
const char *mainGroupName,
|
||||
@@ -543,7 +561,7 @@ int _readParamFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *paramNode)
|
||||
} /* if value */
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "No param name \"%s\" in unit", paramName);
|
||||
DBG_ERROR(NULL, "No param name \"%s\" in unit \"%s\"", paramName, AQHREACT_Unit_GetName(unit));
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
#define DEBUG_DRY_RUN 1 /* don't actually set value if "1" */
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defines
|
||||
@@ -98,8 +100,13 @@ void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAO
|
||||
break;
|
||||
}
|
||||
if (msgOut) {
|
||||
#if DEBUG_DRY_RUN
|
||||
DBG_ERROR(NULL, "Would send data for value \"%s\"", sValueName);
|
||||
GWEN_Msg_free(msgOut);
|
||||
#else
|
||||
DBG_INFO(NULL, "Sending data for value \"%s\"", sValueName);
|
||||
GWEN_MsgEndpoint_AddSendMessage(brokerEndpoint, msgOut);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user