PolicyKit: Branch 'gdbus'

David Zeuthen david at kemper.freedesktop.org
Tue Aug 3 13:38:32 PDT 2010


 docs/polkit/polkit-1-sections.txt                     |    1 
 src/polkitbackend/polkitbackendauthority.c            |   60 -------------
 src/polkitbackend/polkitbackendauthority.h            |   12 --
 src/polkitbackend/polkitbackendinteractiveauthority.c |   78 +++++++++++++++---
 4 files changed, 69 insertions(+), 82 deletions(-)

New commits:
commit 90c0429f668be1cb675da26eba0ef505e6e3f123
Author: David Zeuthen <davidz at redhat.com>
Date:   Tue Aug 3 16:37:49 2010 -0400

    Make NameOwnerChanged a private impl detail of the interactive authority
    
    There's no need to expose this as public API.
    
    Signed-off-by: David Zeuthen <davidz at redhat.com>

diff --git a/docs/polkit/polkit-1-sections.txt b/docs/polkit/polkit-1-sections.txt
index b1b71cc..5826e54 100644
--- a/docs/polkit/polkit-1-sections.txt
+++ b/docs/polkit/polkit-1-sections.txt
@@ -278,7 +278,6 @@ polkit_backend_authority_register_authentication_agent
 polkit_backend_authority_unregister_authentication_agent
 polkit_backend_authority_authentication_agent_response
 polkit_backend_authority_enumerate_actions
-polkit_backend_authority_system_bus_name_owner_changed
 polkit_backend_authority_enumerate_temporary_authorizations
 polkit_backend_authority_revoke_temporary_authorizations
 polkit_backend_authority_get
diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c
index 28a77ba..9dc8943 100644
--- a/src/polkitbackend/polkitbackendauthority.c
+++ b/src/polkitbackend/polkitbackendauthority.c
@@ -81,20 +81,6 @@ polkit_backend_authority_class_init (PolkitBackendAuthorityClass *klass)
                                           0);
 }
 
-void
-polkit_backend_authority_system_bus_name_owner_changed (PolkitBackendAuthority   *authority,
-                                                        const gchar              *name,
-                                                        const gchar              *old_owner,
-                                                        const gchar              *new_owner)
-{
-  PolkitBackendAuthorityClass *klass;
-
-  klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority);
-
-  if (klass->system_bus_name_owner_changed != NULL)
-    klass->system_bus_name_owner_changed (authority, name, old_owner, new_owner);
-}
-
 /**
  * polkit_backend_authority_get_name:
  * @authority: A #PolkitBackendAuthority.
@@ -503,7 +489,6 @@ polkit_backend_authority_revoke_temporary_authorization_by_id (PolkitBackendAuth
 typedef struct
 {
   guint authority_registration_id;
-  guint name_owner_changed_signal_id;
 
   GDBusNodeInfo *introspection_info;
 
@@ -523,14 +508,9 @@ server_free (Server *server)
 {
   g_free (server->object_path);
 
-  //g_signal_handler_disconnect (server->bus, server->name_owner_changed_id);
-
   if (server->authority_registration_id > 0)
     g_dbus_connection_unregister_object (server->connection, server->authority_registration_id);
 
-  if (server->name_owner_changed_signal_id > 0)
-    g_dbus_connection_signal_unsubscribe (server->connection, server->name_owner_changed_signal_id);
-
   if (server->connection != NULL)
     g_object_unref (server->connection);
 
@@ -1221,34 +1201,6 @@ server_handle_get_property (GDBusConnection  *connection,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static void
-server_on_name_owner_changed_signal (GDBusConnection *connection,
-                                     const gchar     *sender_name,
-                                     const gchar     *object_path,
-                                     const gchar     *interface_name,
-                                     const gchar     *signal_name,
-                                     GVariant        *parameters,
-                                     gpointer         user_data)
-{
-  Server *server = user_data;
-  const gchar *name;
-  const gchar *old_owner;
-  const gchar *new_owner;
-
-  g_variant_get (parameters,
-                 "(&s&s&s)",
-                 &name,
-                 &old_owner,
-                 &new_owner);
-
-  polkit_backend_authority_system_bus_name_owner_changed (server->authority,
-                                                          name,
-                                                          old_owner,
-                                                          new_owner);
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
 static const GDBusInterfaceVTable server_vtable =
 {
   server_handle_method_call,
@@ -1311,18 +1263,6 @@ polkit_backend_authority_register (PolkitBackendAuthority   *authority,
       goto error;
     }
 
-  server->name_owner_changed_signal_id =
-    g_dbus_connection_signal_subscribe (server->connection,
-                                        "org.freedesktop.DBus",   /* sender */
-                                        "org.freedesktop.DBus",   /* interface */
-                                        "NameOwnerChanged",       /* member */
-                                        "/org/freedesktop/DBus",  /* path */
-                                        NULL,                     /* arg0 */
-                                        G_DBUS_SIGNAL_FLAGS_NONE,
-                                        server_on_name_owner_changed_signal,
-                                        server,
-                                        NULL); /* GDestroyNotify */
-
   server->authority = g_object_ref (authority);
 
   server->authority_changed_id = g_signal_connect (server->authority,
diff --git a/src/polkitbackend/polkitbackendauthority.h b/src/polkitbackend/polkitbackendauthority.h
index e6a8104..e9879a7 100644
--- a/src/polkitbackend/polkitbackendauthority.h
+++ b/src/polkitbackend/polkitbackendauthority.h
@@ -98,7 +98,6 @@ struct _PolkitBackendAuthority
  * authorization identified by id or %NULL if the backend doesn't support
  * the operation. See polkit_backend_authority_revoke_temporary_authorization_by_id()
  * for details.
- * @system_bus_name_owner_changed: temporary VFunc, to be removed before API is declared stable.
  *
  * VFuncs that authority backends need to implement.
  */
@@ -169,12 +168,6 @@ struct _PolkitBackendAuthorityClass
                                                     const gchar              *id,
                                                     GError                  **error);
 
-  /* TODO: need something more efficient such that we don't watch all name changes */
-  void (*system_bus_name_owner_changed)  (PolkitBackendAuthority   *authority,
-                                          const gchar              *name,
-                                          const gchar              *old_owner,
-                                          const gchar              *new_owner);
-
   /*< private >*/
   /* Padding for future expansion */
   void (*_polkit_reserved1) (void);
@@ -223,11 +216,6 @@ void     polkit_backend_authority_log (PolkitBackendAuthority *authority,
                                        const gchar *format,
                                        ...);
 
-void     polkit_backend_authority_system_bus_name_owner_changed (PolkitBackendAuthority   *authority,
-                                                                 const gchar              *name,
-                                                                 const gchar              *old_owner,
-                                                                 const gchar              *new_owner);
-
 GList   *polkit_backend_authority_enumerate_actions         (PolkitBackendAuthority    *authority,
                                                              PolkitSubject             *caller,
                                                              const gchar               *locale,
diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c
index c4f993f..ab783b4 100644
--- a/src/polkitbackend/polkitbackendinteractiveauthority.c
+++ b/src/polkitbackend/polkitbackendinteractiveauthority.c
@@ -115,10 +115,10 @@ static void authentication_session_cancel (AuthenticationSession *session);
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static void polkit_backend_interactive_authority_system_bus_name_owner_changed (PolkitBackendAuthority   *authority,
-                                                                          const gchar              *name,
-                                                                          const gchar              *old_owner,
-                                                                          const gchar              *new_owner);
+static void polkit_backend_interactive_authority_system_bus_name_owner_changed (PolkitBackendInteractiveAuthority   *authority,
+                                                                                const gchar              *name,
+                                                                                const gchar              *old_owner,
+                                                                                const gchar              *new_owner);
 
 static GList *polkit_backend_interactive_authority_enumerate_actions  (PolkitBackendAuthority   *authority,
                                                                  PolkitSubject            *caller,
@@ -197,6 +197,8 @@ typedef struct
 
   GHashTable *hash_session_to_authentication_agent;
 
+  GDBusConnection *system_bus_connection;
+  guint name_owner_changed_signal_id;
 } PolkitBackendInteractiveAuthorityPrivate;
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -216,6 +218,35 @@ action_pool_changed (PolkitBackendActionPool *action_pool,
   g_signal_emit_by_name (authority, "changed");
 }
 
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_name_owner_changed_signal (GDBusConnection *connection,
+                              const gchar     *sender_name,
+                              const gchar     *object_path,
+                              const gchar     *interface_name,
+                              const gchar     *signal_name,
+                              GVariant        *parameters,
+                              gpointer         user_data)
+{
+  PolkitBackendInteractiveAuthority *authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (user_data);
+  const gchar *name;
+  const gchar *old_owner;
+  const gchar *new_owner;
+
+  g_variant_get (parameters,
+                 "(&s&s&s)",
+                 &name,
+                 &old_owner,
+                 &new_owner);
+
+  polkit_backend_interactive_authority_system_bus_name_owner_changed (authority,
+                                                                      name,
+                                                                      old_owner,
+                                                                      new_owner);
+}
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
@@ -231,6 +262,7 @@ polkit_backend_interactive_authority_init (PolkitBackendInteractiveAuthority *au
 {
   PolkitBackendInteractiveAuthorityPrivate *priv;
   GFile *directory;
+  GError *error;
 
   priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority);
 
@@ -254,6 +286,29 @@ polkit_backend_interactive_authority_init (PolkitBackendInteractiveAuthority *au
                     "changed",
                     G_CALLBACK (on_session_monitor_changed),
                     authority);
+
+  error = NULL;
+  priv->system_bus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+  if (priv->system_bus_connection == NULL)
+    {
+      g_warning ("Error getting system bus: %s", error->message);
+      g_error_free (error);
+    }
+  else
+    {
+      /* TODO: this is a bit inefficient */
+      priv->name_owner_changed_signal_id =
+        g_dbus_connection_signal_subscribe (priv->system_bus_connection,
+                                            "org.freedesktop.DBus",   /* sender */
+                                            "org.freedesktop.DBus",   /* interface */
+                                            "NameOwnerChanged",       /* member */
+                                            "/org/freedesktop/DBus",  /* path */
+                                            NULL,                     /* arg0 */
+                                            G_DBUS_SIGNAL_FLAGS_NONE,
+                                            on_name_owner_changed_signal,
+                                            authority,
+                                            NULL); /* GDestroyNotify */
+    }
 }
 
 static void
@@ -265,6 +320,12 @@ polkit_backend_interactive_authority_finalize (GObject *object)
   interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (object);
   priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority);
 
+  if (priv->name_owner_changed_signal_id > 0)
+    g_dbus_connection_signal_unsubscribe (priv->system_bus_connection, priv->name_owner_changed_signal_id);
+
+  if (priv->system_bus_connection != NULL)
+    g_object_unref (priv->system_bus_connection);
+
   if (priv->action_pool != NULL)
     g_object_unref (priv->action_pool);
 
@@ -310,7 +371,6 @@ polkit_backend_interactive_authority_class_init (PolkitBackendInteractiveAuthori
   authority_class->get_name                        = polkit_backend_interactive_authority_get_name;
   authority_class->get_version                     = polkit_backend_interactive_authority_get_version;
   authority_class->get_features                    = polkit_backend_interactive_authority_get_features;
-  authority_class->system_bus_name_owner_changed   = polkit_backend_interactive_authority_system_bus_name_owner_changed;
   authority_class->enumerate_actions               = polkit_backend_interactive_authority_enumerate_actions;
   authority_class->check_authorization             = polkit_backend_interactive_authority_check_authorization;
   authority_class->check_authorization_finish      = polkit_backend_interactive_authority_check_authorization_finish;
@@ -2122,10 +2182,10 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-polkit_backend_interactive_authority_system_bus_name_owner_changed (PolkitBackendAuthority   *authority,
-                                                              const gchar              *name,
-                                                              const gchar              *old_owner,
-                                                              const gchar              *new_owner)
+polkit_backend_interactive_authority_system_bus_name_owner_changed (PolkitBackendInteractiveAuthority *authority,
+                                                                    const gchar                       *name,
+                                                                    const gchar                       *old_owner,
+                                                                    const gchar                       *new_owner)
 {
   PolkitBackendInteractiveAuthority *interactive_authority;
   PolkitBackendInteractiveAuthorityPrivate *priv;


More information about the hal-commit mailing list