2020-03-23 14:48:49 +00:00
|
|
|
#ifndef cwUI_H
|
|
|
|
#define cwUI_H
|
|
|
|
|
|
|
|
#include "cwUiDecls.h"
|
|
|
|
|
|
|
|
namespace cw
|
|
|
|
{
|
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
typedef handle<struct ui_str> handle_t;
|
|
|
|
|
|
|
|
|
2021-01-20 18:10:56 +00:00
|
|
|
// Callback for application notification.
|
|
|
|
// (e.g. the GUI changed the value of a UI element)
|
2020-04-07 20:24:34 +00:00
|
|
|
typedef rc_t (*uiCallback_t)( void* cbArg, unsigned wsSessId, opId_t opId, unsigned parentAppId, unsigned uuId, unsigned appId, const value_t* value );
|
2021-01-20 18:10:56 +00:00
|
|
|
|
|
|
|
// Callback with messages for the GUI as JSON strings
|
|
|
|
// { "op":"create", "type":<>, "appId":<>, "parentUuId":<>, "name":<> (type specific fields) }
|
|
|
|
// { "op":""value", "uuid":<> "value":<> }
|
2020-04-07 20:24:34 +00:00
|
|
|
typedef rc_t (*sendCallback_t)( void* cbArg, unsigned wsSessId, const void* msg, unsigned msgByteN );
|
|
|
|
|
2020-04-27 12:14:26 +00:00
|
|
|
rc_t create(
|
|
|
|
handle_t& h,
|
|
|
|
sendCallback_t sendCbFunc,
|
|
|
|
void* sendCbArg,
|
|
|
|
uiCallback_t uiCbFunc,
|
|
|
|
void* uiCbArg,
|
2021-01-20 18:10:56 +00:00
|
|
|
const object_t* uiRsrc = nullptr,
|
2020-04-27 12:14:26 +00:00
|
|
|
const appIdMap_t* appIdMapA = nullptr,
|
|
|
|
unsigned appIdMapN = 0,
|
|
|
|
unsigned fmtBufByteN = 4096 );
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-07 20:24:34 +00:00
|
|
|
rc_t destroy( handle_t& h );
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2020-04-26 13:19:19 +00:00
|
|
|
unsigned sessionIdCount(handle_t h);
|
|
|
|
const unsigned* sessionIdArray(handle_t h);
|
|
|
|
|
2020-04-07 20:24:34 +00:00
|
|
|
rc_t onConnect( handle_t h, unsigned wsSessId );
|
|
|
|
rc_t onDisconnect( handle_t h, unsigned wsSessId );
|
|
|
|
rc_t onReceive( handle_t h, unsigned wsSessId, const void* msg, unsigned byteN );
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2021-01-20 18:10:56 +00:00
|
|
|
unsigned findElementAppId( handle_t h, unsigned parentUuId, const char* eleName );
|
2020-04-06 23:17:04 +00:00
|
|
|
unsigned findElementUuId( handle_t h, unsigned parentUuId, const char* eleName );
|
2020-03-23 14:48:49 +00:00
|
|
|
unsigned findElementUuId( handle_t h, unsigned parentUuId, unsigned appId );
|
2020-04-06 23:17:04 +00:00
|
|
|
const char* findElementName( handle_t h, unsigned uuId );
|
2020-04-30 19:10:54 +00:00
|
|
|
unsigned findElementAppId( handle_t h, unsigned uuId );
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2021-01-22 14:46:10 +00:00
|
|
|
// Return the uuid of the first matching 'eleName' or 'appId'.
|
2020-04-06 23:17:04 +00:00
|
|
|
unsigned findElementUuId( handle_t h, const char* eleName );
|
2021-01-22 14:46:10 +00:00
|
|
|
unsigned findElementUuId( handle_t h, unsigned appId );
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-21 18:59:55 +00:00
|
|
|
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 );
|
2020-05-18 15:03:42 +00:00
|
|
|
|
|
|
|
// Create check: w/o value. The value will be read from the engine via the UI 'echo' event.
|
|
|
|
rc_t createCheck( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
|
|
|
|
// Create check: w/ value. The value will be sent to the engine as the new value of the associated varaible.
|
2020-04-21 18:59:55 +00:00
|
|
|
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 );
|
2020-05-18 15:03:42 +00:00
|
|
|
|
2020-04-21 18:59:55 +00:00
|
|
|
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 );
|
2020-05-18 15:03:42 +00:00
|
|
|
rc_t createStr( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
rc_t createStr( 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 createNumbDisplay(handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, unsigned decPl );
|
|
|
|
rc_t createNumbDisplay(handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, unsigned decPl, double value );
|
|
|
|
rc_t createNumb( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double minValue, double maxValue, double stepValue, unsigned decPl );
|
|
|
|
rc_t createNumb( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double minValue, double maxValue, double stepValue, unsigned decPl, double value );
|
|
|
|
rc_t createProg( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double minValue, double maxValue );
|
|
|
|
rc_t createProg( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double minValue, double maxValue, double value );
|
2020-04-21 18:59:55 +00:00
|
|
|
rc_t createText( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
2020-03-31 17:10:45 +00:00
|
|
|
|
2020-04-06 23:17:04 +00:00
|
|
|
// Register parent/child/name app id's
|
2020-04-27 12:14:26 +00:00
|
|
|
rc_t registerAppIdMap( handle_t h, const appIdMap_t* map, unsigned mapN );
|
2020-03-23 14:48:49 +00:00
|
|
|
|
2021-01-20 18:10:56 +00:00
|
|
|
// Send a value from the application to the UI via a JSON messages.
|
2021-01-22 14:46:10 +00:00
|
|
|
// Set wsSessId to kInvalidId to send to all sessions.
|
2020-04-24 14:20:25 +00:00
|
|
|
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 sendValueUInt( handle_t h, unsigned wsSessId, unsigned uuId, unsigned value );
|
|
|
|
rc_t sendValueFloat( handle_t h, unsigned wsSessId, unsigned uuId, float value );
|
|
|
|
rc_t sendValueDouble( handle_t h, unsigned wsSessId, unsigned uuId, double value );
|
|
|
|
rc_t sendValueString( handle_t h, unsigned wsSessId, unsigned uuId, const char* value );
|
|
|
|
|
2020-04-07 20:24:34 +00:00
|
|
|
namespace ws
|
|
|
|
{
|
|
|
|
typedef handle<struct ui_ws_str> handle_t;
|
|
|
|
|
2021-01-20 18:10:56 +00:00
|
|
|
typedef struct args_str
|
|
|
|
{
|
|
|
|
const char* physRootDir;
|
|
|
|
const char* dfltPageFn;
|
|
|
|
object_t* uiRsrc;
|
|
|
|
unsigned port;
|
|
|
|
unsigned rcvBufByteN;
|
|
|
|
unsigned xmtBufByteN;
|
|
|
|
unsigned fmtBufByteN;
|
|
|
|
unsigned wsTimeOutMs;
|
|
|
|
} args_t;
|
|
|
|
|
|
|
|
rc_t parseArgs( const object_t& o, args_t& args, const char* object_label=nullptr );
|
|
|
|
rc_t releaseArgs( args_t& args );
|
|
|
|
|
|
|
|
rc_t create( handle_t& h,
|
|
|
|
const args_t& args,
|
|
|
|
void* cbArg,
|
|
|
|
uiCallback_t uiCbFunc,
|
|
|
|
const object_t* uiRsrc = nullptr,
|
|
|
|
const appIdMap_t* appIdMapA = nullptr,
|
|
|
|
unsigned appIdMapN = 0,
|
|
|
|
websock::cbFunc_t wsCbFunc = nullptr );
|
|
|
|
|
2020-04-07 20:24:34 +00:00
|
|
|
rc_t create( handle_t& h,
|
|
|
|
unsigned port,
|
|
|
|
const char* physRootDir,
|
|
|
|
void* cbArg,
|
2020-04-27 12:14:26 +00:00
|
|
|
uiCallback_t uiCbFunc,
|
2021-01-20 18:10:56 +00:00
|
|
|
const object_t* uiRsrc = nullptr,
|
2020-04-27 12:14:26 +00:00
|
|
|
const appIdMap_t* appIdMapA = nullptr,
|
|
|
|
unsigned appIdMapN = 0,
|
|
|
|
websock::cbFunc_t wsCbFunc = nullptr,
|
2020-04-07 20:24:34 +00:00
|
|
|
const char* dfltPageFn = "index.html",
|
|
|
|
unsigned websockTimeOutMs = 50,
|
|
|
|
unsigned rcvBufByteN = 1024,
|
|
|
|
unsigned xmtBufByteN = 1024,
|
|
|
|
unsigned fmtBufByteN = 4096 );
|
|
|
|
|
|
|
|
rc_t destroy( handle_t& h );
|
|
|
|
|
|
|
|
// This function should be called periodically to send and receive
|
|
|
|
// queued messages to and from the websocket.
|
2021-01-20 18:10:56 +00:00
|
|
|
rc_t exec( handle_t h );
|
2020-04-07 20:24:34 +00:00
|
|
|
|
|
|
|
// This function executes the internal default websock callback function.
|
|
|
|
// It is useful if the user provides a custom websock callback function
|
|
|
|
// and wants to fallback to the default websock->ui interaction.
|
|
|
|
rc_t onReceive( handle_t h, unsigned protocolId, unsigned sessionId, websock::msgTypeId_t msg_type, const void* msg, unsigned byteN );
|
|
|
|
|
|
|
|
websock::handle_t websockHandle( handle_t h );
|
|
|
|
ui::handle_t uiHandle( handle_t h );
|
2020-04-24 14:20:25 +00:00
|
|
|
|
|
|
|
|
2020-04-07 20:24:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace srv
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef handle<struct ui_ws_srv_str> handle_t;
|
2020-04-21 18:59:55 +00:00
|
|
|
|
|
|
|
rc_t create( handle_t& h,
|
2021-01-20 18:10:56 +00:00
|
|
|
const ws::args_t& args,
|
2020-04-21 18:59:55 +00:00
|
|
|
void* cbArg,
|
2021-01-20 18:10:56 +00:00
|
|
|
uiCallback_t uiCbFunc,
|
2020-04-27 12:14:26 +00:00
|
|
|
const appIdMap_t* appIdMapA = nullptr,
|
|
|
|
unsigned appIdMapN = 0,
|
|
|
|
websock::cbFunc_t wsCbFunc = nullptr );
|
2020-04-07 20:24:34 +00:00
|
|
|
|
|
|
|
rc_t create( handle_t& h,
|
|
|
|
unsigned port,
|
|
|
|
const char* physRootDir,
|
|
|
|
void* cbArg,
|
|
|
|
uiCallback_t uiCbFunc,
|
2021-01-20 18:10:56 +00:00
|
|
|
const object_t* uiRsrc = nullptr,
|
2020-04-27 12:14:26 +00:00
|
|
|
const appIdMap_t* appIdMapA = nullptr,
|
|
|
|
unsigned appIdMapN = 0,
|
2020-04-07 20:24:34 +00:00
|
|
|
websock::cbFunc_t wsCbFunc = nullptr,
|
|
|
|
const char* dfltPageFn = "index.html",
|
|
|
|
unsigned websockTimeOutMs = 50,
|
|
|
|
unsigned rcvBufByteN = 1024,
|
|
|
|
unsigned xmtBufByteN = 1024,
|
|
|
|
unsigned fmtBufByteN = 4096 );
|
|
|
|
|
2020-04-21 18:59:55 +00:00
|
|
|
|
2020-04-07 20:24:34 +00:00
|
|
|
rc_t destroy( handle_t& h );
|
|
|
|
|
|
|
|
rc_t start( handle_t h );
|
|
|
|
rc_t stop( handle_t h );
|
|
|
|
|
|
|
|
thread::handle_t threadHandle( handle_t h );
|
|
|
|
websock::handle_t websockHandle( handle_t h );
|
|
|
|
ui::handle_t uiHandle( handle_t h );
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
2020-04-07 20:24:34 +00:00
|
|
|
|
2020-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|