1 /*****************************************************************************
2 * libvlc_callback.c: New libvlc callback control API
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Filippo Carone <filippo@carone.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "libvlc_internal.h"
25 #include <vlc/libvlc.h>
27 static int handle_callback( vlc_object_t *p_this, char const *psz_cmd,
28 vlc_value_t oldval, vlc_value_t newval,
31 struct libvlc_callback_entry_t *entry = p_data;
33 event.type = entry->i_event_type;
37 event.value_type = BOOLEAN_EVENT;
39 case INPUT_POSITION_CHANGED:
44 event.old_value = oldval;
45 event.new_value = newval;
47 /* Call the client entry */
48 entry->f_callback( entry->p_instance, &event, entry->p_user_data );
53 void libvlc_callback_register_for_event( libvlc_instance_t *p_instance,
54 libvlc_event_type_t i_event_type,
55 libvlc_callback_t f_callback,
57 libvlc_exception_t *p_e )
61 RAISEVOID (" Callback function is null ");
63 struct libvlc_callback_entry_t *entry = malloc( sizeof( struct libvlc_callback_entry_t ) );
64 entry->f_callback = f_callback;
65 entry->i_event_type = i_event_type;
66 entry->p_user_data = user_data;
68 const char *callback_name;
70 switch ( i_event_type )
73 callback_name = "volume-change";
75 case INPUT_POSITION_CHANGED:
79 RAISEVOID( "Unsupported event." );
82 int res = var_AddCallback( p_instance->p_libvlc_int,
87 if (res != VLC_SUCCESS)
90 RAISEVOID("Internal callback registration was not successful. Callback not registered.");
93 add_callback_entry( entry, &p_instance->p_callback_list );
98 void libvlc_callback_unregister_for_event( libvlc_instance_t *p_instance,
99 libvlc_event_type_t i_event_type,
100 libvlc_callback_t f_callback,
102 libvlc_exception_t *p_e )
104 struct libvlc_callback_entry_list_t *p_listitem = p_instance->p_callback_list;
108 if( p_listitem->elmt->f_callback == f_callback
109 && ( p_listitem->elmt->i_event_type == i_event_type )
110 && ( p_listitem->elmt->p_user_data == p_user_data )
114 if( p_listitem->prev )
115 p_listitem->prev->next = p_listitem->next;
117 p_instance->p_callback_list = p_listitem->next;
119 p_listitem->next->prev = p_listitem->prev;
123 p_listitem = p_listitem->next;