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);
}
Beispiel #2
0
things_resource_s *create_resource_inst_impl(void *requesthd, void *resourcehd, void *query, void *rep_payload)
{
	things_resource_s *res = (things_resource_s *) things_malloc(sizeof(things_resource_s));
	if (NULL == res) {
		THINGS_LOG_E(TAG, THINGS_MEMORY_ERROR);
		return NULL;
	}

	res->error = 0;				// OC_EH_OK;

	res->dev_addr = NULL;

	res->things_set_dev_addr = &set_dev_addr;
	res->things_get_dev_addr = &get_dev_addr;

	res->things_set_uri = &set_uri;
	res->things_set_error = &set_error;

	res->things_set_command_id = &set_command_id;

	res->things_add_child = &add_child;
	res->things_get_children = &get_children;

	res->things_get_uri = &get_uri;
	res->things_get_res_type = &get_res_type;
	res->things_get_num_of_res_types = &get_num_of_res_types;
	res->things_get_inf_type = &get_inf_type;
	res->things_get_num_of_inf_types = &get_num_of_inf_types;
	res->things_set_representation = &set_representation;
	res->things_get_representation = &get_representation;

	res->things_get_query = &get_query;
	res->things_get_rep_payload = &get_rep_payload;
	res->things_create_payload = &create_payload;
	res->things_is_supporting_interface_type = &is_supporting_interface_type;
	res->things_is_supporting_resource_type = &is_supporting_resource_type;

	res->next = NULL;
	res->things_get_next = &get_next;

	res->resource_handle = resourcehd;
	res->request_handle = requesthd;

	res->uri = NULL;
	const char *uri = OCGetResourceUri(resourcehd);
	if (uri != NULL && strlen(uri) > 0) {
		res->uri = (char *)things_malloc(sizeof(char) * strlen(uri) + 1);
		memset(res->uri, 0, strlen(uri) + 1);
		things_strncpy(res->uri, uri, strlen(uri));
	}

	res->res_type = NULL;
	res->interface_type = NULL;
	res->req_type = 0;
	res->cmd_id = NULL;
	res->rep = NULL;
	res->query = NULL;
	res->size = 1;

	if (NULL != query) {
		things_string_duplicate((char *)query, &(res->query));
	}

	if (NULL != rep_payload) {
		res->rep = things_create_representation_inst(rep_payload);
	}
	// else
	// {
	//     THINGS_LOG_D(TAG, "Representation not created!!");
	// }

	return res;
}
Beispiel #3
0
void set_command_id(things_resource_s *res, char *cmd_id)
{
	things_string_duplicate(cmd_id, &res->cmd_id);
}
Beispiel #4
0
bool get_query(struct things_resource_s *res, char *key, char **value)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);

	if (NULL == key) {
		return 0;
	} else if (NULL == res) {
		return 0;
	} else if (NULL == res->query) {
		return 0;
	} else if (strlen(res->query) < 1) {
		return 0;
	}

	THINGS_LOG_D(TAG, "Query is %s.", res->query);

	*value = NULL;

	char *p_buff = NULL, *p_origin = NULL;
	char *p_ptr = NULL;
	char *p_ptr2 = NULL;

	p_origin = p_buff = (char *)things_malloc(strlen(res->query) + 1);

	if (NULL == p_buff || NULL == p_origin) {
		return 0;
	}

	memset(p_buff, 0, strlen(res->query) + 1);
	THINGS_LOG_D(TAG, "p_buff is initialized by 0.");
	memcpy(p_buff, res->query, strlen(res->query) + 1);
	THINGS_LOG_D(TAG, "p_buff is Initialized as", res->query);

	p_ptr = strtok(p_buff, QUERY_DELIMITER);
	if (p_ptr != NULL) {
		p_ptr2 = p_ptr;
	} else {
		things_free(p_origin);
		return 0;
	}
	//while (p_ptr != NULL)
	while (p_ptr2 != NULL) {
		if (strncmp(p_ptr2, key, strlen(key)) == 0) {
			THINGS_LOG_D(TAG, "\tFind Query : %s", p_ptr2 + strlen(key) + 1);

			things_string_duplicate(p_ptr2 + strlen(key) + 1, value);
			if (NULL == *value) {
				things_free(p_origin);
				return 1;
			}
			THINGS_LOG_D(TAG, "\tRESULT : %s", *value);
			break;
		}

		p_ptr2 = strtok(NULL, QUERY_DELIMITER);
	}

	things_free(p_origin);

	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);

	return 1;
}