resource-c: added support for automatical releasing of resource sets.
authorIsmo Puustinen <ismo.puustinen@intel.com>
Tue, 11 Jun 2013 10:30:59 +0000 (13:30 +0300)
committerIsmo Puustinen <ismo.puustinen@intel.com>
Tue, 11 Jun 2013 10:30:59 +0000 (13:30 +0300)
src/plugins/resource-native/libmurphy-resource/message.c
src/plugins/resource-native/libmurphy-resource/resource-api.h
src/plugins/resource-native/libmurphy-resource/resource-private.h
src/plugins/resource-native/libmurphy-resource/rset.c

index 68e7e45..15129aa 100644 (file)
@@ -510,6 +510,7 @@ int create_resource_set_request(mrp_res_context_t *cx,
 {
     mrp_msg_t *msg = NULL;
     uint32_t i;
+    uint32_t flags = 0;
 
     if (!cx || !rset)
         return -1;
@@ -517,11 +518,14 @@ int create_resource_set_request(mrp_res_context_t *cx,
     if (!cx->priv->connected)
         return -1;
 
+    if (rset->priv->autorelease)
+        flags |= RESPROTO_RSETFLAG_AUTORELEASE;
+
     msg = mrp_msg_create(
             RESPROTO_SEQUENCE_NO, MRP_MSG_FIELD_UINT32, cx->priv->next_seqno,
             RESPROTO_REQUEST_TYPE, MRP_MSG_FIELD_UINT16,
                     RESPROTO_CREATE_RESOURCE_SET,
-            RESPROTO_RESOURCE_FLAGS, MRP_MSG_FIELD_UINT32, 0,
+            RESPROTO_RESOURCE_FLAGS, MRP_MSG_FIELD_UINT32, flags,
             RESPROTO_RESOURCE_PRIORITY, MRP_MSG_FIELD_UINT32, 0,
             RESPROTO_CLASS_NAME, MRP_MSG_FIELD_STRING, rset->application_class,
             RESPROTO_ZONE_NAME, MRP_MSG_FIELD_STRING, cx->zone,
index 6da1da6..e8b2d5b 100644 (file)
@@ -178,6 +178,21 @@ mrp_res_resource_set_t * mrp_res_create_resource_set(mrp_res_context_t *cx,
         const char *app_class, mrp_res_resource_callback_t cb, void *userdata);
 
 /**
+ * Set automatic release mode to the resource set. This means that if an
+ * application loses the resource set, it doesn't automatically get it back
+ * when the resource becomes available again. By default the automatic
+ * release mode is off.
+ *
+ * @param cx murphy connection context.
+ * @param status automatic release status: TRUE means on, FALSE means off
+ * @param rs resource set that is being updated.
+ *
+ * @return true if successful, false otherwise.
+ */
+bool mrp_res_set_autorelease(mrp_res_context_t *cx, bool status,
+        mrp_res_resource_set_t *rs);
+
+/**
  * Delete resource set created with mrp_res_create_resource_set
  * or mrp_res_copy_resource_set.
  *
@@ -220,7 +235,7 @@ bool mrp_res_equal_resource_set(const mrp_res_resource_set_t *a,
  * set in the resource callback.
  *
  * @param cx connnection to Murphy resource engine.
- * @param set resource set you want to acquire.
+ * @param rs resource set you want to acquire.
  *
  * @return murphy error code.
  */
@@ -233,7 +248,7 @@ int mrp_res_acquire_resource_set(mrp_res_context_t *cx,
  * set available status are still delivered.
  *
  * @param cx connnection to Murphy resource engine.
- * @param set resource set you want to release.
+ * @param rs resource set you want to release.
  *
  * @return murphy error code.
  */
index abdb74b..d7152e1 100644 (file)
@@ -81,6 +81,8 @@ struct mrp_res_resource_set_private_s {
     uint32_t internal_ref_count;
     uint32_t seqno;
 
+    bool autorelease;
+
     mrp_res_resource_callback_t cb;
     void *user_data;
 
index 919e423..bbf8628 100644 (file)
@@ -354,6 +354,7 @@ static mrp_res_resource_set_t *create_resource_set(
     rs->priv->cb = cb;
     rs->priv->user_data = userdata;
     rs->state = MRP_RES_RESOURCE_PENDING;
+    rs->priv->autorelease = FALSE;
 
     rs->priv->resources = mrp_allocz_array(mrp_res_resource_t *,
             cx->priv->master_resource_set->priv->num_resources);
@@ -707,6 +708,21 @@ mrp_res_resource_t * mrp_res_get_resource_by_name(mrp_res_context_t *cx,
     return NULL;
 }
 
+bool mrp_res_set_autorelease(mrp_res_context_t *cx, bool status,
+        mrp_res_resource_set_t *rs)
+{
+    if (!cx || !rs)
+        return FALSE;
+
+     /* the resource library doesn't allow updating already  used sets */
+    if (rs->state != MRP_RES_RESOURCE_PENDING)
+        return FALSE;
+
+    rs->priv->autorelease = status;
+
+    return TRUE;
+}
+
 
 int mrp_res_acquire_resource_set(mrp_res_context_t *cx,
                 const mrp_res_resource_set_t *original)