cwUi.h,cpp,cwUiTest.cpp : Added appIdMap[] as arg. to constructor.
This commit is contained in:
parent
a260c3626c
commit
e2f1d9915f
54
cwUi.cpp
54
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; 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.
|
||||
ele_t* _uuIdToEle( ui_t* p, unsigned uuId, bool errorFl=true )
|
||||
{
|
||||
@ -672,12 +684,14 @@ namespace cw
|
||||
}
|
||||
|
||||
cw::rc_t cw::ui::create(
|
||||
handle_t& h,
|
||||
sendCallback_t sendCbFunc,
|
||||
void* sendCbArg,
|
||||
uiCallback_t uiCbFunc,
|
||||
void* uiCbArg,
|
||||
unsigned fmtBufByteN )
|
||||
handle_t& h,
|
||||
sendCallback_t sendCbFunc,
|
||||
void* sendCbArg,
|
||||
uiCallback_t uiCbFunc,
|
||||
void* uiCbArg,
|
||||
const appIdMap_t* appIdMapA,
|
||||
unsigned appIdMapN,
|
||||
unsigned fmtBufByteN )
|
||||
{
|
||||
rc_t rc = kOkRC;
|
||||
ele_t* ele;
|
||||
@ -711,8 +725,13 @@ cw::rc_t cw::ui::create(
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// register any suppled appId maps
|
||||
if((rc = _registerAppIdMap(p,appIdMapA,appIdMapN)) != kOkRC )
|
||||
goto errLabel;
|
||||
|
||||
h.set(p);
|
||||
|
||||
|
||||
errLabel:
|
||||
|
||||
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);
|
||||
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;
|
||||
return _registerAppIdMap( _handleToPtr(h), map, mapN);
|
||||
}
|
||||
|
||||
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,
|
||||
void* cbArg,
|
||||
uiCallback_t uiCbFunc,
|
||||
const appIdMap_t* appIdMapA,
|
||||
unsigned appIdMapN,
|
||||
websock::cbFunc_t wsCbFunc,
|
||||
const char* dfltPageFn,
|
||||
unsigned websockTimeOutMs,
|
||||
@ -1153,7 +1167,7 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
|
||||
}
|
||||
|
||||
// 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.");
|
||||
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<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.");
|
||||
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,
|
||||
|
43
cwUi.h
43
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,
|
||||
|
18
cwUiTest.cpp
18
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<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->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;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user