resource-c: removed printfs.
authorIsmo Puustinen <ismo.puustinen@intel.com>
Fri, 4 Jan 2013 11:07:56 +0000 (13:07 +0200)
committerIsmo Puustinen <ismo.puustinen@intel.com>
Fri, 4 Jan 2013 12:54:12 +0000 (14:54 +0200)
src/plugins/resource-native/libmurphy-resource/message.c
src/plugins/resource-native/libmurphy-resource/resource.c
src/plugins/resource-native/libmurphy-resource/rset.c

index f843de8..fb8dbd5 100644 (file)
@@ -285,7 +285,7 @@ mrp_res_resource_set_t *resource_query_response(mrp_msg_t *msg,
         goto failed;
 
     if (status != 0)
-        printf("Resource query failed (%u): %s\n", status, strerror(status));
+        mrp_log_error("Resource query failed (%u): %s", status, strerror(status));
     else {
         dim = 0;
 
@@ -426,7 +426,7 @@ mrp_res_resource_set_t *acquire_resource_set_response(mrp_msg_t *msg,
     rset = mrp_htbl_lookup(cx->priv->rset_mapping, u_to_p(rset_id));
 
     if (!rset) {
-        printf("no rset found!\n");
+        mrp_log_error("no rset found!");
         goto error;
     }
 
@@ -538,8 +538,6 @@ int create_resource_set_request(mrp_res_context_t *cx,
         if (!res)
             goto error;
 
-        printf("    adding %s\n", res->name);
-
         if (res->priv->shared)
             flags |= RESPROTO_RESFLAG_SHARED;
 
index 8b009e5..05add4c 100644 (file)
@@ -103,28 +103,25 @@ static void resource_event(mrp_msg_t *msg,
 
     mrp_res_resource_set_t *rset;
 
-    printf("\nResource event (request no %u):\n", seqno);
+    mrp_log_info("Resource event (request no %u):", seqno);
 
     if (!fetch_resource_set_id(msg, pcursor, &rset_id) ||
         !fetch_resource_set_state(msg, pcursor, &state) ||
         !fetch_resource_set_mask(msg, pcursor, 0, &grant) ||
         !fetch_resource_set_mask(msg, pcursor, 1, &advice)) {
-        printf("malformed 0.2\n");
+        mrp_log_error("failed to fetch data from message");
         goto malformed;
     }
 
     /* Update our "master copy" of the resource set. */
 
-    printf("going to get rset of id %d\n", rset_id);
     rset = mrp_htbl_lookup(cx->priv->rset_mapping, u_to_p(rset_id));
 
     if (!rset) {
-        printf("resource event before creating the resource set!\n");
+        mrp_log_error("resource event outside the resource set lifecycle");
         goto malformed;
     }
 
-    printf("resource set %p id: %u\n", rset, rset->priv->id);
-
     switch (state) {
         case RESPROTO_RELEASE:
             rset->state = MRP_RES_RESOURCE_LOST;
@@ -138,18 +135,16 @@ static void resource_event(mrp_msg_t *msg,
 
         mrp_res_resource_t *res = NULL;
 
-        printf("iterating through the resources...\n");
-
         if ((tag != RESPROTO_RESOURCE_ID || type != MRP_MSG_FIELD_UINT32) ||
-            !fetch_resource_name(msg, pcursor, &resnam)) {
-            printf("malformed 1\n");
+                !fetch_resource_name(msg, pcursor, &resnam)) {
+            mrp_log_error("failed to read resource from message");
             goto malformed;
         }
 
         res = get_resource_by_name(rset, resnam);
 
         if (!res) {
-            printf("malformed 2\n");
+            mrp_log_error("resource doesn't exist in resource set");
             goto malformed;
         }
 
@@ -169,7 +164,7 @@ static void resource_event(mrp_msg_t *msg,
         n_attrs = fetch_attribute_array(msg, pcursor, ATTRIBUTE_MAX + 1, attrs);
 
         if (n_attrs < 0) {
-            printf("malformed 3\n");
+            mrp_log_error("failed to read attributes from message");
             goto malformed;
         }
 
@@ -213,12 +208,12 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
                 fetch_request(msg, &cursor, &req) < 0)
         goto error;
 
-    printf("received message %d for %p\n", req, cx);
+    mrp_log_info("received message %d for %p", req, cx);
 
     switch (req) {
         case RESPROTO_QUERY_RESOURCES:
 
-            printf("received QUERY_RESOURCES response\n");
+            mrp_log_info("received QUERY_RESOURCES response");
 
             cx->priv->master_resource_set =
                     resource_query_response(msg, &cursor);
@@ -227,7 +222,7 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
             break;
         case RESPROTO_QUERY_CLASSES:
 
-            printf("received QUERY_CLASSES response\n");
+            mrp_log_info("received QUERY_CLASSES response");
 
             cx->priv->master_classes = class_query_response(msg, &cursor);
             if (!cx->priv->master_classes)
@@ -239,7 +234,7 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
             mrp_res_resource_set_t *rset = NULL;
             mrp_list_hook_t *p, *n;
 
-            printf("received CREATE_RESOURCE_SET response\n");
+            mrp_log_info("received CREATE_RESOURCE_SET response");
 
             /* get the correct resource set from the pending_sets list */
 
@@ -262,7 +257,6 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
             if (!create_resource_set_response(msg, rset, &cursor))
                 goto error;
 
-            printf("inserting rset %p of id %d\n", rset, rset->priv->id);
             mrp_htbl_insert(cx->priv->rset_mapping,
                     u_to_p(rset->priv->id), rset);
 
@@ -275,7 +269,7 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
         {
             mrp_res_resource_set_t *rset;
 
-            printf("received ACQUIRE_RESOURCE_SET response\n");
+            mrp_log_info("received ACQUIRE_RESOURCE_SET response");
 
             rset = acquire_resource_set_response(msg, cx, &cursor);
 
@@ -298,7 +292,7 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
         case RESPROTO_RELEASE_RESOURCE_SET:
         {
             mrp_res_resource_set_t *rset;
-            printf("received RELEASE_RESOURCE_SET response\n");
+            mrp_log_info("received RELEASE_RESOURCE_SET response");
 
             rset = acquire_resource_set_response(msg, cx, &cursor);
 
@@ -319,12 +313,13 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
             break;
         }
         case RESPROTO_RESOURCES_EVENT:
-            printf("received RESOURCES_EVENT response\n");
+            mrp_log_info("received RESOURCES_EVENT response");
 
             resource_event(msg, cx, seqno, &cursor);
             break;
         case RESPROTO_DESTROY_RESOURCE_SET:
-            /* TODO */
+            mrp_log_info("received DESTROY_RESOURCE_SET response");
+            /* TODO? */
             break;
         default:
             break;
@@ -340,7 +335,7 @@ static void recvfrom_msg(mrp_transport_t *transp, mrp_msg_t *msg,
     return;
 
 error:
-    printf("error processing a message from Murphy\n");
+    mrp_log_error("error processing a message from the server");
     cx->priv->cb(cx, MRP_RES_ERROR_INTERNAL, cx->priv->user_data);
 }
 
@@ -357,7 +352,7 @@ void closed_evt(mrp_transport_t *transp, int error, void *user_data)
     MRP_UNUSED(transp);
     MRP_UNUSED(error);
 
-    printf("connection closed for %p\n", cx);
+    mrp_log_error("connection closed for %p", cx);
     cx->priv->connected = FALSE;
 }
 
@@ -393,7 +388,7 @@ static void destroy_context(mrp_res_context_t *cx)
 static void htbl_free_rset_mapping(void *key, void *object)
 {
 #if 0
-    printf("> htbl_free_rset_mapping(%d, %p)\n", p_to_u(key), object);
+    mrp_log_info("> htbl_free_rset_mapping(%d, %p)", p_to_u(key), object);
 #else
     MRP_UNUSED(key);
 #endif
@@ -487,7 +482,7 @@ mrp_res_context_t *mrp_res_create(mrp_mainloop_t *ml,
 
 error:
 
-    printf("Error connecting to Murphy!\n");
+    mrp_log_error("error connecting to server");
     destroy_context(cx);
 
     return NULL;
@@ -496,6 +491,5 @@ error:
 
 void mrp_res_destroy(mrp_res_context_t *cx)
 {
-    printf("> mrp_res_destroy\n");
     destroy_context(cx);
 }
index e43c1e2..90a0fbc 100644 (file)
 #include "attribute.h"
 #include "message.h"
 
-#ifndef NO_DEBUG
 void print_resource(mrp_res_resource_t *res)
 {
-    printf("   resource '%s' : %smandatory, %sshared\n",
+    mrp_log_info("   resource '%s' : %smandatory, %sshared",
             res->name, res->priv->mandatory ? " " : "not ",
             res->priv->shared ? "" : "not ");
 }
 
+
 void print_resource_set(mrp_res_resource_set_t *rset)
 {
     int i;
     mrp_res_resource_t *res;
 
-    printf("Resource set %i (%s):\n", rset->priv->id, rset->application_class);
+    mrp_log_info("Resource set %i (%s):", rset->priv->id, rset->application_class);
 
     for (i = 0; i < rset->priv->num_resources; i++) {
     res = rset->priv->resources[i];
         print_resource(res);
     }
 }
-#endif
 
 
 void increase_ref(mrp_res_context_t *cx,
@@ -65,13 +64,10 @@ void increase_ref(mrp_res_context_t *cx,
         return;
 
     rset->priv->internal_ref_count++;
-
-    printf("rset %p ref count increased to %d\n",
-            rset, rset->priv->internal_ref_count);
 }
 
 
-static int destroy_resource_set(mrp_res_context_t *cx,
+static int destroy_resource_set_request(mrp_res_context_t *cx,
         mrp_res_resource_set_t *rset)
 {
     mrp_msg_t *msg = NULL;
@@ -103,8 +99,6 @@ error:
 }
 
 
-
-
 void decrease_ref(mrp_res_context_t *cx,
         mrp_res_resource_set_t *rset)
 {
@@ -113,12 +107,9 @@ void decrease_ref(mrp_res_context_t *cx,
 
     rset->priv->internal_ref_count--;
 
-    printf("rset %p ref count decreased to %d\n",
-            rset, rset->priv->internal_ref_count);
-
     if (rset->priv->internal_ref_count == 0) {
-        printf("delete the server resource set now\n");
-        destroy_resource_set(cx, rset);
+        mrp_log_info("delete the server resource set now");
+        destroy_resource_set_request(cx, rset);
         mrp_htbl_remove(cx->priv->rset_mapping,
                 u_to_p(rset->priv->id), FALSE);
         mrp_htbl_remove(cx->priv->internal_rset_mapping,
@@ -137,8 +128,6 @@ mrp_res_resource_t *get_resource_by_name(mrp_res_resource_set_t *rset,
 
     for (i = 0; i < rset->priv->num_resources; i++) {
         mrp_res_resource_t *res = rset->priv->resources[i];
-        printf("    comparing '%s' with '%s'\n",
-                name, res->name ? res->name : "NULL");
         if (strcmp(res->name, name) == 0) {
             return res;
         }
@@ -169,8 +158,6 @@ void free_resource_set(mrp_res_resource_set_t *rset)
 {
     int i;
 
-    printf("> free resource set %p\n", rset);
-
     if (!rset)
         return;
 
@@ -197,8 +184,6 @@ void delete_resource_set(mrp_res_context_t *cx,
     if (!rs)
         return;
 
-    printf("> delete_resource_set (%p)\n", rs);
-
     if (cx && rs->priv) {
         /* check if the resource set being deleted is a library resource set */
         mrp_res_resource_set_t *internal_rset = mrp_htbl_lookup(
@@ -219,8 +204,6 @@ static mrp_res_resource_t *resource_copy(const mrp_res_resource_t *original,
 {
     mrp_res_resource_t *copy;
 
-    printf("> resource_copy\n");
-
     copy = mrp_allocz(sizeof(mrp_res_resource_t));
 
     if (!copy)
@@ -252,7 +235,7 @@ static mrp_res_resource_t *resource_copy(const mrp_res_resource_t *original,
     return copy;
 
 error:
-    printf("resource_copy error\n");
+    mrp_log_error("failed to copy resource");
 
     if (copy) {
         mrp_free((void *) copy->name);
@@ -277,8 +260,6 @@ mrp_res_resource_set_t *resource_set_copy(
 
     copy = mrp_allocz(sizeof(mrp_res_resource_set_t));
 
-    printf("> resource_set_copy (%p -> %p)\n", original, copy);
-
     if (!copy)
         goto error;
 
@@ -361,8 +342,6 @@ static mrp_res_resource_set_t *create_resource_set(
     mrp_htbl_insert(cx->priv->internal_rset_mapping,
             u_to_p(internal->priv->internal_id), internal);
 
-    printf("< create_resource_set (%p, internal %p)\n", rs, internal);
-
     return rs;
 
 error:
@@ -492,7 +471,7 @@ mrp_res_resource_t *mrp_res_create_resource(mrp_res_context_t *cx,
     return res;
 
 error:
-    printf("mrp_res_create_resource error\n");
+    mrp_log_error("mrp_res_create_resource error");
     free_resource(res);
 
     return NULL;
@@ -541,11 +520,6 @@ int mrp_res_release_resource_set(mrp_res_context_t *cx,
 {
     mrp_res_resource_set_t *internal_set = NULL;
 
-    printf("> mrp_release_resources (rset %d at %p)\n",
-            rset->priv->id, rset);
-
-    print_resource_set(rset);
-
     if (!cx->priv->connected)
         goto error;
 
@@ -562,6 +536,8 @@ int mrp_res_release_resource_set(mrp_res_context_t *cx,
     return release_resource_set_request(cx, internal_set);
 
 error:
+    mrp_log_error("mrp_release_resources error");
+
     return -1;
 }
 
@@ -710,9 +686,6 @@ int mrp_res_acquire_resource_set(mrp_res_context_t *cx,
     rset = mrp_htbl_lookup(cx->priv->internal_rset_mapping,
             u_to_p(original->priv->internal_id));
 
-    printf("> mrp_acquire_resources (client %p, internal %p)\n",
-            original, rset);
-
     if (!rset)
         goto error;
 
@@ -750,6 +723,8 @@ int mrp_res_acquire_resource_set(mrp_res_context_t *cx,
     return 0;
 
 error:
+    mrp_log_error("mrp_res_acquire_resource_set error");
+
     mrp_msg_unref(msg);
     return -1;
 }