Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: IoT_LED_demo ServoTest uWater_Project hackathon ... more
Diff: api/Endpoint.cpp
- Revision:
- 5:a929d65eb385
- Parent:
- 2:853f9ecc12df
--- a/api/Endpoint.cpp Wed Jan 28 12:11:22 2015 +0000
+++ b/api/Endpoint.cpp Wed Jan 28 14:43:46 2015 +0000
@@ -25,6 +25,9 @@
// support for temporary mbedEndpointLib calls...
#include "mbedEndpointLib.h"
+// Tasklet ID
+int main_tasklet_id = -1;
+
// Connector namespace
namespace Connector {
@@ -47,10 +50,9 @@
{
}
-// plumb network
-void Endpoint::plumbNetwork(bool canActAsRouterNode)
-{
- // call into mbedEndpointLib for now...
+// Plumb the network
+void Endpoint::plumbNetwork(bool canActAsRouterNode) {
+ // call into mbedEndpointLib directly for now... (TODO: wont be able to (re)set MAC address in OptionsBuilder as its already been plumbed here...)
init_network(canActAsRouterNode);
}
@@ -58,7 +60,7 @@
void Endpoint::initialize()
{
// Create the NSDL Resource Pointer...
- std::printf("Endpoint::initialize(): initializing NSP resource pointer...\r\n");
+ this->logger()->log("Endpoint::initialize(): initializing NSP resource pointer...");
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));
@@ -71,18 +73,18 @@
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");
+ this->logger()->log("Endpoint::initialize(): adding static resources...");
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());
+ this->logger()->log("Endpoint::initialize(): binding static resource: [%s]...",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");
+ this->logger()->log("Endpoint::initialize(): adding dynamic resources...");
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());
+ this->logger()->log("Endpoint::initialize(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getName().c_str());
dynamic_resources->at(i)->bind(resource_ptr);
}
@@ -98,26 +100,32 @@
void Endpoint::initNetwork()
{
// register with NSP
- DBG("Calling NSP_registration()...\r\n");
+ this->logger()->log("Calling NSP_registration()...");
NSP_registration();
- DBG("NSP_registration() completed\r\n");
+ this->logger()->log("NSP_registration() completed");
}
-// Finalize the endpoint's configuration and begin the endpoint's main even loop
+// Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger)
void Endpoint::start()
-{
+{
// mbedEndpointLib tasklet creation...
- int main_tasklet_id = arm_ns_tasklet_create(&tasklet_main);
+ main_tasklet_id = arm_ns_tasklet_create(&tasklet_main);
if(main_tasklet_id < 0) {
//Tasklet cerate fail
- DBG("startTasklet: Tasklet creation failed...\r\n");
+ std::printf("startTasklet: Tasklet creation failed...\r\n");
return;
}
// mbedEndpointLib event dispatching
- DBG("startTasklet: Beginning event dispatch...\r\n");
+ std::printf("startTasklet: Beginning event dispatch...\r\n");
event_dispatch();
return;
}
+// our logger
+Logger *Endpoint::logger()
+{
+ return this->m_logger;
+}
+
} // namespace Connector
