2018-02-24 00:30:44 +01:00
|
|
|
#ifndef __MESSAGE_SET_H
|
|
|
|
#define __MESSAGE_SET_H
|
|
|
|
|
2018-03-03 17:42:28 +01:00
|
|
|
#include "mlist.h"
|
2018-03-06 03:08:14 +01:00
|
|
|
#include "sock.h"
|
|
|
|
#include "mavl.h"
|
2018-04-14 00:50:58 +02:00
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
#include "val.h"
|
2022-08-09 09:52:30 +02:00
|
|
|
#include "cfg.h"
|
2018-03-03 08:15:19 +01:00
|
|
|
|
|
|
|
struct cw_ElemDef{
|
2018-03-03 17:42:28 +01:00
|
|
|
int proto;
|
|
|
|
int vendor;
|
2018-03-03 08:15:19 +01:00
|
|
|
int id;
|
|
|
|
int mand;
|
|
|
|
int op;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cw_ElemData{
|
2018-03-03 17:42:28 +01:00
|
|
|
int proto;
|
|
|
|
int vendor;
|
|
|
|
int id;
|
2018-03-03 08:15:19 +01:00
|
|
|
int mand;
|
|
|
|
};
|
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
struct cw_ElemHandlerParams {
|
2022-08-13 09:47:12 +02:00
|
|
|
struct cw_Conn * conn; /**< a connection the message belongs to*/
|
|
|
|
struct cw_MsgSet * msgset;
|
2022-07-28 18:25:05 +02:00
|
|
|
struct cw_MsgData * msgdata;
|
2018-03-12 18:01:40 +01:00
|
|
|
struct cw_ElemData * elemdata;
|
2018-03-09 07:44:17 +01:00
|
|
|
struct sockaddr *from;
|
2018-03-11 10:34:20 +01:00
|
|
|
mavl_t mand_found;
|
2022-08-09 09:52:30 +02:00
|
|
|
// cw_Val_t * elem;
|
2018-03-20 18:47:06 +01:00
|
|
|
char * debug_details;
|
2022-08-09 09:52:30 +02:00
|
|
|
cw_Cfg_t * cfg;
|
2022-08-14 12:26:34 +02:00
|
|
|
cw_Cfg_t * cfg_list[10];
|
2018-03-09 07:44:17 +01:00
|
|
|
};
|
|
|
|
|
2018-03-25 22:38:07 +02:00
|
|
|
|
2018-03-25 21:39:31 +02:00
|
|
|
|
2018-03-03 08:15:19 +01:00
|
|
|
struct cw_ElemHandler {
|
|
|
|
const char * name;
|
|
|
|
int id;
|
|
|
|
int vendor;
|
|
|
|
int proto;
|
|
|
|
int min_len;
|
|
|
|
int max_len;
|
2018-03-25 22:38:07 +02:00
|
|
|
/*const struct cw_Type * type;*/
|
|
|
|
const void * type;
|
2018-03-03 08:15:19 +01:00
|
|
|
const char * key;
|
2018-03-09 07:44:17 +01:00
|
|
|
int (*get)(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
|
|
|
uint8_t*data, int len);
|
2018-03-12 18:01:40 +01:00
|
|
|
|
|
|
|
int (*put)(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params, uint8_t * dst);
|
|
|
|
|
2018-04-23 07:51:56 +02:00
|
|
|
int (*mkkey)(const char *pkey, uint8_t*data, int len, char *dst);
|
2018-05-22 07:15:52 +02:00
|
|
|
int (*patch)(uint8_t *dst, void *data );
|
2022-08-09 21:48:15 +02:00
|
|
|
void * param;
|
2018-04-23 07:51:56 +02:00
|
|
|
|
2018-03-03 08:15:19 +01:00
|
|
|
};
|
|
|
|
|
2022-07-29 12:11:19 +02:00
|
|
|
|
|
|
|
struct cw_MsgSet {
|
|
|
|
mavl_t msgdata;
|
|
|
|
mavl_t handlers_by_id;
|
|
|
|
mavl_t handlers_by_key;
|
2022-08-14 14:04:58 +02:00
|
|
|
// mavl_t types_tree;
|
2022-08-11 00:21:01 +02:00
|
|
|
mavl_t statemachine_states;
|
2022-07-29 12:11:19 +02:00
|
|
|
int (*write_header)(struct cw_ElemHandler * handler, uint8_t * dst, int len);
|
|
|
|
int (*header_len)(struct cw_ElemHandler *handler);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
struct cw_State{
|
|
|
|
uint8_t state;
|
|
|
|
uint8_t next;
|
|
|
|
};
|
|
|
|
typedef struct cw_State cw_State_t;
|
|
|
|
|
2018-03-03 08:15:19 +01:00
|
|
|
struct cw_MsgDef{
|
|
|
|
const char * name;
|
|
|
|
int type; /**< Message type */
|
|
|
|
int receiver; /**< Who can receive this message */
|
2022-08-13 10:36:05 +02:00
|
|
|
cw_State_t * states; /**< states in wich the message is allowed */
|
2018-03-03 08:15:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct cw_ElemDef * elements;
|
2022-08-13 10:19:06 +02:00
|
|
|
int (*preprocess)(struct cw_Conn * conn);
|
2022-08-13 09:47:12 +02:00
|
|
|
int (*postprocess)(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len);
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
/* uint8_t next_state;*/
|
2018-03-03 08:15:19 +01:00
|
|
|
};
|
2018-02-26 20:18:53 +01:00
|
|
|
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
|
|
|
|
|
2018-03-02 08:49:37 +01:00
|
|
|
struct cw_MsgData{
|
2018-02-26 20:18:53 +01:00
|
|
|
int type;
|
|
|
|
const char * name;
|
2018-05-07 10:57:12 +02:00
|
|
|
cw_State_t * states;
|
2018-02-28 07:38:02 +01:00
|
|
|
int receiver;
|
2018-02-26 20:18:53 +01:00
|
|
|
mavl_t elements_tree;
|
|
|
|
mlist_t elements_list;
|
2022-08-13 10:36:05 +02:00
|
|
|
mlist_t mand_keys; /**< Keys of mandatory elements */
|
2018-04-08 16:48:13 +02:00
|
|
|
|
2022-08-13 10:19:06 +02:00
|
|
|
int (*preprocess)(struct cw_Conn * conn);
|
2022-08-13 09:47:12 +02:00
|
|
|
int (*postprocess)(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len);
|
2018-05-07 10:57:12 +02:00
|
|
|
/* uint8_t next_state;*/
|
2018-02-26 20:18:53 +01:00
|
|
|
};
|
|
|
|
|
2018-03-03 08:15:19 +01:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
struct cw_StateMachineState{
|
|
|
|
uint8_t prevstate;
|
|
|
|
uint8_t state;
|
|
|
|
const char * timer_key;
|
|
|
|
int timer_default;
|
|
|
|
int retval;
|
|
|
|
const char *dbgmsg;
|
|
|
|
uint8_t jump_prevstate;
|
|
|
|
uint8_t jump_state;
|
2018-03-09 07:44:17 +01:00
|
|
|
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
};
|
|
|
|
typedef struct cw_StateMachineState cw_StateMachineState_t;
|
2018-03-09 07:44:17 +01:00
|
|
|
|
2018-03-03 08:15:19 +01:00
|
|
|
extern struct cw_MsgSet * cw_msgset_create();
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
void cw_msgset_destroy(struct cw_MsgSet * set);
|
|
|
|
int cw_msgset_add(struct cw_MsgSet * set,
|
2018-03-03 17:42:28 +01:00
|
|
|
struct cw_MsgDef messages[], struct cw_ElemHandler handlers[]);
|
2018-05-07 10:57:12 +02:00
|
|
|
|
|
|
|
int cw_msgset_add_states(struct cw_MsgSet * set, cw_StateMachineState_t * states);
|
|
|
|
|
2018-03-12 18:01:40 +01:00
|
|
|
/*mlist_t cw_msgset_get_msg(struct cw_MsgSet * set, int type);*/
|
|
|
|
|
2018-03-04 16:59:20 +01:00
|
|
|
struct cw_MsgData * cw_msgset_get_msgdata(struct cw_MsgSet *set,int type);
|
2018-03-05 20:39:15 +01:00
|
|
|
struct cw_ElemHandler * cw_msgset_get_elemhandler(struct cw_MsgSet * set,
|
|
|
|
int proto, int vendor, int id);
|
2018-02-26 20:18:53 +01:00
|
|
|
|
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
#define CW_MSGSET_POSTPROCESS 1
|
|
|
|
#define CW_MSGSET_PREPROCESS 2
|
|
|
|
|
|
|
|
typedef int (*cw_MsgCallbackFun)(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len);
|
|
|
|
cw_MsgCallbackFun cw_msgset_set_postprocess(struct cw_MsgSet * set,int msg_id,
|
|
|
|
cw_MsgCallbackFun fun);
|
|
|
|
|
|
|
|
|
2018-03-03 08:15:19 +01:00
|
|
|
#endif
|