IPC Gateway 设计

1. IPC Gateway对外提供的功能:

 IPC的register/request/reply/notification服务。

2. IPC Gatew的实现原理:

各个具体的服务注册自己的回调函数,注册时提供服务自身的IPC Channel号。IPC Gateway 创建一个Map结构区记录各自的回调函数,当IPC Gateway接收到来字IPC layer的数据/消息,就会触发之前所注册的回调函数去处理数据。

Callback 函数的类型:

typedef void (*invoke_callback)(const void *ctx, UInt16 function, UInt8 *rx_data,Int32 len);
typedef void (*notification_callback)(UInt16 function, UInt8 *rx_data, Int32 len);
typedef void (*request_callback)(const void *ctx, UInt8 *rx_data, Int32 len);

3. 核心接口的设计:

/*Initialize the ipc gateway. Used to initialize the inside map. */

void ipc_gw_init();  

 /*  Register callback function via channel number.*/

error_type ipc_gw_register(Int32 channel, notification_callback ntf_cb, request_callback req_cb);  

/* Send request ipc message.*/

error_type ipc_gw_send_request(Int32 channel, UInt16 function,const UInt8 *data,Int32 len,const void *context, invoke_callback cb);  

/*Send request ipc message without reply. */

error_type ipc_gw_send_request_no_reply(Int32 channel, UInt16 function,const UInt8 *data,Int32 len); 

/* Reply the request after processing. */

error_type ipc_gw_send_reply(request_context_t *context, const UInt8 *data,Int32 len);   

 /* Send notification without reply. */

error_type ipc_gw_send_notification(Int32 channel, UInt16 function,const UInt8 *data,Int32 len);  

 /*Receive IPC message. Dispatch the message to respect registerd callback functions. */

error_type ipc_gw_receive_msg (Int32 channel, const UInt8* buf, Int32 len);   











 

posted on 2014-03-10 22:24  xiaoxxy  阅读(517)  评论(0编辑  收藏  举报

导航