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:
- 27:b8aaf7dc7023
- Parent:
- 26:d7b009313e3b
- Child:
- 29:be035befb437
--- a/source/ConnectorEndpoint.cpp Sun Jun 12 03:18:25 2016 +0000 +++ b/source/ConnectorEndpoint.cpp Tue Jun 14 04:01:34 2016 +0000 @@ -29,6 +29,9 @@ // Utils support #include "mbed-connector-interface/Utils.h" +// Device Manager support +#include "mbed-connector-interface/DeviceManager.h" + // DEBUG #ifndef NDEBUG #define DEBUG_OUT(...) { printf(__VA_ARGS__); } @@ -39,6 +42,11 @@ // our endpoint instance static Connector::Endpoint *__endpoint = NULL; +// LWIP_INTERFACE +#if defined(MCI_LWIP_INTERFACE) +void *__network_interface = NULL; +#endif + // Connector namespace namespace Connector { @@ -90,6 +98,8 @@ this->m_device_manager = NULL; this->m_connected = false; this->m_registered = false; + this->m_csi = NULL; + this->m_oim = NULL; } // Copy Constructor @@ -104,6 +114,8 @@ this->m_device_manager = ep.m_device_manager; this->m_connected = ep.m_connected; this->m_registered = ep.m_registered; + this->m_csi = ep.m_csi; + this->m_oim = ep.m_oim; } // Destructor @@ -184,6 +196,13 @@ (char *)this->m_options->getDomain().c_str(), network_protocol, // CoAP over UDP or TCP... ip_address_type); // IPv4 addressing or IPv6 addressing + +#if defined (MCI_LWIP_INTERFACE) + if (__network_interface != NULL && this->m_interface != NULL) { + this->logger()->log("Endpoint: Morpheus: binding network..."); + this->m_interface->set_platform_network_handler(__network_interface); + } +#endif } // mbed-client: create_server_instance() @@ -266,29 +285,48 @@ } // object registered -void Endpoint::object_registered(M2MSecurity */*security_object */, const M2MServer &/*server_object*/) { +void Endpoint::object_registered(M2MSecurity *security, const M2MServer &server) { this->logger()->log("Endpoint registered"); this->m_connected = true; this->m_registered = true; + +#if defined (ENDPOINT_EARLY_CONFIG_DEREG_BUTTON) + // setup the shutdown button (if enabled for a given platform...) + this->logger()->log("Configuring optional de-registration button..."); + net_setup_deregistration_button((void *)this); +#endif + + if (this->m_csi != NULL) { + this->m_csi->object_registered((void *)this,(void *)security,(void *)&server); + } } // registration updated -void Endpoint::registration_updated(M2MSecurity */*security_object*/, const M2MServer &/*server_object*/) { +void Endpoint::registration_updated(M2MSecurity *security, const M2MServer &server) { this->logger()->log("Endpoint re-registered."); this->m_connected = true; this->m_registered = true; + if (this->m_csi != NULL) { + this->m_csi->registration_updated((void *)this,(void *)security,(void *)&server); + } } // object unregistered -void Endpoint::object_unregistered(M2MSecurity */*server_object*/) { +void Endpoint::object_unregistered(M2MSecurity *server) { // ready to exit this->logger()->log("Endpoint de-registered... Ready to exit..."); this->m_registered = false; + if (this->m_csi != NULL) { + this->m_csi->object_unregistered((void *)this,(void *)server); + } } // bootstrap done -void Endpoint::bootstrap_done(M2MSecurity * /*server_object */) { +void Endpoint::bootstrap_done(M2MSecurity *server) { this->logger()->log("Bootstrapped"); + if (this->m_csi != NULL) { + this->m_csi->bootstrapped((void *)this,(void *)server); + } } // resource value updated @@ -296,6 +334,9 @@ this->logger()->log("Value Updated"); DynamicResource *target_res = this->lookupDynamicResource(base); target_res->process(base->operation(),type); + if (this->m_csi != NULL) { + this->m_csi->value_updated((void *)this,(void *)base,(int)type); + } } // lookup which DynamicResource cooresponds to a given M2MBase instance... @@ -317,18 +358,46 @@ // build out the endpoint void Endpoint::build_endpoint() { - // initialize as an mbed-client - this->create_interface(); - - // Create our server instance - this->m_server_instance = this->create_server_instance(); + // initialize as an mbed-client + this->create_interface(); - // Loop through Static Resources and bind each of them... - 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::build(): binding device resource: [%s]...",device_resources->at(i)->getFullName().c_str()); - this->m_object_list.push_back(device_resources->at(i)->bind(this)); + // Create our server instance + this->m_server_instance = this->create_server_instance(); + + // We now have to bind our device resources + if (this->m_device_manager != NULL) { + // bind the device manager + ((DeviceManager *)this->m_device_manager)->bind(); + + // push back the Device Resources Object + if (this->m_options->getDeviceResourcesObject() != NULL) { + // DEBUG + this->logger()->log("Endpoint::build(): plumbing device resources object..."); + + // push back the device resources object + this->m_object_list.push_back((M2MObject *)this->m_options->getDeviceResourcesObject()); + } + else { + // unable to plumb device manager + this->logger()->log("Endpoint::build(): Unable to plumb device resources. Not installing device resource object..."); + } + + // push back the Firmware Resources Object + if (this->m_options->getFirmwareResourcesObject() != NULL) { + // DEBUG + this->logger()->log("Endpoint::build(): plumbing firmware resources object..."); + + // push back the firmware resources object + this->m_object_list.push_back((M2MObject *)this->m_options->getFirmwareResourcesObject()); + } + else { + // unable to plumb firmware manager + this->logger()->log("Endpoint::build(): Unable to plumb firmware resources. Not installing firmware resource object..."); + } + } + else { + // no device manager installed + this->logger()->log("Endpoint::build(): No device manager installed."); } // Loop through Static Resources and bind each of them... @@ -336,7 +405,7 @@ const StaticResourcesList *static_resources = this->m_options->getStaticResourceList(); for(int i=0; i<(int)static_resources->size(); ++i) { 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)); + static_resources->at(i)->bind(this); } // Loop through Dynamic Resources and bind each of them... @@ -344,7 +413,22 @@ const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList(); for(int i=0; i<(int)dynamic_resources->size(); ++i) { 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)); + dynamic_resources->at(i)->bind(this); + } + + // Get the ObjectList from the ObjectInstanceManager... + NamedPointerList list = this->getObjectInstanceManager()->getObjectList(); + + // DEBUG + this->logger()->log("Endpoint::build(): All Resources bound. Number of Objects in list: %d",list.size()); + + // add all of the object instances we have created... + for(int i=0;i<list.size();++i) { + // DEBUG + this->logger()->log("Endpoint::build(): adding Object Instance with ObjID: %s...",list.at(i).name().c_str()); + + // push back the object instance... + this->m_object_list.push_back((M2MObject *)(list.at(i).ptr())); } } @@ -363,6 +447,23 @@ return this->m_registered; } +// Set the ConnectionStatusInterface Implementation instance +void Endpoint::setConnectionStatusInterfaceImpl(ConnectionStatusInterface *csi) { + if (__endpoint != NULL) { + __endpoint->setConnectionStatusInterfaceImpl(csi); + } +} + +// Set our ObjectInstanceManager +void Endpoint::setObjectInstanceManager(ObjectInstanceManager *oim) { + this->m_oim = oim; +} + +// Get our ObjectInstanceManager +ObjectInstanceManager *Endpoint::getObjectInstanceManager() { + return this->m_oim; +} + // our logger Logger *Endpoint::logger() {