custom for >5 resources

Fork of mbedConnectorInterface by Doug Anson

Revision:
0:b438482ebbfc
Child:
2:853f9ecc12df
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/api/StaticResource.cpp	Tue Jan 27 22:23:51 2015 +0000
@@ -0,0 +1,63 @@
+/**
+ * @file    StaticResource.h
+ * @brief   mbed CoAP Endpoint Static Resource class
+ * @author  Doug Anson/Chris Paola
+ * @version 1.0
+ * @see     
+ *
+ * Copyright (c) 2014
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+ #include "StaticResource.h"
+ 
+ // NSDL libraries
+ #include "nsdl_support.h"
+ 
+ // Constructor
+ StaticResource::StaticResource(const Logger *logger,const char *name, const char *value) : Resource<string>(logger,string(name),string(value)) {
+ }
+ 
+ // Constructor
+ StaticResource::StaticResource(const Logger *logger,const char *name,const string value) : Resource<string>(logger,string(name),string(value)) {
+ }
+ 
+ // Constructor with buffer lengths
+ StaticResource::StaticResource(const Logger *logger,const string name,const string value) : Resource<string>(logger,string(name),string(value)) {
+ }
+ 
+ // Copy constructor
+ StaticResource::StaticResource(const StaticResource &resource) : Resource<string>((const Resource<string> &)resource) {
+ }
+ 
+ // Destructor
+ StaticResource::~StaticResource() {
+ }
+ 
+ // Bind resource to Endpoint
+ void StaticResource::bind(void *p) {
+    if (p != NULL) {
+        sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s *)p;
+        std::printf("StaticResource: name[%s] value:[%s]\r\n",this->getName().c_str(),this->getValue().c_str());
+        const uint8_t *name = (const uint8_t *)(this->getName().c_str());
+        const uint8_t *value = (const uint8_t *)(this->getValue().c_str());
+        int name_length = this->getName().size();
+        int value_length = this->getValue().size();
+        nsdl_create_static_resource(resource_ptr,name_length,(uint8_t *)name,0,0,(uint8_t *)value,value_length);
+        std::printf("StaticResource[%s(%d)] value: %s(%d) bound\r\n",name,name_length,value,value_length);
+    }
+    else {
+        std::printf("StaticResource: NULL parameter in bind()\r\n");
+    }
+ }
\ No newline at end of file