From 501df345e8c83810f5f4c9d8a6b4a51d817eeb12 Mon Sep 17 00:00:00 2001 From: Ismo Puustinen Date: Tue, 11 Jun 2013 13:30:59 +0300 Subject: [PATCH] resource-c: added support for automatical releasing of resource sets. --- .../resource-native/libmurphy-resource/message.c | 6 +++++- .../resource-native/libmurphy-resource/resource-api.h | 19 +++++++++++++++++-- .../libmurphy-resource/resource-private.h | 2 ++ src/plugins/resource-native/libmurphy-resource/rset.c | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/plugins/resource-native/libmurphy-resource/message.c b/src/plugins/resource-native/libmurphy-resource/message.c index 68e7e45..15129aa 100644 --- a/src/plugins/resource-native/libmurphy-resource/message.c +++ b/src/plugins/resource-native/libmurphy-resource/message.c @@ -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, diff --git a/src/plugins/resource-native/libmurphy-resource/resource-api.h b/src/plugins/resource-native/libmurphy-resource/resource-api.h index 6da1da6..e8b2d5b 100644 --- a/src/plugins/resource-native/libmurphy-resource/resource-api.h +++ b/src/plugins/resource-native/libmurphy-resource/resource-api.h @@ -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. */ diff --git a/src/plugins/resource-native/libmurphy-resource/resource-private.h b/src/plugins/resource-native/libmurphy-resource/resource-private.h index abdb74b..d7152e1 100644 --- a/src/plugins/resource-native/libmurphy-resource/resource-private.h +++ b/src/plugins/resource-native/libmurphy-resource/resource-private.h @@ -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; diff --git a/src/plugins/resource-native/libmurphy-resource/rset.c b/src/plugins/resource-native/libmurphy-resource/rset.c index 919e423..bbf8628 100644 --- a/src/plugins/resource-native/libmurphy-resource/rset.c +++ b/src/plugins/resource-native/libmurphy-resource/rset.c @@ -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) -- 2.7.4