cwUi.h/cpp : Add queueBlkCnt and queueBlkByteCnt to websock based API's.

Removed websockTimeOutMs from UI cfg. and replace it as an argument to ui::ws::exec().
This commit is contained in:
kevin 2024-03-28 19:47:29 -04:00
parent 60e6c2f772
commit 98ed33d2cc
2 changed files with 100 additions and 81 deletions

121
cwUi.cpp
View File

@ -166,7 +166,7 @@ namespace cw
bucket_t* b = p->hashA + hash_idx;
for(; b!=nullptr; b=b->link)
if( b->ele->appId==appId && b->ele->logical_parent->uuId==parentUuId && (chanId==kInvalidId || b->ele->chanId==chanId) )
if( b->ele != nullptr && b->ele->logical_parent!=nullptr && b->ele->appId==appId && b->ele->logical_parent->uuId==parentUuId && (chanId==kInvalidId || b->ele->chanId==chanId) )
return b->ele->uuId;
}
@ -2249,7 +2249,6 @@ namespace cw
void* cbArg;
uiCallback_t uiCbFunc;
websock::cbFunc_t wsCbFunc;
unsigned wsTimeOutMs;
unsigned idleMsgPeriodMs;
time::spec_t lastRecvMsgTimeStamp;
} ui_ws_t;
@ -2331,13 +2330,18 @@ cw::rc_t cw::ui::ws::parseArgs( const object_t& o, args_t& args, const char* ob
"rcvBufByteN", args.rcvBufByteN,
"xmtBufByteN", args.xmtBufByteN,
"fmtBufByteN", args.fmtBufByteN,
"websockTimeOutMs", args.wsTimeOutMs,
"idleMsgPeriodMs", args.idleMsgPeriodMs,
"queueBlkCnt", args.queueBlkCnt,
"queueBlkByteCnt", args.queueBlkByteCnt,
"uiCfgFn", uiCfgFn )) != kOkRC )
{
rc = cwLogError(rc,"'ui' cfg. parse failed.");
}
if( op->find_child("websockTimeOutMs") != nullptr )
cwLogWarning("The UI parameter 'websockTimeOutMs' is obsolete and ignored.");
// expand the physical root directory
if((physRootDir = filesys::expandPath( args.physRootDir)) == nullptr )
{
@ -2388,11 +2392,12 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
appIdMapN,
wsCbFunc,
args.dfltPageFn,
args.wsTimeOutMs,
args.idleMsgPeriodMs,
args.rcvBufByteN,
args.xmtBufByteN,
args.fmtBufByteN );
args.fmtBufByteN,
args.queueBlkCnt,
args.queueBlkByteCnt);
}
@ -2406,11 +2411,12 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
unsigned appIdMapN,
websock::cbFunc_t wsCbFunc,
const char* dfltPageFn,
unsigned websockTimeOutMs,
unsigned idleMsgPeriodMs,
unsigned rcvBufByteN,
unsigned xmtBufByteN,
unsigned fmtBufByteN )
unsigned fmtBufByteN,
unsigned queueBlkCnt,
unsigned queueBlkByteCnt )
{
rc_t rc = kOkRC;
@ -2430,7 +2436,7 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
void* wsCbA = wsCbFunc==nullptr ? p : cbArg;
// create the websocket
if((rc = websock::create(p->wsH, wsCbF, wsCbA, physRootDir, dfltPageFn, port, protocolA, protocolN )) != kOkRC )
if((rc = websock::create(p->wsH, wsCbF, wsCbA, physRootDir, dfltPageFn, port, protocolA, protocolN, queueBlkCnt, queueBlkByteCnt )) != kOkRC )
{
cwLogError(rc,"UI Websock create failed.");
goto errLabel;
@ -2446,7 +2452,6 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
p->cbArg = cbArg;
p->uiCbFunc = uiCbFunc;
p->wsCbFunc = wsCbFunc;
p->wsTimeOutMs = websockTimeOutMs;
p->idleMsgPeriodMs = idleMsgPeriodMs;
// initialize the last received msg
time::get(p->lastRecvMsgTimeStamp);
@ -2479,13 +2484,13 @@ cw::rc_t cw::ui::ws::destroy( handle_t& h )
return rc;
}
cw::rc_t cw::ui::ws::exec( handle_t h )
cw::rc_t cw::ui::ws::exec( handle_t h, unsigned wsTimeOutMs )
{
rc_t rc = kOkRC;
ui_ws_t* p = _handleToPtr(h);
rc_t rc = kOkRC;
time::spec_t t;
if((rc = websock::exec( p->wsH, p->wsTimeOutMs )) != kOkRC)
if((rc = websock::exec( p->wsH, wsTimeOutMs )) != kOkRC)
cwLogError(rc,"The UI websock execution failed.");
// make the idle callback
@ -2500,6 +2505,7 @@ cw::rc_t cw::ui::ws::exec( handle_t h )
return rc;
}
cw::rc_t cw::ui::ws::onReceive( handle_t h, unsigned protocolId, unsigned sessionId, websock::msgTypeId_t msg_type, const void* msg, unsigned byteN )
{
ui_ws_t* p = _handleToPtr(h);
@ -2521,6 +2527,7 @@ cw::ui::handle_t cw::ui::ws::uiHandle( handle_t h )
return p->uiH;
}
void cw::ui::ws::realTimeReport( handle_t h )
{
ui_ws_t* p = _handleToPtr(h);
@ -2539,6 +2546,7 @@ namespace cw
{
ws::handle_t wsUiH;
thread::handle_t thH;
unsigned wsTimeOutMs;
} ui_ws_srv_t;
ui_ws_srv_t* _handleToPtr(handle_t h )
@ -2563,7 +2571,7 @@ namespace cw
ui_ws_srv_t* p = static_cast<ui_ws_srv_t*>(arg);
rc_t rc;
if((rc = ws::exec(p->wsUiH)) != kOkRC )
if((rc = ws::exec(p->wsUiH,p->wsTimeOutMs)) != kOkRC )
{
cwLogError(rc,"Websocket UI exec failed.");
}
@ -2574,20 +2582,51 @@ namespace cw
}
}
cw::rc_t cw::ui::srv::create( handle_t& h,
const ws::args_t& args,
void* cbArg,
uiCallback_t uiCbFunc,
const appIdMap_t* appIdMapA,
unsigned appIdMapN,
unsigned wsTimeOutMs,
websock::cbFunc_t wsCbFunc )
{
return create(h,
args.port,
args.physRootDir,
cbArg,
uiCbFunc,
args.uiRsrc,
appIdMapA,
appIdMapN,
wsTimeOutMs,
wsCbFunc,
args.dfltPageFn,
args.idleMsgPeriodMs,
args.rcvBufByteN,
args.xmtBufByteN,
args.fmtBufByteN,
args.queueBlkCnt,
args.queueBlkByteCnt );
}
cw::rc_t cw::ui::srv::create( handle_t& h,
unsigned port,
const char* physRootDir,
void* cbArg,
uiCallback_t uiCbFunc,
const object_t* uiRsrc,
const appIdMap_t* appIdMapA,
unsigned appIdMapN,
websock::cbFunc_t wsCbFunc,
const char* dfltPageFn,
unsigned websockTimeOutMs,
unsigned rcvBufByteN,
unsigned xmtBufByteN,
unsigned fmtBufByteN )
unsigned port,
const char* physRootDir,
void* cbArg,
uiCallback_t uiCbFunc,
const object_t* uiRsrc,
const appIdMap_t* appIdMapA,
unsigned appIdMapN,
unsigned wsTimeOutMs,
websock::cbFunc_t wsCbFunc,
const char* dfltPageFn,
unsigned idleMsgPeriodMs,
unsigned rcvBufByteN,
unsigned xmtBufByteN,
unsigned fmtBufByteN,
unsigned queueBlkCnt,
unsigned queueBlkByteCnt )
{
rc_t rc = kOkRC;
if((rc = destroy(h)) != kOkRC )
@ -2595,7 +2634,7 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
ui_ws_srv_t* p = mem::allocZ<ui_ws_srv_t>();
if((rc = ws::create(p->wsUiH, port, physRootDir, cbArg, uiCbFunc, uiRsrc,appIdMapA, appIdMapN, wsCbFunc, dfltPageFn, websockTimeOutMs, rcvBufByteN, xmtBufByteN, fmtBufByteN )) != kOkRC )
if((rc = ws::create(p->wsUiH, port, physRootDir, cbArg, uiCbFunc, uiRsrc,appIdMapA, appIdMapN, wsCbFunc, dfltPageFn, idleMsgPeriodMs, rcvBufByteN, xmtBufByteN, fmtBufByteN, queueBlkCnt, queueBlkByteCnt )) != kOkRC )
{
cwLogError(rc,"The websock UI creationg failed.");
goto errLabel;
@ -2607,6 +2646,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
goto errLabel;
}
p->wsTimeOutMs = wsTimeOutMs;
h.set(p);
errLabel:
@ -2616,32 +2657,6 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
return rc;
}
cw::rc_t cw::ui::srv::create( handle_t& h,
const ws::args_t& args,
void* cbArg,
uiCallback_t uiCbFunc,
const appIdMap_t* appIdMapA,
unsigned appIdMapN,
websock::cbFunc_t wsCbFunc )
{
return create(h,
args.port,
args.physRootDir,
cbArg,
uiCbFunc,
args.uiRsrc,
appIdMapA,
appIdMapN,
wsCbFunc,
args.dfltPageFn,
args.wsTimeOutMs,
args.rcvBufByteN,
args.xmtBufByteN,
args.fmtBufByteN );
}
cw::rc_t cw::ui::srv::destroy( handle_t& h )
{
rc_t rc = kOkRC;

58
cwUi.h
View File

@ -188,8 +188,9 @@ namespace cw
unsigned rcvBufByteN;
unsigned xmtBufByteN;
unsigned fmtBufByteN;
unsigned wsTimeOutMs;
unsigned idleMsgPeriodMs; // min period without messages before an idle message is generated
unsigned queueBlkCnt;
unsigned queueBlkByteCnt;
} args_t;
rc_t parseArgs( const object_t& o, args_t& args, const char* object_label="ui" );
@ -214,20 +215,20 @@ namespace cw
unsigned appIdMapN = 0,
websock::cbFunc_t wsCbFunc = nullptr,
const char* dfltPageFn = "index.html",
unsigned websockTimeOutMs = 50,
unsigned idleMsgPeriodMs = 50,
unsigned rcvBufByteN = 1024,
unsigned xmtBufByteN = 1024,
unsigned fmtBufByteN = 4096
);
unsigned fmtBufByteN = 4096,
unsigned queueBlkCnt = 4,
unsigned queueBlkByteCnt = 4096 );
rc_t destroy( handle_t& h );
// This function should be called periodically to send and receive
// queued messages to and from the websocket.
// Note that this call may block for up to 'wsTimeOutMs' milliseconds
// on the websocket handle.
rc_t exec( handle_t h );
// while waiting for incoming websocket messages.
rc_t exec( handle_t h, unsigned wsTimeOutMs );
// This function executes the internal default websock callback function.
// It is useful if the user provides a custom websock callback function
@ -236,8 +237,7 @@ namespace cw
websock::handle_t websockHandle( handle_t h );
ui::handle_t uiHandle( handle_t h );
void realTimeReport( handle_t h );
void realTimeReport( handle_t h );
}
@ -247,27 +247,31 @@ namespace cw
typedef handle<struct ui_ws_srv_str> handle_t;
rc_t create( handle_t& h,
const ws::args_t& args,
void* cbArg,
uiCallback_t uiCbFunc,
const appIdMap_t* appIdMapA = nullptr,
unsigned appIdMapN = 0,
websock::cbFunc_t wsCbFunc = nullptr );
const ws::args_t& args,
void* cbArg,
uiCallback_t uiCbFunc,
const appIdMap_t* appIdMapA = nullptr,
unsigned appIdMapN = 0,
unsigned wsTimeOutMs = 50,
websock::cbFunc_t wsCbFunc = nullptr );
rc_t create( handle_t& h,
unsigned port,
const char* physRootDir,
void* cbArg,
uiCallback_t uiCbFunc,
const object_t* uiRsrc = nullptr,
const appIdMap_t* appIdMapA = nullptr,
unsigned appIdMapN = 0,
websock::cbFunc_t wsCbFunc = nullptr,
const char* dfltPageFn = "index.html",
unsigned websockTimeOutMs = 50,
unsigned rcvBufByteN = 1024,
unsigned xmtBufByteN = 1024,
unsigned fmtBufByteN = 4096 );
unsigned port,
const char* physRootDir,
void* cbArg,
uiCallback_t uiCbFunc,
const object_t* uiRsrc = nullptr,
const appIdMap_t* appIdMapA = nullptr,
unsigned appIdMapN = 0,
unsigned wsTimeOutMs = 50,
websock::cbFunc_t wsCbFunc = nullptr,
const char* dfltPageFn = "index.html",
unsigned idleMsgPeriodMs = 50,
unsigned rcvBufByteN = 1024,
unsigned xmtBufByteN = 1024,
unsigned fmtBufByteN = 4096,
unsigned queueBlkCnt = 4,
unsigned queueBlkByteCnt = 4096 );
rc_t destroy( handle_t& h );