mbed Connector Interface simplification API on top of mbed-client
Fork of mbedConnectorInterfaceV3 by
NOTE:
This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!
Diff: source/ConnectorEndpoint.cpp
- Revision:
- 8:f950fb1b78c0
- Parent:
- 5:14a3a0f709eb
- Child:
- 10:3f79b5e67c22
--- a/source/ConnectorEndpoint.cpp Sun Feb 21 19:05:14 2016 +0000 +++ b/source/ConnectorEndpoint.cpp Wed Feb 24 05:52:00 2016 +0000 @@ -49,29 +49,26 @@ DEBUG_OUT("Endpoint::plumbNetwork: initializing endpoint instance...\r\n"); __endpoint = (Connector::Endpoint *)utils_init_endpoint(canActAsRouterNode); } - + // configure the endpoint now... DEBUG_OUT("Endpoint::plumbNetwork: configuring endpoint...\r\n"); utils_configure_endpoint((void *)__endpoint); // plumb network DEBUG_OUT("Endpoint::plumbNetwork: plumbing network...\r\n"); - net_stubs_plumb_network((void *)__endpoint); + net_plumb_network((void *)__endpoint); } // STATIC: Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger) -void Endpoint::start() { - // complete our registration setup... - DEBUG_OUT("Endpoint::start: registering endpoint with Connector...\r\n"); - utils_register_endpoint((void *)__endpoint); +void Endpoint::start() +{ + // complete setup of our endpoint... + DEBUG_OUT("Endpoint::start: building out endpoint...\r\n"); + utils_build_endpoint((void *)__endpoint); - // Initialize our main loop... - DEBUG_OUT("Endpoint::start: initializing main loop for endpoint...\r\n"); - net_stubs_create_main_loop(__endpoint); - - // Begin the main loop - DEBUG_OUT("Endpoint::start: entering main loop in endpoint...\r\n"); - net_stubs_begin_main_loop(__endpoint); + // register the endpoint + DEBUG_OUT("Endpoint::start: completing endpoint build out..\r\n"); + net_perform_endpoint_registration(__endpoint); } // Constructor @@ -147,6 +144,7 @@ if (server != NULL) { const String url = this->m_options->getConnectorURL(); server->set_resource_value(M2MSecurity::M2MServerUri, url); + server->set_resource_value(M2MSecurity::BootstrapServer, NULL); server->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate); server->set_resource_value(M2MSecurity::ServerPublicKey,this->m_options->getServerCertificate(),this->m_options->getServerCertificateSize()); server->set_resource_value(M2MSecurity::PublicKey,this->m_options->getClientCertificate(),this->m_options->getClientCertificateSize()); @@ -193,15 +191,24 @@ } } -// complete registration of the endpoint -void Endpoint::complete_endpoint_registration(M2MSecurity *register_object, M2MObjectList object_list) { - if (this->m_interface != NULL) { - this->m_interface->register_object(register_object, object_list); - } +// register the endpoint +void Endpoint::register_endpoint(M2MSecurity *server_instance, M2MObjectList resources) { + if (this->m_interface != NULL && server_instance != NULL && resources.size() > 0) { + // register endpoint + this->logger()->log("Registering endpoint..."); + this->m_interface->register_object(server_instance, resources); + } } -// deregister endpoint and stop scheduling -void Endpoint::closedown_endpoint(void) { +// re-register the endpoint +void Endpoint::re_register_endpoint() { + if (this->m_interface != NULL) { + this->m_interface->update_registration(this->m_server_instance, this->m_options->getLifetime()); + } +} + +// de-register endpoint +void Endpoint::de_register_endpoint(void) { if (this->m_interface != NULL) { // de-register endpoint this->logger()->log("De-registering endpoint..."); @@ -209,11 +216,23 @@ } } -// re-register the endpoint -void Endpoint::re_register_endpoint() { - if (this->m_interface != NULL) { - this->m_interface->update_registration(this->m_server_instance, this->m_options->getLifetime()); - } +// object registered +void Endpoint::object_registered(M2MSecurity */*security_object */, const M2MServer &/*server_object*/) { + this->logger()->log("Endpoint registered"); +} + +// registration updated +void Endpoint::registration_updated(M2MSecurity */*security_object*/, const M2MServer &/*server_object*/) { + this->logger()->log("Endpoint re-registered."); +} + +// object unregistered +void Endpoint::object_unregistered(M2MSecurity */*server_object*/) { + // ready to exit + this->logger()->log("Endpoint de-registered... Ready to exit..."); + + // stop + exit(0); } // bootstrap done @@ -221,25 +240,6 @@ this->logger()->log("Bootstrapped"); } -// object registered -void Endpoint::object_registered(M2MSecurity */*security_object */, const M2MServer &/*server_object*/) { - this->logger()->log("Registered"); -} - -// object unregistered -void Endpoint::object_unregistered(M2MSecurity */*server_object*/) { - // ready to exit - this->logger()->log("Endpoint has been deregistered.. Ready to exit..."); - - // EXIT - exit(0); -} - -// registration updated -void Endpoint::registration_updated(M2MSecurity */*security_object*/, const M2MServer &/*server_object*/) { - this->logger()->log("Registration Updated"); -} - // resource value updated void Endpoint::value_updated(M2MBase *base, M2MBase::BaseType type) { this->logger()->log("Value Updated"); @@ -263,8 +263,8 @@ return res; } -// register the endpoint -void Endpoint::register_endpoint() +// build out the endpoint +void Endpoint::build_endpoint() { // initialize as an mbed-client this->create_interface(); @@ -273,26 +273,26 @@ this->m_server_instance = this->create_server_instance(); // Loop through Static Resources and bind each of them... - this->logger()->log("Endpoint::initialize(): adding device resources..."); + this->logger()->log("Endpoint::build(): adding device resources..."); const DeviceResourcesList *device_resources = this->m_options->getDeviceResourceList(); for(int i=0; i<(int)device_resources->size(); ++i) { - this->logger()->log("Endpoint::initialize(): binding device resource: [%s]...",device_resources->at(i)->getFullName().c_str()); + this->logger()->log("Endpoint::build(): binding device resource: [%s]...",device_resources->at(i)->getFullName().c_str()); this->m_object_list.push_back(device_resources->at(i)->bind(this)); } // Loop through Static Resources and bind each of them... - this->logger()->log("Endpoint::initialize(): adding static resources..."); + this->logger()->log("Endpoint::build(): adding static resources..."); const StaticResourcesList *static_resources = this->m_options->getStaticResourceList(); for(int i=0; i<(int)static_resources->size(); ++i) { - this->logger()->log("Endpoint::initialize(): binding static resource: [%s]...",static_resources->at(i)->getFullName().c_str()); + this->logger()->log("Endpoint::build(): binding static resource: [%s]...",static_resources->at(i)->getFullName().c_str()); this->m_object_list.push_back(static_resources->at(i)->bind(this)); } // Loop through Dynamic Resources and bind each of them... - this->logger()->log("Endpoint::initialize(): adding dynamic resources..."); + this->logger()->log("Endpoint::build(): adding dynamic resources..."); const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList(); for(int i=0; i<(int)dynamic_resources->size(); ++i) { - this->logger()->log("Endpoint::initialize(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getFullName().c_str()); + this->logger()->log("Endpoint::build(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getFullName().c_str()); this->m_object_list.push_back(dynamic_resources->at(i)->bind(this)); } } @@ -304,4 +304,3 @@ } } // namespace Connector -