cwIo,cwUi : Added realTimeReport()

This commit is contained in:
kevin 2023-12-03 11:18:02 -05:00
parent e24b5b43b2
commit c0cf1ca956
4 changed files with 35 additions and 10 deletions

View File

@ -3734,3 +3734,11 @@ void cw::io::uiReport( handle_t h )
if(_handleToUiHandle(h,uiH) == kOkRC ) if(_handleToUiHandle(h,uiH) == kOkRC )
ui::report(uiH); ui::report(uiH);
} }
void cw::io::uiRealTimeReport( handle_t h )
{
ui::handle_t uiH;
if(_handleToUiHandle(h,uiH) == kOkRC )
ui::realTimeReport(uiH);
}

1
cwIo.h
View File

@ -398,6 +398,7 @@ namespace cw
rc_t uiSendValue( handle_t h, unsigned uuId, double value ); rc_t uiSendValue( handle_t h, unsigned uuId, double value );
rc_t uiSendValue( handle_t h, unsigned uuId, const char* value ); rc_t uiSendValue( handle_t h, unsigned uuId, const char* value );
void uiRealTimeReport( handle_t h );
void uiReport( handle_t h ); void uiReport( handle_t h );
} }

View File

@ -97,7 +97,6 @@ namespace cw
unsigned sessN; unsigned sessN;
unsigned sessAllocN; unsigned sessAllocN;
bool msgCacheEnableFl; bool msgCacheEnableFl;
unsigned msgCacheSessId; unsigned msgCacheSessId;
char* msgCache; char* msgCache;
@ -106,6 +105,9 @@ namespace cw
unsigned msgCacheN; unsigned msgCacheN;
unsigned msgCacheMsgN; unsigned msgCacheMsgN;
unsigned sentMsgN;
unsigned recvMsgN;
} ui_t; } ui_t;
ui_t* _handleToPtr( handle_t h ) ui_t* _handleToPtr( handle_t h )
@ -326,6 +328,14 @@ namespace cw
return nullptr; return nullptr;
} }
rc_t _send_callback( ui_t* p, unsigned wsSessId, const void* msg, unsigned msgByteN )
{
p->sentMsgN += 1;
rc_t rc = p->sendCbFunc( p->sendCbArg, wsSessId, msg, msgByteN );
return rc;
}
rc_t _cache_flush( ui_t* p ) rc_t _cache_flush( ui_t* p )
{ {
@ -338,7 +348,7 @@ namespace cw
p->msgCache[ p->msgCacheN+1 ] = '}'; p->msgCache[ p->msgCacheN+1 ] = '}';
p->msgCache[ p->msgCacheN+2 ] = 0; p->msgCache[ p->msgCacheN+2 ] = 0;
rc = p->sendCbFunc( p->sendCbArg, p->msgCacheSessId, p->msgCache, strlen(p->msgCache) ); rc = _send_callback(p, p->msgCacheSessId, p->msgCache, strlen(p->msgCache) );
p->msgCacheN = snprintf(p->msgCache,p->msgCacheAllocN,"{\"op\":\"cache\", \"array\": ["); p->msgCacheN = snprintf(p->msgCache,p->msgCacheAllocN,"{\"op\":\"cache\", \"array\": [");
p->msgCacheSessId = kInvalidId; p->msgCacheSessId = kInvalidId;
@ -369,7 +379,7 @@ namespace cw
rc = _cache_flush(p); rc = _cache_flush(p);
if( msgByteN > p->msgCacheDataN ) if( msgByteN > p->msgCacheDataN )
rc = p->sendCbFunc( p->sendCbArg, wsSessId, msg, msgByteN ); rc = _send_callback(p, wsSessId, msg, msgByteN );
else else
{ {
assert( p->msgCacheN + msgByteCommaN <= p->msgCacheDataN ); assert( p->msgCacheN + msgByteCommaN <= p->msgCacheDataN );
@ -396,7 +406,7 @@ namespace cw
if( p->msgCacheEnableFl ) if( p->msgCacheEnableFl )
rc = _cache_send( p, sessId, msg, msgByteCnt ); rc = _cache_send( p, sessId, msg, msgByteCnt );
else else
rc = p->sendCbFunc( p->sendCbArg, sessId, msg, msgByteCnt ); rc = _send_callback(p, sessId, msg, msgByteCnt );
return rc; return rc;
} }
@ -1296,6 +1306,7 @@ cw::rc_t cw::ui::create(
rc = cwLogError(rc,"Create from UI resource failed."); rc = cwLogError(rc,"Create from UI resource failed.");
} }
h.set(p); h.set(p);
@ -1454,6 +1465,8 @@ cw::rc_t cw::ui::onReceive( handle_t h, unsigned wsSessId, const void* void_msg,
while( (msg = _get_msg_from_recv_buffer(p)) != NULL ) while( (msg = _get_msg_from_recv_buffer(p)) != NULL )
{ {
p->recvMsgN += 1;
// parse the 'opId' from the message // parse the 'opId' from the message
opId = _labelToOpId(msg); opId = _labelToOpId(msg);
@ -2111,11 +2124,14 @@ void cw::ui::report( handle_t h )
printf("%s, ", p->buf ); printf("%s, ", p->buf );
} }
printf("\n"); printf("\n");
} }
} }
void cw::ui::realTimeReport( handle_t h )
{
ui_t* p = _handleToPtr(h);
printf("UI msg count: recv:%i send:%i\n",p->recvMsgN,p->sentMsgN);
}
namespace cw namespace cw

2
cwUi.h
View File

@ -171,7 +171,7 @@ namespace cw
void report( handle_t h ); void report( handle_t h );
void realTimeReport( handle_t h );
namespace ws namespace ws