aqhome-react: major rebuild of unit handling.

now nested networks are allowed to allow for complex networks.
This commit is contained in:
Martin Preuss
2024-04-17 22:26:17 +02:00
parent ec816bddcf
commit 1050ee1c75
34 changed files with 1336 additions and 1616 deletions

View File

@@ -39,29 +39,23 @@
<headers dist="true" >
dataobject.h
dataobject_p.h
inputslot.h
inputslot_p.h
outputslot.h
outputslot_p.h
port.h
port_p.h
link.h
link_p.h
param.h
param_p.h
unit.h
unit_p.h
unitnet.h
unitnet_p.h
</headers>
<sources>
$(local/typefiles)
dataobject.c
inputslot.c
outputslot.c
port.c
link.c
param.c
unit.c
unitnet.c
</sources>
<useTargets>

View File

@@ -199,6 +199,20 @@ const char *AQHREACT_DataObjectType_toString(int t)
int AQHREACT_DataObjectType_fromString(const char *s)
{
if (s && *s) {
if (strcasecmp(s, "double")==0)
return AQHREACT_DATAOBJECTTYPE_DOUBLE;
else if (strcasecmp(s, "string")==0)
return AQHREACT_DATAOBJECTTYPE_STRING;
}
return AQHREACT_DATAOBJECTTYPE_UNKNOWN;
}
void AQHREACT_DataObject_Dump(const AQHREACT_DATAOBJECT *dataObject, GWEN_BUFFER *buf, int indent)
{
if (dataObject && buf) {

View File

@@ -59,6 +59,7 @@ void AQHREACT_DataObject_Dump(const AQHREACT_DATAOBJECT *dataObject, GWEN_BUFFER
const char *AQHREACT_DataObjectType_toString(int t);
int AQHREACT_DataObjectType_fromString(const char *s);
#endif

View File

@@ -90,6 +90,21 @@ void AQHREACT_Link_SetTargetUnit(AQHREACT_LINK *lnk, AQHREACT_UNIT *unit)
AQHREACT_PORT *AQHREACT_Link_GetTargetPort(const AQHREACT_LINK *lnk)
{
return lnk?lnk->targetPort:NULL;
}
void AQHREACT_Link_SetTargetPort(AQHREACT_LINK *lnk, AQHREACT_PORT *port)
{
if (lnk)
lnk->targetPort=port;
}
void AQHREACT_Link_Dump(const AQHREACT_LINK *lnk, GWEN_BUFFER *buf, int indent)
{
if (lnk && buf) {

View File

@@ -18,6 +18,7 @@ GWEN_LIST_FUNCTION_DEFS(AQHREACT_LINK, AQHREACT_Link)
#include "aqhome-react/types/unit.h"
#include "aqhome-react/types/port.h"
AQHREACT_LINK *AQHREACT_Link_new();
@@ -33,6 +34,9 @@ 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);
AQHREACT_PORT *AQHREACT_Link_GetTargetPort(const AQHREACT_LINK *lnk);
void AQHREACT_Link_SetTargetPort(AQHREACT_LINK *lnk, AQHREACT_PORT *port);
void AQHREACT_Link_Dump(const AQHREACT_LINK *lnk, GWEN_BUFFER *buf, int indent);
void AQHREACT_Link_List_Dump(const AQHREACT_LINK_LIST *lnkList, GWEN_BUFFER *buf, int indent, const char *title);

View File

@@ -20,6 +20,7 @@ struct AQHREACT_LINK {
int targetInputSlotIdForUnit;
AQHREACT_UNIT *targetUnit;
AQHREACT_PORT *targetPort;
};

View File

@@ -0,0 +1,313 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "./port_p.h"
#include "aqhome-react/types/dataobject.h"
#include <gwenhywfar/debug.h>
GWEN_LIST_FUNCTIONS(AQHREACT_PORT, AQHREACT_Port)
AQHREACT_PORT *AQHREACT_Port_new()
{
AQHREACT_PORT *port;
GWEN_NEW_OBJECT(AQHREACT_PORT, port);
GWEN_LIST_INIT(AQHREACT_PORT, port);
port->linkList=AQHREACT_Link_List_new();
return port;
}
AQHREACT_PORT *AQHREACT_Port_dup(const AQHREACT_PORT *srcPort)
{
if (srcPort) {
AQHREACT_PORT *newPort;
newPort=AQHREACT_Port_new();
AQHREACT_Port_SetName(newPort, srcPort->name);
newPort->idForUnit=srcPort->idForUnit;
AQHREACT_Port_SetDescription(newPort, srcPort->description);
newPort->flags=srcPort->flags;
newPort->dataType=srcPort->dataType;
/* don't copy current dataObject */
/* don't copy current links */
return newPort;
}
return NULL;
}
void AQHREACT_Port_free(AQHREACT_PORT *port)
{
if (port) {
GWEN_LIST_FINI(AQHREACT_PORT, port);
AQHREACT_DataObject_free(port->currentDataObject);
AQHREACT_Link_List_free(port->linkList);
free(port->name);
free(port->description);
GWEN_FREE_OBJECT(port);
}
}
const char *AQHREACT_Port_GetName(const AQHREACT_PORT *port)
{
return port?port->name:NULL;
}
void AQHREACT_Port_SetName(AQHREACT_PORT *port, const char *s)
{
if (port) {
free(port->name);
port->name=s?strdup(s):NULL;
}
}
int AQHREACT_Port_GetIdForUnit(const AQHREACT_PORT *port)
{
return port?port->idForUnit:0;
}
void AQHREACT_Port_SetIdForUnit(AQHREACT_PORT *port, int i)
{
if (port)
port->idForUnit=i;
}
const char *AQHREACT_Port_GetDescription(const AQHREACT_PORT *port)
{
return port?port->description:NULL;
}
void AQHREACT_Port_SetDescription(AQHREACT_PORT *port, const char *s)
{
if (port) {
free(port->description);
port->description=s?strdup(s):NULL;
}
}
uint32_t AQHREACT_Port_GetFlags(const AQHREACT_PORT *port)
{
return port?port->flags:0;
}
void AQHREACT_Port_SetFlags(AQHREACT_PORT *port, uint32_t f)
{
if (port)
port->flags=f;
}
void AQHREACT_Port_AddFlags(AQHREACT_PORT *port, uint32_t f)
{
if (port)
port->flags|=f;
}
void AQHREACT_Port_SubFlags(AQHREACT_PORT *port, uint32_t f)
{
if (port)
port->flags&=~f;
}
int AQHREACT_Port_GetDataType(const AQHREACT_PORT *port)
{
return port?port->dataType:AQHREACT_DATAOBJECTTYPE_UNKNOWN;
}
void AQHREACT_Port_SetDataType(AQHREACT_PORT *port, int i)
{
if (port)
port->dataType=i;
}
AQHREACT_DATAOBJECT *AQHREACT_Port_GetCurrentDataObject(const AQHREACT_PORT *port)
{
return port?port->currentDataObject:NULL;
}
void AQHREACT_Port_SetCurrentDataObject(AQHREACT_PORT *port, AQHREACT_DATAOBJECT *dataObject)
{
if (port){
AQHREACT_DataObject_free(port->currentDataObject);
port->currentDataObject=dataObject;
}
}
AQHREACT_LINK_LIST *AQHREACT_Port_GetLinkList(const AQHREACT_PORT *port)
{
return port?port->linkList:NULL;
}
void AQHREACT_Port_AddLink(AQHREACT_PORT *port, AQHREACT_LINK *lnk)
{
if (port)
AQHREACT_Link_List_Add(lnk, port->linkList);
}
void AQHREACT_Port_SendData(const AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
{
AQHREACT_LINK_LIST *linkList;
linkList=AQHREACT_Port_GetLinkList(port);
if (linkList) {
AQHREACT_LINK *lnk;
lnk=AQHREACT_Link_List_First(linkList);
while(lnk) {
AQHREACT_UNIT *targetUnit;
AQHREACT_PORT *targetPort;
targetUnit=AQHREACT_Link_GetTargetUnit(lnk);
targetPort=AQHREACT_Link_GetTargetPort(lnk);
if (targetUnit && targetPort) {
DBG_DEBUG(NULL, "%s: Sending data to %s:%s",
AQHREACT_Port_GetName(port), AQHREACT_Unit_GetId(targetUnit), AQHREACT_Port_GetName(targetPort));
AQHREACT_Unit_InputData(targetUnit, targetPort, dataObject);
}
lnk=AQHREACT_Link_List_Next(lnk);
} /* while */
} /* if linkList */
}
AQHREACT_PORT *AQHREACT_Port_List_GetByName(const AQHREACT_PORT_LIST *portList, const char *name)
{
if (portList && name) {
AQHREACT_PORT *port;
port=AQHREACT_Port_List_First(portList);
while(port) {
const char *s;
s=AQHREACT_Port_GetName(port);
if (s && strcasecmp(s, name)==0)
return port;
port=AQHREACT_Port_List_Next(port);
}
}
return NULL;
}
AQHREACT_PORT *AQHREACT_Port_List_GetByIdForUnit(const AQHREACT_PORT_LIST *portList, int id)
{
if (portList) {
AQHREACT_PORT *port;
port=AQHREACT_Port_List_First(portList);
while(port) {
if (id==AQHREACT_Port_GetIdForUnit(port))
return port;
port=AQHREACT_Port_List_Next(port);
}
}
return NULL;
}
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:");
}
}
void AQHREACT_Port_List_Dump(const AQHREACT_PORT_LIST *portList, GWEN_BUFFER *buf, int indent, const char *title)
{
if (portList && buf) {
const AQHREACT_PORT *port;
if (indent)
GWEN_Buffer_FillWithBytes(buf, ' ', indent);
GWEN_Buffer_AppendArgs(buf, "%s\n", (title && *title)?title:"Port List:\n");
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);
port=AQHREACT_Port_List_Next(port);
}
}
}

View File

@@ -0,0 +1,67 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQHOME_REACT_PORT_H
#define AQHOME_REACT_PORT_H
#include <gwenhywfar/list.h>
typedef struct AQHREACT_PORT AQHREACT_PORT;
GWEN_LIST_FUNCTION_DEFS(AQHREACT_PORT, AQHREACT_Port)
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/link.h"
#include "aqhome-react/types/dataobject.h"
AQHREACT_PORT *AQHREACT_Port_new();
AQHREACT_PORT *AQHREACT_Port_dup(const AQHREACT_PORT *srcPort);
void AQHREACT_Port_free(AQHREACT_PORT *port);
const char *AQHREACT_Port_GetName(const AQHREACT_PORT *port);
void AQHREACT_Port_SetName(AQHREACT_PORT *port, const char *s);
int AQHREACT_Port_GetIdForUnit(const AQHREACT_PORT *port);
void AQHREACT_Port_SetIdForUnit(AQHREACT_PORT *port, int i);
const char *AQHREACT_Port_GetDescription(const AQHREACT_PORT *port);
void AQHREACT_Port_SetDescription(AQHREACT_PORT *port, const char *s);
uint32_t AQHREACT_Port_GetFlags(const AQHREACT_PORT *port);
void AQHREACT_Port_SetFlags(AQHREACT_PORT *port, uint32_t f);
void AQHREACT_Port_AddFlags(AQHREACT_PORT *port, uint32_t f);
void AQHREACT_Port_SubFlags(AQHREACT_PORT *port, uint32_t f);
int AQHREACT_Port_GetDataType(const AQHREACT_PORT *port);
void AQHREACT_Port_SetDataType(AQHREACT_PORT *port, int i);
AQHREACT_DATAOBJECT *AQHREACT_Port_GetCurrentDataObject(const AQHREACT_PORT *port);
void AQHREACT_Port_SetCurrentDataObject(AQHREACT_PORT *port, AQHREACT_DATAOBJECT *dataObject);
void AQHREACT_Port_SendData(const AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
AQHREACT_LINK_LIST *AQHREACT_Port_GetLinkList(const AQHREACT_PORT *port);
void AQHREACT_Port_AddLink(AQHREACT_PORT *port, AQHREACT_LINK *lnk);
AQHREACT_PORT *AQHREACT_Port_List_GetByName(const AQHREACT_PORT_LIST *portList, const char *name);
AQHREACT_PORT *AQHREACT_Port_List_GetByIdForUnit(const AQHREACT_PORT_LIST *portList, int id);
void AQHREACT_Port_Dump(const AQHREACT_PORT *port, GWEN_BUFFER *buf, int indent);
void AQHREACT_Port_List_Dump(const AQHREACT_PORT_LIST *portList, GWEN_BUFFER *buf, int indent, const char *title);
#endif

View File

@@ -0,0 +1,31 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQHOME_REACT_PORT_P_H
#define AQHOME_REACT_PORT_P_H
#include "aqhome-react/types/port.h"
struct AQHREACT_PORT {
GWEN_LIST_ELEMENT(AQHREACT_PORT)
char *name;
char *description;
int idForUnit;
uint32_t flags;
int dataType;
AQHREACT_DATAOBJECT *currentDataObject;
AQHREACT_LINK_LIST *linkList;
};
#endif

View File

@@ -30,9 +30,9 @@ AQHREACT_UNIT *AQHREACT_Unit_new(AQHOME_REACT *aqh)
GWEN_LIST_INIT(AQHREACT_UNIT, unit);
unit->aqHomeReact=aqh;
unit->inputSlotList=AQHREACT_InputSlot_List_new();
unit->outputSlotList=AQHREACT_OutputSlot_List_new();
unit->paramList=AQHREACT_Param_List_new();
unit->inputPortList=AQHREACT_Port_List_new();
unit->outputPortList=AQHREACT_Port_List_new();
return unit;
}
@@ -46,8 +46,8 @@ void AQHREACT_Unit_free(AQHREACT_UNIT *unit)
GWEN_INHERIT_FINI(AQHREACT_UNIT, unit);
free(unit->name);
free(unit->description);
AQHREACT_InputSlot_List_free(unit->inputSlotList);
AQHREACT_OutputSlot_List_free(unit->outputSlotList);
AQHREACT_Port_List_free(unit->outputPortList);
AQHREACT_Port_List_free(unit->inputPortList);
AQHREACT_Param_List_free(unit->paramList);
GWEN_FREE_OBJECT(unit);
}
@@ -113,17 +113,10 @@ void AQHREACT_Unit_SetId(AQHREACT_UNIT *unit, const char *s)
int AQHREACT_Unit_GetNextInputSlotId(const AQHREACT_UNIT *unit)
{
return unit?unit->nextInputSlotId:-1;
}
void AQHREACT_Unit_SetNextInputSlotId(AQHREACT_UNIT *unit, int i)
void AQHREACT_Unit_SetNextInputPortId(AQHREACT_UNIT *unit, int i)
{
if (unit)
unit->nextInputSlotId=i;
unit->nextInputPortId=i;
}
@@ -174,36 +167,102 @@ void AQHREACT_Unit_SetGpTimestamp(AQHREACT_UNIT *unit, uint64_t t)
AQHREACT_INPUT_SLOT_LIST *AQHREACT_Unit_GetInputSlots(const AQHREACT_UNIT *unit)
AQHREACT_PORT_LIST *AQHREACT_Unit_GetInputPortList(const AQHREACT_UNIT *unit)
{
return unit?unit->inputSlotList:NULL;
return unit?unit->inputPortList:NULL;
}
void AQHREACT_Unit_AddInputSlot(AQHREACT_UNIT *unit, AQHREACT_INPUT_SLOT *inSlot)
void AQHREACT_Unit_AddInputPort(AQHREACT_UNIT *unit, AQHREACT_PORT *port)
{
if (unit)
AQHREACT_InputSlot_List_Add(inSlot, unit->inputSlotList);
if (unit && port)
AQHREACT_Port_List_Add(port, unit->inputPortList);
}
AQHREACT_OUTPUT_SLOT_LIST *AQHREACT_Unit_GetOutputSlots(const AQHREACT_UNIT *unit)
AQHREACT_PORT *AQHREACT_Unit_GetInputPortByName(const AQHREACT_UNIT *unit, const char *name)
{
return unit?unit->outputSlotList:NULL;
return (unit && name)?AQHREACT_Port_List_GetByName(unit->inputPortList, name):NULL;
}
void AQHREACT_Unit_AddOutputSlot(AQHREACT_UNIT *unit, AQHREACT_OUTPUT_SLOT *outSlot)
AQHREACT_PORT *AQHREACT_Unit_GetInputPortByIdForUnit(const AQHREACT_UNIT *unit, int id)
{
if (unit)
AQHREACT_OutputSlot_List_Add(outSlot, unit->outputSlotList);
return unit?AQHREACT_Port_List_GetByIdForUnit(unit->inputPortList, id):NULL;
}
AQHREACT_PORT *AQHREACT_Unit_GetOrCreateUnusedInputPortByName(AQHREACT_UNIT *unit, const char *s)
{
if (unit && unit->inputPortList && s && *s) {
AQHREACT_PORT *port;
port=AQHREACT_Unit_GetInputPortByName(unit, s);
if (port) {
uint32_t flags;
const char *portName;
portName=AQHREACT_Port_GetName(port);
flags=AQHREACT_Port_GetFlags(port);
if (!(flags & AQHREACT_UNIT_FLAGS_INUSE))
return port;
if (flags & AQHREACT_UNIT_FLAGS_MULTI) { /* can we just duplicate existing? */
AQHREACT_PORT *newPort;
newPort=AQHREACT_Port_dup(port);
AQHREACT_Unit_AddInputPort(unit, newPort);
return newPort;
}
else {
DBG_INFO(NULL, "Port \"%s\" found but in use, no multi flag", portName);
}
}
}
return NULL;
}
AQHREACT_PORT_LIST *AQHREACT_Unit_GetOutputPortList(const AQHREACT_UNIT *unit)
{
return unit?unit->outputPortList:NULL;
}
void AQHREACT_Unit_AddOutputPort(AQHREACT_UNIT *unit, AQHREACT_PORT *port)
{
if (unit && port)
AQHREACT_Port_List_Add(port, unit->outputPortList);
}
AQHREACT_PORT *AQHREACT_Unit_GetOutputPortByName(const AQHREACT_UNIT *unit, const char *name)
{
return (unit && name)?AQHREACT_Port_List_GetByName(unit->outputPortList, name):NULL;
}
AQHREACT_PORT *AQHREACT_Unit_GetOutputPortByIdForUnit(const AQHREACT_UNIT *unit, int id)
{
return unit?AQHREACT_Port_List_GetByIdForUnit(unit->outputPortList, id):NULL;
}
AQHREACT_PARAM_LIST *AQHREACT_Unit_GetParamList(const AQHREACT_UNIT *unit)
{
return unit?unit->paramList:NULL;
@@ -383,94 +442,62 @@ AQHREACT_UNIT_PROCESS_FN AQHREACT_Unit_SetProcessFn(AQHREACT_UNIT *unit, AQHREAC
void AQHREACT_Unit_OutputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
void AQHREACT_Unit_OutputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
{
if (unit) {
if (unit && port) {
if (unit->outputDataFn)
(unit->outputDataFn)(unit, slotIdForUnit, dataObject);
(unit->outputDataFn)(unit, port, dataObject);
else {
if (unit->outputSlotList) {
AQHREACT_OUTPUT_SLOT *slot;
slot=AQHREACT_Unit_GetOutputSlotByIdForUnit(unit, slotIdForUnit);
if (slot) {
AQHREACT_LINK_LIST *linkList;
linkList=AQHREACT_OutputSlot_GetLinkList(slot);
if (linkList) {
AQHREACT_LINK *lnk;
lnk=AQHREACT_Link_List_First(linkList);
while(lnk) {
AQHREACT_UNIT *targetUnit;
int targetSlotIdForUnit;
targetUnit=AQHREACT_Link_GetTargetUnit(lnk);
targetSlotIdForUnit=AQHREACT_Link_GetTargetInputSlotIdForUnit(lnk);
if (targetUnit && targetSlotIdForUnit>=0) {
DBG_DEBUG(NULL, "%s: Sending data to %s:%d",
AQHREACT_Unit_GetId(unit),
AQHREACT_Link_GetTargetUnitId(lnk), AQHREACT_Link_GetTargetInputSlotIdForUnit(lnk));
AQHREACT_Unit_InputData(targetUnit, targetSlotIdForUnit, dataObject);
}
lnk=AQHREACT_Link_List_Next(lnk);
} /* while */
} /* if linkList */
} /* if slot */
} /* if output slot list */
} /* else */
} /* if unit */
AQHREACT_Port_SendData(port, dataObject);
}
}
}
void AQHREACT_Unit_OutputDoubleData(AQHREACT_UNIT *unit, int slotIndex, double data)
void AQHREACT_Unit_OutputDoubleData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, double data)
{
if (unit && unit->outputSlotList) {
if (unit && unit->outputPortList) {
AQHREACT_DATAOBJECT *dataObject;
dataObject=AQHREACT_DataObject_new();
AQHREACT_DataObject_SetDataType(dataObject, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_DataObject_SetDoubleData(dataObject, data);
AQHREACT_Unit_OutputData(unit, slotIndex, dataObject);
AQHREACT_Unit_OutputData(unit, port, dataObject);
AQHREACT_DataObject_free(dataObject);
}
}
void AQHREACT_Unit_OutputStringData(AQHREACT_UNIT *unit, int slotIndex, const char *data)
void AQHREACT_Unit_OutputStringData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const char *data)
{
if (unit && unit->outputSlotList) {
if (unit && unit->outputPortList) {
AQHREACT_DATAOBJECT *dataObject;
dataObject=AQHREACT_DataObject_new();
AQHREACT_DataObject_SetDataType(dataObject, AQHREACT_DATAOBJECTTYPE_STRING);
AQHREACT_DataObject_SetStringData(dataObject, data);
AQHREACT_Unit_OutputData(unit, slotIndex, dataObject);
AQHREACT_Unit_OutputData(unit, port, dataObject);
AQHREACT_DataObject_free(dataObject);
}
}
void AQHREACT_Unit_InputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
void AQHREACT_Unit_InputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
{
if (unit) {
if (unit && port) {
if (unit->inputDataFn)
(unit->inputDataFn)(unit, slotIdForUnit, dataObject);
(unit->inputDataFn)(unit, port, dataObject);
else {
if (dataObject) {
AQHREACT_INPUT_SLOT *inSlot;
inSlot=AQHREACT_Unit_GetInputSlotByIdForUnit(unit, slotIdForUnit);
if (inSlot) {
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_InputSlot_GetAcceptedDataType(inSlot)) {
AQHREACT_InputSlot_SetCurrentDataObject(inSlot, AQHREACT_DataObject_dup(dataObject));
AQHREACT_InputSlot_AddFlags(inSlot, AQHREACT_UNIT_FLAGS_CHANGED);
AQHREACT_Unit_AddFlags(unit, AQHREACT_UNIT_FLAGS_CHANGED);
}
}
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_Port_GetDataType(port)) {
AQHREACT_Port_SetCurrentDataObject(port, AQHREACT_DataObject_dup(dataObject));
AQHREACT_Port_SendData(port, dataObject);
AQHREACT_Port_AddFlags(port, AQHREACT_UNIT_FLAGS_CHANGED);
AQHREACT_Unit_AddFlags(unit, AQHREACT_UNIT_FLAGS_CHANGED);
}
}
}
}
@@ -481,13 +508,14 @@ void AQHREACT_Unit_InputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHRE
int AQHREACT_Unit_Process(AQHREACT_UNIT *unit)
{
if (unit) {
if (unit->processFn)
return (unit->processFn)(unit);
else
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputPorts(unit);
}
return 0;
@@ -495,129 +523,16 @@ int AQHREACT_Unit_Process(AQHREACT_UNIT *unit)
AQHREACT_INPUT_SLOT *AQHREACT_Unit_GetInputSlotByIdForUnit(const AQHREACT_UNIT *unit, int id)
{
if (unit && unit->inputSlotList && id>=0) {
AQHREACT_INPUT_SLOT *slot;
slot=AQHREACT_InputSlot_List_First(unit->inputSlotList);
while(slot) {
if (AQHREACT_InputSlot_GetIdForUnit(slot)==id)
return slot;
slot=AQHREACT_InputSlot_List_Next(slot);
}
}
return NULL;
}
AQHREACT_INPUT_SLOT *AQHREACT_Unit_GetInputSlotByName(const AQHREACT_UNIT *unit, const char *s)
{
if (unit && unit->inputSlotList && s && *s) {
AQHREACT_INPUT_SLOT *slot;
slot=AQHREACT_InputSlot_List_First(unit->inputSlotList);
while(slot) {
const char *slotName;
slotName=AQHREACT_InputSlot_GetName(slot);
if (slotName && *slotName && strcasecmp(slotName, s)==0)
return slot;
slot=AQHREACT_InputSlot_List_Next(slot);
}
}
return NULL;
}
AQHREACT_INPUT_SLOT *AQHREACT_Unit_GetOrCreateUnusedInputSlotByName(AQHREACT_UNIT *unit, const char *s)
{
if (unit && unit->inputSlotList && s && *s) {
AQHREACT_INPUT_SLOT *slot;
slot=AQHREACT_Unit_GetInputSlotByName(unit, s);
if (slot) {
uint32_t flags;
const char *slotName;
slotName=AQHREACT_InputSlot_GetName(slot);
flags=AQHREACT_InputSlot_GetFlags(slot);
if (!(flags & AQHREACT_UNIT_FLAGS_INUSE))
return slot;
if (flags & AQHREACT_UNIT_FLAGS_MULTI) { /* can we just duplicate existing? */
AQHREACT_INPUT_SLOT *newSlot;
newSlot=AQHREACT_InputSlot_dup(slot);
AQHREACT_InputSlot_SetIdForUnit(newSlot, (unit->nextInputSlotId)++);
AQHREACT_Unit_AddInputSlot(unit, newSlot);
return newSlot;
}
else {
DBG_INFO(NULL, "Slot \"%s\" found but in use, no multi flag", slotName);
}
}
}
return NULL;
}
AQHREACT_OUTPUT_SLOT *AQHREACT_Unit_GetOutputSlotByIdForUnit(const AQHREACT_UNIT *unit, int id)
{
if (unit && unit->outputSlotList && id>=0) {
AQHREACT_OUTPUT_SLOT *slot;
slot=AQHREACT_OutputSlot_List_First(unit->outputSlotList);
while(slot) {
if (AQHREACT_OutputSlot_GetIdForUnit(slot)==id)
return slot;
slot=AQHREACT_OutputSlot_List_Next(slot);
}
}
return NULL;
}
AQHREACT_OUTPUT_SLOT *AQHREACT_Unit_GetOutputSlotByName(const AQHREACT_UNIT *unit, const char *s)
{
if (unit && unit->outputSlotList && s && *s) {
AQHREACT_OUTPUT_SLOT *slot;
slot=AQHREACT_OutputSlot_List_First(unit->outputSlotList);
while(slot) {
const char *slotName;
slotName=AQHREACT_OutputSlot_GetName(slot);
if (slotName && *slotName && strcasecmp(slotName, s)==0)
return slot;
slot=AQHREACT_OutputSlot_List_Next(slot);
}
return slot;
}
return NULL;
}
void AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(AQHREACT_UNIT *unit)
void AQHREACT_Unit_ClearChangeFlagsInUnitAndInputPorts(AQHREACT_UNIT *unit)
{
if (unit) {
AQHREACT_INPUT_SLOT *slot;
AQHREACT_PORT *port;
unit->flags&=~AQHREACT_UNIT_FLAGS_CHANGED;
slot=AQHREACT_InputSlot_List_First(unit->inputSlotList);
while(slot) {
AQHREACT_InputSlot_SubFlags(slot, AQHREACT_UNIT_FLAGS_CHANGED);
slot=AQHREACT_InputSlot_List_Next(slot);
port=AQHREACT_Port_List_First(unit->inputPortList);
while(port) {
AQHREACT_Port_SubFlags(port, AQHREACT_UNIT_FLAGS_CHANGED);
port=AQHREACT_Port_List_Next(port);
}
}
}
@@ -627,16 +542,16 @@ void AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(AQHREACT_UNIT *unit)
int AQHREACT_Unit_InputHasChanged(const AQHREACT_UNIT *unit)
{
if (unit) {
AQHREACT_INPUT_SLOT *slot;
AQHREACT_PORT *port;
if (unit->flags & AQHREACT_UNIT_FLAGS_CHANGED)
return 1;
slot=AQHREACT_InputSlot_List_First(unit->inputSlotList);
while(slot) {
if (AQHREACT_InputSlot_GetFlags(slot) & AQHREACT_UNIT_FLAGS_CHANGED)
port=AQHREACT_Port_List_First(unit->inputPortList);
while(port) {
if (AQHREACT_Port_GetFlags(port) & AQHREACT_UNIT_FLAGS_CHANGED)
return 1;
slot=AQHREACT_InputSlot_List_Next(slot);
port=AQHREACT_Port_List_Next(port);
}
}
return 0;
@@ -685,8 +600,8 @@ void AQHREACT_Unit_Dump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent)
GWEN_Buffer_AppendArgs(buf, "flags......: %08x\n", unit->flags);
AQHREACT_Param_List_Dump(unit->paramList, buf, indent, "Unit Parameter List:");
AQHREACT_InputSlot_List_Dump(unit->inputSlotList, buf, indent, "Input Slot List:");
AQHREACT_OutputSlot_List_Dump(unit->outputSlotList, buf, indent, "Output Slot List:");
AQHREACT_Port_List_Dump(unit->inputPortList, buf, indent, "Input Port List:");
AQHREACT_Port_List_Dump(unit->outputPortList, buf, indent, "Output Port List:");
}
}

View File

@@ -25,19 +25,19 @@ GWEN_INHERIT_FUNCTION_DEFS(AQHREACT_UNIT)
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/inputslot.h"
#include "aqhome-react/types/outputslot.h"
#include "aqhome-react/types/port.h"
#include "aqhome-react/types/param.h"
#include "aqhome-react/types/dataobject.h"
typedef void (*AQHREACT_UNIT_INPUTDATA_FN)(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
typedef void (*AQHREACT_UNIT_OUTPUTDATA_FN)(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
typedef void (*AQHREACT_UNIT_INPUTDATA_FN)(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
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);
AQHREACT_UNIT *AQHREACT_Unit_new(AQHOME_REACT *aqh);
void AQHREACT_Unit_free(AQHREACT_UNIT *unit);
@@ -52,9 +52,6 @@ void AQHREACT_Unit_SetDescription(AQHREACT_UNIT *unit, const char *s);
const char *AQHREACT_Unit_GetId(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_SetId(AQHREACT_UNIT *unit, const char *s);
int AQHREACT_Unit_GetNextInputSlotId(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_SetNextInputSlotId(AQHREACT_UNIT *unit, int i);
uint32_t AQHREACT_Unit_GetFlags(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_SetFlags(AQHREACT_UNIT *unit, uint32_t i);
void AQHREACT_Unit_AddFlags(AQHREACT_UNIT *unit, uint32_t i);
@@ -65,19 +62,20 @@ uint64_t AQHREACT_Unit_GetGpTimestamp(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_SetGpTimestamp(AQHREACT_UNIT *unit, uint64_t t);
AQHREACT_INPUT_SLOT_LIST *AQHREACT_Unit_GetInputSlots(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_AddInputSlot(AQHREACT_UNIT *unit, AQHREACT_INPUT_SLOT *inSlot);
AQHREACT_INPUT_SLOT *AQHREACT_Unit_GetInputSlotByIdForUnit(const AQHREACT_UNIT *unit, int id);
AQHREACT_INPUT_SLOT *AQHREACT_Unit_GetInputSlotByName(const AQHREACT_UNIT *unit, const char *s);
AQHREACT_INPUT_SLOT *AQHREACT_Unit_GetOrCreateUnusedInputSlotByName(AQHREACT_UNIT *unit, const char *s);
AQHREACT_PORT_LIST *AQHREACT_Unit_GetInputPortList(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_AddInputPort(AQHREACT_UNIT *unit, AQHREACT_PORT *port);
AQHREACT_PORT *AQHREACT_Unit_GetInputPortByName(const AQHREACT_UNIT *unit, const char *s);
AQHREACT_PORT *AQHREACT_Unit_GetInputPortByIdForUnit(const AQHREACT_UNIT *unit, int id);
AQHREACT_PORT *AQHREACT_Unit_GetOrCreateUnusedInputPortByName(AQHREACT_UNIT *unit, const char *s);
AQHREACT_PORT_LIST *AQHREACT_Unit_GetOutputPortList(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_AddOutputPort(AQHREACT_UNIT *unit, AQHREACT_PORT *port);
AQHREACT_PORT *AQHREACT_Unit_GetOutputPortByName(const AQHREACT_UNIT *unit, const char *s);
AQHREACT_PORT *AQHREACT_Unit_GetOutputPortByIdForUnit(const AQHREACT_UNIT *unit, int id);
AQHREACT_OUTPUT_SLOT_LIST *AQHREACT_Unit_GetOutputSlots(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_AddOutputSlot(AQHREACT_UNIT *unit, AQHREACT_OUTPUT_SLOT *outSlot);
AQHREACT_OUTPUT_SLOT *AQHREACT_Unit_GetOutputSlotByIdForUnit(const AQHREACT_UNIT *unit, int idx);
AQHREACT_OUTPUT_SLOT *AQHREACT_Unit_GetOutputSlotByName(const AQHREACT_UNIT *unit, const char *s);
void AQHREACT_Unit_SetNextInputPortId(AQHREACT_UNIT *unit, int i);
void AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(AQHREACT_UNIT *unit);
void AQHREACT_Unit_ClearChangeFlagsInUnitAndInputPorts(AQHREACT_UNIT *unit);
int AQHREACT_Unit_InputHasChanged(const AQHREACT_UNIT *unit);
@@ -89,12 +87,12 @@ void AQHREACT_Unit_SetParamValueDouble(AQHREACT_UNIT *unit, const char *paramNam
const char *AQHREACT_Unit_GetParamValueString(const AQHREACT_UNIT *unit, const char *paramName, const char *defVal);
void AQHREACT_Unit_SetParamValueString(AQHREACT_UNIT *unit, const char *paramName, const char *val);
void AQHREACT_Unit_OutputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
void AQHREACT_Unit_OutputDoubleData(AQHREACT_UNIT *unit, int slotIdForUnit, double data);
void AQHREACT_Unit_OutputStringData(AQHREACT_UNIT *unit, int slotIdForUnit, const char *data);
void AQHREACT_Unit_OutputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
void AQHREACT_Unit_OutputDoubleData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, double data);
void AQHREACT_Unit_OutputStringData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const char *data);
void AQHREACT_Unit_InputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
void AQHREACT_Unit_InputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
/**
* Process inputs and generate output.

View File

@@ -25,10 +25,10 @@ struct AQHREACT_UNIT {
uint32_t flags;
uint64_t gpTimestamp;
int nextInputSlotId;
int nextInputPortId;
AQHREACT_INPUT_SLOT_LIST *inputSlotList;
AQHREACT_OUTPUT_SLOT_LIST *outputSlotList;
AQHREACT_PORT_LIST *inputPortList;
AQHREACT_PORT_LIST *outputPortList;
AQHREACT_PARAM_LIST *paramList;