From d5f75f961c6e67e986c4c15d7b9c1225538b520e Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 28 Mar 2024 19:48:46 -0400 Subject: [PATCH] Added 'timeOutMs' arg. to all calls to ui::ws::exec(). --- cwIo.cpp | 8 +++++--- cwIo.h | 7 ++++--- cwIoAudioMidi.cpp | 12 ++++++++++-- cwIoAudioMidiApp.cpp | 12 ++++++++++-- cwIoMinTest.cpp | 12 ++++++++++-- cwIoPresetSelApp.cpp | 46 +++++++++++++++++++++++++++++--------------- cwIoTest.cpp | 12 ++++++++++-- cwUiTest.cpp | 7 ++++--- cwWebSockSvr.cpp | 10 +++++++--- cwWebSockSvr.h | 4 +++- 10 files changed, 94 insertions(+), 36 deletions(-) diff --git a/cwIo.cpp b/cwIo.cpp index c00f79a..5a0ebc5 100644 --- a/cwIo.cpp +++ b/cwIo.cpp @@ -2439,7 +2439,8 @@ cw::rc_t cw::io::stop( handle_t h ) 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; io_t* p = _handleToPtr(h); @@ -2447,8 +2448,9 @@ cw::rc_t cw::io::exec( handle_t h, void* execCbArg ) if( p->wsUiH.isValid() ) { ui::flushCache( ui::ws::uiHandle( p->wsUiH )); + // 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); @@ -2490,7 +2492,7 @@ void cw::io::report( handle_t h ) } for(unsigned i=0; ibeg_play_loc, "end_play_loc", app->end_play_loc, "dflt_perf_label", app->dflt_perf_label, + "run_dur_secs", app->run_dur_secs, "live_mode_fl", app->useLiveMidiFl, "enable_recording_fl", app->enableRecordFl, "midi_record_dir", midi_record_dir, @@ -553,8 +555,8 @@ namespace cw { app_t* app = (app_t*)arg; unsigned logUuId = uiFindElementUuId( app->ioH, kLogId); - - uiSetLogLine( app->ioH, logUuId, text ); + + //uiSetLogLine( app->ioH, logUuId, text ); log::defaultOutput(nullptr,level,text); } @@ -711,6 +713,7 @@ namespace cw char* perf_fname = nullptr; char* meta_fname = nullptr; bool skip_fl = false; + // create the performance recording file path if((perf_fname = filesys::makeFn(dir,fname,nullptr,recording_folder,nullptr)) == nullptr ) { @@ -782,8 +785,11 @@ namespace cw mem::release(meta_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 ) @@ -1813,7 +1819,7 @@ namespace cw errLabel: 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; } @@ -1900,7 +1906,7 @@ namespace cw // read the preset data file 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; } @@ -3019,7 +3025,7 @@ rc_t _on_ui_play_loc(app_t* app, unsigned appId, unsigned loc); break; case kIoReportBtnId: - io::report( app->ioH ); + io::realTimeReport( app->ioH ); break; 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; ui::appIdMap_t bigMap[ bigMapN ]; double sysSampleRate = 0; + time::spec_t start_time = time::current_time(); for(unsigned i=0; i 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 diff --git a/cwIoTest.cpp b/cwIoTest.cpp index 298736b..94c27ed 100644 --- a/cwIoTest.cpp +++ b/cwIoTest.cpp @@ -308,8 +308,16 @@ cw::rc_t cw::io::test( const object_t* cfg ) // execuite the io framework while( !isShuttingDown(app.ioH)) { - exec(app.ioH); - sleepMs(50); + const unsigned wsTimeOutMs = 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: diff --git a/cwUiTest.cpp b/cwUiTest.cpp index cefc571..48054b9 100644 --- a/cwUiTest.cpp +++ b/cwUiTest.cpp @@ -378,8 +378,9 @@ namespace cw cw::rc_t cw::ui::test( const object_t* cfg ) { - rc_t rc = kOkRC; - ui::ws::args_t args = {}; + rc_t rc = kOkRC; + unsigned wsTimeOutMs = 50; + ui::ws::args_t args = {}; // Application Id's for the resource based UI elements. 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"; // 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; if((rc = uiTestCreateUi( app )) != kOkRC ) diff --git a/cwWebSockSvr.cpp b/cwWebSockSvr.cpp index e55dbc4..9c083c8 100644 --- a/cwWebSockSvr.cpp +++ b/cwWebSockSvr.cpp @@ -56,7 +56,9 @@ cw::rc_t cw::websockSrv::create( int port, const websock::protocol_t* protocolA, unsigned protocolN, - unsigned timeOutMs ) + unsigned timeOutMs, + unsigned queueBlkCnt, + unsigned queueBlkByteCnt ) { rc_t rc; if((rc = destroy(h)) != kOkRC ) @@ -64,7 +66,7 @@ cw::rc_t cw::websockSrv::create( websockSrv_t* p = mem::allocZ(); - 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; @@ -176,6 +178,8 @@ cw::rc_t cw::websockSrvTest( const object_t* cfg ) int port = 5687; unsigned rcvBufByteN = 128; unsigned xmtBufByteN = 128; + unsigned queueBlkCnt = 3; + unsigned queueBlkByteCnt= 4096; appCtx_t appCtx; enum @@ -198,7 +202,7 @@ cw::rc_t cw::websockSrvTest( const object_t* cfg ) 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; appCtx.wsH = websockSrv::websockHandle(h); diff --git a/cwWebSockSvr.h b/cwWebSockSvr.h index fdab325..2be27e4 100644 --- a/cwWebSockSvr.h +++ b/cwWebSockSvr.h @@ -16,7 +16,9 @@ namespace cw { int port, const websock::protocol_t* protocolA, unsigned protocolN, - unsigned websockTimeOutMs ); + unsigned websockTimeOutMs, + unsigned queueBlkCnt, + unsigned queueBlkByteCnt); rc_t destroy( handle_t& h );