X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Finhibit.c;h=b6a8151b145e5ad8da4292702713299e30e3a547;hb=8a163fd8273e5feaa366c2a4dacc0eb75d0dbf77;hp=b2c590fd471a9b4b3fd56e9000984d8f822cca03;hpb=3561b9b28f58eb7a4183e158a8fd973800d31ceb;p=vlc diff --git a/modules/misc/inhibit.c b/modules/misc/inhibit.c index b2c590fd47..b6a8151b14 100644 --- a/modules/misc/inhibit.c +++ b/modules/misc/inhibit.c @@ -38,11 +38,12 @@ #include #include #include +#include #include #define PM_SERVICE "org.freedesktop.PowerManagement" -#define PM_PATH "/org/freedesktop/PowerManagement/Inhibit" +#define PM_PATH "/org/freedesktop/PowerManagement/Inhibit" #define PM_INTERFACE "org.freedesktop.PowerManagement.Inhibit" /***************************************************************************** @@ -53,6 +54,9 @@ static void Deactivate ( vlc_object_t * ); static void Run ( intf_thread_t *p_intf ); +static int Inhibit( intf_thread_t *p_intf ); +static int UnInhibit( intf_thread_t *p_intf ); + struct intf_sys_t { DBusConnection *p_conn; @@ -62,11 +66,11 @@ struct intf_sys_t /***************************************************************************** * Module descriptor *****************************************************************************/ -vlc_module_begin(); - set_description( N_("Power Management Inhibitor") ); - set_capability( "interface", 0 ); - set_callbacks( Activate, Deactivate ); -vlc_module_end(); +vlc_module_begin () + set_description( N_("Power Management Inhibitor") ) + set_capability( "interface", 0 ) + set_callbacks( Activate, Deactivate ) +vlc_module_end () /***************************************************************************** * Activate: initialize and create stuff @@ -76,11 +80,8 @@ static int Activate( vlc_object_t *p_this ) intf_thread_t *p_intf = (intf_thread_t*)p_this; DBusError error; - p_intf->pf_run = Run; - p_intf->p_sys = (intf_sys_t *) calloc( 1, sizeof( intf_sys_t ) ); - if( !p_intf->p_sys ) return VLC_ENOMEM; @@ -106,6 +107,9 @@ static int Activate( vlc_object_t *p_this ) static void Deactivate( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t*)p_this; + if( p_intf->p_sys->i_cookie ) + UnInhibit( p_intf ); + dbus_connection_unref( p_intf->p_sys->p_conn ); free( p_intf->p_sys ); } @@ -122,8 +126,6 @@ static int Inhibit( intf_thread_t *p_intf ) DBusMessage *p_msg; DBusMessageIter args; DBusMessage *p_reply; - DBusError error; - dbus_error_init( &error ); dbus_uint32_t i_cookie; p_conn = p_intf->p_sys->p_conn; @@ -136,7 +138,8 @@ static int Inhibit( intf_thread_t *p_intf ) dbus_message_iter_init_append( p_msg, &args ); char *psz_app = strdup( PACKAGE ); - if( !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_app ) ) + if( !psz_app || + !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_app ) ) { free( psz_app ); dbus_message_unref( p_msg ); @@ -144,7 +147,7 @@ static int Inhibit( intf_thread_t *p_intf ) } free( psz_app ); - char *psz_inhibit_reason = strdup( "Playing some media." ); + char *psz_inhibit_reason = strdup( _("Playing some media.") ); if( !psz_inhibit_reason ) { dbus_message_unref( p_msg ); @@ -160,8 +163,7 @@ static int Inhibit( intf_thread_t *p_intf ) free( psz_inhibit_reason ); p_reply = dbus_connection_send_with_reply_and_block( p_conn, p_msg, - 50, &error ); /* blocks 50ms maximum */ - + 50, NULL ); /* blocks 50ms maximum */ dbus_message_unref( p_msg ); if( p_reply == NULL ) { /* g-p-m is not active, or too slow. Better luck next time? */ @@ -169,7 +171,7 @@ static int Inhibit( intf_thread_t *p_intf ) } /* extract the cookie from the reply */ - if( dbus_message_get_args( p_reply, &error, + if( dbus_message_get_args( p_reply, NULL, DBUS_TYPE_UINT32, &i_cookie, DBUS_TYPE_INVALID ) == FALSE ) { @@ -191,8 +193,6 @@ static int UnInhibit( intf_thread_t *p_intf ) DBusConnection *p_conn; DBusMessage *p_msg; DBusMessageIter args; - DBusError error; - dbus_error_init( &error ); dbus_uint32_t i_cookie; p_conn = p_intf->p_sys->p_conn; @@ -226,42 +226,41 @@ static int UnInhibit( intf_thread_t *p_intf ) *****************************************************************************/ static void Run( intf_thread_t *p_intf ) { - vlc_object_lock( p_intf ); - while( vlc_object_alive( p_intf ) ) - { - input_thread_t *p_input; + playlist_t *p_playlist = pl_Hold( p_intf ); + input_thread_t *p_input; + + for( ;; ) + { /* Check playing state every 30 seconds */ - vlc_object_timedwait( p_intf, mdate() + 30000000 ); + msleep( 30 * CLOCK_FREQ ); - p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE ); + p_input = playlist_CurrentInput( p_playlist ); if( p_input ) { - if( PLAYING_S == p_input->i_state && !p_intf->p_sys->i_cookie ) + const int i_state = var_GetInteger( p_input, "state" ); + vlc_object_release( p_input ); + + if( PLAYING_S == i_state ) { - if( !Inhibit( p_intf ) ) - { - vlc_object_release( p_input ); - goto end; - } + if( !p_intf->p_sys->i_cookie ) + { + if( !Inhibit( p_intf ) ) + break; + } } else if( p_intf->p_sys->i_cookie ) { if( !UnInhibit( p_intf ) ) - { - vlc_object_release( p_input ); - goto end; - } + break; } - vlc_object_release( p_input ); } else if( p_intf->p_sys->i_cookie ) { if( !UnInhibit( p_intf ) ) - goto end; + break; } } -end: - vlc_object_unlock( p_intf ); + pl_Release( p_intf ); }