Commit 3babc98d authored by Simon Morlat's avatar Simon Morlat
Browse files

implement easy sip listener creation (for non object styled code)

parent ddacf79f
......@@ -102,6 +102,7 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sdp_version_t),
BELLE_SIP_TYPE_ID(belle_sdp_base_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_mime_parameter_t),
BELLE_SIP_TYPE_ID(belle_sip_callbacks_t),
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -48,5 +48,22 @@ belle_sip_server_transaction_t *belle_sip_request_event_get_server_transaction(c
belle_sip_dialog_t *belle_sip_request_event_get_dialog(const belle_sip_request_event_t* event);
struct belle_sip_listener_callbacks{
void (*process_dialog_terminated)(void *user_ctx, const belle_sip_dialog_terminated_event_t *event);
void (*process_io_error)(void *user_ctx, const belle_sip_io_error_event_t *event);
void (*process_request_event)(void *user_ctx, const belle_sip_request_event_t *event);
void (*process_response_event)(void *user_ctx, const belle_sip_response_event_t *event);
void (*process_timeout)(void *user_ctx, const belle_sip_timeout_event_t *event);
void (*process_transaction_terminated)(void *user_ctx, const belle_sip_transaction_terminated_event_t *event);
};
typedef struct belle_sip_listener_callbacks belle_sip_listener_callbacks_t;
/**
* Creates an object implementing the belle_sip_listener_t interface.
* This object passes the events to the callbacks, providing also the user context.
**/
belle_sip_listener_t *belle_sip_listener_create_from_callbacks(const belle_sip_listener_callbacks_t *callbacks, void *user_ctx);
#endif
......@@ -26,3 +26,89 @@ belle_sip_client_transaction_t *belle_sip_response_event_get_client_transaction(
return event->client_transaction;
}
belle_sip_dialog_t *belle_sip_response_event_get_dialog(const belle_sip_response_event_t* event){
return event->dialog;
}
belle_sip_request_t* belle_sip_request_event_get_request(const belle_sip_request_event_t* event){
return event->request;
}
belle_sip_server_transaction_t *belle_sip_request_event_get_server_transaction(const belle_sip_request_event_t* event){
return event->server_transaction;
}
belle_sip_dialog_t *belle_sip_request_event_get_dialog(const belle_sip_request_event_t* event){
return event->dialog;
}
typedef struct belle_sip_callbacks belle_sip_callbacks_t;
struct belle_sip_callbacks{
belle_sip_object_t base;
belle_sip_listener_callbacks_t cbs;
void *user_ctx;
};
static void process_dialog_terminated(belle_sip_listener_t *l, const belle_sip_dialog_terminated_event_t *event){
belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
if (obj->cbs.process_dialog_terminated)
obj->cbs.process_dialog_terminated(obj->user_ctx,event);
}
static void process_io_error(belle_sip_listener_t *l, const belle_sip_io_error_event_t *event){
belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
if (obj->cbs.process_io_error)
obj->cbs.process_io_error(obj->user_ctx,event);
}
static void process_request_event(belle_sip_listener_t *l, const belle_sip_request_event_t *event){
belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
if (obj->cbs.process_request_event)
obj->cbs.process_request_event(obj->user_ctx,event);
}
static void process_response_event(belle_sip_listener_t *l, const belle_sip_response_event_t *event){
belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
if (obj->cbs.process_response_event)
obj->cbs.process_response_event(obj->user_ctx,event);
}
static void process_timeout(belle_sip_listener_t *l, const belle_sip_timeout_event_t *event){
belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
if (obj->cbs.process_timeout)
obj->cbs.process_timeout(obj->user_ctx,event);
}
static void process_transaction_terminated(belle_sip_listener_t *l, const belle_sip_transaction_terminated_event_t *event){
belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
if (obj->cbs.process_transaction_terminated)
obj->cbs.process_transaction_terminated(obj->user_ctx,event);
}
BELLE_SIP_DECLARE_VPTR(belle_sip_callbacks_t);
BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_sip_callbacks_t,belle_sip_listener_t)
process_dialog_terminated,
process_io_error,
process_request_event,
process_response_event,
process_timeout,
process_transaction_terminated
BELLE_SIP_IMPLEMENT_INTERFACE_END
BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(belle_sip_callbacks_t,belle_sip_listener_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_callbacks_t,belle_sip_object_t,NULL,NULL,NULL,FALSE);
belle_sip_listener_t *belle_sip_listener_create_from_callbacks(const belle_sip_listener_callbacks_t *callbacks, void *user_ctx){
belle_sip_callbacks_t *obj=belle_sip_object_new(belle_sip_callbacks_t);
memcpy(&obj->cbs,callbacks,sizeof(belle_sip_listener_callbacks_t));
obj->user_ctx=user_ctx;
return BELLE_SIP_LISTENER(obj);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment