Added 'timeOutMs' arg. to all calls to ui::ws::exec().

This commit is contained in:
kevin 2024-03-28 19:48:46 -04:00
parent 98ed33d2cc
commit d5f75f961c
10 changed files with 94 additions and 36 deletions

View File

@ -2439,7 +2439,8 @@ cw::rc_t cw::io::stop( handle_t h )
return rc; return rc;
} }
cw::rc_t cw::io::exec( handle_t h, void* execCbArg )
cw::rc_t cw::io::exec( handle_t h, unsigned timeOutMs, void* execCbArg )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
io_t* p = _handleToPtr(h); io_t* p = _handleToPtr(h);
@ -2447,8 +2448,9 @@ cw::rc_t cw::io::exec( handle_t h, void* execCbArg )
if( p->wsUiH.isValid() ) if( p->wsUiH.isValid() )
{ {
ui::flushCache( ui::ws::uiHandle( p->wsUiH )); ui::flushCache( ui::ws::uiHandle( p->wsUiH ));
// Note this call blocks on the websocket handle: See cwUi.h:ws:exec() // Note this call blocks on the websocket handle: See cwUi.h:ws:exec()
rc = ui::ws::exec( p->wsUiH ); rc = ui::ws::exec( p->wsUiH, timeOutMs );
} }
time::get(p->t0); time::get(p->t0);
@ -2490,7 +2492,7 @@ void cw::io::report( handle_t h )
} }
for(unsigned i=0; i<audioDeviceCount(h); ++i) for(unsigned i=0; i<audioDeviceCount(h); ++i)
printf("audio: %s\n", audioDeviceName(h,i)); printf("audio: %s\n", cwStringNullGuard(audioDeviceName(h,i)));
} }
void cw::io::realTimeReport( handle_t h ) void cw::io::realTimeReport( handle_t h )

7
cwIo.h
View File

@ -164,10 +164,11 @@ namespace cw
rc_t start( handle_t h ); rc_t start( handle_t h );
rc_t pause( handle_t h ); rc_t pause( handle_t h );
rc_t stop( handle_t h ); rc_t stop( handle_t h );
// Note that this call blocks on the the UI websocket handle.
// Note that this call blocks on the the UI websocket handle for up to 'timeOutMs'.
// See ui:ws:exec(). // See ui:ws:exec().
rc_t exec( handle_t h, void* execCbArg=nullptr ); rc_t exec( handle_t h, unsigned timeOutMs, void* execCbArg=nullptr );
bool isShuttingDown( handle_t h ); bool isShuttingDown( handle_t h );
void report( handle_t h ); void report( handle_t h );

View File

@ -1024,8 +1024,16 @@ cw::rc_t cw::io::audio_midi::main( const object_t* cfg )
// execute the io framework // execute the io framework
while( !isShuttingDown(app.ioH)) while( !isShuttingDown(app.ioH))
{ {
exec(app.ioH); const unsigned wsTimeOutMs = 50;
sleepMs(50); time::spec_t t0 = time::current_time();
exec(app.ioH,wsTimeOutMs);
time::spec_t t1 = time::current_time();
unsigned dMs = time::elapsedMs(t0,t1);
if( dMs < wsTimeOutMs )
sleepMs(wsTimeOutMs-dMs);
} }
errLabel: errLabel:

View File

@ -580,8 +580,16 @@ cw::rc_t cw::audio_midi_app::main( const object_t* cfg )
// execute the io framework // execute the io framework
while( !isShuttingDown(app.ioH)) while( !isShuttingDown(app.ioH))
{ {
exec(app.ioH); const unsigned wsTimeOutMs = 50;
sleepMs(50); time::spec_t t0 = time::current_time();
exec(app.ioH,wsTimeOutMs);
time::spec_t t1 = time::current_time();
unsigned dMs = time::elapsedMs(t0,t1);
if( dMs < wsTimeOutMs )
sleepMs(wsTimeOutMs-dMs);
} }
errLabel: errLabel:

View File

@ -118,8 +118,16 @@ cw::rc_t cw::min_test( const object_t* cfg )
// execuite the io framework // execuite the io framework
while( !isShuttingDown(app.ioH)) while( !isShuttingDown(app.ioH))
{ {
exec(app.ioH); const unsigned wsTimeOutMs = 50;
sleepMs(500); time::spec_t t0 = time::current_time();
exec(app.ioH,wsTimeOutMs);
time::spec_t t1 = time::current_time();
unsigned dMs = time::elapsedMs(t0,t1);
if( dMs < wsTimeOutMs )
sleepMs(wsTimeOutMs-dMs);
if( isKeyWaiting() ) if( isKeyWaiting() )
break; break;

View File

@ -372,6 +372,7 @@ namespace cw
const char* dflt_perf_label; const char* dflt_perf_label;
unsigned dflt_perf_app_id; unsigned dflt_perf_app_id;
unsigned run_dur_secs;
} app_t; } app_t;
@ -446,6 +447,7 @@ namespace cw
"beg_play_loc", app->beg_play_loc, "beg_play_loc", app->beg_play_loc,
"end_play_loc", app->end_play_loc, "end_play_loc", app->end_play_loc,
"dflt_perf_label", app->dflt_perf_label, "dflt_perf_label", app->dflt_perf_label,
"run_dur_secs", app->run_dur_secs,
"live_mode_fl", app->useLiveMidiFl, "live_mode_fl", app->useLiveMidiFl,
"enable_recording_fl", app->enableRecordFl, "enable_recording_fl", app->enableRecordFl,
"midi_record_dir", midi_record_dir, "midi_record_dir", midi_record_dir,
@ -553,8 +555,8 @@ namespace cw
{ {
app_t* app = (app_t*)arg; app_t* app = (app_t*)arg;
unsigned logUuId = uiFindElementUuId( app->ioH, kLogId); unsigned logUuId = uiFindElementUuId( app->ioH, kLogId);
uiSetLogLine( app->ioH, logUuId, text ); //uiSetLogLine( app->ioH, logUuId, text );
log::defaultOutput(nullptr,level,text); log::defaultOutput(nullptr,level,text);
} }
@ -711,6 +713,7 @@ namespace cw
char* perf_fname = nullptr; char* perf_fname = nullptr;
char* meta_fname = nullptr; char* meta_fname = nullptr;
bool skip_fl = false; bool skip_fl = false;
// create the performance recording file path // create the performance recording file path
if((perf_fname = filesys::makeFn(dir,fname,nullptr,recording_folder,nullptr)) == nullptr ) if((perf_fname = filesys::makeFn(dir,fname,nullptr,recording_folder,nullptr)) == nullptr )
{ {
@ -782,8 +785,11 @@ namespace cw
mem::release(meta_fname); mem::release(meta_fname);
mem::release(perf_fname); mem::release(perf_fname);
return rc;
if( meta_cfg != nullptr )
meta_cfg->free();
return rc;
} }
rc_t _parse_perf_recording_dir( app_t* app, const char* dir, const char* fname, const object_t* velTblCfg ) rc_t _parse_perf_recording_dir( app_t* app, const char* dir, const char* fname, const object_t* velTblCfg )
@ -1813,7 +1819,7 @@ namespace cw
errLabel: errLabel:
if(rc != kOkRC ) if(rc != kOkRC )
rc = cwLogError(rc,"Preset control index '%i' create failed."); rc = cwLogError(rc,"Preset control index '%i' create failed.", preset_idx);
return rc; return rc;
} }
@ -1900,7 +1906,7 @@ namespace cw
// read the preset data file // read the preset data file
if((rc = preset_sel::read( app->psH, fn)) != kOkRC ) if((rc = preset_sel::read( app->psH, fn)) != kOkRC )
{ {
rc = cwLogError(rc,"File write failed on preset select."); rc = cwLogError(rc,"File read failed on preset select.");
goto errLabel; goto errLabel;
} }
@ -3019,7 +3025,7 @@ rc_t _on_ui_play_loc(app_t* app, unsigned appId, unsigned loc);
break; break;
case kIoReportBtnId: case kIoReportBtnId:
io::report( app->ioH ); io::realTimeReport( app->ioH );
break; break;
case kNetPrintBtnId: case kNetPrintBtnId:
@ -3586,6 +3592,7 @@ cw::rc_t cw::preset_sel_app::main( const object_t* cfg, int argc, const char* ar
unsigned bigMapN = mapN + vtMapN; unsigned bigMapN = mapN + vtMapN;
ui::appIdMap_t bigMap[ bigMapN ]; ui::appIdMap_t bigMap[ bigMapN ];
double sysSampleRate = 0; double sysSampleRate = 0;
time::spec_t start_time = time::current_time();
for(unsigned i=0; i<mapN; ++i) for(unsigned i=0; i<mapN; ++i)
bigMap[i] = mapA[i]; bigMap[i] = mapA[i];
@ -3709,18 +3716,27 @@ cw::rc_t cw::preset_sel_app::main( const object_t* cfg, int argc, const char* ar
// execute the io framework // execute the io framework
while( !io::isShuttingDown(app.ioH)) while( !io::isShuttingDown(app.ioH))
{ {
//time::spec_t t0; const unsigned wsTimeOutMs = 50;
//time::get(t0); time::spec_t t0 = time::current_time();
unsigned timeOutMs = app.psNextFrag != nullptr ? 0 : wsTimeOutMs;
// This call may block on the websocket handle. // This call may block on the websocket handle.
io::exec(app.ioH); io::exec(app.ioH,timeOutMs);
//unsigned dMs = time::elapsedMs(t0);
//if( dMs < 50 && app.psNextFrag == nullptr )
//{
// sleepMs( 50-dMs );
//}
time::spec_t t1 = time::current_time();
unsigned dMs = time::elapsedMs(t0,t1);
if( dMs < wsTimeOutMs && app.psNextFrag == nullptr )
{
sleepMs( wsTimeOutMs-dMs );
}
if( app.run_dur_secs != 0 && time::elapsedMs( start_time )/1000 > app.run_dur_secs )
{
printf("Run duration expired (%i secs). Shutting down.\n",app.run_dur_secs);
io::stop(app.ioH);
}
} }
// stop the io framework // stop the io framework

View File

@ -308,8 +308,16 @@ cw::rc_t cw::io::test( const object_t* cfg )
// execuite the io framework // execuite the io framework
while( !isShuttingDown(app.ioH)) while( !isShuttingDown(app.ioH))
{ {
exec(app.ioH); const unsigned wsTimeOutMs = 50;
sleepMs(50); time::spec_t t0 = time::current_time();
exec(app.ioH,wsTimeOutMs);
time::spec_t t1 = time::current_time();
unsigned dMs = time::elapsedMs(t0,t1);
if( dMs < wsTimeOutMs )
sleepMs(wsTimeOutMs-dMs);
} }
errLabel: errLabel:

View File

@ -378,8 +378,9 @@ namespace cw
cw::rc_t cw::ui::test( const object_t* cfg ) cw::rc_t cw::ui::test( const object_t* cfg )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
ui::ws::args_t args = {}; unsigned wsTimeOutMs = 50;
ui::ws::args_t args = {};
// Application Id's for the resource based UI elements. // Application Id's for the resource based UI elements.
appIdMap_t mapA[] = appIdMap_t mapA[] =
@ -437,7 +438,7 @@ cw::rc_t cw::ui::test( const object_t* cfg )
//app->uiCfgFn = "/home/kevin/src/cwtest/src/libcw/html/uiTest/ui.cfg"; //app->uiCfgFn = "/home/kevin/src/cwtest/src/libcw/html/uiTest/ui.cfg";
// create the UI server // create the UI server
if((rc = srv::create(app->wsUiSrvH, args, app, _uiTestCallback, mapA, mapN, nullptr )) != kOkRC ) if((rc = srv::create(app->wsUiSrvH, args, app, _uiTestCallback, mapA, mapN, wsTimeOutMs, nullptr )) != kOkRC )
return rc; return rc;
if((rc = uiTestCreateUi( app )) != kOkRC ) if((rc = uiTestCreateUi( app )) != kOkRC )

View File

@ -56,7 +56,9 @@ cw::rc_t cw::websockSrv::create(
int port, int port,
const websock::protocol_t* protocolA, const websock::protocol_t* protocolA,
unsigned protocolN, unsigned protocolN,
unsigned timeOutMs ) unsigned timeOutMs,
unsigned queueBlkCnt,
unsigned queueBlkByteCnt )
{ {
rc_t rc; rc_t rc;
if((rc = destroy(h)) != kOkRC ) if((rc = destroy(h)) != kOkRC )
@ -64,7 +66,7 @@ cw::rc_t cw::websockSrv::create(
websockSrv_t* p = mem::allocZ<websockSrv_t>(); websockSrv_t* p = mem::allocZ<websockSrv_t>();
if((rc = websock::create( p->_websockH, cbFunc, cbArg, physRootDir, dfltHtmlPageFn, port, protocolA, protocolN )) != kOkRC ) if((rc = websock::create( p->_websockH, cbFunc, cbArg, physRootDir, dfltHtmlPageFn, port, protocolA, protocolN, queueBlkCnt, queueBlkByteCnt )) != kOkRC )
goto errLabel; goto errLabel;
@ -176,6 +178,8 @@ cw::rc_t cw::websockSrvTest( const object_t* cfg )
int port = 5687; int port = 5687;
unsigned rcvBufByteN = 128; unsigned rcvBufByteN = 128;
unsigned xmtBufByteN = 128; unsigned xmtBufByteN = 128;
unsigned queueBlkCnt = 3;
unsigned queueBlkByteCnt= 4096;
appCtx_t appCtx; appCtx_t appCtx;
enum enum
@ -198,7 +202,7 @@ cw::rc_t cw::websockSrvTest( const object_t* cfg )
unsigned protocolN = sizeof(protocolA)/sizeof(protocolA[0]); unsigned protocolN = sizeof(protocolA)/sizeof(protocolA[0]);
if((rc = websockSrv::create( h, websockCb, &appCtx, physRootDir, dfltHtmlPageFn, port, protocolA, protocolN, timeOutMs )) != kOkRC ) if((rc = websockSrv::create( h, websockCb, &appCtx, physRootDir, dfltHtmlPageFn, port, protocolA, protocolN, timeOutMs, queueBlkCnt, queueBlkByteCnt )) != kOkRC )
return rc; return rc;
appCtx.wsH = websockSrv::websockHandle(h); appCtx.wsH = websockSrv::websockHandle(h);

View File

@ -16,7 +16,9 @@ namespace cw {
int port, int port,
const websock::protocol_t* protocolA, const websock::protocol_t* protocolA,
unsigned protocolN, unsigned protocolN,
unsigned websockTimeOutMs ); unsigned websockTimeOutMs,
unsigned queueBlkCnt,
unsigned queueBlkByteCnt);
rc_t destroy( handle_t& h ); rc_t destroy( handle_t& h );