Commit 3f75f779 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

control/event.c: Change the event API to be per-object driven. It is not yet in use.

parent 1605af57
......@@ -884,49 +884,50 @@ VLC_PUBLIC_API libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterat
/** @} */
/*****************************************************************************
* Callbacks handling
* Event handling
*****************************************************************************/
/** defgroup libvlc_callbacks Callbacks
* \ingroup libvlc
* LibVLC Event Callbacks
* LibVLC Events
* @{
*/
/**
* Register for a callback notification
* \param p_instance the libvlc instance
* \param i_event_type the desired event mask to which we want to listen
* Register for an event notification
* \param p_event_manager the event manager to which you want to attach to
* Generally it is obtained by vlc_my_object_event_manager() where my_object
* Is the object you want to listen to.
* \param i_event_type the desired event to which we want to listen
* \param f_callback the function to call when i_event_type occurs
* \param user_data user provided data to carry with the event
* \param p_e an initialized exception pointer
*/
VLC_PUBLIC_API void libvlc_event_add_callback( libvlc_instance_t *p_instance,
libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback,
void *user_data,
libvlc_exception_t *p_e );
VLC_PUBLIC_API void libvlc_event_attach( libvlc_event_manager_t *p_event_manager,
libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback,
void *user_data,
libvlc_exception_t *p_e );
/**
* Unregister all callbacks notification from an instance
* \param p_instance the libvlc instance
* Unregister an event notification
* \param p_event_manager the event manager
* \param i_event_type the desired event to which we want to unregister
* \param f_callback the function to call when i_event_type occurs
* \param p_e an initialized exception pointer
*/
VLC_PUBLIC_API void libvlc_event_remove_all_callbacks( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e );
VLC_PUBLIC_API void libvlc_event_detach( libvlc_event_manager_t *p_event_manager,
libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback,
void *p_user_data,
libvlc_exception_t *p_e );
/**
* Unregister a callback notification
* \param p_instance the libvlc instance
* \param i_event_type the desired event mask to which we want to unregister
* \param f_callback the function to call when i_event_type occurs
* \param p_e an initialized exception pointer
* Get an event type name
* \param i_event_type the desired event
*/
VLC_PUBLIC_API void libvlc_event_remove_callback( libvlc_instance_t *p_instance,
libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback,
void *p_user_data,
libvlc_exception_t *p_e );
#define libvlc_event_type_name(a) #a
/** @} */
......
......@@ -182,7 +182,7 @@ typedef struct libvlc_log_message_t
*/
/**
* Available events:
* Available events: (XXX: being reworked)
* - libvlc_VolumeChanged
* - libvlc_InputPositionChanged
*/
......@@ -192,9 +192,17 @@ typedef enum libvlc_event_type_t {
libvlc_InputPositionChanged,
} libvlc_event_type_t;
/**
* An Event
* \param type the even type
* \param p_obj the sender object
* \param u Event dependent content
*/
typedef struct libvlc_event_t
{
libvlc_event_type_t type;
void * p_obj;
union
{
struct
......@@ -208,14 +216,19 @@ typedef struct libvlc_event_t
} u;
} libvlc_event_t;
/**
* Event manager that belongs to a libvlc object, and from whom events can
* be received.
*/
typedef struct libvlc_event_manager_t libvlc_event_manager_t;
/**
* Callback function notification
* \param p_instance the libvlc instance
* \param p_event the event triggering the callback
* \param p_user_data user provided data
*/
typedef void ( *libvlc_callback_t )( struct libvlc_instance_t *, libvlc_event_t *, void * );
typedef void ( *libvlc_callback_t )( const libvlc_event_t * );
/**@} */
......
This diff is collapsed.
......@@ -32,6 +32,7 @@ extern "C" {
#include <vlc/vlc.h>
#include <vlc/libvlc_structures.h>
#include <vlc_arrays.h>
#include <vlc_input.h>
/***************************************************************************
......@@ -52,21 +53,6 @@ VLC_EXPORT (void, libvlc_event_fini, ( libvlc_instance_t *, libvlc_exception_t *
* Opaque structures for libvlc API
***************************************************************************/
struct libvlc_callback_entry_t
{
libvlc_instance_t *p_instance;
libvlc_callback_t f_callback;
libvlc_event_type_t i_event_type;
void *p_user_data;
};
struct libvlc_callback_entry_list_t
{
struct libvlc_callback_entry_t *elmt;
struct libvlc_callback_entry_list_t *next;
struct libvlc_callback_entry_list_t *prev;
};
struct libvlc_instance_t
{
libvlc_int_t *p_libvlc_int;
......@@ -94,24 +80,103 @@ struct libvlc_media_instance_t
libvlc_media_descriptor_t *p_md; /* current media descriptor */
};
/*
* Event Handling
*/
/* Example usage
*
* struct libvlc_cool_object_t
* {
* ...
* libvlc_event_manager_t * p_event_manager;
* ...
* }
*
* libvlc_my_cool_object_new()
* {
* ...
* p_self->p_event_manager = libvlc_event_manager_init( p_self,
* p_self->p_libvlc_instance, p_e);
* libvlc_event_manager_register_event_type(p_self->p_event_manager,
* libvlc_MyCoolObjectDidSomething, p_e)
* ...
* }
*
* libvlc_my_cool_object_release()
* {
* ...
* libvlc_event_manager_release( p_self->p_event_manager );
* ...
* }
*
* libvlc_my_cool_object_do_something()
* {
* ...
* libvlc_event_t event;
* event.type = libvlc_MyCoolObjectDidSomething;
* event.my_cool_object_did_something.what_it_did = kSomething;
* libvlc_event_send( p_self->p_event_manager, &event );
* }
* */
typedef struct libvlc_event_listener_t
{
libvlc_event_type_t event_type;
void * p_user_data;
libvlc_callback_t pf_callback;
} libvlc_event_listener_t;
typedef struct libvlc_event_listeners_group_t
{
libvlc_event_type_t event_type;
DECL_ARRAY(libvlc_event_listener_t *) listeners;
} libvlc_event_listeners_group_t;
typedef struct libvlc_event_manager_t
{
void * p_obj;
struct libvlc_instance_t * p_libvlc_instance;
DECL_ARRAY(libvlc_event_listeners_group_t *) listeners_groups;
} libvlc_event_sender_t;
/***************************************************************************
* Other internal functions
***************************************************************************/
VLC_EXPORT (input_thread_t *, libvlc_get_input_thread,
( struct libvlc_media_instance_t *, libvlc_exception_t * ) );
/* Media instance */
VLC_EXPORT (libvlc_media_instance_t *, libvlc_media_instance_new_from_input_thread,
( struct libvlc_instance_t *, input_thread_t *, libvlc_exception_t * ) );
VLC_EXPORT (void, libvlc_media_instance_destroy,
( libvlc_media_instance_t * ) );
/* Media Descriptor */
VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_new_from_input_item,
( struct libvlc_instance_t *, input_item_t *, libvlc_exception_t * ) );
VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_duplicate,
( libvlc_media_descriptor_t * ) );
/* Events */
VLC_EXPORT (void, libvlc_event_init, ( libvlc_instance_t *p_instance, libvlc_exception_t *p_e ) );
VLC_EXPORT (void, libvlc_event_fini, ( libvlc_instance_t *p_instance, libvlc_exception_t *p_e ) );
VLC_EXPORT (libvlc_event_manager_t *, libvlc_event_manager_init, ( void * p_obj, libvlc_instance_t * p_libvlc_inst, libvlc_exception_t *p_e ) );
VLC_EXPORT (void, libvlc_event_manager_release, ( libvlc_event_manager_t * p_em ) );
VLC_EXPORT (void, libvlc_event_manager_register_event_type, ( libvlc_event_manager_t * p_em, libvlc_event_type_t event_type, libvlc_exception_t * p_e ) );
VLC_EXPORT (void, libvlc_event_send, ( libvlc_event_manager_t * p_em, libvlc_event_t * p_event ) );
/* Exception shorcuts */
#define RAISENULL( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \
return NULL; }
#define RAISEVOID( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \
......
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