From 0ee52ddb9727565c6efb0bcbe8be0a5305c5691c Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 8 Jul 2024 16:57:47 -0400 Subject: [PATCH] cwFlowTypes.h/cpp, cwFlowNet.cpp : Implemented network global blob store and retreive. --- cwFlowNet.cpp | 10 ++++++++++ cwFlowTypes.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ cwFlowTypes.h | 20 ++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/cwFlowNet.cpp b/cwFlowNet.cpp index 1e3d3a0..47025bd 100644 --- a/cwFlowNet.cpp +++ b/cwFlowNet.cpp @@ -139,6 +139,16 @@ namespace cw mem::release(net.preset_pairA); net.preset_pairN = 0; + + net_global_var_t* gv=net.globalVarL; + while( gv != nullptr ) + { + net_global_var_t* gv0 = gv->link; + mem::release(gv->var_label); + mem::release(gv->blob); + mem::release(gv); + gv = gv0; + } return rc; } diff --git a/cwFlowTypes.cpp b/cwFlowTypes.cpp index 2edba0b..4609220 100644 --- a/cwFlowTypes.cpp +++ b/cwFlowTypes.cpp @@ -1620,6 +1620,51 @@ void cw::flow::network_print( const network_t& net ) } } +void* cw::flow::network_global_var( proc_t* proc, const char* var_label ) +{ + net_global_var_t* gv; + + assert( proc->net != nullptr ); + + for(gv=proc->net->globalVarL; gv!=nullptr; gv=gv->link ) + if( textIsEqual(proc->class_desc->label,gv->class_label) && textIsEqual(gv->var_label,var_label) ) + return gv->blob; + + return nullptr; +} + +cw::rc_t cw::flow::network_global_var_alloc( proc_t* proc, const char* var_label, const void* blob, unsigned blobByteN ) +{ + rc_t rc = kOkRC; + net_global_var_t* gv; + void* v; + + unsigned allocWordN = 0; + + if((v = network_global_var(proc,var_label)) != nullptr ) + { + rc = cwLogError(kInvalidArgRC,"The global variable '%s:%s' already exists.",cwStringNullGuard(proc->class_desc->label),cwStringNullGuard(var_label)); + goto errLabel; + } + + gv = mem::allocZ(); + + allocWordN = std::max(blobByteN/sizeof(unsigned),1ul); + + gv->class_label = proc->class_desc->label; + gv->var_label = mem::duplStr(var_label); + gv->blob = mem::allocZ(allocWordN); + gv->blobByteN = blobByteN; + memcpy(gv->blob,blob,blobByteN); + + gv->link = proc->net->globalVarL; + proc->net->globalVarL = gv; + +errLabel: + return rc; +} + + const cw::flow::network_preset_t* cw::flow::network_preset_from_label( const network_t& net, const char* preset_label ) { for(unsigned i=0; i