cwUi.h/cpp : Added createFromObject().

This commit is contained in:
kevin.larke 2020-04-21 14:59:55 -04:00
parent 8e1fce703c
commit a2588cdfd7
2 changed files with 78 additions and 13 deletions

View File

@ -5,11 +5,12 @@
#include "cwThread.h"
#include "cwWebSock.h"
#include "cwWebSockSvr.h"
#include "cwUi.h"
#include "cwText.h"
#include "cwNumericConvert.h"
#include "cwObject.h"
#include "cwUi.h"
namespace cw
{
namespace ui
@ -749,6 +750,29 @@ unsigned cw::ui::findElementUuId( handle_t h, const char* eleName )
return _findElementUuId(p,eleName);
}
cw::rc_t cw::ui::createFromObject( handle_t h, const object_t* o, unsigned wsSessId, unsigned parentUuId, const char* eleName )
{
ui_t* p = _handleToPtr(h);
rc_t rc = kOkRC;
if( eleName != nullptr )
if((o = o->find(eleName)) == nullptr )
{
rc = cwLogError(kSyntaxErrorRC,"Unable to locate the 'engine' sub-configuration.");
goto errLabel;
}
if((rc = _createFromObj( p, o, wsSessId, parentUuId )) != kOkRC )
goto errLabel;
errLabel:
if(rc != kOkRC )
rc = cwLogError(rc,"UI instantiation from object failed.", cwStringNullGuard(fn));
return rc;
}
cw::rc_t cw::ui::createFromFile( handle_t h, const char* fn, unsigned wsSessId, unsigned parentUuId)
{
@ -969,6 +993,7 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
return rc;
}
cw::rc_t cw::ui::ws::destroy( handle_t& h )
{
rc_t rc = kOkRC;
@ -1108,6 +1133,27 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
return rc;
}
cw::rc_t cw::ui::srv::create( handle_t& h,
const args_t& args,
void* cbArg,
uiCallback_t uiCbFunc,
websock::cbFunc_t wsCbFunc )
{
return create(h,
args.port,
args.physRootDir,
cbArg,
uiCbFunc,
wsCbFunc,
args.dfltHtmlPageFn,
args.timeOutMs,
args.recvBufByteN,
args.xmitBufByteN,
args.fmtBufByteN );
}
cw::rc_t cw::ui::srv::destroy( handle_t& h )
{
rc_t rc = kOkRC;

43
cwUi.h
View File

@ -80,18 +80,19 @@ namespace cw
// Return the uuid of the first matching 'eleName'.
unsigned findElementUuId( handle_t h, const char* eleName );
rc_t createFromFile( handle_t h, const char* fn, unsigned wsSessId, unsigned parentUuId=kInvalidId);
rc_t createFromText( handle_t h, const char* text, unsigned wsSessId, unsigned parentUuId=kInvalidId);
rc_t createDiv( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createTitle( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createButton( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createCheck( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, bool value );
rc_t createSelect( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createOption( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createString( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, const char* value );
rc_t createNumber( 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, double stepValue, unsigned decPl );
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 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);
rc_t createFromText( handle_t h, const char* text, unsigned wsSessId, unsigned parentUuId=kInvalidId);
rc_t createDiv( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createTitle( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createButton( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createCheck( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, bool value );
rc_t createSelect( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createOption( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
rc_t createString( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, const char* value );
rc_t createNumber( 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, double stepValue, unsigned decPl );
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
{
@ -139,8 +140,25 @@ namespace cw
namespace srv
{
typedef struct args_str
{
const char* physRootDir;
const char* dfltHtmlPageFn;
unsigned port;
unsigned timeOutMs;
unsigned recvBufByteN;
unsigned xmitBufByteN;
unsigned fmtBufByteN;
} args_t;
typedef handle<struct ui_ws_srv_str> handle_t;
rc_t create( handle_t& h,
const args_t& args,
void* cbArg,
uiCallback_t uiCbFunc,
websock::cbFunc_t wsCbFunc = nullptr );
rc_t create( handle_t& h,
unsigned port,
const char* physRootDir,
@ -153,6 +171,7 @@ namespace cw
unsigned xmtBufByteN = 1024,
unsigned fmtBufByteN = 4096 );
rc_t destroy( handle_t& h );
rc_t start( handle_t h );