observe updates
Fork of mbedConnectorInterface by
Embed:
(wiki syntax)
Show/hide line numbers
ConnectorEndpoint.cpp
Go to the documentation of this file.
00001 /** 00002 * @file ConnectorEndpoint.cpp 00003 * @brief mbed CoAP Endpoint base class 00004 * @author Doug Anson/Chris Paola 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #include "ConnectorEndpoint.h" 00024 00025 // lower level network stubs integration 00026 #include "mbedEndpointNetworkStubs.h" 00027 00028 // Connector namespace 00029 namespace Connector { 00030 00031 // STATIC: Plumb the network 00032 void Endpoint::plumbNetwork(bool canActAsRouterNode) { 00033 // call into our network stubs to (pre-configure) plumb the network... 00034 DBG("plumbNetwork: pre-configure plumb of network...\r\n"); 00035 net_stubs_pre_plumb_network(canActAsRouterNode); 00036 00037 // configure the endpoint now... 00038 DBG("plumbNetwork: configuring endpoint...\r\n"); 00039 utils_configure_endpoint(); 00040 00041 // call into our network stubs to (pre-configure) plumb the network... 00042 DBG("plumbNetwork: post-configure plumb of network...\r\n"); 00043 net_stubs_post_plumb_network(); 00044 } 00045 00046 // STATIC: Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger) 00047 void Endpoint::start() 00048 { 00049 // initialize our endpoint and register it 00050 DBG("Endpoint::start(): creating endpoint instance and registering with mDS...\r\n"); 00051 utils_init_and_register_endpoint(); 00052 00053 // create the main loop plumbing for our lower network stack 00054 DBG("Endpoint::start(): creating main loop plumbing...\r\n"); 00055 net_stubs_create_main_loop(); 00056 00057 // call into the lower network stubs to start event processing 00058 DBG("Endpoint::start(): beginning main event loop...\r\n"); 00059 net_stubs_begin_main_loop(); 00060 } 00061 00062 // Constructor 00063 Endpoint::Endpoint(const Logger *logger, const Options *options) 00064 { 00065 this->m_logger = (Logger *)logger; 00066 this->m_options = (Options *)options; 00067 } 00068 00069 // Copy Constructor 00070 Endpoint::Endpoint(const Endpoint &ep) 00071 { 00072 this->m_logger = ep.m_logger; 00073 this->m_options = ep.m_options; 00074 } 00075 00076 // Destructor 00077 Endpoint::~Endpoint() 00078 { 00079 } 00080 00081 // register the endpoint 00082 void Endpoint::register_endpoint() 00083 { 00084 // Create the NSDL Resource Pointer... 00085 this->logger()->log("Endpoint::initialize(): initializing NSP resource pointer..."); 00086 sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s)); 00087 if(!resource_ptr) return; 00088 memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s)); 00089 00090 resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s)); 00091 if(!resource_ptr->resource_parameters_ptr) { 00092 nsdl_free(resource_ptr); 00093 return; 00094 } 00095 memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00096 00097 // Loop through Static Resources and bind each of them... 00098 this->logger()->log("Endpoint::initialize(): adding static resources..."); 00099 const StaticResourcesList *static_resources = this->m_options->getStaticResourceList(); 00100 for(int i=0; i<static_resources->size(); ++i) { 00101 this->logger()->log("Endpoint::initialize(): binding static resource: [%s]...",static_resources->at(i)->getName().c_str()); 00102 static_resources->at(i)->bind(resource_ptr); 00103 } 00104 00105 // Loop through Dynamic Resources and bind each of them... 00106 this->logger()->log("Endpoint::initialize(): adding dynamic resources..."); 00107 const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList(); 00108 for(int i=0; i<dynamic_resources->size(); ++i) { 00109 this->logger()->log("Endpoint::initialize(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getName().c_str()); 00110 dynamic_resources->at(i)->bind(resource_ptr); 00111 } 00112 00113 // register the endpoint 00114 net_stubs_register_endpoint(); 00115 00116 // clean up 00117 nsdl_free(resource_ptr->resource_parameters_ptr); 00118 nsdl_free(resource_ptr); 00119 } 00120 00121 // our logger 00122 Logger *Endpoint::logger() 00123 { 00124 return this->m_logger; 00125 } 00126 00127 } // namespace Connector
Generated on Wed Jul 13 2022 02:11:49 by 1.7.2