cwFlowTypes.h/cpp, cwFlowNet.cpp : Implemented network global blob store and retreive.

This commit is contained in:
kevin 2024-07-08 16:57:47 -04:00
parent 065ff3f555
commit 0ee52ddb97
3 changed files with 75 additions and 0 deletions

View File

@ -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;
}

View File

@ -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<net_global_var_t>();
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<unsigned>(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<net.presetN; ++i)

View File

@ -306,6 +306,17 @@ namespace cw
const value_t* value; //
} network_preset_pair_t;
typedef struct net_global_var_str
{
const char* class_label;
char* var_label;
void* blob;
unsigned blobByteN;
struct net_global_var_str* link;
} net_global_var_t;
typedef struct network_str
{
const object_t* procsCfg; // network proc list
@ -324,6 +335,7 @@ namespace cw
network_preset_pair_t* preset_pairA;
unsigned preset_pairN;
net_global_var_t* globalVarL;
} network_t;
@ -435,6 +447,14 @@ namespace cw
//
// Network
//
// Access a blob stored via network_global_var()
void* network_global_var( proc_t* proc, const char* var_label );
// Copy a named blob into the network global variable space.
rc_t network_global_var_alloc( proc_t* proc, const char* var_label, const void* blob, unsigned blobByteN );
void network_print(const network_t& net );
const network_preset_t* network_preset_from_label( const network_t& net, const char* preset_label );