Move event handling from global variable to handle

- remove global event function pointer
- add event function pointer to handle structure
- add handle parameter to register functions
- move all register functions to mbus-protocol-aux.c
This commit is contained in:
Stefan Wahren
2013-10-13 21:49:40 +02:00
parent 9e23818152
commit 0cf57bfc35
6 changed files with 53 additions and 60 deletions

View File

@ -93,6 +93,10 @@ typedef struct _mbus_handle {
int (*send) (struct _mbus_handle *handle, mbus_frame *frame);
int (*recv) (struct _mbus_handle *handle, mbus_frame *frame);
void (*free_auxdata) (struct _mbus_handle *handle);
void (*recv_event) (unsigned char src_type, const char *buff, size_t len);
void (*send_event) (unsigned char src_type, const char *buff, size_t len);
void (*scan_progress) (struct _mbus_handle *handle, const char *mask);
void (*found_event) (struct _mbus_handle *handle, mbus_frame *frame);
void *auxdata;
} mbus_handle;
@ -148,17 +152,16 @@ typedef enum _mbus_context_option {
MBUS_OPTION_PURGE_FIRST_FRAME /**< option controls the echo cancelation for mbus_recv_frame */
} mbus_context_option;
/**
* Event callback functions
*/
extern void (*_mbus_scan_progress)(mbus_handle * handle, const char *mask);
extern void (*_mbus_found_event)(mbus_handle * handle, mbus_frame *frame);
/**
* Event register functions
*/
void mbus_register_scan_progress(void (*event)(mbus_handle * handle, const char *mask));
void mbus_register_found_event(void (*event)(mbus_handle * handle, mbus_frame *frame));
//
// Event register functions
//
void mbus_register_recv_event(mbus_handle *handle, void (*event)(unsigned char src_type, const char *buff, size_t len));
void mbus_register_send_event(mbus_handle *handle, void (*event)(unsigned char src_type, const char *buff, size_t len));
void mbus_register_scan_progress(mbus_handle *handle, void (*event)(mbus_handle *handle, const char *mask));
void mbus_register_found_event(mbus_handle *handle, void (*event)(mbus_handle *handle, mbus_frame *frame));
/**
* Allocate and initialize M-Bus serial context.