X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Finhibit.c;h=b50d8e95acc0a744363bd9c03c81ccf4704d997b;hb=f6cc8a39507a630bb20c865b81039eafa72834b6;hp=fa374b2df18bdbb18d6396a1e1987ebf20a41733;hpb=87bc70075835e1b2f22b611e63f251dd8cb153af;p=vlc diff --git a/modules/misc/inhibit.c b/modules/misc/inhibit.c index fa374b2df1..b50d8e95ac 100644 --- a/modules/misc/inhibit.c +++ b/modules/misc/inhibit.c @@ -30,14 +30,19 @@ * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#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" /***************************************************************************** @@ -58,7 +63,7 @@ struct intf_sys_t * Module descriptor *****************************************************************************/ vlc_module_begin(); - set_description( _("Power Management Inhibiter") ); + set_description( N_("Power Management Inhibitor") ); set_capability( "interface", 0 ); set_callbacks( Activate, Deactivate ); vlc_module_end(); @@ -71,11 +76,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; @@ -109,7 +111,7 @@ static void Deactivate( vlc_object_t *p_this ) * Inhibit: Notify the power management daemon that it shouldn't suspend * the computer because of inactivity * - * returns VLC_FALSE if Out of memory, else VLC_TRUE + * returns false if Out of memory, else true *****************************************************************************/ static int Inhibit( intf_thread_t *p_intf ) { @@ -117,8 +119,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; @@ -126,16 +126,17 @@ static int Inhibit( intf_thread_t *p_intf ) p_msg = dbus_message_new_method_call( PM_SERVICE, PM_PATH, PM_INTERFACE, "Inhibit" ); if( !p_msg ) - return VLC_FALSE; + return false; 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 ); - return VLC_FALSE; + return false; } free( psz_app ); @@ -143,51 +144,48 @@ static int Inhibit( intf_thread_t *p_intf ) if( !psz_inhibit_reason ) { dbus_message_unref( p_msg ); - return VLC_FALSE; + return false; } if( !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_inhibit_reason ) ) { free( psz_inhibit_reason ); dbus_message_unref( p_msg ); - return VLC_FALSE; + return false; } 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? */ - return VLC_TRUE; + return true; } /* 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 ) { - return VLC_FALSE; + return false; } /* Save the cookie */ p_intf->p_sys->i_cookie = i_cookie; - return VLC_TRUE; + return true; } /***************************************************************************** * UnInhibit: Notify the power management daemon that we aren't active anymore * - * returns VLC_FALSE if Out of memory, else VLC_TRUE + * returns false if Out of memory, else true *****************************************************************************/ 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; @@ -195,7 +193,7 @@ static int UnInhibit( intf_thread_t *p_intf ) p_msg = dbus_message_new_method_call( PM_SERVICE, PM_PATH, PM_INTERFACE, "UnInhibit" ); if( !p_msg ) - return VLC_FALSE; + return false; dbus_message_iter_init_append( p_msg, &args ); @@ -203,17 +201,17 @@ static int UnInhibit( intf_thread_t *p_intf ) if( !dbus_message_iter_append_basic( &args, DBUS_TYPE_UINT32, &i_cookie ) ) { dbus_message_unref( p_msg ); - return VLC_FALSE; + return false; } if( !dbus_connection_send( p_conn, p_msg, NULL ) ) - return VLC_FALSE; + return false; dbus_connection_flush( p_conn ); dbus_message_unref( p_msg ); p_intf->p_sys->i_cookie = 0; - return VLC_TRUE; + return true; } /***************************************************************************** @@ -221,44 +219,34 @@ static int UnInhibit( intf_thread_t *p_intf ) *****************************************************************************/ static void Run( intf_thread_t *p_intf ) { - for(;;) + for( ;; ) { input_thread_t *p_input; - vlc_bool_t b_quit; /* Check playing state every 30 seconds */ - vlc_object_lock( p_intf ); - b_quit = vlc_object_timedwait( p_intf, mdate() + 30000000 ) < 0; - vlc_object_unlock( p_intf ); - - if( b_quit ) - break; + msleep( 30 * CLOCK_FREQ ); p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE ); if( p_input ) { - if( PLAYING_S == p_input->i_state && !p_intf->p_sys->i_cookie ) + int i_state = p_input->i_state; + vlc_object_release( p_input ); + + if( PLAYING_S == i_state && !p_intf->p_sys->i_cookie ) { if( !Inhibit( p_intf ) ) - { - vlc_object_release( p_input ); - return; - } + break; } else if( p_intf->p_sys->i_cookie ) { if( !UnInhibit( p_intf ) ) - { - vlc_object_release( p_input ); - return; - } + break; } - vlc_object_release( p_input ); } else if( p_intf->p_sys->i_cookie ) { if( !UnInhibit( p_intf ) ) - return; + break; } } }