From: Andrea Zagli <azagli@libero.it>
Date: Wed, 16 Mar 2016 15:42:03 +0000 (+0100)
Subject: Started flow until task.
X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=72f977ee49555c02e684e32ed7daae628a07f828;p=libzakgflow

Started flow until task.
---

diff --git a/src/instance.c b/src/instance.c
index 98eb074..e638d0d 100644
--- a/src/instance.c
+++ b/src/instance.c
@@ -35,6 +35,8 @@
 static void zak_gflow_instance_class_init (ZakGFlowInstanceClass *class);
 static void zak_gflow_instance_init (ZakGFlowInstance *zak_gflow_instance);
 
+static void zak_gflow_instance_next (ZakGFlowInstance *instance, const gchar *node_id, GNode *cur_node);
+
 static void zak_gflow_instance_set_property (GObject *object,
                                guint property_id,
                                const GValue *value,
@@ -75,6 +77,56 @@ zak_gflow_instance_init (ZakGFlowInstance *zak_gflow_instance)
 	priv->nodes_history = g_node_new (NULL);
 }
 
+static void
+zak_gflow_instance_next (ZakGFlowInstance *instance, const gchar *node_id, GNode *cur_node)
+{
+	xmlNode *cur;
+
+	GNode *_cur_node;
+
+	xmlNodeSet *xnodeset;
+
+	ZakGFlowInstancePrivate *priv;
+
+	priv = zak_gflow_instance_get_instance_private (instance);
+
+	cur = g_hash_table_lookup (priv->ht_nodes, node_id);
+	if (cur != NULL)
+		{
+			_cur_node = g_node_insert_data (cur_node, -1, cur);
+			if (xmlStrcmp (cur->name, (const xmlChar *)"startEvent") == 0)
+				{
+					g_message ("%s: %s", cur->name, (gchar *)xmlGetProp (cur, (const xmlChar *)"name"));
+
+					xnodeset = zak_gflow_commons_xml_search (priv->xpcontext, cur, (const xmlChar *)"child::bpmn:outgoing");
+					if (xnodeset != NULL
+						&& xnodeset->nodeNr > 0)
+						{
+							zak_gflow_instance_next (instance, (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0]), _cur_node);
+						}
+				}
+			else if (xmlStrcmp (cur->name, (const xmlChar *)"sequenceFlow") == 0)
+				{
+					g_message ("%s: %s (targetRef %s)", cur->name, (gchar *)xmlGetProp (cur, (const xmlChar *)"name"), (gchar *)xmlGetProp (cur, (const xmlChar *)"targetRef"));
+
+					zak_gflow_instance_next (instance, (const gchar *)xmlGetProp (cur, (const xmlChar *)"targetRef"), _cur_node);
+				}
+			else if (xmlStrcmp (cur->name, (const xmlChar *)"task") == 0
+					 || xmlStrcmp (cur->name, (const xmlChar *)"userTask") == 0)
+				{
+					g_message ("%s", cur->name);
+				}
+			else
+				{
+					g_message ("Node %s not implemented.", cur->name);
+				}
+		}
+	else
+		{
+			g_warning ("Node not found: %s.", node_id);
+		}
+}
+
 /*+
  * zak_gflow_instance_new:
  * @ht_nodes:
@@ -87,11 +139,6 @@ ZakGFlowInstance
 	ZakGFlowInstance *instance;
 	ZakGFlowInstancePrivate *priv;
 
-	xmlNode *cur;
-	GNode *cur_node;
-
-	xmlNodeSet *xnodeset;
-
 	g_return_val_if_fail (xpcontext != NULL, NULL);
 	g_return_val_if_fail (ht_nodes != NULL, NULL);
 	g_return_val_if_fail (node_id != NULL, NULL);
@@ -103,35 +150,7 @@ ZakGFlowInstance
 	priv->xpcontext = xpcontext;
 	priv->ht_nodes = g_hash_table_ref (ht_nodes);
 
-	cur = g_hash_table_lookup (priv->ht_nodes, node_id);
-	if (cur == NULL)
-		{
-			g_warning ("No first/start node found/setted.");
-		}
-	else
-		{
-			cur_node = g_node_insert_data (priv->nodes_history, -1, cur);
-			if (xmlStrcmp (cur->name, (const xmlChar *)"startEvent") == 0)
-				{
-					g_message ("%s: %s", cur->name, (gchar *)xmlGetProp (cur, (const xmlChar *)"name"));
-
-					xnodeset = zak_gflow_commons_xml_search (priv->xpcontext, cur, (const xmlChar *)"child::bpmn:outgoing");
-					if (xnodeset != NULL
-						&& xnodeset->nodeNr > 0)
-						{
-							cur = g_hash_table_lookup (priv->ht_nodes, xmlNodeGetContent (xnodeset->nodeTab[0]));
-							if (cur != NULL)
-								{
-									cur_node = g_node_insert_data (cur_node, -1, cur);
-									g_message ("\tnext: %s %s", cur->name, (gchar *)xmlGetProp (cur, (const xmlChar *)"id"));
-								}
-							else
-								{
-									g_message ("\tnext: no next found");
-								}
-						}
-				}
-		}
+	zak_gflow_instance_next (instance, node_id, priv->nodes_history);
 
 	return instance;
 }