cwUi.h,cpp,cwUiTest.cpp : Added appIdMap[] as arg. to constructor.
This commit is contained in:
parent
a260c3626c
commit
e2f1d9915f
42
cwUi.cpp
42
cwUi.cpp
@ -139,6 +139,18 @@ namespace cw
|
|||||||
return rc;
|
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; i<mapN; ++i)
|
||||||
|
if((rc = _allocAppIdMap( p, map[i].parentAppId, map[i].appId, map[i].eleName )) != kOkRC )
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
// Given a uuId return a pointer to the associated element.
|
// Given a uuId return a pointer to the associated element.
|
||||||
ele_t* _uuIdToEle( ui_t* p, unsigned uuId, bool errorFl=true )
|
ele_t* _uuIdToEle( ui_t* p, unsigned uuId, bool errorFl=true )
|
||||||
{
|
{
|
||||||
@ -677,6 +689,8 @@ cw::rc_t cw::ui::create(
|
|||||||
void* sendCbArg,
|
void* sendCbArg,
|
||||||
uiCallback_t uiCbFunc,
|
uiCallback_t uiCbFunc,
|
||||||
void* uiCbArg,
|
void* uiCbArg,
|
||||||
|
const appIdMap_t* appIdMapA,
|
||||||
|
unsigned appIdMapN,
|
||||||
unsigned fmtBufByteN )
|
unsigned fmtBufByteN )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
@ -711,8 +725,13 @@ cw::rc_t cw::ui::create(
|
|||||||
goto errLabel;
|
goto errLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// register any suppled appId maps
|
||||||
|
if((rc = _registerAppIdMap(p,appIdMapA,appIdMapN)) != kOkRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
h.set(p);
|
h.set(p);
|
||||||
|
|
||||||
|
|
||||||
errLabel:
|
errLabel:
|
||||||
|
|
||||||
if( rc != kOkRC )
|
if( rc != kOkRC )
|
||||||
@ -999,16 +1018,9 @@ cw::rc_t cw::ui::createText( handle_t h, unsigned& uuIdRef, unsigned wsSessId,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cw::rc_t cw::ui::registerAppIds( handle_t h, const appIdMap_t* map, unsigned mapN )
|
cw::rc_t cw::ui::registerAppIdMap( handle_t h, const appIdMap_t* map, unsigned mapN )
|
||||||
{
|
{
|
||||||
ui_t* p = _handleToPtr(h);
|
return _registerAppIdMap( _handleToPtr(h), map, mapN);
|
||||||
rc_t rc = kOkRC;
|
|
||||||
|
|
||||||
for(unsigned i=0; i<mapN; ++i)
|
|
||||||
if((rc = _allocAppIdMap( p, map[i].parentAppId, map[i].appId, map[i].eleName )) != kOkRC )
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cw::rc_t cw::ui::sendValueBool( handle_t h, unsigned wsSessId, unsigned uuId, bool value )
|
cw::rc_t cw::ui::sendValueBool( handle_t h, unsigned wsSessId, unsigned uuId, bool value )
|
||||||
@ -1121,6 +1133,8 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
|
|||||||
const char* physRootDir,
|
const char* physRootDir,
|
||||||
void* cbArg,
|
void* cbArg,
|
||||||
uiCallback_t uiCbFunc,
|
uiCallback_t uiCbFunc,
|
||||||
|
const appIdMap_t* appIdMapA,
|
||||||
|
unsigned appIdMapN,
|
||||||
websock::cbFunc_t wsCbFunc,
|
websock::cbFunc_t wsCbFunc,
|
||||||
const char* dfltPageFn,
|
const char* dfltPageFn,
|
||||||
unsigned websockTimeOutMs,
|
unsigned websockTimeOutMs,
|
||||||
@ -1153,7 +1167,7 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the ui
|
// create the ui
|
||||||
if((rc = ui::create(p->uiH, _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.");
|
cwLogError(rc,"UI object create failed.");
|
||||||
goto errLabel;
|
goto errLabel;
|
||||||
@ -1279,6 +1293,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
|
|||||||
const char* physRootDir,
|
const char* physRootDir,
|
||||||
void* cbArg,
|
void* cbArg,
|
||||||
uiCallback_t uiCbFunc,
|
uiCallback_t uiCbFunc,
|
||||||
|
const appIdMap_t* appIdMapA,
|
||||||
|
unsigned appIdMapN,
|
||||||
websock::cbFunc_t wsCbFunc,
|
websock::cbFunc_t wsCbFunc,
|
||||||
const char* dfltPageFn,
|
const char* dfltPageFn,
|
||||||
unsigned websockTimeOutMs,
|
unsigned websockTimeOutMs,
|
||||||
@ -1292,7 +1308,7 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
|
|||||||
|
|
||||||
ui_ws_srv_t* p = mem::allocZ<ui_ws_srv_t>();
|
ui_ws_srv_t* p = mem::allocZ<ui_ws_srv_t>();
|
||||||
|
|
||||||
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.");
|
cwLogError(rc,"The websock UI creationg failed.");
|
||||||
goto errLabel;
|
goto errLabel;
|
||||||
@ -1319,6 +1335,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
|
|||||||
const args_t& args,
|
const args_t& args,
|
||||||
void* cbArg,
|
void* cbArg,
|
||||||
uiCallback_t uiCbFunc,
|
uiCallback_t uiCbFunc,
|
||||||
|
const appIdMap_t* appIdMapA,
|
||||||
|
unsigned appIdMapN,
|
||||||
websock::cbFunc_t wsCbFunc )
|
websock::cbFunc_t wsCbFunc )
|
||||||
{
|
{
|
||||||
return create(h,
|
return create(h,
|
||||||
@ -1326,6 +1344,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
|
|||||||
args.physRootDir,
|
args.physRootDir,
|
||||||
cbArg,
|
cbArg,
|
||||||
uiCbFunc,
|
uiCbFunc,
|
||||||
|
appIdMapA,
|
||||||
|
appIdMapN,
|
||||||
wsCbFunc,
|
wsCbFunc,
|
||||||
args.dfltHtmlPageFn,
|
args.dfltHtmlPageFn,
|
||||||
args.timeOutMs,
|
args.timeOutMs,
|
||||||
|
27
cwUi.h
27
cwUi.h
@ -58,14 +58,24 @@ namespace cw
|
|||||||
} u;
|
} u;
|
||||||
} value_t;
|
} 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 (*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 );
|
typedef rc_t (*sendCallback_t)( void* cbArg, unsigned wsSessId, const void* msg, unsigned msgByteN );
|
||||||
|
|
||||||
rc_t create( handle_t& h,
|
rc_t create(
|
||||||
|
handle_t& h,
|
||||||
sendCallback_t sendCbFunc,
|
sendCallback_t sendCbFunc,
|
||||||
void* sendCbArg,
|
void* sendCbArg,
|
||||||
uiCallback_t uiCbFunc,
|
uiCallback_t uiCbFunc,
|
||||||
void* uiCbArg,
|
void* uiCbArg,
|
||||||
|
const appIdMap_t* appIdMapA = nullptr,
|
||||||
|
unsigned appIdMapN = 0,
|
||||||
unsigned fmtBufByteN = 4096 );
|
unsigned fmtBufByteN = 4096 );
|
||||||
|
|
||||||
rc_t destroy( handle_t& h );
|
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 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 );
|
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
|
// 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 sendValueBool( handle_t h, unsigned wsSessId, unsigned uuId, bool value );
|
||||||
rc_t sendValueInt( handle_t h, unsigned wsSessId, unsigned uuId, int value );
|
rc_t sendValueInt( handle_t h, unsigned wsSessId, unsigned uuId, int value );
|
||||||
@ -125,6 +128,8 @@ namespace cw
|
|||||||
const char* physRootDir,
|
const char* physRootDir,
|
||||||
void* cbArg,
|
void* cbArg,
|
||||||
uiCallback_t uiCbFunc,
|
uiCallback_t uiCbFunc,
|
||||||
|
const appIdMap_t* appIdMapA = nullptr,
|
||||||
|
unsigned appIdMapN = 0,
|
||||||
websock::cbFunc_t wsCbFunc = nullptr,
|
websock::cbFunc_t wsCbFunc = nullptr,
|
||||||
const char* dfltPageFn = "index.html",
|
const char* dfltPageFn = "index.html",
|
||||||
unsigned websockTimeOutMs = 50,
|
unsigned websockTimeOutMs = 50,
|
||||||
@ -170,6 +175,8 @@ namespace cw
|
|||||||
const args_t& args,
|
const args_t& args,
|
||||||
void* cbArg,
|
void* cbArg,
|
||||||
uiCallback_t uiCbFunc,
|
uiCallback_t uiCbFunc,
|
||||||
|
const appIdMap_t* appIdMapA = nullptr,
|
||||||
|
unsigned appIdMapN = 0,
|
||||||
websock::cbFunc_t wsCbFunc = nullptr );
|
websock::cbFunc_t wsCbFunc = nullptr );
|
||||||
|
|
||||||
rc_t create( handle_t& h,
|
rc_t create( handle_t& h,
|
||||||
@ -177,6 +184,8 @@ namespace cw
|
|||||||
const char* physRootDir,
|
const char* physRootDir,
|
||||||
void* cbArg,
|
void* cbArg,
|
||||||
uiCallback_t uiCbFunc,
|
uiCallback_t uiCbFunc,
|
||||||
|
const appIdMap_t* appIdMapA = nullptr,
|
||||||
|
unsigned appIdMapN = 0,
|
||||||
websock::cbFunc_t wsCbFunc = nullptr,
|
websock::cbFunc_t wsCbFunc = nullptr,
|
||||||
const char* dfltPageFn = "index.html",
|
const char* dfltPageFn = "index.html",
|
||||||
unsigned websockTimeOutMs = 50,
|
unsigned websockTimeOutMs = 50,
|
||||||
|
18
cwUiTest.cpp
18
cwUiTest.cpp
@ -54,17 +54,11 @@ namespace cw
|
|||||||
unsigned selUuId = kInvalidId;
|
unsigned selUuId = kInvalidId;
|
||||||
unsigned divUuId = 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);
|
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 )
|
if((rc = createDiv( uiH, divUuId, wsSessId, kInvalidId, "myDivId", kDivId, "divClass", "My Panel" )) != kOkRC )
|
||||||
goto errLabel;
|
goto errLabel;
|
||||||
@ -234,6 +228,14 @@ cw::rc_t cw::ui::test( )
|
|||||||
char sbuf[ sbufN+1 ];
|
char sbuf[ sbufN+1 ];
|
||||||
ui_test_t* app = mem::allocZ<ui_test_t>();
|
ui_test_t* app = mem::allocZ<ui_test_t>();
|
||||||
|
|
||||||
|
appIdMap_t mapA[] =
|
||||||
|
{
|
||||||
|
{ kRootAppId, kPanelDivId, "panelDivId" },
|
||||||
|
{ kPanelDivId, kPanelBtnId, "myBtn1Id" },
|
||||||
|
{ kPanelDivId, kPanelCheckId, "myCheck1Id" },
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned mapN = sizeof(mapA)/sizeof(mapA[0]);
|
||||||
|
|
||||||
app->appCheckFl = true;
|
app->appCheckFl = true;
|
||||||
app->appSelectIndex = 1;
|
app->appSelectIndex = 1;
|
||||||
@ -246,7 +248,7 @@ cw::rc_t cw::ui::test( )
|
|||||||
app->uiCfgFn = "/home/kevin/src/cwtest/src/libcw/html/uiTest/ui.cfg";
|
app->uiCfgFn = "/home/kevin/src/cwtest/src/libcw/html/uiTest/ui.cfg";
|
||||||
|
|
||||||
// create the UI server
|
// 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;
|
return rc;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user