libresource: Add context to resource sets, set a set for listing resources
authorJan Ekström <jan.ekstrom@intel.com>
Wed, 25 Jun 2014 13:59:51 +0000 (16:59 +0300)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Thu, 26 Jun 2014 13:22:36 +0000 (16:22 +0300)
This enables the removal of passing of contexts and resource sets
unneededly.

src/plugins/resource-native/libmurphy-resource/message.c
src/plugins/resource-native/libmurphy-resource/message.h
src/plugins/resource-native/libmurphy-resource/resource-private.h
src/plugins/resource-native/libmurphy-resource/resource.c
src/plugins/resource-native/libmurphy-resource/rset.c

index e542f70..0d3797a 100644 (file)
@@ -258,7 +258,8 @@ bool fetch_resource_name(mrp_msg_t *msg, void **pcursor,
 }
 
 
-static int priv_res_to_mrp_res(uint32_t id, resource_def_t *src, mrp_res_resource_t *dst)
+static int priv_res_to_mrp_res(uint32_t id, resource_def_t *src, mrp_res_resource_t *dst,
+        mrp_res_resource_set_t *set)
 {
     dst->name  = mrp_strdup(src->name);
     dst->state = MRP_RES_RESOURCE_LOST;
@@ -269,12 +270,13 @@ static int priv_res_to_mrp_res(uint32_t id, resource_def_t *src, mrp_res_resourc
 
     dst->priv->num_attributes = src->num_attrs;
     dst->priv->attrs = src->attrs;
+    dst->priv->set = set;
     return 0;
 }
 
 
-mrp_res_resource_set_t *resource_query_response(mrp_msg_t *msg,
-        void **pcursor)
+mrp_res_resource_set_t *resource_query_response(mrp_res_context_t *cx,
+        mrp_msg_t *msg, void **pcursor)
 {
     int             status;
     uint32_t        dim, i;
@@ -283,6 +285,9 @@ mrp_res_resource_set_t *resource_query_response(mrp_msg_t *msg,
     resource_def_t *src;
     mrp_res_resource_set_t *arr = NULL;
 
+    if (!cx)
+        goto failed;
+
     if (!fetch_status(msg, pcursor, &status))
         goto failed;
 
@@ -320,6 +325,7 @@ mrp_res_resource_set_t *resource_query_response(mrp_msg_t *msg,
 
         arr->application_class = NULL;
         arr->state = MRP_RES_RESOURCE_LOST;
+        arr->priv->cx = cx;
         arr->priv->num_resources = dim;
 
         arr->priv->resources = mrp_allocz_array(mrp_res_resource_t *, dim);
@@ -341,7 +347,7 @@ mrp_res_resource_set_t *resource_query_response(mrp_msg_t *msg,
                 arr->priv->num_resources = i;
                 goto failed;
             }
-            priv_res_to_mrp_res(i, src, arr->priv->resources[i]);
+            priv_res_to_mrp_res(i, src, arr->priv->resources[i], arr);
         }
     }
 
index 68a320c..008e6b8 100644 (file)
@@ -62,8 +62,8 @@ bool fetch_resource_name(mrp_msg_t *msg, void **pcursor,
 
 /* handling of the message responses */
 
-mrp_res_resource_set_t *resource_query_response(mrp_msg_t *msg,
-        void **pcursor);
+mrp_res_resource_set_t *resource_query_response(mrp_res_context_t *cx,
+        mrp_msg_t *msg, void **pcursor);
 
 mrp_res_string_array_t *class_query_response(mrp_msg_t *msg, void **pcursor);
 
index ecf8d6e..18ec44b 100644 (file)
@@ -84,6 +84,7 @@ struct mrp_res_resource_private_s {
 
 struct mrp_res_resource_set_private_s {
     mrp_res_resource_set_t *pub; /* composition */
+    mrp_res_context_t *cx; /* the context of this resource set */
     uint32_t id; /* id given by the server */
     uint32_t internal_id; /* id for checking identity */
     uint32_t internal_ref_count;
index e852d66..d712101 100644 (file)
@@ -267,7 +267,7 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
             mrp_res_info("received QUERY_RESOURCES response");
 
             cx->priv->master_resource_set =
-                    resource_query_response(msg, &cursor);
+                    resource_query_response(cx, msg, &cursor);
             if (!cx->priv->master_resource_set)
                 goto error;
             break;
index f88eab6..f6fbf23 100644 (file)
@@ -353,6 +353,7 @@ static mrp_res_resource_set_t *create_resource_set(
     rs->application_class = mrp_strdup(klass);
 
     rs->priv->pub = rs;
+    rs->priv->cx = cx;
     rs->priv->id = 0;
     rs->priv->internal_id = cx->priv->next_internal_id++;
     rs->priv->seqno = 0;
@@ -506,6 +507,7 @@ mrp_res_resource_t *mrp_res_create_resource(mrp_res_context_t *cx,
     res->priv->mandatory = mandatory;
     res->priv->shared = shared;
     res->priv->pub = res;
+    res->priv->set = set;
 
     /* copy the attributes with the default values */
     res->priv->attrs = mrp_attribute_array_dup(proto->priv->num_attributes,