]> git.sesse.net Git - vlc/blobdiff - modules/misc/inhibit.c
Fix memleaks (use vlclua_dir_list_free).
[vlc] / modules / misc / inhibit.c
index 1103bd0c4f2e1cbbd7e6ea9d7c596dd3711ca5be..b2c590fd471a9b4b3fd56e9000984d8f822cca03 100644 (file)
  * Preamble
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_input.h>
 #include <vlc_interface.h>
 
@@ -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();
@@ -109,7 +114,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 )
 {
@@ -126,7 +131,7 @@ 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 );
 
@@ -135,7 +140,7 @@ static int Inhibit( intf_thread_t *p_intf )
     {
         free( psz_app );
         dbus_message_unref( p_msg );
-        return VLC_FALSE;
+        return false;
     }
     free( psz_app );
 
@@ -143,14 +148,14 @@ 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 );
 
@@ -160,7 +165,7 @@ static int Inhibit( intf_thread_t *p_intf )
     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 */
@@ -168,18 +173,18 @@ static int Inhibit( intf_thread_t *p_intf )
             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 )
 {
@@ -195,7 +200,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,16 +208,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 );
 
-    return VLC_TRUE;
+    p_intf->p_sys->i_cookie = 0;
+    return true;
 }
 
 /*****************************************************************************
@@ -220,18 +226,13 @@ static int UnInhibit( intf_thread_t *p_intf )
  *****************************************************************************/
 static void Run( intf_thread_t *p_intf )
 {
-    for(;;)
+    vlc_object_lock( p_intf );
+    while( vlc_object_alive( p_intf ) )
     {
         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;
+        vlc_object_timedwait( p_intf, mdate() + 30000000 );
 
         p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
         if( p_input )
@@ -241,7 +242,7 @@ static void Run( intf_thread_t *p_intf )
                 if( !Inhibit( p_intf ) )
                 {
                     vlc_object_release( p_input );
-                    return;
+                    goto end;
                 }
             }
             else if( p_intf->p_sys->i_cookie )
@@ -249,7 +250,7 @@ static void Run( intf_thread_t *p_intf )
                 if( !UnInhibit( p_intf ) )
                 {
                     vlc_object_release( p_input );
-                    return;
+                    goto end;
                 }
             }
             vlc_object_release( p_input );
@@ -257,7 +258,10 @@ static void Run( intf_thread_t *p_intf )
         else if( p_intf->p_sys->i_cookie )
         {
             if( !UnInhibit( p_intf ) )
-                return;
+                goto end;
         }
     }
+
+end:
+    vlc_object_unlock( p_intf );
 }