[gnome-keyring/dbus-api] [gck] Add signals to GckManager, for objects added, deleted, changed



commit 563046a7f521ebb63a2606fcdabc8157b7e47e94
Author: Stef Walter <stef memberwebs com>
Date:   Tue Aug 18 03:41:20 2009 +0000

    [gck] Add signals to GckManager, for objects added, deleted, changed
    
    Also add gck_manager_find_by_class() function, for easily getting
    a list of objects of a certain class.

 pkcs11/gck/gck-manager.c    |   49 ++++++++++++++++++++++++++++++++++++++++++-
 pkcs11/gck/gck-manager.h    |   11 +++++++++
 pkcs11/gck/gck-marshal.list |    1 +
 3 files changed, 60 insertions(+), 1 deletions(-)
---
diff --git a/pkcs11/gck/gck-manager.c b/pkcs11/gck/gck-manager.c
index 7829889..9fbe867 100644
--- a/pkcs11/gck/gck-manager.c
+++ b/pkcs11/gck/gck-manager.c
@@ -23,6 +23,7 @@
 
 #include "gck-attributes.h"
 #include "gck-manager.h"
+#include "gck-marshal.h"
 #include "gck-util.h"
 
 #include <glib.h>
@@ -35,6 +36,15 @@ enum {
 	PROP_FOR_TOKEN
 };
 
+enum {
+	OBJECT_ADDED,
+	OBJECT_REMOVED,
+	ATTRIBUTE_CHANGED,
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 struct _GckManagerPrivate {
 	gboolean for_token;
 	GList *objects;
@@ -375,6 +385,9 @@ notify_attribute (GckObject *object, CK_ATTRIBUTE_TYPE attr_type, GckManager *se
 	index = g_hash_table_lookup (self->pv->index_by_attribute, &attr_type);
 	if (index != NULL) 
 		index_update (index, object);
+
+	/* Tell everyone that this attribute changed on this object */
+	g_signal_emit (self, signals[ATTRIBUTE_CHANGED], 0, object, attr_type);
 }
 
 static void
@@ -421,6 +434,9 @@ add_object (GckManager *self, GckObject *object)
 	g_hash_table_foreach (self->pv->index_by_property, index_object_each, object);
 	g_signal_connect (object, "notify-attribute", G_CALLBACK (notify_attribute), self);
 	g_signal_connect (object, "notify", G_CALLBACK (notify_property), self);
+
+	/* Tell everyone we added this object */
+	g_signal_emit (self, signals[OBJECT_ADDED], 0, object);
 }
 
 static void
@@ -444,6 +460,9 @@ remove_object (GckManager *self, GckObject *object)
 	/* Release object management */		
 	self->pv->objects = g_list_remove (self->pv->objects, object);
 	g_object_set (object, "manager", NULL, NULL);
+
+	/* Tell everyone this object is gone */
+	g_signal_emit (self, signals[OBJECT_REMOVED], 0, object);
 }
 
 static void
@@ -712,7 +731,21 @@ gck_manager_class_init (GckManagerClass *klass)
 	g_object_class_install_property (gobject_class, PROP_FOR_TOKEN,
 	         g_param_spec_boolean ("for-token", "For Token", "Whether this manager is for token objects or not", 
 	                               FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-	
+
+	signals[OBJECT_ADDED] = g_signal_new ("object-added", GCK_TYPE_MANAGER,
+	                                      G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GckManagerClass, object_added),
+	                                      NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
+	                                      G_TYPE_NONE, 1, GCK_TYPE_OBJECT);
+
+	signals[OBJECT_REMOVED] = g_signal_new ("object-removed", GCK_TYPE_MANAGER,
+	                                        G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GckManagerClass, object_removed),
+	                                        NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
+	                                        G_TYPE_NONE, 1, GCK_TYPE_OBJECT);
+
+	signals[ATTRIBUTE_CHANGED] = g_signal_new ("attribute-removed", GCK_TYPE_MANAGER,
+	                                           G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GckManagerClass, attribute_changed),
+	                                           NULL, NULL, gck_marshal_VOID__OBJECT_ULONG,
+	                                           G_TYPE_NONE, 1, GCK_TYPE_OBJECT);
 }
 
 /* ------------------------------------------------------------------------
@@ -878,6 +911,20 @@ gck_manager_find_by_attributes (GckManager *self, CK_ATTRIBUTE_PTR attrs, CK_ULO
 	return finder.results;
 }
 
+GList*
+gck_manager_find_by_class (GckManager *self, CK_OBJECT_CLASS klass)
+{
+	CK_ATTRIBUTE attr;
+
+	g_return_val_if_fail (GCK_IS_MANAGER (self), NULL);
+
+	attr.type = CKA_CLASS;
+	attr.ulValueLen = sizeof (klass);
+	attr.pValue = &klass;
+
+	return gck_manager_find_by_attributes (self, &attr, 1);
+}
+
 GckObject*
 gck_manager_find_related (GckManager *self, CK_OBJECT_CLASS klass, GckObject *related_to)
 {
diff --git a/pkcs11/gck/gck-manager.h b/pkcs11/gck/gck-manager.h
index 5cbd843..54d2a6c 100644
--- a/pkcs11/gck/gck-manager.h
+++ b/pkcs11/gck/gck-manager.h
@@ -71,6 +71,14 @@ struct _GckManager {
 
 struct _GckManagerClass {
 	GObjectClass parent_class;
+
+	/* signals */
+
+	void (*object_added) (GckManager *self, GckObject *object);
+
+	void (*object_removed) (GckManager *self, GckObject *object);
+
+	void (*attribute_changed) (GckManager *self, GckObject *object, CK_ATTRIBUTE_TYPE type);
 };
 
 GType                   gck_manager_get_type                    (void) G_GNUC_CONST;
@@ -114,6 +122,9 @@ GList*                  gck_manager_find_by_attributes          (GckManager *sel
                                                                  CK_ATTRIBUTE_PTR template, 
                                                                  CK_ULONG n_attrs);
 
+GList*                  gck_manager_find_by_class               (GckManager *self,
+                                                                 CK_OBJECT_CLASS klass);
+
 GckObject*              gck_manager_find_one_by_attributes      (GckManager *self, 
                                                                  CK_ATTRIBUTE_PTR template, 
                                                                  CK_ULONG n_attrs);
diff --git a/pkcs11/gck/gck-marshal.list b/pkcs11/gck/gck-marshal.list
index 2fc40cc..a4eba40 100644
--- a/pkcs11/gck/gck-marshal.list
+++ b/pkcs11/gck/gck-marshal.list
@@ -1,2 +1,3 @@
 BOOLEAN:VOID
 VOID:STRING,ULONG
+VOID:OBJECT,ULONG



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]