diff --git a/cwUi.cpp b/cwUi.cpp index a347391..db256f7 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -212,6 +212,15 @@ namespace cw return kInvalidId; } + unsigned _findElementUuId( ui_t* p, unsigned appId ) + { + for(unsigned i=0; ieleN; ++i) + if( p->eleA[i]->appId == appId ) + return p->eleA[i]->uuId; + + return kInvalidId; + } + const char* _findEleEleName( ui_t* p, unsigned uuId ) { for(unsigned i=0; ieleN; ++i) @@ -229,7 +238,15 @@ namespace cw if( p->sendCbFunc != nullptr ) { unsigned msgByteN = msg==nullptr ? 0 : strlen(msg); - return p->sendCbFunc( p->sendCbArg, wsSessId, msg, msgByteN ); + + if( wsSessId != kInvalidId ) + rc = p->sendCbFunc( p->sendCbArg, wsSessId, msg, msgByteN ); + else + { + for(unsigned i=0; isessN; ++i) + rc = p->sendCbFunc( p->sendCbArg, p->sessA[i], msg, msgByteN ); + + } } return rc; @@ -723,7 +740,8 @@ namespace cw if( snprintf(mbuf,mbufN,mFmt,uuId,vbuf) >= mbufN-1 ) return cwLogError(kBufTooSmallRC,"The msg buffer is too small."); - p->sendCbFunc(p->sendCbArg,wsSessId,mbuf,strlen(mbuf)); + //p->sendCbFunc(p->sendCbArg,wsSessId,mbuf,strlen(mbuf)); + _websockSend(p,wsSessId,mbuf); } return rc; @@ -977,6 +995,14 @@ unsigned cw::ui::findElementUuId( handle_t h, const char* eleName ) return _findElementUuId(p,eleName); } +unsigned cw::ui::findElementUuId( handle_t h, unsigned appId ) +{ + ui_t* p = _handleToPtr(h); + + return _findElementUuId(p,appId); +} + + unsigned cw::ui::findElementAppId( handle_t h, unsigned uuId ) { ui_t* p = _handleToPtr(h); diff --git a/cwUi.h b/cwUi.h index 7dbfb81..1dba1b2 100644 --- a/cwUi.h +++ b/cwUi.h @@ -45,8 +45,9 @@ namespace cw const char* findElementName( handle_t h, unsigned uuId ); unsigned findElementAppId( handle_t h, unsigned uuId ); - // Return the uuid of the first matching 'eleName'. + // Return the uuid of the first matching 'eleName' or 'appId'. unsigned findElementUuId( handle_t h, const char* eleName ); + unsigned findElementUuId( handle_t h, unsigned appId ); rc_t createFromObject( handle_t h, const object_t* o, unsigned wsSessId, unsigned parentUuId=kInvalidId, const char* eleName=nullptr); rc_t createFromFile( handle_t h, const char* fn, unsigned wsSessId, unsigned parentUuId=kInvalidId); @@ -77,6 +78,7 @@ namespace cw rc_t registerAppIdMap( handle_t h, const appIdMap_t* map, unsigned mapN ); // Send a value from the application to the UI via a JSON messages. + // Set wsSessId to kInvalidId to send to all sessions. rc_t sendValueBool( handle_t h, unsigned wsSessId, unsigned uuId, bool value ); rc_t sendValueInt( handle_t h, unsigned wsSessId, unsigned uuId, int value ); rc_t sendValueUInt( handle_t h, unsigned wsSessId, unsigned uuId, unsigned value );