Пример #1
0
void set_device_info(things_server_builder_s *builder, char *device_name, char *device_type)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);

	THINGS_LOG_D(TAG, "[/oic/d] name :%s", device_name);
	THINGS_LOG_D(TAG, "[/oic/d] type :%s", device_type);

	OCDeviceInfo device_info;
	device_info.deviceName = NULL;
	device_info.types = NULL;
	device_info.specVersion = NULL;
	device_info.dataModelVersions = NULL;

	things_string_duplicate(device_name, &device_info.deviceName);
	things_string_duplicate(OC_SPEC_VERSION, &device_info.specVersion);
	device_info.dataModelVersions = OCCreateOCStringLL(DEFAULT_DATA_MODEL_VERSIONS);
	device_info.types = OCCreateOCStringLL(device_type);
	OCResourcePayloadAddStringLL(&device_info.types, OC_RSRVD_RESOURCE_TYPE_DEVICE);

	iotivity_api_lock();

	OCSetDeviceInfo(device_info);

	iotivity_api_unlock();

	// OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, KEY_ATTR_DEVICE_NAME, device_name);

	things_free(device_info.deviceName);
	things_free(device_info.specVersion);
	OCFreeOCStringLL(device_info.dataModelVersions);
	OCFreeOCStringLL(device_info.types);

	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
}
OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModelVersions)
{
    if(!DuplicateString(&deviceInfo.deviceName, deviceName))
    {
        return OC_STACK_ERROR;
    }
    if(!DuplicateString(&deviceInfo.specVersion, specVersion))
    {
        return OC_STACK_ERROR;
    }
    OCFreeOCStringLL(deviceInfo.dataModelVersions);
    deviceInfo.dataModelVersions = OCCreateOCStringLL(dataModelVersions);
    if (!deviceInfo.dataModelVersions)
    {
        return OC_STACK_ERROR;
    }
    return OC_STACK_OK;
}