[vlc-devel] [PATCH 2/9] dbus: Rework the main loop using a poll() based model

Rémi Denis-Courmont remi at remlab.net
Tue Feb 8 22:46:52 CET 2011


Le mardi 8 février 2011 23:35:57 Mirsal Ennaime, vous avez écrit :
> From: Mirsal Ennaime <mirsal.ennaime at gmail.com>
> 
> ---
>  modules/control/dbus/dbus.c        |  437
> ++++++++++++++++++++++++++++++++++- modules/control/dbus/dbus_common.h |  
>  4 +
>  2 files changed, 428 insertions(+), 13 deletions(-)
> 
> diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
> index a16d920..45b47c9 100644
> --- a/modules/control/dbus/dbus.c
> +++ b/modules/control/dbus/dbus.c
> @@ -56,8 +56,14 @@
>  #include <vlc_interface.h>
>  #include <vlc_playlist.h>
>  #include <vlc_meta.h>
> +#include <vlc_mtime.h>
> 
>  #include <assert.h>
> +#include <string.h>
> +
> +#include <poll.h>
> +#include <errno.h>
> +#include <unistd.h>
> 
>  /*************************************************************************
> **** * Local prototypes.
> @@ -71,12 +77,33 @@ static int StateChange( intf_thread_t * );
>  static int TrackChange( intf_thread_t * );
>  static int AllCallback( vlc_object_t*, const char*, vlc_value_t,
> vlc_value_t, void* );
> 
> +static void dispatch_status_cb( DBusConnection *p_conn,
> +                                DBusDispatchStatus i_status,
> +                                void *p_data);
> +
> +static dbus_bool_t add_timeout ( DBusTimeout *p_timeout, void *p_data );
> +static dbus_bool_t add_watch   ( DBusWatch *p_watch, void *p_data );
> +
> +static void remove_timeout  ( DBusTimeout *p_timeout, void *p_data );
> +static void remove_watch    ( DBusWatch *p_watch, void *p_data );
> +
> +static void timeout_toggled ( DBusTimeout *p_timeout, void *p_data );
> +static void watch_toggled   ( DBusWatch *p_watch, void *p_data );
> +
> +static void wakeup_main_loop( void *p_data );
> +
>  typedef struct
>  {
>      int signal;
>      int i_node;
>  } callback_info_t;
> 
> +typedef struct
> +{
> +    mtime_t      i_remaining;
> +    DBusTimeout *p_timeout;
> +} timeout_info_t;
> +
>  /*************************************************************************
> **** * Module descriptor
>  
> **************************************************************************
> ***/ @@ -112,12 +139,21 @@ static int Open( vlc_object_t *p_this )
>      if( !p_sys )
>          return VLC_ENOMEM;
> 
> +    dbus_threads_init_default();
> +

Missing error check?

>      p_sys->b_meta_read = false;
>      p_sys->i_caps = CAPS_NONE;
>      p_sys->b_dead = false;
>      p_sys->p_input = NULL;
>      p_sys->i_playing_state = -1;
> 
> +    if( pipe( &p_sys->i_pipe_fd_out ) )

We have vlc_pipe() for this.

> +    {
> +        free( p_sys );
> +        msg_Err( p_intf, "Could not create pipe" );
> +        return VLC_EGENERIC;
> +    }
> +
>      p_sys->b_unique = var_CreateGetBool( p_intf, "dbus-unique-service-id"
> ); if( p_sys->b_unique )
>      {
> @@ -135,8 +171,10 @@ static int Open( vlc_object_t *p_this )
> 
>      dbus_error_init( &error );
> 
> -    /* connect to the session bus */
> -    p_conn = dbus_bus_get( DBUS_BUS_SESSION, &error );
> +    /* connect privately to the session bus
> +     * the connection will not be shared with other vlc modules which use
> dbus, +     * thus avoiding a whole class of concurrency issues */
> +    p_conn = dbus_bus_get_private( DBUS_BUS_SESSION, &error );
>      if( !p_conn )
>      {
>          msg_Err( p_this, "Failed to connect to the D-Bus session daemon:
> %s", @@ -147,6 +185,8 @@ static int Open( vlc_object_t *p_this )
>          return VLC_EGENERIC;
>      }
> 
> +    dbus_connection_set_exit_on_disconnect( p_conn, FALSE );
> +
>      /* register a well-known name on the bus */
>      dbus_bus_request_name( p_conn, psz_service_name, 0, &error );
>      if( dbus_error_is_set( &error ) )
> @@ -175,6 +215,8 @@ static int Open( vlc_object_t *p_this )
>      p_intf->p_sys = p_sys;
>      p_sys->p_conn = p_conn;
>      p_sys->p_events = vlc_array_new();
> +    p_sys->p_timeouts = vlc_array_new();
> +    p_sys->p_watches = vlc_array_new();
>      vlc_mutex_init( &p_sys->lock );
> 
>      p_playlist = pl_Get( p_intf );
> @@ -188,6 +230,44 @@ static int Open( vlc_object_t *p_this )
>      var_AddCallback( p_playlist, "repeat", AllCallback, p_intf );
>      var_AddCallback( p_playlist, "loop", AllCallback, p_intf );
> 
> +    dbus_connection_set_dispatch_status_function( p_conn,
> +                                                  dispatch_status_cb,
> +                                                  p_intf, NULL );
> +
> +    if( !dbus_connection_set_timeout_functions( p_conn,
> +                                                add_timeout,
> +                                                remove_timeout,
> +                                                timeout_toggled,
> +                                                p_intf, NULL ) )
> +    {
> +        dbus_connection_set_dispatch_status_function( p_conn,
> +                                                      NULL, NULL, NULL );
> +        dbus_connection_unref( p_conn );
> +        free( psz_service_name );
> +        free( p_sys );
> +        return VLC_ENOMEM;
> +    }
> +
> +    if( !dbus_connection_set_watch_functions( p_conn,
> +                                              add_watch,
> +                                              remove_watch,
> +                                              watch_toggled,
> +                                              p_intf, NULL ) )
> +    {
> +        dbus_connection_set_dispatch_status_function( p_conn,
> +                                                      NULL, NULL, NULL );
> +        dbus_connection_set_timeout_functions( p_conn,
> +                                               NULL, NULL, NULL, NULL,
> NULL );

What's that for??


-- 
Rémi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis



More information about the vlc-devel mailing list