mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface
Diff: source/DeviceFirmwareCompositeResource.cpp
- Revision:
- 13:9edad7677211
- Child:
- 14:d9ce4e56684e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/DeviceFirmwareCompositeResource.cpp Wed Jun 08 22:32:08 2016 +0000 @@ -0,0 +1,118 @@ +/** + * @file DeviceFirmwareCompositeResource.cpp + * @brief mbed CoAP Endpoint Device Firmware Composited Resource + * @author Doug Anson + * @version 1.0 + * @see + * + * Copyright (c) 2014 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Class +#include "mbed-connector-interface/DeviceFirmwareCompositeResource.h" + +// Endpoint Class +#include "mbed-connector-interface/ConnectorEndpoint.h" + +// Options Builder +#include "mbed-connector-interface/OptionsBuilder.h" + +// DeviceManagementResponder +#include "mbed-connector-interface/DeviceManagementResponder.h" + +// DeviceStringResource +#include "mbed-connector-interface/DeviceStringResource.h" + +// DeviceIntegerResource +#include "mbed-connector-interface/DeviceIntegerResource.h" + +// DeviceFirmwareUpdateResource +#include "mbed-connector-interface/DeviceFirmwareUpdateResource.h" + +// DeviceFirmwareManifestResource +#include "mbed-connector-interface/DeviceFirmwareManifestResource.h" + +// Default Constructor +DeviceFirmwareCompositeResource::DeviceFirmwareCompositeResource(const Logger *logger,const char *obj_name,const void *dm_responder) { + this->m_logger = (Logger *)logger; + this->m_dm_responder = (void *)dm_responder; + this->m_obj_name = (char *)obj_name; + for(int i=0;i<NUM_FIRMWARE_RESOURCES;++i) { + this->m_firmware_resource[i] = NULL; + } +} + +// Copy Constructor +DeviceFirmwareCompositeResource::DeviceFirmwareCompositeResource(const DeviceFirmwareCompositeResource &res) { + this->m_logger = res.m_logger; + this->m_dm_responder = res.m_dm_responder; + this->m_obj_name = res.m_obj_name; + for(int i=0;i<NUM_FIRMWARE_RESOURCES;++i) { + this->m_firmware_resource[i] = res.m_firmware_resource[i]; + } +} + +// Destructor +DeviceFirmwareCompositeResource::~DeviceFirmwareCompositeResource() { +} + +// Build out our Firmware Resources +void DeviceFirmwareCompositeResource::buildResources() { + // LWM2M_DEV_FIRMWARE_PACKAGE_ID == 0 (TODO: Needs to be OPAQUE and full firmware blob...) + this->m_firmware_resource[0] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PACKAGE_ID,"fw_package",this->m_dm_responder,false); + + // LWM2M_DEV_FIRMWARE_PACKAGE_URI_ID == 1 + this->m_firmware_resource[1] = new DeviceFirmwareManifestResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PACKAGE_URI_ID,this->m_dm_responder,false); + + // LWM2M_DEV_FIRMWARE_UPDATE_ID == 2 + this->m_firmware_resource[2] = new DeviceFirmwareUpdateResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_UPDATE_ID,this->m_dm_responder,false); + + // LWM2M_DEV_FIRMWARE_STATE_ID == 3 + this->m_firmware_resource[3] = new DeviceIntegerResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_STATE_ID,"fw_state",this->m_dm_responder,false); + + // LWM2M_DEV_FIRMWARE_RESULT_ID == 5 + this->m_firmware_resource[5] = new DeviceIntegerResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_RESULT_ID,"fw_result",this->m_dm_responder,false); + + // LWM2M_DEV_FIRMWARE_PKG_NAME_ID = 6 + this->m_firmware_resource[6] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PKG_NAME_ID,"fw_pkg_name",this->m_dm_responder,false); + + // LWM2M_DEV_FIRMWARE_PKG_VERSION_ID = 7 + this->m_firmware_resource[7] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PKG_VERSION_ID,"fw_pkg_version",this->m_dm_responder,false); + + // Establish default values for State and Result + this->m_firmware_resource[3]->put("1"); // idle == 1 + this->m_firmware_resource[5]->put("0"); // default result + + // Tie State and Result resources for future updating by the dm_responder functions + DeviceManagementResponder *dmr = (DeviceManagementResponder *)this->m_dm_responder; + dmr->setStateResource(this->m_firmware_resource[3]); + dmr->setResultResource(this->m_firmware_resource[5]); +} + +// add resources +void DeviceFirmwareCompositeResource::addResources(void *cfg) { + // our Endpoint configuration + Connector::OptionsBuilder *configure_options = (Connector::OptionsBuilder *)cfg; + + // loop through the internal resources and add them... + for(int i=0;i<NUM_FIRMWARE_RESOURCES;++i) { + if (this->m_firmware_resource[i] != NULL) { + configure_options->addResource(this->m_firmware_resource[i]); + } + } +} + + + \ No newline at end of file