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 "cwThread.h"
#include "cwWebSock.h" #include "cwWebSock.h"
#include "cwWebSockSvr.h" #include "cwWebSockSvr.h"
#include "cwUi.h"
#include "cwText.h" #include "cwText.h"
#include "cwNumericConvert.h" #include "cwNumericConvert.h"
#include "cwObject.h" #include "cwObject.h"
#include "cwUi.h"
namespace cw namespace cw
{ {
namespace ui namespace ui
@ -749,6 +750,29 @@ unsigned cw::ui::findElementUuId( handle_t h, const char* eleName )
return _findElementUuId(p,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) 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; return rc;
} }
cw::rc_t cw::ui::ws::destroy( handle_t& h ) cw::rc_t cw::ui::ws::destroy( handle_t& h )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
@ -1108,6 +1133,27 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
return rc; 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 ) cw::rc_t cw::ui::srv::destroy( handle_t& h )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;

19
cwUi.h
View File

@ -80,6 +80,7 @@ namespace cw
// Return the uuid of the first matching 'eleName'. // Return the uuid of the first matching 'eleName'.
unsigned findElementUuId( handle_t h, const char* eleName ); unsigned findElementUuId( handle_t h, const char* eleName );
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 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 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 createDiv( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
@ -139,8 +140,25 @@ namespace cw
namespace srv 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; 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, rc_t create( handle_t& h,
unsigned port, unsigned port,
const char* physRootDir, const char* physRootDir,
@ -153,6 +171,7 @@ namespace cw
unsigned xmtBufByteN = 1024, unsigned xmtBufByteN = 1024,
unsigned fmtBufByteN = 4096 ); unsigned fmtBufByteN = 4096 );
rc_t destroy( handle_t& h ); rc_t destroy( handle_t& h );
rc_t start( handle_t h ); rc_t start( handle_t h );