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)
2021-11-03 15:03:30 +00:00
typedef rc_t ( * uiCallback_t ) ( void * cbArg , unsigned wsSessId , opId_t opId , unsigned parentAppId , unsigned uuId , unsigned appId , unsigned chanId , 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
2023-05-20 01:59:35 +00:00
rc_t enableCache ( handle_t h , unsigned cacheByteCnt = 4096 ) ;
rc_t flushCache ( handle_t h ) ;
2021-11-01 14:11:27 +00:00
unsigned sessionIdCount ( handle_t h ) ; // Count of connected remote UI's
const unsigned * sessionIdArray ( handle_t h ) ; // Array of 'sessionIdCount()' remote UI id's
2020-04-26 13:19:19 +00:00
2021-11-01 14:11:27 +00:00
// A new remote UI was connected
2020-04-07 20:24:34 +00:00
rc_t onConnect ( handle_t h , unsigned wsSessId ) ;
2021-11-01 14:11:27 +00:00
// A UI was disconnected
2020-04-07 20:24:34 +00:00
rc_t onDisconnect ( handle_t h , unsigned wsSessId ) ;
2021-11-01 14:11:27 +00:00
2022-05-14 14:16:09 +00:00
// Receive a msg from a remote UI.
//
// Note that individual messages are delinated with zero termination.
// Therefore a message which is not zero terminated is considered
// a partial message and will be buffered until the suffix of the message
// arrives.
2020-04-07 20:24:34 +00:00
rc_t onReceive ( handle_t h , unsigned wsSessId , const void * msg , unsigned byteN ) ;
2020-03-23 14:48:49 +00:00
2021-11-02 01:46:59 +00:00
// Locate an element whose parent uuid is 'parentUuId' with a child named 'eleName'.
2021-11-06 02:21:25 +00:00
unsigned parentAndNameToAppId ( handle_t h , unsigned parentAppId , const char * eleName ) ;
2021-11-04 13:33:42 +00:00
unsigned parentAndNameToUuId ( handle_t h , unsigned parentAppId , const char * eleName ) ;
unsigned parentAndAppIdToUuId ( handle_t h , unsigned parentAppId , unsigned appId ) ;
2021-11-02 01:46:59 +00:00
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'.
2021-11-06 02:21:25 +00:00
unsigned findElementUuId ( handle_t h , const char * eleName , unsigned chanId = kInvalidId ) ;
unsigned findElementUuId ( handle_t h , unsigned appId , unsigned chanId = kInvalidId ) ;
unsigned findElementUuId ( handle_t h , unsigned parentUuId , const char * eleName , unsigned chanId = kInvalidId ) ;
unsigned findElementUuId ( handle_t h , unsigned parentUuId , unsigned appId , unsigned chanId = kInvalidId ) ;
2021-01-31 16:07:29 +00:00
2020-03-31 17:10:45 +00:00
2021-01-31 16:07:29 +00:00
// Create multiple UI elements from an object_t representation.
2021-11-03 15:03:30 +00:00
// The channel id of all elements created from the object will be assigned 'chanId'.
2022-12-13 21:53:10 +00:00
// The 'label' string identifies a child wihtin the outer object (e.g. o,fn,text, create( ... uiRsrc, ...)) which should be used to create the element.
rc_t createFromObject ( handle_t h , const object_t * o , unsigned parentUuId = kInvalidId , unsigned chanId = kInvalidId , const char * label = nullptr ) ;
2021-11-03 15:03:30 +00:00
rc_t createFromFile ( handle_t h , const char * fn , unsigned parentUuId = kInvalidId , unsigned chanId = kInvalidId ) ;
rc_t createFromText ( handle_t h , const char * text , unsigned parentUuId = kInvalidId , unsigned chanId = kInvalidId ) ;
2022-12-13 21:53:10 +00:00
// This function uses 'label' to locate the child of the internal uiRsrc (passed to 'create()') as the element configuration resource.
rc_t createFromRsrc ( handle_t h , const char * label , unsigned parentUuId = kInvalidId , unsigned chanId = kInvalidId ) ;
2021-01-31 16:07:29 +00:00
//
// Create Sincgle UI elements on the UI instance identified by wsSessId.
//
// uuIdRef: Returns the automatically generated id for this element.
// It is unique across all elements associated with this ui::handle.
// Note that this id is NOT generated per wsSession, it is only generated
// the first time a particular element of this ui::handle is created.
//
// wsSessId: Identifies a particular instance (websock session) of the UI.
// Multiple instances of a UI may exist for a single application instance each will have a unique wsSessId.
// Set this value to kInvalidId to create this element on all existing websock sessions. Note that this is
// an unusual use since UI elements are usually created when new sessions are connected and therefore
// a specific wsSessId is available.
//
// parentUuId: uuid of parent element that the new element will be a child of.
//
// eleName: (optional) HTML ele id of the new element.
//
// appId: (optional) Application id. This is the application variable which this UI element represents.
// This id is generally the same across all UI instances.
//
// clas: (optional) HTML class of the new element
//
// title: (optional) Visible Text label associated with this element.
//
2021-11-03 15:03:30 +00:00
rc_t createDiv ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
rc_t createLabel ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
rc_t createButton ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , 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.
2021-11-03 15:03:30 +00:00
rc_t createCheck ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
2020-05-18 15:03:42 +00:00
// Create check: w/ value. The value will be sent to the engine as the new value of the associated varaible.
2021-11-03 15:03:30 +00:00
rc_t createCheck ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title , bool value ) ;
2020-05-18 15:03:42 +00:00
2021-11-03 15:03:30 +00:00
rc_t createSelect ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
rc_t createOption ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
2021-12-27 21:48:58 +00:00
rc_t createStrDisplay ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
rc_t createStrDisplay ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title , const char * value ) ;
2021-11-03 15:03:30 +00:00
rc_t createStr ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
rc_t createStr ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title , const char * value ) ;
rc_t createNumbDisplay ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title , unsigned decPl ) ;
rc_t createNumbDisplay ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title , unsigned decPl , double value ) ;
rc_t createNumb ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title , double minValue , double maxValue , double stepValue , unsigned decPl ) ;
rc_t createNumb ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , 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 parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title , double minValue , double maxValue ) ;
rc_t createProg ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title , double minValue , double maxValue , double value ) ;
rc_t createLog ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
2024-10-12 19:18:05 +00:00
rc_t createVList ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
rc_t createHList ( handle_t h , unsigned & uuIdRef , unsigned parentUuId , const char * eleName , unsigned appId , unsigned chanId , const char * clas , const char * title ) ;
2021-11-03 15:03:30 +00:00
2024-10-12 19:18:05 +00:00
rc_t setTitle ( handle_t h , unsigned uuId , const char * title ) ;
2021-11-03 15:03:30 +00:00
rc_t setNumbRange ( handle_t h , unsigned uuId , double minValue , double maxValue , double stepValue , unsigned decPl , double value ) ;
rc_t setProgRange ( handle_t h , unsigned uuId , double minValue , double maxValue , double value ) ;
rc_t setLogLine ( handle_t h , unsigned uuId , const char * text ) ;
2024-09-21 21:18:12 +00:00
rc_t emptyParent ( handle_t h , unsigned uuId ) ;
2021-11-03 15:03:30 +00:00
rc_t setClickable ( handle_t h , unsigned uuId , bool clickableFl = true ) ;
rc_t clearClickable ( handle_t h , unsigned uuId ) ;
bool isClickable ( handle_t h , unsigned uuId ) ;
rc_t setSelect ( handle_t h , unsigned uuId , bool enableFl = true ) ;
rc_t clearSelect ( handle_t h , unsigned uuId ) ;
bool isSelected ( handle_t h , unsigned uuId ) ;
2021-11-04 13:33:42 +00:00
rc_t setVisible ( handle_t h , unsigned uuId , bool enableFl = true ) ;
rc_t clearVisible ( handle_t h , unsigned uuId ) ;
bool isVisible ( handle_t h , unsigned uuId ) ;
rc_t setEnable ( handle_t h , unsigned uuId , bool enableFl = true ) ;
rc_t clearEnable ( handle_t h , unsigned uuId ) ;
bool isEnabled ( handle_t h , unsigned uuId ) ;
2021-11-14 16:54:52 +00:00
rc_t setOrderKey ( handle_t h , unsigned uuId , int orderKey ) ;
int getOrderKey ( handle_t h , unsigned uuId ) ;
2024-05-11 16:10:21 +00:00
// Scroll the element identified by 'uuId' to the top of the list.
// (uuId must identify a list element whose parent is a 'uiList')
rc_t setScrollTop ( handle_t h , unsigned uuId ) ;
2024-10-12 19:18:05 +00:00
// setBlob() allocates internal memeory and copies the contents of blob[blobByeN]
2021-11-14 16:54:52 +00:00
rc_t setBlob ( handle_t h , unsigned uuId , const void * blob , unsigned blobByteN ) ;
const void * getBlob ( handle_t h , unsigned uuId , unsigned & blobByteN_Ref ) ;
rc_t clearBlob ( handle_t h , unsigned uuId ) ;
2021-10-12 20:52:08 +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
2024-10-19 16:36:12 +00:00
unsigned elementChildCount ( handle_t h , unsigned uuId ) ;
rc_t elementChildUuId ( handle_t h , unsigned uuId , unsigned * bufA , unsigned bufN , unsigned & actualN ) ;
unsigned elementPhysChildCount ( handle_t h , unsigned uuId ) ;
rc_t elementPhysChildUuId ( handle_t h , unsigned uuId , unsigned * bufA , unsigned bufN , unsigned & actualN ) ;
2021-11-14 16:54:52 +00:00
// Release an element an all of it's children.
rc_t destroyElement ( handle_t h , unsigned uuId ) ;
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.
2021-11-03 15:03:30 +00:00
rc_t sendValueBool ( handle_t h , unsigned uuId , bool value ) ;
rc_t sendValueInt ( handle_t h , unsigned uuId , int value ) ;
rc_t sendValueUInt ( handle_t h , unsigned uuId , unsigned value ) ;
rc_t sendValueFloat ( handle_t h , unsigned uuId , float value ) ;
rc_t sendValueDouble ( handle_t h , unsigned uuId , double value ) ;
rc_t sendValueString ( handle_t h , unsigned uuId , const char * value ) ;
2021-10-12 20:52:08 +00:00
2024-01-06 13:44:53 +00:00
rc_t sendMsg ( handle_t h , const char * msg ) ;
2021-11-03 15:03:30 +00:00
2021-11-01 14:11:27 +00:00
void report ( handle_t h ) ;
2023-12-03 16:18:02 +00:00
void realTimeReport ( handle_t h ) ;
2021-10-12 20:52:08 +00:00
2020-04-24 14:20:25 +00:00
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 ;
2022-12-13 21:53:10 +00:00
unsigned idleMsgPeriodMs ; // min period without messages before an idle message is generated
2024-03-28 23:47:29 +00:00
unsigned queueBlkCnt ;
unsigned queueBlkByteCnt ;
2024-09-12 21:18:42 +00:00
bool extraLogsFl ; // Report the websock LLL_NOTICE logs
2021-01-20 18:10:56 +00:00
} args_t ;
2021-11-03 15:03:30 +00:00
rc_t parseArgs ( const object_t & o , args_t & args , const char * object_label = " ui " ) ;
2021-01-20 18:10:56 +00:00
rc_t releaseArgs ( args_t & args ) ;
rc_t create ( handle_t & h ,
2022-12-13 21:53:10 +00:00
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 ) ;
2021-01-20 18:10:56 +00:00
2020-04-07 20:24:34 +00:00
rc_t create ( handle_t & h ,
2022-12-13 21:53:10 +00:00
unsigned port ,
const char * physRootDir ,
void * cbArg ,
uiCallback_t uiCbFunc ,
const object_t * uiRsrc = nullptr ,
const appIdMap_t * appIdMapA = nullptr ,
unsigned appIdMapN = 0 ,
websock : : cbFunc_t wsCbFunc = nullptr ,
const char * dfltPageFn = " index.html " ,
unsigned idleMsgPeriodMs = 50 ,
unsigned rcvBufByteN = 1024 ,
unsigned xmtBufByteN = 1024 ,
2024-03-28 23:47:29 +00:00
unsigned fmtBufByteN = 4096 ,
unsigned queueBlkCnt = 4 ,
2024-09-12 21:18:42 +00:00
unsigned queueBlkByteCnt = 4096 ,
bool extraLogsFl = false ) ;
2020-04-07 20:24:34 +00:00
rc_t destroy ( handle_t & h ) ;
// This function should be called periodically to send and receive
// queued messages to and from the websocket.
2024-01-06 13:44:53 +00:00
// Note that this call may block for up to 'wsTimeOutMs' milliseconds
2024-03-28 23:47:29 +00:00
// while waiting for incoming websocket messages.
rc_t exec ( handle_t h , unsigned wsTimeOutMs ) ;
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 ) ;
2024-03-28 23:47:29 +00:00
void realTimeReport ( handle_t h ) ;
2024-03-25 18:29:58 +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 ,
2024-03-28 23:47:29 +00:00
const ws : : args_t & args ,
void * cbArg ,
uiCallback_t uiCbFunc ,
const appIdMap_t * appIdMapA = nullptr ,
unsigned appIdMapN = 0 ,
unsigned wsTimeOutMs = 50 ,
websock : : cbFunc_t wsCbFunc = nullptr ) ;
2020-04-07 20:24:34 +00:00
rc_t create ( handle_t & h ,
2024-03-28 23:47:29 +00:00
unsigned port ,
const char * physRootDir ,
void * cbArg ,
uiCallback_t uiCbFunc ,
const object_t * uiRsrc = nullptr ,
const appIdMap_t * appIdMapA = nullptr ,
unsigned appIdMapN = 0 ,
unsigned wsTimeOutMs = 50 ,
websock : : cbFunc_t wsCbFunc = nullptr ,
const char * dfltPageFn = " index.html " ,
unsigned idleMsgPeriodMs = 50 ,
unsigned rcvBufByteN = 1024 ,
unsigned xmtBufByteN = 1024 ,
unsigned fmtBufByteN = 4096 ,
unsigned queueBlkCnt = 4 ,
2024-09-12 21:18:42 +00:00
unsigned queueBlkByteCnt = 4096 ,
bool extraLogsFl = false ) ;
2020-04-07 20:24:34 +00:00
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