[aravis] genicam: implement register read cache.



commit f9b8a1dc5d89b99cb63a569d367c0d11dd76bf45
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Apr 5 10:42:24 2010 +0200

    genicam: implement register read cache.

 src/arvgc.c         |    4 ++--
 src/arvgcnode.c     |   20 ++++++++++++++++++++
 src/arvgcnode.h     |   32 +++++++++++++++++---------------
 src/arvgcregister.c |   35 +++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 17 deletions(-)
---
diff --git a/src/arvgc.c b/src/arvgc.c
index 201f9e3..2413a99 100644
--- a/src/arvgc.c
+++ b/src/arvgc.c
@@ -79,7 +79,7 @@ arv_gc_create_node (ArvGc *genicam, const char *type)
 
 	if (node != NULL) {
 		arv_gc_node_set_genicam (node, genicam);
-		arv_debug ("genicam",
+		arv_debug ("parser",
 			   "[Gc::create_node] Node '%s' created", type);
 	}
 
@@ -178,7 +178,7 @@ arv_gc_parser_insert_node (ArvGcParserState *state, ArvGcNode *node)
 	node_name = arv_gc_node_get_name (node);
 	if (node_name != NULL) {
 		g_hash_table_insert (state->genicam->nodes, (char *) node_name, node);
-		arv_debug ("genicam",
+		arv_debug ("paser",
 			   "[GcParser::end_element] Insert node '%s'", node_name);
 	} else
 		g_object_unref (node);
diff --git a/src/arvgcnode.c b/src/arvgcnode.c
index 71a2af7..063643b 100644
--- a/src/arvgcnode.c
+++ b/src/arvgcnode.c
@@ -36,6 +36,8 @@ struct _ArvGcNodePrivate {
 	char *display_name;
 
 	GSList *childs;
+
+	gint modification_count;
 };
 
 const char *
@@ -193,6 +195,22 @@ arv_gc_node_get_value_type (ArvGcNode *node)
 	return 0;
 }
 
+void
+arv_gc_node_inc_modification_count (ArvGcNode *gc_node)
+{
+	g_return_if_fail (ARV_IS_GC_NODE (gc_node));
+
+	gc_node->priv->modification_count++;
+}
+
+gint
+arv_gc_node_get_modification_count (ArvGcNode *node)
+{
+	g_return_val_if_fail (ARV_IS_GC_NODE (node), 0);
+
+	return node->priv->modification_count;
+}
+
 static void
 arv_gc_node_init (ArvGcNode *gc_node)
 {
@@ -203,6 +221,8 @@ arv_gc_node_init (ArvGcNode *gc_node)
 	gc_node->priv->description = NULL;
 	gc_node->priv->display_name = NULL;
 	gc_node->priv->childs = NULL;
+
+	gc_node->priv->modification_count = 0;
 }
 
 static void
diff --git a/src/arvgcnode.h b/src/arvgcnode.h
index ac98284..8929da9 100644
--- a/src/arvgcnode.h
+++ b/src/arvgcnode.h
@@ -46,28 +46,30 @@ struct _ArvGcNode {
 struct _ArvGcNodeClass {
 	GObjectClass parent_class;
 
-	void		(*set_attribute)		(ArvGcNode *node, const char *name, const char *value);
-	void 		(*add_element)			(ArvGcNode *node, const char *name, const char *content,
+	void		(*set_attribute)		(ArvGcNode *gc_node, const char *name, const char *value);
+	void 		(*add_element)			(ArvGcNode *gc_node, const char *name, const char *content,
 							 const char **attributes);
-	GType		(*get_value_type)		(ArvGcNode *node);
-	gboolean 	(*can_add_child) 		(ArvGcNode *node, ArvGcNode *child);
+	GType		(*get_value_type)		(ArvGcNode *gc_node);
+	gboolean 	(*can_add_child) 		(ArvGcNode *gc_node, ArvGcNode *child);
 };
 
 GType arv_gc_node_get_type (void);
 
 ArvGcNode * 	arv_gc_node_new 			(void);
-GType 		arv_gc_node_get_value_type 		(ArvGcNode *node);
-void		arv_gc_node_set_genicam			(ArvGcNode *node, ArvGc *genicam);
-ArvGc * 	arv_gc_node_get_genicam			(ArvGcNode *node);
-const char *	arv_gc_node_get_name			(ArvGcNode *node);
-const char *	arv_gc_node_get_tooltip			(ArvGcNode *node);
-const char *	arv_gc_node_get_description		(ArvGcNode *node);
-void		arv_gc_node_set_attribute 		(ArvGcNode *node, const char *name, const char *value);
-void 		arv_gc_node_add_element 		(ArvGcNode *node, const char *name, const char *content,
+GType 		arv_gc_node_get_value_type 		(ArvGcNode *gc_node);
+void		arv_gc_node_set_genicam			(ArvGcNode *gc_node, ArvGc *genicam);
+ArvGc * 	arv_gc_node_get_genicam			(ArvGcNode *gc_node);
+const char *	arv_gc_node_get_name			(ArvGcNode *gc_node);
+const char *	arv_gc_node_get_tooltip			(ArvGcNode *gc_node);
+const char *	arv_gc_node_get_description		(ArvGcNode *gc_node);
+void		arv_gc_node_set_attribute 		(ArvGcNode *gc_node, const char *name, const char *value);
+void 		arv_gc_node_add_element 		(ArvGcNode *gc_node, const char *name, const char *content,
 							 const char **attributes);
-gboolean 	arv_gc_node_can_add_child 		(ArvGcNode *node, ArvGcNode *child);
-void 		arv_gc_node_add_child 			(ArvGcNode *node, ArvGcNode *child);
-const GSList *	arv_gc_node_get_childs 			(ArvGcNode *node);
+gboolean 	arv_gc_node_can_add_child 		(ArvGcNode *gc_node, ArvGcNode *child);
+void 		arv_gc_node_add_child 			(ArvGcNode *gc_node, ArvGcNode *child);
+const GSList *	arv_gc_node_get_childs 			(ArvGcNode *gc_node);
+void 		arv_gc_node_inc_modification_count 	(ArvGcNode *gc_node);
+gint 		arv_gc_node_get_modification_count 	(ArvGcNode *gc_node);
 
 G_END_DECLS
 
diff --git a/src/arvgcregister.c b/src/arvgcregister.c
index 326a36d..f3a5585 100644
--- a/src/arvgcregister.c
+++ b/src/arvgcregister.c
@@ -103,6 +103,29 @@ arv_gc_register_add_element (ArvGcNode *node, const char *name, const char *cont
 
 /* ArvGcRegister implementation */
 
+gboolean
+_get_cache_validity (ArvGcRegister *gc_register)
+{
+	ArvGc *genicam;
+	GSList *iter;
+	gint modification_count;
+	gboolean is_cache_valid = gc_register->is_cache_valid;
+
+	genicam = arv_gc_node_get_genicam (ARV_GC_NODE (gc_register));
+
+	for (iter = gc_register->invalidators; iter != NULL; iter = iter->next) {
+		ArvGcInvalidator *invalidator = iter->data;
+
+		modification_count = invalidator->modification_count;
+		invalidator->modification_count = arv_gc_node_get_modification_count
+			(arv_gc_get_node (genicam, invalidator->node));
+		if (modification_count != invalidator->modification_count)
+			is_cache_valid = FALSE;
+	}
+
+	return is_cache_valid;
+}
+
 static void
 _update_cache_size (ArvGcRegister *gc_register, ArvGc *genicam)
 {
@@ -123,6 +146,11 @@ _read_cache (ArvGcRegister *gc_register)
 	ArvGc *genicam;
 	ArvGcNode *port;
 
+	if (gc_register->is_cache_valid == TRUE) {
+		arv_debug ("genicam", "[GcRegister::read_cache] Cache is valid");
+		return;
+	}
+
 	genicam = arv_gc_node_get_genicam (ARV_GC_NODE (gc_register));
 	g_return_if_fail (ARV_IS_GC (genicam));
 
@@ -136,6 +164,8 @@ _read_cache (ArvGcRegister *gc_register)
 			  gc_register->cache,
 			  arv_gc_register_get_address (gc_register),
 			  gc_register->cache_size);
+
+	gc_register->is_cache_valid = TRUE;
 }
 
 static void
@@ -147,6 +177,8 @@ _write_cache (ArvGcRegister *gc_register)
 	genicam = arv_gc_node_get_genicam (ARV_GC_NODE (gc_register));
 	g_return_if_fail (ARV_IS_GC (genicam));
 
+	arv_gc_node_inc_modification_count (ARV_GC_NODE (gc_register));
+
 	port = arv_gc_get_node (genicam, gc_register->port_name);
 	if (!ARV_IS_GC_PORT (port))
 		return;
@@ -157,6 +189,9 @@ _write_cache (ArvGcRegister *gc_register)
 			   gc_register->cache,
 			   arv_gc_register_get_address (gc_register),
 			   gc_register->cache_size);
+
+	if (gc_register->cachable == ARV_GC_CACHABLE_WRITE_TRHOUGH)
+		gc_register->is_cache_valid = TRUE;
 }
 
 void



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