Commit e7779161 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

include/vlc_input.h: Emit vlc_InputItemMetaChanged event.

include/vlc_events.h: Opt for the vlc_object_name_function_name naming scheme.
parent fbb3035b
......@@ -26,6 +26,7 @@
# define VLC_EVENTS_H
#include <vlc_arrays.h>
#include <vlc_meta.h>
/**
* \file
......@@ -115,11 +116,11 @@ typedef struct vlc_event_t
{
vlc_event_type_t type;
void * p_obj; /* Sender object, automatically filled by event_Send() */
union event_type_specific
union vlc_event_type_specific
{
struct
struct vlc_input_item_meta_changed
{
int meta; /* One of the meta identified in include/vlc_meta.h */
vlc_meta_type_t meta_type;
} input_item_meta_changed;
} u;
} vlc_event_t;
......@@ -135,38 +136,40 @@ typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
* p_obj points to the object that owns the event manager, and from
* which events are sent
*/
int event_manager_Create( vlc_event_manager_t * p_em, void * p_obj );
VLC_EXPORT(int, vlc_event_manager_init, ( vlc_event_manager_t * p_em,
void * p_obj ));
/*
* Destroy
*/
void event_manager_Destroy( vlc_event_manager_t * p_em );
VLC_EXPORT(void, vlc_event_manager_fini, ( vlc_event_manager_t * p_em ));
/*
* Tells a specific event manager that it will handle event_type object
*/
int event_manager_RegisterEventType( vlc_event_manager_t * p_em,
vlc_event_type_t event_type );
VLC_EXPORT(int, vlc_event_manager_register_event_type,
( vlc_event_manager_t * p_em, vlc_event_type_t event_type ));
/*
* Send an event to the listener attached to this p_em.
*/
void event_Send( vlc_event_manager_t * p_em, vlc_event_t * p_event );
VLC_EXPORT(void, vlc_event_send, ( vlc_event_manager_t * p_em,
vlc_event_t * p_event ));
/*
* Add a callback for an event.
*/
int event_Attach( vlc_event_manager_t * p_event_manager,
vlc_event_type_t event_type,
vlc_event_callback_t pf_callback,
void *p_user_data );
VLC_EXPORT(int, vlc_event_attach, ( vlc_event_manager_t * p_event_manager,
vlc_event_type_t event_type,
vlc_event_callback_t pf_callback,
void *p_user_data ));
/*
* Remove a callback for an event.
*/
int event_Detach( vlc_event_manager_t *p_event_manager,
vlc_event_type_t event_type,
vlc_event_callback_t pf_callback,
void *p_user_data );
VLC_EXPORT(int, vlc_event_detach, ( vlc_event_manager_t *p_event_manager,
vlc_event_type_t event_type,
vlc_event_callback_t pf_callback,
void *p_user_data ));
#endif /* VLC_EVENTS_H */
......@@ -33,6 +33,7 @@
#include <vlc_es.h>
#include <vlc_meta.h>
#include <vlc_epg.h>
#include <vlc_events.h>
struct vlc_meta_t;
......@@ -79,7 +80,9 @@ struct input_item_t
int i_nb_played; /**< Number of times played */
vlc_meta_t *p_meta;
vlc_event_manager_t event_manager;
vlc_mutex_t lock; /**< Lock for the item */
};
......@@ -111,6 +114,9 @@ static inline void input_ItemInit( vlc_object_t *p_o, input_item_t *p_i )
p_i->p_meta = NULL;
vlc_mutex_init( p_o, &p_i->lock );
vlc_event_manager_init( &p_i->event_manager, p_i );
vlc_event_manager_register_event_type( &p_i->event_manager,
vlc_InputItemMetaChanged );
}
static inline void input_ItemCopyOptions( input_item_t *p_parent,
......@@ -135,6 +141,8 @@ static inline void input_ItemClean( input_item_t *p_i )
{
int i;
vlc_event_manager_fini( &p_i->event_manager );
free( p_i->psz_name );
free( p_i->psz_uri );
if( p_i->p_stats )
......@@ -187,9 +195,15 @@ static inline void input_ItemClean( input_item_t *p_i )
static inline void input_item_SetMeta( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz_val )
{
vlc_event_t event;
if( !p_i->p_meta )
p_i->p_meta = vlc_meta_New();
vlc_meta_Set( p_i->p_meta, meta_type, psz_val );
/* Notify interested third parties */
event.type = vlc_InputItemMetaChanged;
event.u.input_item_meta_changed.meta_type = meta_type;
vlc_event_send( &p_i->event_manager, &event );
}
static inline const char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
......
......@@ -68,7 +68,7 @@ typedef struct vlc_event_listeners_group_t
* necessarily a vlc_object_t (an input_item_t is not a vlc_object_t
* for instance).
*/
int event_manager_Create( vlc_event_manager_t * p_em, void * p_obj )
int vlc_event_manager_init( vlc_event_manager_t * p_em, void * p_obj )
{
p_em->p_obj = p_obj;
ARRAY_INIT( p_em->listeners_groups );
......@@ -78,7 +78,7 @@ int event_manager_Create( vlc_event_manager_t * p_em, void * p_obj )
/**
* Destroy the event manager
*/
void event_manager_Destroy( vlc_event_manager_t * p_em )
void vlc_event_manager_fini( vlc_event_manager_t * p_em )
{
struct vlc_event_listeners_group_t * listeners_group;
struct vlc_event_listener_t * listener;
......@@ -95,7 +95,7 @@ void event_manager_Destroy( vlc_event_manager_t * p_em )
/**
* Destroy the event manager
*/
int event_manager_RegisterEventType(
int vlc_event_manager_register_event_type(
vlc_event_manager_t * p_em,
vlc_event_type_t event_type )
{
......@@ -116,8 +116,8 @@ int event_manager_RegisterEventType(
/**
* Send an event to the listener attached to this p_em.
*/
void event_Send( vlc_event_manager_t * p_em,
vlc_event_t * p_event )
void vlc_event_send( vlc_event_manager_t * p_em,
vlc_event_t * p_event )
{
vlc_event_listeners_group_t * listeners_group;
vlc_event_listener_t * listener;
......@@ -140,10 +140,10 @@ void event_Send( vlc_event_manager_t * p_em,
/**
* Add a callback for an event.
*/
int event_Attach( vlc_event_manager_t * p_event_manager,
vlc_event_type_t event_type,
vlc_event_callback_t pf_callback,
void *p_user_data )
int vlc_event_attach( vlc_event_manager_t * p_event_manager,
vlc_event_type_t event_type,
vlc_event_callback_t pf_callback,
void *p_user_data )
{
vlc_event_listeners_group_t * listeners_group;
vlc_event_listener_t * listener;
......@@ -169,10 +169,10 @@ int event_Attach( vlc_event_manager_t * p_event_manager,
/**
* Remove a callback for an event.
*/
int event_Detach( vlc_event_manager_t *p_event_manager,
vlc_event_type_t event_type,
vlc_event_callback_t pf_callback,
void *p_user_data )
int vlc_event_detach( vlc_event_manager_t *p_event_manager,
vlc_event_type_t event_type,
vlc_event_callback_t pf_callback,
void *p_user_data )
{
vlc_event_listeners_group_t * listeners_group;
struct vlc_event_listener_t * listener;
......
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