custom for >5 resources

Fork of mbedConnectorInterface by Doug Anson

Revision:
5:a929d65eb385
Parent:
2:853f9ecc12df
Child:
20:abfbaf524192
--- a/api/DynamicResource.cpp	Wed Jan 28 12:11:22 2015 +0000
+++ b/api/DynamicResource.cpp	Wed Jan 28 14:43:46 2015 +0000
@@ -67,7 +67,6 @@
 {
     if (p != NULL) {
         sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p;
-        std::printf("DynamicResource: name[%s] type:[%s] mask: 0x%.2x\r\n",this->getName().c_str(),this->m_res_type.c_str(),this->m_res_mask);
         const uint8_t *name = (const uint8_t *)(this->getName().c_str());
         const uint8_t *res_type = (const uint8_t *)this->m_res_type.c_str();
         int name_length = this->getName().size();
@@ -77,9 +76,9 @@
         const string *key = new string(this->getName());
         ipt_helper_add_instance_pointer(key,this);
         nsdl_create_dynamic_resource(resource_ptr,name_length,(uint8_t *)name,res_type_length,(uint8_t *)res_type,is_observable,&ipt_helper_nsdl_callback_stub,this->m_res_mask);
-        std::printf("DynamicResource[%s(%d)] type: %s(%d) bound mask: 0x%.2x\r\n",name,name_length,res_type,res_type_length,this->m_res_mask);
+        this->logger()->log("DynamicResource: [%s] type: [%s] bound",name,res_type);
     } else {
-        std::printf("DynamicResource: NULL parameter in bind()\r\n");
+        this->logger()->log("DynamicResource: NULL parameter in bind()");
     }
 }
 
@@ -92,17 +91,16 @@
     string key = this->coapDataToString(received_coap_ptr->uri_path_ptr,received_coap_ptr->uri_path_len);
 
     if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) {
-        std::printf("GET requested for [%s]...\r\n",key.c_str());
         coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
 
         // process the GET if we have registered a callback for it...
         if ((this->m_res_mask&SN_GRS_GET_ALLOWED) != 0) {
             // call the resource get() to get the resource value
-            std::printf("Calling resource(GET) for [%s]...\r\n",key.c_str());
+            this->logger()->log("Calling resource(GET) for [%s]...",key.c_str());
             string value = this->get();
 
             // convert the string from the GET to something suitable for CoAP payloads
-            std::printf("Building payload for [%s]=[%s]...\r\n",key.c_str(),value.c_str());
+            this->logger()->log("Building payload for [%s]=[%s]...",key.c_str(),value.c_str());
             int length = value.size();
             char value_buffer[MAX_VALUE_BUFFER_LENGTH+1];
             if (length > MAX_VALUE_BUFFER_LENGTH) length = MAX_VALUE_BUFFER_LENGTH;
@@ -116,10 +114,9 @@
             // build out the response and send...
             sn_nsdl_send_coap_message(address, coap_res_ptr);
         } else {
-            std::printf("ERROR: resource(GET) mask is munged (mask: 0x%x)\r\n",this->m_res_mask);
+            this->logger()->log("ERROR: resource(GET) mask is munged (mask: 0x%x)",this->m_res_mask);
         }
     } else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) {
-        std::printf("PUT requested for [%s]...\r\n",key.c_str());
         if(received_coap_ptr->payload_len > 0) {
             // process the PUT if we have registered a callback for it...
             if ((this->m_res_mask&SN_GRS_PUT_ALLOWED) != 0) {
@@ -127,18 +124,18 @@
                 string value = this->coapDataToString(received_coap_ptr->payload_ptr,received_coap_ptr->payload_len);
 
                 // call the resource put() to set the resource value
-                std::printf("Calling resource(PUT) with [%s]=[%s]...\r\n",key.c_str(),value.c_str());
+                this->logger()->log("Calling resource(PUT) with [%s]=[%s]...",key.c_str(),value.c_str());
                 this->put(value);
 
                 // build out the response and send...
-                std::printf("resource(PUT) completed for [%s]...\r\n",key.c_str());
+                this->logger()->log("resource(PUT) completed for [%s]...",key.c_str());
                 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
                 sn_nsdl_send_coap_message(address, coap_res_ptr);
             } else {
-                std::printf("ERROR: resource(PUT) mask is munged (mask: 0x%x)\r\n",this->m_res_mask);
+                this->logger()->log("ERROR: resource(PUT) mask is munged (mask: 0x%x)",this->m_res_mask);
             }
         } else {
-            std::printf("ERROR: Binder(PUT) payload is NULL...\r\n");
+            this->logger()->log("ERROR: Binder(PUT) payload is NULL...");
         }
     }