cwUi.h/cpp : Added sendMsg(). eleA[] now doubles in size with each reallocation.

This commit is contained in:
kevin 2024-01-06 08:44:53 -05:00
parent c7cbb5f62f
commit 6ed0f6c080
2 changed files with 21 additions and 12 deletions

View File

@ -307,15 +307,14 @@ namespace cw
return kRootUuId; return kRootUuId;
for(unsigned i=0; i<p->eleN; ++i) for(unsigned i=0; i<p->eleN; ++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 ) && return p->eleA[i]->uuId;
( chanId == kInvalidId || p->eleA[i]->chanId == chanId ) &&
p->eleA[i]->appId == appId )
{
return p->eleA[i]->uuId;
}
} }
return kInvalidId; return kInvalidId;
} }
@ -608,7 +607,7 @@ namespace cw
// if there are no available slots // if there are no available slots
if( avail_ele_idx == p->eleAllocN ) if( avail_ele_idx == p->eleAllocN )
{ {
p->eleAllocN += 128; p->eleAllocN *= 2;
p->eleA = mem::resizeZ<ele_t*>(p->eleA,p->eleAllocN); p->eleA = mem::resizeZ<ele_t*>(p->eleA,p->eleAllocN);
} }
@ -1268,7 +1267,7 @@ cw::rc_t cw::ui::create(
ui_t* p = mem::allocZ<ui_t>(); ui_t* p = mem::allocZ<ui_t>();
p->eleAllocN = 128; p->eleAllocN = 1024;
p->eleA = mem::allocZ<ele_t*>( p->eleAllocN ); p->eleA = mem::allocZ<ele_t*>( p->eleAllocN );
p->eleN = 0; p->eleN = 0;
p->uiCbFunc = uiCbFunc; p->uiCbFunc = uiCbFunc;
@ -2103,6 +2102,12 @@ cw::rc_t cw::ui::sendValueString( handle_t h, unsigned uuId, const char* value )
//return _sendValue<const char*>(p,kInvalidId,uuId,"\"%s\"",value,"value",strlen(value)+10); //return _sendValue<const char*>(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 ) void cw::ui::report( handle_t h )
{ {
ui_t* p = _handleToPtr(h); ui_t* p = _handleToPtr(h);
@ -2198,8 +2203,9 @@ namespace cw
rc_t _webSockSend( void* cbArg, unsigned wsSessId, const void* msg, unsigned msgByteN ) rc_t _webSockSend( void* cbArg, unsigned wsSessId, const void* msg, unsigned msgByteN )
{ {
ui_ws_t* p = static_cast<ui_ws_t*>(cbArg); //ui_ws_t* p = static_cast<ui_ws_t*>(cbArg);
return websock::send( p->wsH, kUiProtocolId, wsSessId, msg, msgByteN ); //return websock::send( p->wsH, kUiProtocolId, wsSessId, msg, msgByteN );
return kOkRC;
} }
} }

3
cwUi.h
View File

@ -169,6 +169,7 @@ namespace cw
rc_t sendValueDouble( handle_t h, unsigned uuId, double value ); rc_t sendValueDouble( handle_t h, unsigned uuId, double value );
rc_t sendValueString( handle_t h, unsigned uuId, const char* 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 report( handle_t h );
void realTimeReport( handle_t h ); void realTimeReport( handle_t h );
@ -224,6 +225,8 @@ namespace cw
// This function should be called periodically to send and receive // This function should be called periodically to send and receive
// queued messages to and from the websocket. // 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 ); rc_t exec( handle_t h );
// This function executes the internal default websock callback function. // This function executes the internal default websock callback function.