add a hash() method to the Subject interface
authorDavid Zeuthen <davidz@redhat.com>
Tue, 20 Jan 2009 18:31:41 +0000 (13:31 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Tue, 20 Jan 2009 18:31:41 +0000 (13:31 -0500)
src/polkit/polkitsubject.c
src/polkit/polkitsubject.h
src/polkit/polkitsystembusname.c
src/polkit/polkitunixprocess.c
src/polkit/polkitunixsession.c

index 5df1a65..124a595 100644 (file)
@@ -66,6 +66,12 @@ polkit_subject_get_type (void)
   return iface_type;
 }
 
+guint
+polkit_subject_hash (PolkitSubject *subject)
+{
+  return POLKIT_SUBJECT_GET_IFACE (subject)->hash (subject);
+}
+
 gboolean
 polkit_subject_equal (PolkitSubject *a,
                       PolkitSubject *b)
index 22899ee..6f95c29 100644 (file)
@@ -42,6 +42,8 @@ struct _PolkitSubjectIface
 {
   GTypeInterface parent_iface;
 
+  guint    (*hash)      (PolkitSubject *subject);
+
   gboolean (*equal)     (PolkitSubject *a,
                          PolkitSubject *b);
 
@@ -49,6 +51,7 @@ struct _PolkitSubjectIface
 };
 
 GType          polkit_subject_get_type     (void) G_GNUC_CONST;
+guint          polkit_subject_hash         (PolkitSubject *subject);
 gboolean       polkit_subject_equal        (PolkitSubject *a,
                                             PolkitSubject *b);
 gchar         *polkit_subject_to_string    (PolkitSubject *subject);
index 7045dbe..bd0c13d 100644 (file)
@@ -166,6 +166,14 @@ polkit_system_bus_name_new (const gchar *name)
                                        NULL));
 }
 
+static guint
+polkit_system_bus_name_hash (PolkitSubject *subject)
+{
+  PolkitSystemBusName *system_bus_name = POLKIT_SYSTEM_BUS_NAME (subject);
+
+  return g_str_hash (system_bus_name->name);
+}
+
 static gboolean
 polkit_system_bus_name_equal (PolkitSubject *a,
                               PolkitSubject *b)
@@ -190,6 +198,7 @@ polkit_system_bus_name_to_string (PolkitSubject *subject)
 static void
 subject_iface_init (PolkitSubjectIface *subject_iface)
 {
+  subject_iface->hash      = polkit_system_bus_name_hash;
   subject_iface->equal     = polkit_system_bus_name_equal;
   subject_iface->to_string = polkit_system_bus_name_to_string;
 }
index d2fab0c..f3f67de 100644 (file)
@@ -203,6 +203,13 @@ polkit_unix_process_new_full (pid_t pid,
   return POLKIT_SUBJECT (process);
 }
 
+static guint
+polkit_unix_process_hash (PolkitSubject *subject)
+{
+  PolkitUnixProcess *process = POLKIT_UNIX_PROCESS (subject);
+
+  return g_direct_hash (GINT_TO_POINTER ((process->pid + process->start_time))) ;
+}
 
 static gboolean
 polkit_unix_process_equal (PolkitSubject *a,
@@ -230,6 +237,7 @@ polkit_unix_process_to_string (PolkitSubject *subject)
 static void
 subject_iface_init (PolkitSubjectIface *subject_iface)
 {
+  subject_iface->hash      = polkit_unix_process_hash;
   subject_iface->equal     = polkit_unix_process_equal;
   subject_iface->to_string = polkit_unix_process_to_string;
 }
index b81bbd0..ff0c36a 100644 (file)
@@ -154,6 +154,14 @@ polkit_unix_session_new (const gchar *session_id)
                                        NULL));
 }
 
+static guint
+polkit_unix_session_hash (PolkitSubject *subject)
+{
+  PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
+
+  return g_str_hash (session->session_id);
+}
+
 static gboolean
 polkit_unix_session_equal (PolkitSubject *a,
                            PolkitSubject *b)
@@ -178,6 +186,7 @@ polkit_unix_session_to_string (PolkitSubject *subject)
 static void
 subject_iface_init (PolkitSubjectIface *subject_iface)
 {
+  subject_iface->hash      = polkit_unix_session_hash;
   subject_iface->equal     = polkit_unix_session_equal;
   subject_iface->to_string = polkit_unix_session_to_string;
 }