cwFlow.h/cpp: Added ui_net(), _create_class_ui_desc() and set/get_variable_value() in terms of ui_var_t.

This commit is contained in:
kevin 2024-10-12 15:29:39 -04:00
parent 72bd9f189a
commit e5bff5cd9c
2 changed files with 100 additions and 8 deletions

View File

@ -270,6 +270,25 @@ namespace cw
return rc; return rc;
} }
rc_t _create_class_ui_desc( class_desc_t* desc )
{
desc->ui = mem::allocZ<ui_proc_desc_t>();
desc->ui->label = desc->label;
for(class_preset_t* p0 = desc->presetL; p0!=nullptr; p0=p0->link)
desc->ui->presetN += 1;
desc->ui->presetA = mem::allocZ<ui_preset_t>(desc->ui->presetN);
unsigned i=0;
for(class_preset_t* p0 = desc->presetL; i<desc->ui->presetN; ++i,p0=p0->link)
{
desc->ui->presetA[i].label = p0->label;
desc->ui->presetA[i].preset_idx = i;
}
return kOkRC;
}
rc_t _parse_class_cfg(flow_t* p, const object_t* classCfg) rc_t _parse_class_cfg(flow_t* p, const object_t* classCfg)
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
@ -330,6 +349,14 @@ namespace cw
} }
} }
// create the class descripiton
if((rc = _create_class_ui_desc(cd)) != kOkRC )
{
cwLogError(rc,"Class desc UI record create failed on '%s'.",cwStringNullGuard(cd->label));
goto errLabel;
}
// parse the variable dictionary // parse the variable dictionary
if( varD != nullptr ) if( varD != nullptr )
{ {
@ -378,7 +405,6 @@ namespace cw
cd->varDescL = vd; cd->varDescL = vd;
} }
} }
} }
errLabel: errLabel:
@ -693,7 +719,6 @@ namespace cw
} }
return rc; return rc;
} }
void _release_class_desc_array( class_desc_t*& classDescA, unsigned classDescN ) void _release_class_desc_array( class_desc_t*& classDescA, unsigned classDescN )
@ -945,6 +970,13 @@ cw::rc_t cw::flow::initialize( handle_t h,
if( p->init_net_preset_label != nullptr && p->net != nullptr ) if( p->init_net_preset_label != nullptr && p->net != nullptr )
network_apply_preset( *p->net, p->init_net_preset_label ); network_apply_preset( *p->net, p->init_net_preset_label );
// form the UI description
if((rc = create_net_ui_desc(p)) != kOkRC )
{
rc = cwLogError(rc,"UI description formation failed.");
goto errLabel;
}
p->isInRuntimeFl = true; p->isInRuntimeFl = true;
cwLogInfo("Entering runtime."); cwLogInfo("Entering runtime.");
@ -972,6 +1004,22 @@ cw::rc_t cw::flow::destroy( handle_t& hRef )
} }
const cw::flow::ui_net_t* cw::flow::ui_net( handle_t h )
{
flow_t* p = _handleToPtr(h);
if( p->net == nullptr )
{
cwLogError(kInvalidStateRC,"No UI net exists because the no net exists.");
return nullptr;
}
if( p->net->ui_net == nullptr )
return nullptr;
return p->net->ui_net;
}
cw::rc_t cw::flow::exec_cycle( handle_t h ) cw::rc_t cw::flow::exec_cycle( handle_t h )
{ {
rc_t rc = kOkRC;; rc_t rc = kOkRC;;
@ -1053,6 +1101,31 @@ cw::rc_t cw::flow::get_variable_value( handle_t h, const char* inst_label, const
cw::rc_t cw::flow::get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef ) cw::rc_t cw::flow::get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef )
{ return get_variable_value( *_handleToPtr(h)->net, inst_label, var_label, chIdx, valueRef ); } { return get_variable_value( *_handleToPtr(h)->net, inst_label, var_label, chIdx, valueRef ); }
cw::rc_t cw::flow::set_variable_value( handle_t h, const ui_var_t* ui_var, bool value )
{ return set_variable_value( *_handleToPtr(h)->net, ui_var, value ); }
cw::rc_t cw::flow::set_variable_value( handle_t h, const ui_var_t* ui_var, int value )
{ return set_variable_value( *_handleToPtr(h)->net, ui_var, value ); }
cw::rc_t cw::flow::set_variable_value( handle_t h, const ui_var_t* ui_var, unsigned value )
{ return set_variable_value( *_handleToPtr(h)->net, ui_var, value ); }
cw::rc_t cw::flow::set_variable_value( handle_t h, const ui_var_t* ui_var, float value )
{ return set_variable_value( *_handleToPtr(h)->net, ui_var, value ); }
cw::rc_t cw::flow::set_variable_value( handle_t h, const ui_var_t* ui_var, double value )
{ return set_variable_value( *_handleToPtr(h)->net, ui_var, value ); }
cw::rc_t cw::flow::set_variable_value( handle_t h, const ui_var_t* ui_var, const char* value )
{ return set_variable_value( *_handleToPtr(h)->net, ui_var, value ); }
cw::rc_t cw::flow::get_variable_value( handle_t h, const ui_var_t* ui_var, bool& value_ref )
{ return get_variable_value( *_handleToPtr(h)->net, ui_var, value_ref ); }
cw::rc_t cw::flow::get_variable_value( handle_t h, const ui_var_t* ui_var, int& value_ref )
{ return get_variable_value( *_handleToPtr(h)->net, ui_var, value_ref ); }
cw::rc_t cw::flow::get_variable_value( handle_t h, const ui_var_t* ui_var, unsigned& value_ref )
{ return get_variable_value( *_handleToPtr(h)->net, ui_var, value_ref ); }
cw::rc_t cw::flow::get_variable_value( handle_t h, const ui_var_t* ui_var, float& value_ref )
{ return get_variable_value( *_handleToPtr(h)->net, ui_var, value_ref ); }
cw::rc_t cw::flow::get_variable_value( handle_t h, const ui_var_t* ui_var, double& value_ref )
{ return get_variable_value( *_handleToPtr(h)->net, ui_var, value_ref ); }
cw::rc_t cw::flow::get_variable_value( handle_t h, const ui_var_t* ui_var, const char*& value_ref )
{ return get_variable_value( *_handleToPtr(h)->net, ui_var, value_ref ); }
void cw::flow::print_class_list( handle_t h ) void cw::flow::print_class_list( handle_t h )

View File

@ -1,5 +1,5 @@
#ifndef cwFlowSys_h #ifndef cwFlow_h
#define cwFlowSys_h #define cwFlow_h
namespace cw namespace cw
{ {
@ -39,6 +39,9 @@ namespace cw
rc_t destroy( handle_t& hRef ); rc_t destroy( handle_t& hRef );
// The ui_net() is not available until the network has been initialized.
const ui_net_t* ui_net( handle_t h );
// Run one cycle of the network. // Run one cycle of the network.
rc_t exec_cycle( handle_t h ); rc_t exec_cycle( handle_t h );
@ -62,6 +65,22 @@ namespace cw
rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, float& valueRef ); rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, float& valueRef );
rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef ); rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef );
rc_t set_variable_value( handle_t h, const ui_var_t* ui_var, bool value );
rc_t set_variable_value( handle_t h, const ui_var_t* ui_var, int value );
rc_t set_variable_value( handle_t h, const ui_var_t* ui_var, unsigned value );
rc_t set_variable_value( handle_t h, const ui_var_t* ui_var, float value );
rc_t set_variable_value( handle_t h, const ui_var_t* ui_var, double value );
rc_t set_variable_value( handle_t h, const ui_var_t* ui_var, const char* value );
rc_t get_variable_value( handle_t h, const ui_var_t* ui_var, bool& value_ref );
rc_t get_variable_value( handle_t h, const ui_var_t* ui_var, int& value_ref );
rc_t get_variable_value( handle_t h, const ui_var_t* ui_var, unsigned& value_ref );
rc_t get_variable_value( handle_t h, const ui_var_t* ui_var, float& value_ref );
rc_t get_variable_value( handle_t h, const ui_var_t* ui_var, double& value_ref );
rc_t get_variable_value( handle_t h, const ui_var_t* ui_var, const char*& value_ref );
void print_class_list( handle_t h ); void print_class_list( handle_t h );
void print_network( handle_t h ); void print_network( handle_t h );