]> saetta.ns0.it Git - libzakgflow/commitdiff
ZakGFlowInstance::task_complete now returns next nodes.
authorAndrea Zagli <azagli@libero.it>
Wed, 16 Mar 2016 20:00:48 +0000 (21:00 +0100)
committerAndrea Zagli <azagli@libero.it>
Wed, 16 Mar 2016 20:00:48 +0000 (21:00 +0100)
src/instance.c
src/instance.h
tests/instance.c

index cdcdfb15e327097ebedfb16e5fd98df118290bde..f76cd562056bda7e08a7c2fa110fd2b444ff400d 100644 (file)
@@ -35,7 +35,7 @@
 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 gchar *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,
@@ -77,9 +77,11 @@ 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)
+static gchar
+*zak_gflow_instance_next (ZakGFlowInstance *instance, const gchar *node_id, GNode *cur_node)
 {
+       gchar *ret;
+
        xmlNode *cur;
 
        GNode *_cur_node;
@@ -88,6 +90,8 @@ zak_gflow_instance_next (ZakGFlowInstance *instance, const gchar *node_id, GNode
 
        ZakGFlowInstancePrivate *priv;
 
+       ret = NULL;
+
        priv = zak_gflow_instance_get_instance_private (instance);
 
        cur = g_hash_table_lookup (priv->ht_nodes, node_id);
@@ -102,6 +106,7 @@ zak_gflow_instance_next (ZakGFlowInstance *instance, const gchar *node_id, GNode
                                        if (xnodeset != NULL
                                                && xnodeset->nodeNr > 0)
                                                {
+                                                       ret = g_strdup ((const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0]));
                                                        zak_gflow_instance_next (instance, (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0]), _cur_node);
                                                }
                                }
@@ -109,12 +114,21 @@ zak_gflow_instance_next (ZakGFlowInstance *instance, const gchar *node_id, GNode
                                {
                                        g_message ("%s: %s (targetRef %s)", cur->name, (gchar *)xmlGetProp (cur, (const xmlChar *)"name"), (gchar *)xmlGetProp (cur, (const xmlChar *)"targetRef"));
 
+                                       ret = g_strdup ((const 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: %s", cur->name, (gchar *)xmlGetProp (cur, (const xmlChar *)"name"));
+
+                                       ret = g_strdup ((gchar *)xmlGetProp (cur, (const xmlChar *)"id"));
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"exclusiveGateway") == 0)
+                               {
+                                       g_message ("%s: %s", cur->name, (gchar *)xmlGetProp (cur, (const xmlChar *)"name"));
+
+                                       ret = g_strdup ((gchar *)xmlGetProp (cur, (const xmlChar *)"id"));
                                }
                        else
                                {
@@ -125,6 +139,8 @@ zak_gflow_instance_next (ZakGFlowInstance *instance, const gchar *node_id, GNode
                {
                        g_warning ("Node not found: %s.", node_id);
                }
+
+       return ret;
 }
 
 /*+
@@ -195,10 +211,10 @@ GPtrArray
  * @node_id:
  *
  */
-gboolean
-zak_gflow_instance_task_complete (ZakGFlowInstance *instance, const gchar *node_id)
+GPtrArray
+*zak_gflow_instance_task_complete (ZakGFlowInstance *instance, const gchar *node_id)
 {
-       gboolean ret;
+       GPtrArray *ret;
 
        xmlNode *xnode;
 
@@ -206,9 +222,13 @@ zak_gflow_instance_task_complete (ZakGFlowInstance *instance, const gchar *node_
 
        xmlNodeSet *xnodeset;
 
+       gint i;
+
+       gchar *cur_node_id;
+
        ZakGFlowInstancePrivate *priv = zak_gflow_instance_get_instance_private (instance);
 
-       ret = FALSE;
+       ret = g_ptr_array_new ();
 
        xnode = (xmlNode *)g_hash_table_lookup (priv->ht_nodes, node_id);
        if (xnode != NULL)
@@ -224,7 +244,12 @@ zak_gflow_instance_task_complete (ZakGFlowInstance *instance, const gchar *node_
                                        if (xnodeset != NULL
                                                && xnodeset->nodeNr > 0)
                                                {
-                                                       zak_gflow_instance_next (instance, (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0]), node);
+                                                       for (i = 0; i < xnodeset->nodeNr; i++)
+                                                               {
+                                                                       cur_node_id = zak_gflow_instance_next (instance, (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[i]), node);
+                                                                       g_ptr_array_add (ret, g_strdup (cur_node_id));
+                                                                       g_free (cur_node_id);
+                                                               }
                                                }
                                }
                        else
index 7b373ecf54b575cb722225a29c638fe2e1d843cc..883f497f35da6b304d2f79ac40c05c4d66137e14 100644 (file)
@@ -42,7 +42,7 @@ ZakGFlowInstance *zak_gflow_instance_new (xmlXPathContext *xpcontext, GHashTable
 
 GPtrArray *zak_gflow_instance_get_current_nodes (ZakGFlowInstance *instance);
 
-gboolean zak_gflow_instance_task_complete (ZakGFlowInstance *instance, const gchar *node_id);
+GPtrArray *zak_gflow_instance_task_complete (ZakGFlowInstance *instance, const gchar *node_id);
 
 
 G_END_DECLS
index 9ed613166610768e6e32aa1228501ccb4d8b1d05..508888b51788f481c29c3ee302288afebc189cad 100644 (file)
@@ -39,6 +39,7 @@ main (int argc, char *argv[])
                {
                        instance = zak_gflow_model_start (model, argv[2]);
 
+                       /* general current nodes */
                        ar = zak_gflow_instance_get_current_nodes (instance);
                        for (i = 0; i < ar->len; i++)
                                {
@@ -52,8 +53,13 @@ main (int argc, char *argv[])
                        zak_gflow_instance_task_complete (instance, "StartEvent_1");
 
                        /* right node_id */
-                       zak_gflow_instance_task_complete (instance, (gchar *)g_ptr_array_index (ar, 0));
+                       ar = zak_gflow_instance_task_complete (instance, (gchar *)g_ptr_array_index (ar, 0));
+                       for (i = 0; i < ar->len; i++)
+                               {
+                                       g_printf ("Currente node after task_complete: %s\n", (gchar *)g_ptr_array_index (ar, i));
+                               }
 
+                       /* general current nodes */
                        ar = zak_gflow_instance_get_current_nodes (instance);
                        for (i = 0; i < ar->len; i++)
                                {