M2MResource* M2MDevice::create_resource(DeviceResource resource) { M2MResource* res = NULL; if(!is_resource_present(resource)) { String device_Id; if(FactoryReset == resource) { device_Id = DEVICE_FACTORY_RESET; } else if(ResetErrorCode == resource) { device_Id = DEVICE_RESET_ERROR_CODE; } if(_device_instance && !device_Id.empty()) { res = _device_instance->create_dynamic_resource(device_Id, OMA_RESOURCE_TYPE, M2MResourceInstance::OPAQUE, true); M2MResource *resource = _device_instance->resource(device_Id); if(resource) { resource->set_register_uri(false); } if(res) { res->set_operation(M2MBase::POST_ALLOWED); res->set_register_uri(false); } } } return res; }
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)) { 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, false); if(res ) { res->set_operation(operation); res->set_value((const uint8_t*)value.c_str(), (uint32_t)value.length()); } } } return res; }
M2MResource* M2MDevice::create_resource(DeviceResource resource, int64_t value) { M2MResource* res = NULL; String device_id = ""; M2MBase::Operation operation = M2MBase::GET_ALLOWED; if(!is_resource_present(resource)) { switch(resource) { case BatteryLevel: if(check_value_range(resource, value)) { device_id = DEVICE_BATTERY_LEVEL; } break; case BatteryStatus: if(check_value_range(resource, value)) { device_id = DEVICE_BATTERY_STATUS; } break; case MemoryFree: device_id = DEVICE_MEMORY_FREE; break; case MemoryTotal: device_id = DEVICE_MEMORY_TOTAL; break; case CurrentTime: device_id = DEVICE_CURRENT_TIME; 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::INTEGER, true); if(res) { char *buffer = (char*)malloc(BUFFER_SIZE); if(buffer) { uint32_t size = m2m::itoa_c(value, buffer); if (size <= BUFFER_SIZE) { res->set_operation(operation); res->set_value((const uint8_t*)buffer, size); } free(buffer); } res->set_register_uri(false); } } } return res; }
M2MResource* M2MDevice::create_resource(DeviceResource resource, int64_t value) { M2MResource* res = NULL; String device_id = ""; M2MBase::Operation operation = M2MBase::GET_ALLOWED; if(!is_resource_present(resource)) { switch(resource) { case BatteryLevel: if(0 <= value && value <= 100) { device_id = DEVICE_BATTERY_LEVEL; } break; case BatteryStatus: if(0 <= value && value <= 6) { device_id = DEVICE_BATTERY_STATUS; } break; case MemoryFree: device_id = DEVICE_MEMORY_FREE; break; case MemoryTotal: device_id = DEVICE_MEMORY_TOTAL; break; case CurrentTime: device_id = DEVICE_CURRENT_TIME; 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::INTEGER, false); if(res) { char *buffer = (char*)memory_alloc(20); if(buffer) { int size = snprintf(buffer, 20,"%ld",value); res->set_operation(operation); res->set_value((const uint8_t*)buffer, (const uint32_t)size); memory_free(buffer); } } } } return res; }
M2MResource* M2MServer::create_resource(ServerResource resource) { M2MResource* res = NULL; if(!is_resource_present(resource)) { if(M2MServer::Disable == resource) { if(_server_instance) { res = _server_instance->create_dynamic_resource(SERVER_DISABLE, OMA_RESOURCE_TYPE, M2MResourceInstance::OPAQUE, false); if(res) { res->set_operation(M2MBase::POST_ALLOWED); } } } } return res; }
M2MResource* M2MSecurity::create_resource(SecurityResource resource, uint32_t value) { M2MResource* res = NULL; String security_id = ""; if(!is_resource_present(resource)) { switch(resource) { case SMSSecurityMode: security_id = SECURITY_SMS_SECURITY_MODE; break; case M2MServerSMSNumber: security_id = SECURITY_M2M_SERVER_SMS_NUMBER; break; case ShortServerID: security_id = SECURITY_SHORT_SERVER_ID; break; case ClientHoldOffTime: security_id = SECURITY_CLIENT_HOLD_OFF_TIME; break; default: break; } } if(!security_id.empty()) { if(_server_instance) { res = _server_instance->create_dynamic_resource(security_id,OMA_RESOURCE_TYPE, M2MResourceInstance::INTEGER, false); if(res) { res->set_operation(M2MBase::NOT_ALLOWED); char *buffer = (char*)malloc(BUFFER_SIZE); if(buffer) { uint32_t size = m2m::itoa_c(value, buffer); if (size <= BUFFER_SIZE) { res->set_value((const uint8_t*)buffer, size); } free(buffer); } } } } return res; }
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; }
M2MResource* M2MServer::create_resource(ServerResource resource, uint32_t value) { M2MResource* res = NULL; String server_id = ""; if(!is_resource_present(resource)) { switch(resource) { case DefaultMinPeriod: server_id = SERVER_DEFAULT_MIN_PERIOD; break; case DefaultMaxPeriod: server_id = SERVER_DEFAULT_MAX_PERIOD; break; case DisableTimeout: server_id = SERVER_DISABLE_TIMEOUT; break; default: break; } } if(!server_id.empty()) { if(_server_instance) { res = _server_instance->create_dynamic_resource(server_id, OMA_RESOURCE_TYPE, M2MResourceInstance::INTEGER, true); if(res) { res->set_operation(M2MBase::GET_PUT_POST_ALLOWED); // If resource is created then set the value. char *buffer = (char*)malloc(20); if(buffer) { int size = snprintf(buffer, 20,"%ld",(long int)value); res->set_value((const uint8_t*)buffer,(const uint32_t)size); free(buffer); } } } } return res; }
M2MResource* M2MFirmware::create_resource(FirmwareResource resource, int64_t value) { M2MResource* res = NULL; const char* firmware_id_ptr = ""; M2MBase::Operation operation = M2MBase::GET_ALLOWED; if(!is_resource_present(resource)) { switch(resource) { case UpdateSupportedObjects: if(check_value_range(resource, value)) { firmware_id_ptr = FIRMWARE_UPDATE_SUPPORTED_OBJECTS; operation = M2MBase::GET_PUT_ALLOWED; } break; default: break; } } const String firmware_id(firmware_id_ptr); if(!firmware_id.empty()) { if(_firmware_instance) { res = _firmware_instance->create_dynamic_resource(firmware_id, OMA_RESOURCE_TYPE, M2MResourceInstance::INTEGER, false); if(res) { res->set_register_uri(false); res->set_operation(operation); res->set_value(value); } } } return res; }