From e2f1d9915fda85936f176260d21834b9b01e9ad2 Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Mon, 27 Apr 2020 08:14:26 -0400 Subject: [PATCH] cwUi.h,cpp,cwUiTest.cpp : Added appIdMap[] as arg. to constructor. --- cwUi.cpp | 54 +++++++++++++++++++++++++++++++++++----------------- cwUi.h | 43 ++++++++++++++++++++++++----------------- cwUiTest.cpp | 18 ++++++++++-------- 3 files changed, 73 insertions(+), 42 deletions(-) diff --git a/cwUi.cpp b/cwUi.cpp index 378c672..e327d56 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -139,6 +139,18 @@ namespace cw return rc; } + rc_t _registerAppIdMap( ui_t* p, const appIdMap_t* map, unsigned mapN ) + { + rc_t rc = kOkRC; + + if( map != nullptr ) + for(unsigned i=0; iuiH, _webSockSend, p, uiCbFunc, cbArg, fmtBufByteN )) != kOkRC ) + if((rc = ui::create(p->uiH, _webSockSend, p, uiCbFunc, cbArg, appIdMapA, appIdMapN, fmtBufByteN )) != kOkRC ) { cwLogError(rc,"UI object create failed."); goto errLabel; @@ -1279,6 +1293,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h, const char* physRootDir, void* cbArg, uiCallback_t uiCbFunc, + const appIdMap_t* appIdMapA, + unsigned appIdMapN, websock::cbFunc_t wsCbFunc, const char* dfltPageFn, unsigned websockTimeOutMs, @@ -1292,7 +1308,7 @@ cw::rc_t cw::ui::srv::create( handle_t& h, ui_ws_srv_t* p = mem::allocZ(); - if((rc = ws::create(p->wsUiH, port, physRootDir, cbArg, uiCbFunc, wsCbFunc, dfltPageFn, websockTimeOutMs, rcvBufByteN, xmtBufByteN, fmtBufByteN )) != kOkRC ) + if((rc = ws::create(p->wsUiH, port, physRootDir, cbArg, uiCbFunc, appIdMapA, appIdMapN, wsCbFunc, dfltPageFn, websockTimeOutMs, rcvBufByteN, xmtBufByteN, fmtBufByteN )) != kOkRC ) { cwLogError(rc,"The websock UI creationg failed."); goto errLabel; @@ -1319,6 +1335,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h, const args_t& args, void* cbArg, uiCallback_t uiCbFunc, + const appIdMap_t* appIdMapA, + unsigned appIdMapN, websock::cbFunc_t wsCbFunc ) { return create(h, @@ -1326,6 +1344,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h, args.physRootDir, cbArg, uiCbFunc, + appIdMapA, + appIdMapN, wsCbFunc, args.dfltHtmlPageFn, args.timeOutMs, diff --git a/cwUi.h b/cwUi.h index 4d5884d..bab764f 100644 --- a/cwUi.h +++ b/cwUi.h @@ -58,15 +58,25 @@ namespace cw } u; } value_t; + typedef struct appIdMap_str + { + unsigned parentAppId; + unsigned appId; + const char* eleName; + } appIdMap_t; + typedef rc_t (*uiCallback_t)( void* cbArg, unsigned wsSessId, opId_t opId, unsigned parentAppId, unsigned uuId, unsigned appId, const value_t* value ); typedef rc_t (*sendCallback_t)( void* cbArg, unsigned wsSessId, const void* msg, unsigned msgByteN ); - rc_t create( handle_t& h, - sendCallback_t sendCbFunc, - void* sendCbArg, - uiCallback_t uiCbFunc, - void* uiCbArg, - unsigned fmtBufByteN = 4096 ); + rc_t create( + handle_t& h, + sendCallback_t sendCbFunc, + void* sendCbArg, + uiCallback_t uiCbFunc, + void* uiCbArg, + const appIdMap_t* appIdMapA = nullptr, + unsigned appIdMapN = 0, + unsigned fmtBufByteN = 4096 ); rc_t destroy( handle_t& h ); @@ -99,15 +109,8 @@ namespace cw rc_t createProgress( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double value, double minValue, double maxValue ); rc_t createText( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title ); - typedef struct appIdMap_str - { - unsigned parentAppId; - unsigned appId; - const char* eleName; - } appIdMap_t; - // Register parent/child/name app id's - rc_t registerAppIds( handle_t h, const appIdMap_t* map, unsigned mapN ); + rc_t registerAppIdMap( handle_t h, const appIdMap_t* map, unsigned mapN ); rc_t sendValueBool( handle_t h, unsigned wsSessId, unsigned uuId, bool value ); rc_t sendValueInt( handle_t h, unsigned wsSessId, unsigned uuId, int value ); @@ -124,8 +127,10 @@ namespace cw unsigned port, const char* physRootDir, void* cbArg, - uiCallback_t uiCbFunc, - websock::cbFunc_t wsCbFunc = nullptr, + uiCallback_t uiCbFunc, + const appIdMap_t* appIdMapA = nullptr, + unsigned appIdMapN = 0, + websock::cbFunc_t wsCbFunc = nullptr, const char* dfltPageFn = "index.html", unsigned websockTimeOutMs = 50, unsigned rcvBufByteN = 1024, @@ -170,13 +175,17 @@ namespace cw const args_t& args, void* cbArg, uiCallback_t uiCbFunc, - websock::cbFunc_t wsCbFunc = nullptr ); + const appIdMap_t* appIdMapA = nullptr, + unsigned appIdMapN = 0, + websock::cbFunc_t wsCbFunc = nullptr ); rc_t create( handle_t& h, unsigned port, const char* physRootDir, void* cbArg, uiCallback_t uiCbFunc, + const appIdMap_t* appIdMapA = nullptr, + unsigned appIdMapN = 0, websock::cbFunc_t wsCbFunc = nullptr, const char* dfltPageFn = "index.html", unsigned websockTimeOutMs = 50, diff --git a/cwUiTest.cpp b/cwUiTest.cpp index b55f0ff..1a1225d 100644 --- a/cwUiTest.cpp +++ b/cwUiTest.cpp @@ -54,17 +54,11 @@ namespace cw unsigned selUuId = kInvalidId; unsigned divUuId = kInvalidId; - appIdMap_t mapA[] = - { - { ui::kRootAppId, kPanelDivId, "panelDivId" }, - { ui::kPanelDivId, kPanelBtnId, "myBtn1Id" }, - { ui::kPanelDivId, kPanelCheckId, "myCheck1Id" }, - }; handle_t uiH = srv::uiHandle(p->wsUiSrvH); - registerAppIds(uiH, mapA, sizeof(mapA)/sizeof(mapA[0])); + //registerAppIdMap(uiH, mapA, sizeof(mapA)/sizeof(mapA[0])); if((rc = createDiv( uiH, divUuId, wsSessId, kInvalidId, "myDivId", kDivId, "divClass", "My Panel" )) != kOkRC ) goto errLabel; @@ -234,7 +228,15 @@ cw::rc_t cw::ui::test( ) char sbuf[ sbufN+1 ]; ui_test_t* app = mem::allocZ(); + appIdMap_t mapA[] = + { + { kRootAppId, kPanelDivId, "panelDivId" }, + { kPanelDivId, kPanelBtnId, "myBtn1Id" }, + { kPanelDivId, kPanelCheckId, "myCheck1Id" }, + }; + unsigned mapN = sizeof(mapA)/sizeof(mapA[0]); + app->appCheckFl = true; app->appSelectIndex = 1; app->appInteger = 5; @@ -246,7 +248,7 @@ cw::rc_t cw::ui::test( ) app->uiCfgFn = "/home/kevin/src/cwtest/src/libcw/html/uiTest/ui.cfg"; // create the UI server - if((rc = srv::create(app->wsUiSrvH, port, physRootDir, app, _uiTestCallback, nullptr, dfltPageFn, websockTimeOutMs, rcvBufByteN, xmtBufByteN, fmtBufByteN )) != kOkRC ) + if((rc = srv::create(app->wsUiSrvH, port, physRootDir, app, _uiTestCallback, mapA, mapN, nullptr, dfltPageFn, websockTimeOutMs, rcvBufByteN, xmtBufByteN, fmtBufByteN )) != kOkRC ) return rc;