Doug Anson / mbedConnectorInterface

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Revision:
2:853f9ecc12df
Parent:
1:cabdd0350707
Child:
5:a929d65eb385
--- a/api/Endpoint.cpp	Tue Jan 27 22:52:25 2015 +0000
+++ b/api/Endpoint.cpp	Tue Jan 27 23:41:34 2015 +0000
@@ -3,7 +3,7 @@
  * @brief   mbed CoAP Endpoint base class
  * @author  Doug Anson/Chris Paola
  * @version 1.0
- * @see     
+ * @see
  *
  * Copyright (c) 2014
  *
@@ -19,96 +19,105 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
- #include "Endpoint.h"
- 
- // support for temporary mbedEndpointLib calls...
- #include "mbedEndpointLib.h"
- 
- // Connector namespace
- namespace Connector {
-     // Constructor
-     Endpoint::Endpoint(const Logger *logger, const Options *options) {
-         this->m_logger = (Logger *)logger;
-         this->m_options = (Options *)options;
-     }
-     
-     // Copy Constructor
-     Endpoint::Endpoint(const Endpoint &ep) {
-         this->m_logger = ep.m_logger;
-         this->m_options = ep.m_options;
-     }
-     
-     // Destructor
-     Endpoint::~Endpoint() {
-     }
-     
-     // plumb network
-     void Endpoint::plumbNetwork(bool canActAsRouterNode) {
-        // call into mbedEndpointLib for now...
-        init_network(canActAsRouterNode);
-     }
-     
-     // initialize the endpoint
-     void Endpoint::initialize() {    
-        // Create the NSDL Resource Pointer...
-        std::printf("Endpoint::initialize(): initializing NSP resource pointer...\r\n");
-        sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s));
-        if(!resource_ptr) return;
-        memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
-    
-        resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s));
-        if(!resource_ptr->resource_parameters_ptr) {
-            nsdl_free(resource_ptr);
-            return;
-        }
-        memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
-        
-        // Loop through Static Resources and bind each of them...
-        std::printf("Endpoint::initialize(): adding static resources...\r\n");
-        const StaticResourcesList *static_resources = this->m_options->getStaticResourceList();
-        for(int i=0;i<static_resources->size();++i) {
-            std::printf("Endpoint::initialize(): binding static resource: [%s]...\r\n",static_resources->at(i)->getName().c_str());
-            static_resources->at(i)->bind(resource_ptr);
-        } 
-        
-        // Loop through Dynamic Resources and bind each of them...
-        std::printf("Endpoint::initialize(): adding dynamic resources...\r\n");
-        const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList();
-        for(int i=0;i<dynamic_resources->size();++i) {
-            std::printf("Endpoint::initialize(): binding dynamic resource: [%s]...\r\n",dynamic_resources->at(i)->getName().c_str());
-            dynamic_resources->at(i)->bind(resource_ptr);
-        }
-            
-        // initialize the Network
-        this->initNetwork();
-        
-        // clean up
-        nsdl_free(resource_ptr->resource_parameters_ptr);
+
+#include "Endpoint.h"
+
+// support for temporary mbedEndpointLib calls...
+#include "mbedEndpointLib.h"
+
+// Connector namespace
+namespace Connector {
+
+// Constructor
+Endpoint::Endpoint(const Logger *logger, const Options *options)
+{
+    this->m_logger = (Logger *)logger;
+    this->m_options = (Options *)options;
+}
+
+// Copy Constructor
+Endpoint::Endpoint(const Endpoint &ep)
+{
+    this->m_logger = ep.m_logger;
+    this->m_options = ep.m_options;
+}
+
+// Destructor
+Endpoint::~Endpoint()
+{
+}
+
+// plumb network
+void Endpoint::plumbNetwork(bool canActAsRouterNode)
+{
+    // call into mbedEndpointLib for now...
+    init_network(canActAsRouterNode);
+}
+
+// initialize the endpoint
+void Endpoint::initialize()
+{
+    // Create the NSDL Resource Pointer...
+    std::printf("Endpoint::initialize(): initializing NSP resource pointer...\r\n");
+    sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s));
+    if(!resource_ptr) return;
+    memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
+
+    resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s));
+    if(!resource_ptr->resource_parameters_ptr) {
         nsdl_free(resource_ptr);
-    } 
-    
-    // initialize the NSDL Network
-    void Endpoint::initNetwork() {
-        // register with NSP
-        DBG("Calling NSP_registration()...\r\n");
-        NSP_registration();
-        DBG("NSP_registration() completed\r\n");
-    }
-     
-    // Finalize the endpoint's configuration and begin the endpoint's main even loop
-    void Endpoint::start() {
-        // mbedEndpointLib tasklet creation...   
-        int main_tasklet_id = arm_ns_tasklet_create(&tasklet_main);
-        if(main_tasklet_id < 0) {
-            //Tasklet cerate fail
-            DBG("startTasklet: Tasklet creation failed...\r\n"); 
-            return;
-        }
-      
-        // mbedEndpointLib event dispatching
-        DBG("startTasklet: Beginning event dispatch...\r\n");
-        event_dispatch();
         return;
     }
-}
\ No newline at end of file
+    memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
+
+    // Loop through Static Resources and bind each of them...
+    std::printf("Endpoint::initialize(): adding static resources...\r\n");
+    const StaticResourcesList *static_resources = this->m_options->getStaticResourceList();
+    for(int i=0; i<static_resources->size(); ++i) {
+        std::printf("Endpoint::initialize(): binding static resource: [%s]...\r\n",static_resources->at(i)->getName().c_str());
+        static_resources->at(i)->bind(resource_ptr);
+    }
+
+    // Loop through Dynamic Resources and bind each of them...
+    std::printf("Endpoint::initialize(): adding dynamic resources...\r\n");
+    const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList();
+    for(int i=0; i<dynamic_resources->size(); ++i) {
+        std::printf("Endpoint::initialize(): binding dynamic resource: [%s]...\r\n",dynamic_resources->at(i)->getName().c_str());
+        dynamic_resources->at(i)->bind(resource_ptr);
+    }
+
+    // initialize the Network
+    this->initNetwork();
+
+    // clean up
+    nsdl_free(resource_ptr->resource_parameters_ptr);
+    nsdl_free(resource_ptr);
+}
+
+// initialize the NSDL Network
+void Endpoint::initNetwork()
+{
+    // register with NSP
+    DBG("Calling NSP_registration()...\r\n");
+    NSP_registration();
+    DBG("NSP_registration() completed\r\n");
+}
+
+// Finalize the endpoint's configuration and begin the endpoint's main even loop
+void Endpoint::start()
+{
+    // mbedEndpointLib tasklet creation...
+    int main_tasklet_id = arm_ns_tasklet_create(&tasklet_main);
+    if(main_tasklet_id < 0) {
+        //Tasklet cerate fail
+        DBG("startTasklet: Tasklet creation failed...\r\n");
+        return;
+    }
+
+    // mbedEndpointLib event dispatching
+    DBG("startTasklet: Beginning event dispatch...\r\n");
+    event_dispatch();
+    return;
+}
+
+} // namespace Connector