bool M2MFirmware::set_resource_value(FirmwareResource resource,
                                   const String &value)
{
    bool success = false;
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MFirmware::PackageUri == resource  ||
           M2MFirmware::PackageName == resource ||
           M2MFirmware::PackageVersion == resource) {
            if (value.size() < 256) {
                if(value.empty()) {
                    res->clear_value();
                    success = true;
                } else {
                    success = res->set_value((const uint8_t*)value.c_str(),(uint32_t)value.length());
                }
            }
        }
    }
    return success;
}
M2MResource* M2MFirmware::create_resource(FirmwareResource resource, const String &value)
{
    M2MResource* res = NULL;
    const char* firmware_id_ptr = "";
    M2MBase::Operation operation = M2MBase::GET_ALLOWED;
    if(!is_resource_present(resource)) {
        switch(resource) {
            case PackageName:
                firmware_id_ptr = FIRMWARE_PACKAGE_NAME;
                break;
            case PackageVersion:
                firmware_id_ptr = FIRMWARE_PACKAGE_VERSION;
                break;
            default:
                break;
        }
    }
    String firmware_id(firmware_id_ptr);

    if(!firmware_id.empty() && value.size() < 256) {
        if(_firmware_instance) {
            res = _firmware_instance->create_dynamic_resource(firmware_id,
                                                            OMA_RESOURCE_TYPE,
                                                            M2MResourceInstance::STRING,
                                                            false);

            if(res) {
                res->set_register_uri(false);
                res->set_operation(operation);
                if(value.empty()) {
                    res->clear_value();
                } else {
                    res->set_value((const uint8_t*)value.c_str(),
                                   (uint32_t)value.length());
                }
            }
        }
    }
    return res;
}
Exemple #3
0
M2MResource* M2MDevice::create_resource(DeviceResource resource, const String &value)
{
    M2MResource* res = NULL;
    String device_id = "";
    M2MBase::Operation operation = M2MBase::GET_ALLOWED;
    if(!is_resource_present(resource) && value.size() <= MAX_ALLOWED_STRING_LENGTH) {
        switch(resource) {
            case Manufacturer:
               device_id = DEVICE_MANUFACTURER;
               break;
            case DeviceType:
                device_id = DEVICE_DEVICE_TYPE;
                break;
            case ModelNumber:
                device_id = DEVICE_MODEL_NUMBER;
                break;
            case SerialNumber:
                device_id = DEVICE_SERIAL_NUMBER;
                break;
            case HardwareVersion:
                device_id = DEVICE_HARDWARE_VERSION;
                break;
            case FirmwareVersion:
                device_id = DEVICE_FIRMWARE_VERSION;
                break;
            case SoftwareVersion:
                device_id = DEVICE_SOFTWARE_VERSION;
                break;
            case UTCOffset:
                device_id = DEVICE_UTC_OFFSET;
                operation = M2MBase::GET_PUT_ALLOWED;
                break;
            case Timezone:
                device_id = DEVICE_TIMEZONE;
                operation = M2MBase::GET_PUT_ALLOWED;
                break;
            default:
                break;
        }
    }
    if(!device_id.empty()) {
        if(_device_instance) {
            res = _device_instance->create_dynamic_resource(device_id,
                                                            OMA_RESOURCE_TYPE,
                                                            M2MResourceInstance::STRING,
                                                            true);

            if(res ) {
                res->set_operation(operation);
                if (value.empty()) {
                    res->clear_value();
                } else {
                    res->set_value((const uint8_t*)value.c_str(),
                                   (uint32_t)value.length());
                }
                res->set_register_uri(false);
            }
        }
    }
    return res;
}