From 6ed0f6c0803099dbf2894f3a8e0d61f4d2c8ce18 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 6 Jan 2024 08:44:53 -0500 Subject: [PATCH] cwUi.h/cpp : Added sendMsg(). eleA[] now doubles in size with each reallocation. --- cwUi.cpp | 30 ++++++++++++++++++------------ cwUi.h | 3 +++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cwUi.cpp b/cwUi.cpp index d790d05..8045e59 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -305,17 +305,16 @@ namespace cw { if( appId == kRootAppId ) return kRootUuId; - + for(unsigned i=0; ieleN; ++i) - if( p->eleA[i]!=nullptr && p->eleA[i]->logical_parent != nullptr ) //skip the root + if( p->eleA[i] != nullptr + && p->eleA[i]->appId == appId + && ( parentUuId == kInvalidId || (p->eleA[i]->logical_parent!=nullptr && p->eleA[i]->logical_parent->uuId == parentUuId) ) + && ( chanId == kInvalidId || p->eleA[i]->chanId == chanId ) ) { - if( ( parentUuId == kInvalidId || p->eleA[i]->logical_parent->uuId == parentUuId ) && - ( chanId == kInvalidId || p->eleA[i]->chanId == chanId ) && - p->eleA[i]->appId == appId ) - { - return p->eleA[i]->uuId; - } + return p->eleA[i]->uuId; } + return kInvalidId; } @@ -608,7 +607,7 @@ namespace cw // if there are no available slots if( avail_ele_idx == p->eleAllocN ) { - p->eleAllocN += 128; + p->eleAllocN *= 2; p->eleA = mem::resizeZ(p->eleA,p->eleAllocN); } @@ -1268,7 +1267,7 @@ cw::rc_t cw::ui::create( ui_t* p = mem::allocZ(); - p->eleAllocN = 128; + p->eleAllocN = 1024; p->eleA = mem::allocZ( p->eleAllocN ); p->eleN = 0; p->uiCbFunc = uiCbFunc; @@ -2103,6 +2102,12 @@ cw::rc_t cw::ui::sendValueString( handle_t h, unsigned uuId, const char* value ) //return _sendValue(p,kInvalidId,uuId,"\"%s\"",value,"value",strlen(value)+10); } +cw::rc_t cw::ui::sendMsg( handle_t h, const char* msg ) +{ + ui_t* p = _handleToPtr(h); + return _websockSend(p,kInvalidId,msg); +} + void cw::ui::report( handle_t h ) { ui_t* p = _handleToPtr(h); @@ -2198,8 +2203,9 @@ namespace cw rc_t _webSockSend( void* cbArg, unsigned wsSessId, const void* msg, unsigned msgByteN ) { - ui_ws_t* p = static_cast(cbArg); - return websock::send( p->wsH, kUiProtocolId, wsSessId, msg, msgByteN ); + //ui_ws_t* p = static_cast(cbArg); + //return websock::send( p->wsH, kUiProtocolId, wsSessId, msg, msgByteN ); + return kOkRC; } } diff --git a/cwUi.h b/cwUi.h index 4198109..7bbf535 100644 --- a/cwUi.h +++ b/cwUi.h @@ -169,6 +169,7 @@ namespace cw rc_t sendValueDouble( handle_t h, unsigned uuId, double value ); rc_t sendValueString( handle_t h, unsigned uuId, const char* value ); + rc_t sendMsg( handle_t h, const char* msg ); void report( handle_t h ); void realTimeReport( handle_t h ); @@ -224,6 +225,8 @@ namespace cw // 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 ); // This function executes the internal default websock callback function.