module units now are units created from previous networks of units thus introducing nested units.
818 lines
24 KiB
C
818 lines
24 KiB
C
/****************************************************************************
|
|
* 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 "./u_module_p.h"
|
|
|
|
#include <gwenhywfar/debug.h>
|
|
#include <gwenhywfar/xml.h>
|
|
#include <gwenhywfar/text.h>
|
|
|
|
//TODO: set params
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* defines
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
GWEN_INHERIT(AQHREACT_UNIT, AQHREACT_UNIT_MODULE);
|
|
|
|
GWEN_LIST_FUNCTIONS(MODULE_PROXY_DESCR, ModuleProxyDescr);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* forward declarations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
|
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
|
static void _cbOutputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
|
static AQHREACT_PARAM *_cbGetParamByName(const AQHREACT_UNIT *unit, const char *paramName);
|
|
static int _cbProcess(AQHREACT_UNIT *unit);
|
|
|
|
static void _readProxyFromXml(AQHREACT_UNIT *unit,
|
|
GWEN_XMLNODE *xmlNode,
|
|
MODULE_PROXY_DESCR_LIST *proxyDescrList,
|
|
const char *mainGroupName,
|
|
const char *groupName,
|
|
const char *nameProperty,
|
|
const char *targetObjectProperty,
|
|
const char *targetNameProperty);
|
|
static void _readInputSlotsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
|
static void _readOutputSlotsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
|
static int _finishInSlots(AQHREACT_UNIT *unit);
|
|
static int _finishOutSlots(AQHREACT_UNIT *unit);
|
|
static int _finishParams(AQHREACT_UNIT *unit);
|
|
static void _readUnitsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
|
static AQHREACT_UNIT *_readOneUnitFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *parentUnit, GWEN_XMLNODE *xmlNode);
|
|
static int _readParamsFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNodeUnit, const char *mainGroupName);
|
|
static int _readParamFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *paramNode);
|
|
static int _setParamDataFromString(AQHREACT_PARAM *param, const char *value);
|
|
static int _readLinksFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
|
static int _readLinkFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *linkNode);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* implementations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* ModuleProxyDescr
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
MODULE_PROXY_DESCR *ModuleProxyDescr_new(const char *name, const char *targetObject, const char *targetName)
|
|
{
|
|
MODULE_PROXY_DESCR *pd;
|
|
|
|
GWEN_NEW_OBJECT(MODULE_PROXY_DESCR, pd);
|
|
GWEN_LIST_INIT(MODULE_PROXY_DESCR, pd);
|
|
pd->name=name?strdup(name):NULL;
|
|
pd->targetObject=targetObject?strdup(targetObject):NULL;
|
|
pd->targetName=targetName?strdup(targetName):NULL;
|
|
|
|
return pd;
|
|
}
|
|
|
|
|
|
|
|
void ModuleProxyDescr_free(MODULE_PROXY_DESCR *pd)
|
|
{
|
|
if (pd) {
|
|
GWEN_LIST_FINI(MODULE_PROXY_DESCR, pd);
|
|
free(pd->targetName);
|
|
free(pd->targetObject);
|
|
free(pd->name);
|
|
GWEN_FREE_OBJECT(pd);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
MODULE_PROXY_DESCR *ModuleProxyDescr_List_FindByName(const MODULE_PROXY_DESCR_LIST *pdList, const char *s)
|
|
{
|
|
if (pdList && s && *s) {
|
|
MODULE_PROXY_DESCR *pd;
|
|
|
|
pd=ModuleProxyDescr_List_First(pdList);
|
|
while(pd) {
|
|
if (pd->name && strcasecmp(pd->name, s)==0)
|
|
return pd;
|
|
pd=ModuleProxyDescr_List_Next(pd);
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* AqHomeReact_UnitModule
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
AQHREACT_UNIT *AqHomeReact_UnitModule_new(AQHOME_REACT *aqh)
|
|
{
|
|
AQHREACT_UNIT *unit;
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
|
|
unit=AQHREACT_Unit_new(aqh);
|
|
GWEN_NEW_OBJECT(AQHREACT_UNIT_MODULE, xunit);
|
|
GWEN_INHERIT_SETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit, xunit, _freeData);
|
|
|
|
xunit->paramProxyList=ModuleProxyDescr_List_new();
|
|
xunit->inSlotProxyList=ModuleProxyDescr_List_new();
|
|
xunit->outSlotProxyList=ModuleProxyDescr_List_new();
|
|
xunit->unitList=AQHREACT_Unit_List_new();
|
|
|
|
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
|
AQHREACT_Unit_SetOutputDataFn(unit, _cbOutputData);
|
|
AQHREACT_Unit_SetGetParamByNameFn(unit, _cbGetParamByName);
|
|
AQHREACT_Unit_SetProcessFn(unit, _cbProcess);
|
|
|
|
return unit;
|
|
}
|
|
|
|
|
|
|
|
void _freeData(void *bp, void *p)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*) p;
|
|
|
|
AQHREACT_Unit_List_free(xunit->unitList);
|
|
ModuleProxyDescr_List_free(xunit->outSlotProxyList);
|
|
ModuleProxyDescr_List_free(xunit->inSlotProxyList);
|
|
ModuleProxyDescr_List_free(xunit->paramProxyList);
|
|
|
|
GWEN_FREE_OBJECT(xunit);
|
|
}
|
|
|
|
|
|
|
|
AQHREACT_UNIT *AqHomeReact_UnitModule_fromXml(AQHOME_REACT *aqh, GWEN_XMLNODE *xmlNode)
|
|
{
|
|
const char *t;
|
|
|
|
t=GWEN_XMLNode_GetProperty(xmlNode, "type", NULL);
|
|
if (t && *t) {
|
|
AQHREACT_UNIT *unit;
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
int rv;
|
|
|
|
unit=AqHomeReact_UnitModule_new(aqh);
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
AQHREACT_Unit_SetName(unit, t);
|
|
|
|
_readProxyFromXml(unit, xmlNode, xunit->paramProxyList, "paramdefs", "param", "name", "targetModule", "targetParam");
|
|
|
|
_readInputSlotsFromXml(aqh, unit, xmlNode);
|
|
_readOutputSlotsFromXml(aqh, unit, xmlNode);
|
|
|
|
_readUnitsFromXml(aqh, unit, xmlNode);
|
|
|
|
rv=_finishInSlots(unit);
|
|
if (rv<0) {
|
|
DBG_INFO(NULL, "here (%d)", rv);
|
|
AQHREACT_Unit_free(unit);
|
|
return NULL;
|
|
}
|
|
rv=_finishOutSlots(unit);
|
|
if (rv<0) {
|
|
DBG_INFO(NULL, "here (%d)", rv);
|
|
AQHREACT_Unit_free(unit);
|
|
return NULL;
|
|
}
|
|
|
|
rv=_finishParams(unit);
|
|
if (rv<0) {
|
|
DBG_INFO(NULL, "here (%d)", rv);
|
|
AQHREACT_Unit_free(unit);
|
|
return NULL;
|
|
}
|
|
|
|
rv=_readParamsFromXml(unit, xmlNode, "paramDefs");
|
|
if (rv<0) {
|
|
DBG_INFO(NULL, "here (%d)", rv);
|
|
AQHREACT_Unit_free(unit);
|
|
return NULL;
|
|
}
|
|
|
|
rv=_readLinksFromXml(aqh, unit, xmlNode);
|
|
if (rv<0) {
|
|
DBG_INFO(NULL, "here (%d)", rv);
|
|
AQHREACT_Unit_free(unit);
|
|
return NULL;
|
|
}
|
|
|
|
return unit;
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "No \"type\" property in xml node for module");
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
if (xunit) {
|
|
AQHREACT_INPUT_SLOT *slot;
|
|
|
|
slot=AQHREACT_Unit_GetInputSlotByIdForUnit(unit, slotIdForUnit);
|
|
if (slot) {
|
|
const char *slotName;
|
|
const MODULE_PROXY_DESCR *pd;
|
|
|
|
slotName=AQHREACT_InputSlot_GetName(slot);
|
|
pd=ModuleProxyDescr_List_FindByName(xunit->inSlotProxyList, slotName);
|
|
if (pd)
|
|
AQHREACT_Unit_InputData(pd->targetObjectPtr, pd->targetIdForModule, dataObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _cbOutputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
if (xunit) {
|
|
AQHREACT_OUTPUT_SLOT *slot;
|
|
|
|
slot=AQHREACT_Unit_GetOutputSlotByIdForUnit(unit, slotIdForUnit);
|
|
if (slot) {
|
|
const char *slotName;
|
|
const MODULE_PROXY_DESCR *pd;
|
|
|
|
slotName=AQHREACT_OutputSlot_GetName(slot);
|
|
pd=ModuleProxyDescr_List_FindByName(xunit->outSlotProxyList, slotName);
|
|
if (pd)
|
|
AQHREACT_Unit_OutputData(pd->targetObjectPtr, pd->targetIdForModule, dataObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
AQHREACT_PARAM *_cbGetParamByName(const AQHREACT_UNIT *unit, const char *paramName)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
|
|
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);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
int _cbProcess(AQHREACT_UNIT *unit)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
int result=0;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
if (xunit) {
|
|
AQHREACT_UNIT *subUnit;
|
|
|
|
subUnit=AQHREACT_Unit_List_First(xunit->unitList);
|
|
while(subUnit) {
|
|
int rv;
|
|
|
|
rv=AQHREACT_Unit_Process(subUnit);
|
|
if (rv<0)
|
|
result=rv;
|
|
else if (result>=0)
|
|
result=rv;
|
|
subUnit=AQHREACT_Unit_List_Next(subUnit);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
void _readProxyFromXml(AQHREACT_UNIT *unit,
|
|
GWEN_XMLNODE *xmlNode,
|
|
MODULE_PROXY_DESCR_LIST *proxyDescrList,
|
|
const char *mainGroupName,
|
|
const char *groupName,
|
|
const char *nameProperty,
|
|
const char *targetObjectProperty,
|
|
const char *targetNameProperty)
|
|
{
|
|
GWEN_XMLNODE *nGroup;
|
|
|
|
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, mainGroupName, NULL, NULL);
|
|
if (nGroup) {
|
|
GWEN_XMLNODE *n;
|
|
|
|
n=GWEN_XMLNode_FindFirstTag(nGroup, groupName, NULL, NULL);
|
|
while(n) {
|
|
const char *name;
|
|
const char *targetObject;
|
|
const char *targetName;
|
|
|
|
name=GWEN_XMLNode_GetProperty(n, nameProperty, NULL);
|
|
targetObject=GWEN_XMLNode_GetProperty(n, targetObjectProperty, NULL);
|
|
targetName=GWEN_XMLNode_GetProperty(n, targetNameProperty, NULL);
|
|
|
|
if (name && targetObject && targetName) {
|
|
MODULE_PROXY_DESCR *pd;
|
|
|
|
pd=ModuleProxyDescr_new(name, targetObject, targetName);
|
|
ModuleProxyDescr_List_Add(pd, proxyDescrList);
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Incomplete entry in list \"%s\", ignoring", mainGroupName);
|
|
}
|
|
n=GWEN_XMLNode_FindNextTag(n, groupName, NULL, NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _readInputSlotsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
GWEN_XMLNODE *nGroup;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
|
|
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, "inputSlots", NULL, NULL);
|
|
if (nGroup) {
|
|
GWEN_XMLNODE *n;
|
|
|
|
n=GWEN_XMLNode_FindFirstTag(nGroup, "inputSlot", NULL, NULL);
|
|
while(n) {
|
|
const char *name;
|
|
const char *targetUnit;
|
|
const char *targetSlot;
|
|
int slotIdForUnit;
|
|
|
|
name=GWEN_XMLNode_GetProperty(n, "name", NULL);
|
|
targetUnit=GWEN_XMLNode_GetProperty(n, "targetUnit", NULL);
|
|
targetSlot=GWEN_XMLNode_GetProperty(n, "targetSlot", NULL);
|
|
slotIdForUnit=GWEN_XMLNode_GetIntProperty(n, "idForUnit", 0);
|
|
|
|
if (name && targetUnit && targetSlot) {
|
|
MODULE_PROXY_DESCR *pd;
|
|
AQHREACT_INPUT_SLOT *slot;
|
|
|
|
pd=ModuleProxyDescr_new(name, targetUnit, targetSlot); /* set pd->targetObjectPtr later */
|
|
ModuleProxyDescr_List_Add(pd, xunit->inSlotProxyList);
|
|
|
|
slot=AQHREACT_InputSlot_new();
|
|
AQHREACT_InputSlot_SetName(slot, name);
|
|
AQHREACT_InputSlot_SetIdForUnit(slot, slotIdForUnit);
|
|
AQHREACT_Unit_AddInputSlot(unit, slot);
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Incomplete input slot, ignoring");
|
|
}
|
|
n=GWEN_XMLNode_FindNextTag(n, "inputSlot", NULL, NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _readOutputSlotsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
GWEN_XMLNODE *nGroup;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
|
|
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, "outputSlots", NULL, NULL);
|
|
if (nGroup) {
|
|
GWEN_XMLNODE *n;
|
|
|
|
n=GWEN_XMLNode_FindFirstTag(nGroup, "outputSlot", NULL, NULL);
|
|
while(n) {
|
|
const char *name;
|
|
const char *targetUnit;
|
|
const char *targetSlot;
|
|
int slotIdForUnit;
|
|
|
|
name=GWEN_XMLNode_GetProperty(n, "name", NULL);
|
|
targetUnit=GWEN_XMLNode_GetProperty(n, "targetUnit", NULL);
|
|
targetSlot=GWEN_XMLNode_GetProperty(n, "targetSlot", NULL);
|
|
slotIdForUnit=GWEN_XMLNode_GetIntProperty(n, "idForUnit", 0);
|
|
|
|
if (name && targetUnit && targetSlot) {
|
|
MODULE_PROXY_DESCR *pd;
|
|
AQHREACT_OUTPUT_SLOT *slot;
|
|
|
|
pd=ModuleProxyDescr_new(name, targetUnit, targetSlot); /* set pd->targetObjectPtr later */
|
|
ModuleProxyDescr_List_Add(pd, xunit->outSlotProxyList);
|
|
|
|
slot=AQHREACT_OutputSlot_new();
|
|
AQHREACT_OutputSlot_SetName(slot, name);
|
|
AQHREACT_OutputSlot_SetIdForUnit(slot, slotIdForUnit);
|
|
AQHREACT_Unit_AddOutputSlot(unit, slot);
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Incomplete output slot, ignoring");
|
|
}
|
|
n=GWEN_XMLNode_FindNextTag(n, "outputSlot", NULL, NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int _finishInSlots(AQHREACT_UNIT *unit)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
MODULE_PROXY_DESCR *pd;
|
|
const char *unitName;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
unitName=AQHREACT_Unit_GetName(unit);
|
|
pd=ModuleProxyDescr_List_First(xunit->inSlotProxyList);
|
|
while(pd) {
|
|
AQHREACT_UNIT *subUnit;
|
|
const AQHREACT_INPUT_SLOT *subUnitSlot;
|
|
AQHREACT_INPUT_SLOT *moduleSlot;
|
|
|
|
subUnit=AQHREACT_Unit_List_GetById(xunit->unitList, pd->targetObject);
|
|
if (subUnit==NULL) {
|
|
DBG_ERROR(NULL, "Subunit \"%s\" not found for input slot", pd->targetObject);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
pd->targetObjectPtr=subUnit;
|
|
|
|
moduleSlot=AQHREACT_Unit_GetInputSlotByName(subUnit, pd->name);
|
|
if (moduleSlot==NULL) {
|
|
DBG_ERROR(NULL, "Unit %s: Input slot \"%s\" not defined", unitName, pd->targetName);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
|
|
subUnitSlot=AQHREACT_Unit_GetInputSlotByName(subUnit, pd->targetName);
|
|
if (subUnitSlot==NULL) {
|
|
DBG_ERROR(NULL, "Unit %s: Input slot \"%s\" not found for subunit \"%s\"", unitName, pd->targetName, pd->targetObject);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
|
|
AQHREACT_InputSlot_SetDescription(moduleSlot, AQHREACT_InputSlot_GetDescription(subUnitSlot));
|
|
AQHREACT_InputSlot_SetFlags(moduleSlot, AQHREACT_InputSlot_GetFlags(subUnitSlot));
|
|
AQHREACT_InputSlot_SetAcceptedDataType(moduleSlot, AQHREACT_InputSlot_GetAcceptedDataType(subUnitSlot));
|
|
|
|
pd->targetIdForModule=AQHREACT_InputSlot_GetIdForUnit(subUnitSlot);
|
|
|
|
pd=ModuleProxyDescr_List_Next(pd);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int _finishOutSlots(AQHREACT_UNIT *unit)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
MODULE_PROXY_DESCR *pd;
|
|
const char *unitName;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
unitName=AQHREACT_Unit_GetName(unit);
|
|
pd=ModuleProxyDescr_List_First(xunit->outSlotProxyList);
|
|
while(pd) {
|
|
AQHREACT_UNIT *subUnit;
|
|
const AQHREACT_OUTPUT_SLOT *subUnitSlot;
|
|
AQHREACT_OUTPUT_SLOT *moduleSlot;
|
|
|
|
subUnit=AQHREACT_Unit_List_GetById(xunit->unitList, pd->targetObject);
|
|
if (subUnit==NULL) {
|
|
DBG_ERROR(NULL, "Subunit \"%s\" not found for output slot", pd->targetObject);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
pd->targetObjectPtr=subUnit;
|
|
|
|
moduleSlot=AQHREACT_Unit_GetOutputSlotByName(subUnit, pd->name);
|
|
if (moduleSlot==NULL) {
|
|
DBG_ERROR(NULL, "Unit %s: Output slot \"%s\" not defined", unitName, pd->targetName);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
|
|
subUnitSlot=AQHREACT_Unit_GetOutputSlotByName(subUnit, pd->targetName);
|
|
if (subUnitSlot==NULL) {
|
|
DBG_ERROR(NULL, "Unit %s: Output slot \"%s\" not found for subunit \"%s\"", unitName, pd->targetName, pd->targetObject);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
|
|
AQHREACT_OutputSlot_SetDescription(moduleSlot, AQHREACT_OutputSlot_GetDescription(subUnitSlot));
|
|
AQHREACT_OutputSlot_SetFlags(moduleSlot, AQHREACT_OutputSlot_GetFlags(subUnitSlot));
|
|
AQHREACT_OutputSlot_SetEmittedDataType(moduleSlot, AQHREACT_OutputSlot_GetEmittedDataType(subUnitSlot));
|
|
|
|
pd->targetIdForModule=AQHREACT_OutputSlot_GetIdForUnit(subUnitSlot);
|
|
|
|
pd=ModuleProxyDescr_List_Next(pd);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int _finishParams(AQHREACT_UNIT *unit)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
MODULE_PROXY_DESCR *pd;
|
|
const char *unitName;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
unitName=AQHREACT_Unit_GetName(unit);
|
|
pd=ModuleProxyDescr_List_First(xunit->paramProxyList);
|
|
while(pd) {
|
|
AQHREACT_UNIT *subUnit;
|
|
|
|
subUnit=AQHREACT_Unit_List_GetById(xunit->unitList, pd->targetObject);
|
|
if (subUnit==NULL) {
|
|
DBG_ERROR(NULL, "Unit %s: Subunit \"%s\" not found for param \"%s\"", unitName, pd->targetObject, pd->name);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
pd->targetObjectPtr=subUnit;
|
|
|
|
pd=ModuleProxyDescr_List_Next(pd);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
void _readUnitsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode)
|
|
{
|
|
GWEN_XMLNODE *nGroup;
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
|
|
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, "units", NULL, NULL);
|
|
if (nGroup) {
|
|
GWEN_XMLNODE *n;
|
|
|
|
n=GWEN_XMLNode_FindFirstTag(nGroup, "unit", NULL, NULL);
|
|
while(n) {
|
|
AQHREACT_UNIT *subUnit;
|
|
|
|
subUnit=_readOneUnitFromXml(aqh, unit, n);
|
|
if (subUnit)
|
|
AQHREACT_Unit_List_Add(subUnit, xunit->unitList);
|
|
else {
|
|
DBG_INFO(NULL, "Error reading unit from XML node");
|
|
}
|
|
|
|
n=GWEN_XMLNode_FindNextTag(n, "unit", NULL, NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
AQHREACT_UNIT *_readOneUnitFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *parentUnit, GWEN_XMLNODE *xmlNode)
|
|
{
|
|
const char *id;
|
|
const char *t;
|
|
|
|
id=GWEN_XMLNode_GetProperty(xmlNode, "id", NULL);
|
|
t=GWEN_XMLNode_GetProperty(xmlNode, "type", NULL);
|
|
|
|
if (id && t) {
|
|
AQHREACT_UNIT *subUnit;
|
|
int rv;
|
|
|
|
subUnit=AqHomeReact_CreateUnitByName(aqh, t);
|
|
AQHREACT_Unit_SetId(subUnit, id);
|
|
rv=_readParamsFromXml(subUnit, xmlNode, "params");
|
|
if (rv<0) {
|
|
DBG_INFO(NULL, "here (%d)", rv);
|
|
AQHREACT_Unit_free(subUnit);
|
|
return NULL;
|
|
}
|
|
return subUnit;
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Incomplete unit, ignoring");
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int _readParamsFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNodeUnit, const char *mainGroupName)
|
|
{
|
|
GWEN_XMLNODE *nGroup;
|
|
|
|
nGroup=GWEN_XMLNode_FindFirstTag(xmlNodeUnit, mainGroupName, NULL, NULL);
|
|
if (nGroup) {
|
|
GWEN_XMLNODE *n;
|
|
|
|
n=GWEN_XMLNode_FindFirstTag(nGroup, "param", NULL, NULL);
|
|
while(n) {
|
|
int rv;
|
|
|
|
rv=_readParamFromXml(unit, n);
|
|
if (rv<0) {
|
|
DBG_INFO(NULL, "here (%d)", rv);
|
|
return rv;
|
|
}
|
|
n=GWEN_XMLNode_FindNextTag(n, "param", NULL, NULL);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int _readParamFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *paramNode)
|
|
{
|
|
const char *paramName;
|
|
|
|
paramName=GWEN_XMLNode_GetProperty(paramNode, "name", NULL);
|
|
if (paramName && *paramName) {
|
|
AQHREACT_PARAM *param;
|
|
|
|
param=AQHREACT_Unit_GetParamByName(unit, paramName);
|
|
if (param) {
|
|
const char *value;
|
|
|
|
value=GWEN_XMLNode_GetCharValue(paramNode, NULL, NULL);
|
|
if (value && *value) {
|
|
int rv;
|
|
|
|
rv=_setParamDataFromString(param, value);
|
|
if (rv<0) {
|
|
DBG_ERROR(NULL, "Error setting param data for param \"%s\" (%d)", paramName, rv);
|
|
return rv;
|
|
}
|
|
} /* if value */
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "No param name \"%s\" in unit", paramName);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int _setParamDataFromString(AQHREACT_PARAM *param, const char *value)
|
|
{
|
|
if (value && *value) {
|
|
int dataType;
|
|
|
|
dataType=AQHREACT_Param_GetDataType(param);
|
|
switch(dataType) {
|
|
case AQHREACT_DATAOBJECTTYPE_DOUBLE:
|
|
{
|
|
int rv;
|
|
double valueAsDouble;
|
|
|
|
rv=GWEN_Text_StringToDouble(value, &valueAsDouble);
|
|
if (rv<0) {
|
|
DBG_ERROR(NULL, "Not a DOUBLE value for param \"%s\" [%s]", AQHREACT_Param_GetName(param), value);
|
|
return rv;
|
|
}
|
|
AQHREACT_Param_SetDoubleValue(param, valueAsDouble);
|
|
break;
|
|
}
|
|
case AQHREACT_DATAOBJECTTYPE_STRING:
|
|
default:
|
|
AQHREACT_Param_SetStringValue(param, value);
|
|
break;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int _readLinksFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode)
|
|
{
|
|
GWEN_XMLNODE *nGroup;
|
|
|
|
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, "links", NULL, NULL);
|
|
if (nGroup) {
|
|
GWEN_XMLNODE *n;
|
|
|
|
n=GWEN_XMLNode_FindFirstTag(nGroup, "link", NULL, NULL);
|
|
while(n) {
|
|
int rv;
|
|
|
|
rv=_readLinkFromXml(aqh, unit, n);
|
|
if (rv<0) {
|
|
DBG_ERROR(NULL, "Error reading link in net \"%s\" (%d)", AQHREACT_Unit_GetName(unit), rv);
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
n=GWEN_XMLNode_FindNextTag(n, "link", NULL, NULL);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int _readLinkFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *linkNode)
|
|
{
|
|
AQHREACT_UNIT_MODULE *xunit;
|
|
const char *sourceUnitName;
|
|
const char *sourceSlotName;
|
|
const char *targetUnitName;
|
|
const char *targetSlotName;
|
|
AQHREACT_UNIT *sourceUnit;
|
|
AQHREACT_UNIT *targetUnit;
|
|
AQHREACT_INPUT_SLOT *inputSlot;
|
|
AQHREACT_OUTPUT_SLOT *outputSlot;
|
|
AQHREACT_LINK *link;
|
|
|
|
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
|
|
|
sourceUnitName=GWEN_XMLNode_GetProperty(linkNode, "sourceUnit", NULL);
|
|
sourceSlotName=GWEN_XMLNode_GetProperty(linkNode, "sourceSlot", NULL);
|
|
targetUnitName=GWEN_XMLNode_GetProperty(linkNode, "targetUnit", NULL);
|
|
targetSlotName=GWEN_XMLNode_GetProperty(linkNode, "targetSlot", NULL);
|
|
|
|
if (!(sourceUnitName && *sourceUnitName && sourceSlotName && *sourceSlotName &&
|
|
targetUnitName && *targetUnitName && targetSlotName && *targetSlotName)) {
|
|
DBG_ERROR(NULL,
|
|
"Link in net \"%s\" needs properties sourceUnit, sourceSlot, targetUnit and targetSlot",
|
|
AQHREACT_Unit_GetName(unit));
|
|
return GWEN_ERROR_BAD_DATA;
|
|
}
|
|
|
|
sourceUnit=AQHREACT_Unit_List_GetById(xunit->unitList, sourceUnitName);
|
|
if (sourceUnit==NULL)
|
|
sourceUnit=AqHomeReact_FindUnitByNetNameAndUnitId(aqh, NULL, sourceUnitName);
|
|
if (sourceUnit==NULL) {
|
|
DBG_ERROR(NULL, "Source unit \"%s\" not found", sourceUnitName);
|
|
return GWEN_ERROR_NOT_FOUND;
|
|
}
|
|
outputSlot=AQHREACT_Unit_GetOutputSlotByName(sourceUnit, sourceSlotName);
|
|
if (outputSlot==NULL) {
|
|
DBG_ERROR(NULL, "Output slot \"%s\" not found for source unit \"%s\"", sourceSlotName, sourceUnitName);
|
|
return GWEN_ERROR_NOT_FOUND;
|
|
}
|
|
|
|
targetUnit=AQHREACT_Unit_List_GetById(xunit->unitList, targetUnitName);
|
|
if (targetUnit==NULL)
|
|
targetUnit=AqHomeReact_FindUnitByNetNameAndUnitId(aqh, NULL, targetUnitName);
|
|
if (targetUnit==NULL) {
|
|
DBG_ERROR(NULL, "Target unit \"%s\" not found", targetUnitName);
|
|
return GWEN_ERROR_NOT_FOUND;
|
|
}
|
|
inputSlot=AQHREACT_Unit_GetOrCreateUnusedInputSlotByName(targetUnit, targetSlotName);
|
|
if (inputSlot==NULL) {
|
|
DBG_ERROR(NULL, "Input slot \"%s\" not found for target unit \"%s\"", targetSlotName, targetUnitName);
|
|
return GWEN_ERROR_NOT_FOUND;
|
|
}
|
|
|
|
link=AQHREACT_Link_new();
|
|
AQHREACT_Link_SetTargetUnitId(link, targetUnitName);
|
|
AQHREACT_Link_SetTargetUnit(link, targetUnit);
|
|
AQHREACT_Link_SetTargetInputSlotIdForUnit(link, AQHREACT_InputSlot_GetIdForUnit(inputSlot));
|
|
AQHREACT_OutputSlot_AddLink(outputSlot, link);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|