cwUi.cpp : Eliminated use of 'initFl' and changed _findOrCreateElement() to allow certain matching parent/name pairs.

This commit is contained in:
kevin.larke 2020-04-26 17:27:29 -04:00
parent 87455db469
commit a260c3626c

View File

@ -47,7 +47,6 @@ namespace cw
appIdMapRecd_t* appIdMap; // map of application parent/child/js id's appIdMapRecd_t* appIdMap; // map of application parent/child/js id's
char* buf; // buf[bufN] output message formatting buffer char* buf; // buf[bufN] output message formatting buffer
unsigned bufN; // unsigned bufN; //
bool initFl; // This UI has been initialized.
unsigned* sessA; unsigned* sessA;
unsigned sessN; unsigned sessN;
@ -116,11 +115,6 @@ namespace cw
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
// if this UI has already been initialized then don't accept more appIdMaps
// because they will duplicate those from earlier sessions.
if( p->initFl )
return rc;
// The 'eleName' must be valid (or there is no reason to create the map. // The 'eleName' must be valid (or there is no reason to create the map.
// (since it will ultimately be used to locate the appId give the parentAppId and eleName) // (since it will ultimately be used to locate the appId give the parentAppId and eleName)
if( eleName == nullptr || strlen(eleName) == 0 ) if( eleName == nullptr || strlen(eleName) == 0 )
@ -252,13 +246,28 @@ namespace cw
e->appId = m->appId; e->appId = m->appId;
} }
printf("uuid:%i appId:%i %s\n", e->uuId,e->appId,cwStringNullGuard(e->eleName));
return e; return e;
} }
ele_t* _findOrCreateEle( ui_t* p, ele_t* parentEle, const char* eleName, unsigned appId=kInvalidId ) ele_t* _findOrCreateEle( ui_t* p, ele_t* parentEle, const char* eleName, unsigned appId=kInvalidId )
{ {
ele_t* ele; ele_t* ele = nullptr;
if((ele = _parentUuId_EleName_ToEle( p, parentEle->uuId, eleName, false )) == nullptr )
// if an ele name was given
if( eleName != nullptr )
{
// check for an existing child of parentEle with the same name
ele = _parentUuId_EleName_ToEle( p, parentEle->uuId, eleName, false );
// if a child with the same name does exist but has a different id then
// ignore the match and create a new element
if( ele != nullptr && appId != kInvalidId && ele->appId != appId )
ele = nullptr;
}
if(ele == nullptr )
ele = _createEle(p, parentEle, appId, eleName ); ele = _createEle(p, parentEle, appId, eleName );
return ele; return ele;
@ -730,6 +739,7 @@ cw::rc_t cw::ui::destroy( handle_t& h )
return rc; return rc;
} }
unsigned cw::ui::sessionIdCount(handle_t h) unsigned cw::ui::sessionIdCount(handle_t h)
{ {
ui_t* p = _handleToPtr(h); ui_t* p = _handleToPtr(h);
@ -796,7 +806,6 @@ cw::rc_t cw::ui::onReceive( handle_t h, unsigned wsSessId, const void* msg, unsi
case kInitOpId: case kInitOpId:
// Pass on the 'init' msg to the app. // Pass on the 'init' msg to the app.
p->uiCbFunc( p->uiCbArg, wsSessId, opId, kInvalidId, kInvalidId, kInvalidId, nullptr ); p->uiCbFunc( p->uiCbArg, wsSessId, opId, kInvalidId, kInvalidId, kInvalidId, nullptr );
p->initFl = true;
break; break;
case kValueOpId: case kValueOpId: