コード例 #1
0
ファイル: things_req_handler.c プロジェクト: tool3210/TizenRT
static OCEntityHandlerResult process_get_request(things_resource_s *target_resource)
{

	OCEntityHandlerResult eh_result = OC_EH_ERROR;

	char *device_id = NULL;

	device_id = strrchr(target_resource->uri, '/') + 1;
	THINGS_LOG_D(TAG, "Get Device ID in Resources URI = %s", device_id);

	things_representation_s *rep = things_create_representation_inst(NULL);
	target_resource->things_set_representation(target_resource, rep);

	if (strstr(target_resource->uri, URI_SEC) != NULL && strstr(target_resource->uri, URI_PROVINFO) != NULL) {
		// 1. Get request for the Access point list
		eh_result = get_provisioning_info(target_resource);
#ifdef CONFIG_ST_THINGS_FOTA
	} else if (strstr(target_resource->uri, URI_FIRMWARE) != NULL) {
		eh_result = fmwup_get_data(target_resource);
#endif
	} else {
		if (g_handle_request_get_cb != NULL) {
			int ret = g_handle_request_get_cb(target_resource);
			if (1 == ret) {
				eh_result = OC_EH_OK;
			} else {
				THINGS_LOG_E(TAG, "Handled as ERROR from App.");
			}
		} else {
			THINGS_LOG_E(TAG, "g_handle_request_get_cb is not registered");
		}
	}

	return eh_result;
}
コード例 #2
0
ファイル: things_req_handler.c プロジェクト: tool3210/TizenRT
static OCEntityHandlerResult process_post_request(things_resource_s **target_res)
{
	OCEntityHandlerResult eh_result = OC_EH_ERROR;

	things_resource_s *target_resource = *target_res;

	if (strstr(target_resource->uri, URI_SEC) != NULL && strstr(target_resource->uri, URI_PROVINFO) != NULL) {
		// 1. Post request for the Easy-Setup reset
		eh_result = set_provisioning_info(target_resource);
#ifdef CONFIG_ST_THINGS_FOTA
	} else if (strstr(target_resource->uri, URI_FIRMWARE) != NULL) {
		eh_result = fmwup_set_data(target_resource);
#endif
	} else {
		if (g_handle_request_set_cb != NULL) {
			int ret = g_handle_request_set_cb(target_resource);
			if (1 == ret) {
				eh_result = OC_EH_OK;
			} else {
				THINGS_LOG_E(TAG, "Handled as ERROR from App.");
			}
		} else {
			THINGS_LOG_E(TAG, "g_handle_request_set_cb is not registered");
		}
	}

	return eh_result;
}
コード例 #3
0
ファイル: st_things.c プロジェクト: tool3210/TizenRT
int st_things_reset(void)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);

	if (STACK_STARTED != g_stack_status) {
		int ret_val = ST_THINGS_ERROR_OPERATION_FAILED;
		switch (g_stack_status) {
		case STACK_NOT_INITIALIZED:
			THINGS_LOG_E(TAG, "Stack is not initialized. Before reset, stack should be initialized and started.");
			ret_val = ST_THINGS_ERROR_STACK_NOT_INITIALIZED;
			break;
		case STACK_INITIALIZED:
			THINGS_LOG_E(TAG, "Stack is initialized but not started.");
			ret_val = ST_THINGS_ERROR_STACK_NOT_STARTED;
			break;
		default:
			THINGS_LOG_E(TAG, "Invalid stack state: %d.", g_stack_status);
			break;
		}

		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ret_val;
	}

	int result = 0;
	if (1 != (result = things_reset(NULL, RST_AUTO_RESET))) {
		THINGS_LOG_E(TAG, "things_reset failed (result:%d)", result);
		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ST_THINGS_ERROR_OPERATION_FAILED;
	}

	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
	return ST_THINGS_ERROR_NONE;
}
コード例 #4
0
struct things_resource_s *create_resource(struct things_server_builder_s *builder, char *uri, char *type, char *interface, int isDiscoverable, int isObserable, int isSecure)
{
	things_resource_s *res = NULL;
	OCResourceHandle hd = NULL;
	uint8_t rsc_properties = OC_DISCOVERABLE;

	if (builder->handler == NULL) {
		THINGS_LOG_E(TAG, "Handler for serverbuilder is not registered");
		return res;
	}

	if (1 != isDiscoverable) {
		rsc_properties = OC_ACTIVE;
	}

	if (1 == isObserable) {
		rsc_properties |= OC_OBSERVABLE;
	}

	if (1 == isSecure) {
#ifdef __SECURED__
		rsc_properties |= OC_SECURE;
#else
		THINGS_LOG_D(TAG, "Stack is in UNSECURED Mode");
#endif
	}

	iotivity_api_lock();
	OCStackResult ret = OCCreateResource(&hd,
										 type,
										 interface,
										 uri,
										 builder->handler,
										 NULL,
										 rsc_properties);
	iotivity_api_unlock();
	if (ret != OC_STACK_OK) {
		THINGS_LOG_V(TAG, "Resource Creation Failed - ret = %d, %s", ret, uri);
		return NULL;
	}

	res = things_create_resource_inst(NULL, hd, NULL, NULL);

	if (NULL == res) {
		THINGS_LOG_E(TAG, "things_create_resource_inst is failed");
		return res;
	}

	res->res_type = things_strdup(type);

	builder->gres_arr[builder->res_num++] = res;

	THINGS_LOG_D(TAG, "Created hd [%x], prop [0x%X] uri : %s", res->resource_handle, rsc_properties, res->uri);
	THINGS_LOG_D(TAG, "DISCOVERABLE : %s", (isDiscoverable == 1 ? "YES" : "NO"));
	THINGS_LOG_D(TAG, "OBSERABLE : %s", (isObserable == 1 ? "YES" : "NO"));
	THINGS_LOG_D(TAG, "SECURE : %s", (isSecure == 1 ? "YES" : "NO"));

	return res;
}
コード例 #5
0
static int handle_post_req_on_single_rsrc(things_resource_s *single_rsrc)
{
	RET_VAL_IF_PARAM_IS_NULL(TAG, single_rsrc, 0);

	// Retrieve the request representation. This representation will hold all the input properties of post request.
	// Payload in this representation will be used to form the request message which will be given to the application.
	struct things_representation_s *req_rep = NULL;
	bool rep_exist = single_rsrc->things_get_representation(single_rsrc, &req_rep);
	if (!rep_exist || NULL == req_rep || NULL == req_rep->payload) {
		THINGS_LOG_E(TAG, "Empty payload in POST request.");
		return 0;				// TODO: When a post request comes with empty payload, how do we handle?
	}
	// Setup the response representation. This representation will be handed over to the underlying stack.
	// The payload which is passed as a parameter will be updated with the common properties.
	things_representation_s *resp_rep = things_create_representation_inst(NULL);
	RET_VAL_IF_NULL(TAG, resp_rep, "Failed to create response representation.", 0);

	if (!OCRepPayloadSetUri(resp_rep->payload, single_rsrc->uri)) {
		THINGS_LOG_E(TAG, "Failed to set the resource uri(%s) in response payload.", single_rsrc->uri);
		things_release_representation_inst(resp_rep);
		return 0;
	}

	THINGS_LOG_D(TAG, "Resource uri(%s) is set in the response payload.", single_rsrc->uri);

	// Get interface type from query parameter
	char *if_type = NULL;
	if (NULL != single_rsrc->query && strlen(single_rsrc->query) > 0) {
		bool found = false;
		bool result = get_query_value_internal(single_rsrc->query, OC_RSRVD_INTERFACE, &if_type, &found);
		if (found && !result) {	// If query is present but API returns false.
			THINGS_LOG_E(TAG, "Failed to get the interface type from query parameter(%s).", single_rsrc->query);
			things_release_representation_inst(resp_rep);
			return 0;
		}
	}
	// Set the common properties in the payload (Only for baseline interface).
	// The payload which is passed as a parameter will be updated with the common properties.
	if (NULL == if_type || !strncmp(if_type, OC_RSRVD_INTERFACE_DEFAULT, strlen(OC_RSRVD_INTERFACE_DEFAULT))) {
		if (!add_common_props(single_rsrc, false, resp_rep->payload)) {
			THINGS_LOG_E(TAG, "Failed to add the common properties in response payload.");
			things_release_representation_inst(resp_rep);
			things_free(if_type);
			return 0;
		}
		THINGS_LOG_D(TAG, "Added common properties in response payload.");
	}
	// Give the request properties to application and get the response back.
	bool res = handle_post_req_helper(single_rsrc->uri, single_rsrc->query, req_rep->payload, resp_rep->payload);
	if (res) {
		// Set the response representation in the resource.
		single_rsrc->things_set_representation(single_rsrc, resp_rep);
	} else {
		things_release_representation_inst(resp_rep);
	}
	things_free(if_type);
	return res ? 1 : 0;
}
コード例 #6
0
ファイル: fmwup_util_http.c プロジェクト: drashti304/TizenRT
int wget_from_url(char *download_url) 
{
	THINGS_LOG_V(TAG, "download url : %s\n", download_url);

	struct http_client_request_t request;
	struct http_keyvalue_list_t headers;
	struct http_client_response_t response;
	struct http_client_ssl_config_t *ssl_config = NULL;

	int ret;
	ret = -1;

	if (webclient_init_request(download_url, &request) != 0) {
		THINGS_LOG_E(TAG, "webclient_init_request error");
		return NULL;
	}

	ssl_config = g_https ? &g_config : NULL;

	/* before sending request,
	 * must initialize keyvalue list for request headers
	 */
	http_keyvalue_list_init(&headers);
	http_keyvalue_list_add(&headers, headerfield_connect, headerfield_close);
	http_keyvalue_list_add(&headers, headerfield_useragent, headerfield_tinyara);
	request.headers = &headers;

	/* before sending request by sync function,
	 * must initialize response structure
	 */
	if (http_client_send_request_async(&request, ssl_config, (wget_callback_t)callback)) {
		THINGS_LOG_E(TAG, "fail to send request");
		goto release_out;
	}
	/* sleep for end request */
	while (request.async_flag > 0) {
		usleep(100000);
	}

	if (request.async_flag < 0) {
		THINGS_LOG_E(TAG, "fail to send request");
		goto release_out;
	}

	ret = 1;

release_out:
	/* before finish of app,
	 * must release keyvalue list for request headers
	 */
	http_keyvalue_list_release(&headers);
	THINGS_LOG_D(TAG, "end request");

	return ret;
}
コード例 #7
0
static int handle_get_req_on_single_rsrc(things_resource_s *single_rsrc)
{
	RET_VAL_IF_PARAM_IS_NULL(TAG, single_rsrc, 0);

	// Setup the response representation. This representation will be handed over to the underlying stack.
	things_representation_s *resp_rep = things_create_representation_inst(NULL);
	RET_VAL_IF_NULL(TAG, resp_rep, "Failed to create response representation.", 0);

	bool result = OCRepPayloadSetUri(resp_rep->payload, single_rsrc->uri);
	if (!result) {
		THINGS_LOG_E(TAG, "Failed to set the resource uri(%s) in response payload.", single_rsrc->uri);
		things_release_representation_inst(resp_rep);
		return 0;
	}

	THINGS_LOG_D(TAG, "Resource uri(%s) is set in the response payload.", single_rsrc->uri);

	// Set the common properties in the payload (Only for baseline interface).
	char *if_type = NULL;
	if (NULL != single_rsrc->query && strlen(single_rsrc->query) > 0) {
		bool found = false;
		bool result = get_query_value_internal(single_rsrc->query, OC_RSRVD_INTERFACE, &if_type, &found);
		if (found && !result) {	// If query is present but API returns false.
			THINGS_LOG_E(TAG, "Failed to get the interface type from query parameter(%s).", single_rsrc->query);
			things_release_representation_inst(resp_rep);
			return 0;
		}
	}

	if (NULL == if_type || strlen(if_type) < 1 || !strncmp(if_type, OC_RSRVD_INTERFACE_DEFAULT, strlen(OC_RSRVD_INTERFACE_DEFAULT))) {
		if (!add_common_props(single_rsrc, false, resp_rep->payload)) {
			THINGS_LOG_E(TAG, "Failed to add the common properties in response payload.");
			things_release_representation_inst(resp_rep);
			things_free(if_type);
			return 0;
		}
		THINGS_LOG_D(TAG, "Added common properties in response payload.");
	}
	// Get the resource's properties from the application.
	result = handle_get_req_helper(single_rsrc->uri, single_rsrc->query, resp_rep->payload);
	if (!result) {
		things_release_representation_inst(resp_rep);
		things_free(if_type);
		return 0;
	}
	// Set the response representation in the resource.
	single_rsrc->things_set_representation(single_rsrc, resp_rep);

	things_free(if_type);
	return 1;
}
コード例 #8
0
struct things_resource_s *create_collection_resource(struct things_server_builder_s *builder, char *uri, char *type)
{
	things_resource_s *res = NULL;
	OCResourceHandle hd = NULL;
	uint8_t rsc_properties = OC_DISCOVERABLE | OC_OBSERVABLE;

	if (builder->handler == NULL) {
		THINGS_LOG_E(TAG, "Handler for serverbuilder is not registered");
		return res;
	}
#ifdef __SECURED__

	rsc_properties |= OC_SECURE;

#endif							//#ifdef __SECURED__
	iotivity_api_lock();
	OCStackResult ret = OCCreateResource(&hd,
										 type,
										 OIC_INTERFACE_LINKEDLIST,
										 uri,
										 builder->handler,
										 NULL,
										 rsc_properties);
	if (ret != OC_STACK_OK) {
		THINGS_LOG_V(TAG, "Resource Creation Failed - ret = %d, %s", ret, uri);
		iotivity_api_unlock();
		return NULL;
	}

	OCBindResourceTypeToResource(hd, OIC_RTYPE_COLLECTION_WK);
	OCBindResourceInterfaceToResource(hd, OIC_INTERFACE_BATCH);
	iotivity_api_unlock();

	res = things_create_resource_inst(NULL, hd, NULL, NULL);

	if (NULL == res) {
		THINGS_LOG_E(TAG, "things_create_resource_inst is failed");
		return res;
	}

	res->res_type = things_strdup(type);

	builder->gres_arr[builder->res_num++] = res;

	THINGS_LOG_V(TAG, "Created hd [%x], prop [0x%X] uri : %s", res->resource_handle, rsc_properties, uri);

	return res;
}
コード例 #9
0
things_server_builder_s *get_builder_instance()
{
	if (g_builder == NULL) {
		g_builder = (things_server_builder_s *) things_malloc(sizeof(things_server_builder_s));
		if (g_builder != NULL) {
			g_builder->init_module = &init_builder;
			g_builder->deinit_module = &deinit_builder;
			g_builder->set_device_info = &set_device_info;
			g_builder->set_platform_info = &set_platform_info;
			g_builder->create_resource = &create_resource;
			// g_builder->CreateActiveResource = &CreateActiveResource;
#ifdef CONFIG_ST_THINGS_COLLECTION
			g_builder->create_collection_resource = &create_collection_resource;
#endif
			g_builder->get_resource = &get_resource;
			g_builder->delete_resource = &delete_resource;
			g_builder->add_interface_type = &add_interface_type;
			g_builder->add_resource_type = &add_resource_type;
			g_builder->bind = &things_bind;
			g_builder->bind_all = &bind_all;
			g_builder->res_num = 0;
			g_builder->handler = NULL;

			return g_builder;
		} else {
			THINGS_LOG_E(TAG, "Not enough Memory for Builder Instance");
			return NULL;
		}
	} else {
		THINGS_LOG_D(TAG, "Builder Instance Already Created");
		return g_builder;
	}
}
コード例 #10
0
ファイル: things_resource.c プロジェクト: tool3210/TizenRT
bool things_get_string_arrayvalue(struct things_representation_s *mother, char *key, int *length, char ***array)
{
	THINGS_LOG_D(TAG, "There're (%d) Number of children resources in the Payload : %d", mother->num_children);

	bool find_value = false;

	OCRepPayloadValue *payload_value = NULL;

	payload_value = things_rep_payload_find_values((OCRepPayload *)(mother->payload), key);

	if (payload_value != NULL) {
		size_t dimension_size = calcDimTotal(payload_value->arr.dimensions);
		size_t dimensions[3] = { dimension_size, 0, 0 };

		find_value = OCRepPayloadGetStringArray((OCRepPayload *)(mother->payload), key, array, dimensions);
		THINGS_LOG_D(TAG, "Find Value : %d", find_value);
		if (find_value) {

			*length = dimension_size;
		}
	} else {
		THINGS_LOG_E(TAG, "DATA NOT EXIST~!!!!");
	}

	return find_value;
}
コード例 #11
0
ファイル: st_things.c プロジェクト: tool3210/TizenRT
/**
 * This callback will be registered with the DA Stack to get the request for user's confirmation for reset.
 * Application's callback will be invoked to get the user's opinion.
 */
int get_reset_confirm_cb(things_reset_result_func_type *func_carrier, things_es_enrollee_reset_e reset_type)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);
	if (NULL == g_handle_reset_confirm_cb) {
		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return 0;
	}

	if (RST_NEED_CONFIRM == reset_type) {
		// Invoke application's callback to get user's confirmation and pass the result to DA Stack.
		bool confirm = g_handle_reset_confirm_cb();
		THINGS_LOG_D(TAG, "User's confirmation for reset : %s", confirm ? "true" : "false");
		if (confirm) {
			things_return_user_opinion_for_reset(1);
		} else {
			things_return_user_opinion_for_reset(0);
		}
	} else if (RST_AUTO_RESET == reset_type) {
		THINGS_LOG_D(TAG, "Reset will start automatically");
		things_return_user_opinion_for_reset(1);
	} else {
		THINGS_LOG_E(TAG, "reset_type(%d) is invalid", reset_type);
		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return 0;
	}

	// Set the callback through this function's value-result paramter with DA Stack to get the result of reset.
	*func_carrier = get_reset_result_cb;

	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
	return 1;
}
コード例 #12
0
ファイル: things_resource.c プロジェクト: tool3210/TizenRT
void /*OCRepPayload */ *get_rep_payload(struct things_resource_s *res)
{
	if (res->rep != NULL) {
		// Create Payload for the mother resource
		// It applies not only single resource but also the collection resource..
		things_resource_s *p_temp;
		OCRepPayload *rep_payload;

		if (NULL != res->things_get_children(res) && (NULL != strstr(res->uri, URI_DEVICE_COL)) && (strstr(res->query, OIC_INTERFACE_BATCH) != NULL)) {
			p_temp = res->next;
			rep_payload = p_temp->things_create_payload(p_temp, p_temp->query);
			p_temp = p_temp->next;
		}

		else {
			rep_payload = res->things_create_payload(res, res->query);
			// Create payload for the children resource(s)
			p_temp = res->things_get_children(res);
		}

		while (NULL != p_temp) {
			if (NULL != p_temp->rep) {
				OCRepPayloadAppend(rep_payload, p_temp->things_create_payload(p_temp, p_temp->query));
			}
			p_temp = p_temp->next;
		}

		return rep_payload;
	} else {
		THINGS_LOG_E(TAG, "ROOT(Parent) Paylaod is NULL.");
		return NULL;
	}
}
コード例 #13
0
ファイル: things_req_handler.c プロジェクト: tool3210/TizenRT
void notify_result_of_reset(things_resource_s *target_resource, bool result)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);

	OCEntityHandlerResult eh_result = OC_EH_ERROR;

	if (target_resource == NULL) {
		THINGS_LOG_D(TAG, "Not exist remote-client.");
		return;
	}

	if (result == true) {		// reset Success.
		OCRepPayload *rep_payload = target_resource->things_get_rep_payload(target_resource);

		eh_result = send_response(target_resource->request_handle,	// reqInfo->reqHandle,
								  target_resource->resource_handle,	// reqInfo->resHandle,
								  target_resource->error, target_resource->uri, rep_payload);

		OCPayloadDestroy((OCPayload *) rep_payload);
		rep_payload = NULL;

	} else {
		THINGS_LOG_E(TAG, "Handing Request Failed, Sending ERROR Response");

		send_response(target_resource->request_handle, target_resource->resource_handle, eh_result, target_resource->uri, NULL);
	}

	things_release_resource_inst(target_resource);

	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
}
コード例 #14
0
ファイル: things_req_handler.c プロジェクト: tool3210/TizenRT
OCEntityHandlerResult handle_message(things_resource_s *target_resource)
{
	OCEntityHandlerResult eh_result = OC_EH_ERROR;

	if (NULL == target_resource) {
		THINGS_LOG_D(TAG, "Request Item is NULL.");
		return OC_EH_ERROR;
	}

	THINGS_LOG_D(TAG, "Request Handle : %x, Resource Handle : %x", target_resource->request_handle, target_resource->resource_handle);

	if (target_resource->req_type == OC_REST_GET) {
		THINGS_LOG_V(TAG, "\t\tReq. : GET on %s", target_resource->uri);
		THINGS_LOG_V(TAG, "\t\tQuery: %s", target_resource->query);
		eh_result = process_get_request(target_resource);
	} else if (target_resource->req_type == OC_REST_POST) {
		THINGS_LOG_V(TAG, "\t\tReq. : POST on  %s", target_resource->uri);
		THINGS_LOG_V(TAG, "\t\tQuery: %s", target_resource->query);
		eh_result = process_post_request(&target_resource);
	} else {
		THINGS_LOG_E(TAG, " Invalid Request Received : %d", target_resource->req_type);
	}
	THINGS_LOG_D(TAG, " @@@@@ target_resource ->size : %d", target_resource->size);

	if (is_can_not_response_case(target_resource, target_resource->req_type, eh_result) == false) {
		if (eh_result != OC_EH_OK && eh_result != OC_EH_SLOW) {
			THINGS_LOG_E(TAG, "Handing Request Failed, Sending ERROR Response");

			send_response(target_resource->request_handle, target_resource->resource_handle, eh_result, target_resource->uri, NULL);

			eh_result = OC_EH_OK;
		} else {
			OCRepPayload *rep_payload = target_resource->things_get_rep_payload(target_resource);

			eh_result = send_response(target_resource->request_handle,	// reqInfo->reqHandle,
									  target_resource->resource_handle,	// reqInfo->resHandle,
									  target_resource->error, target_resource->uri, rep_payload);

			OCPayloadDestroy((OCPayload *) rep_payload);
			rep_payload = NULL;
		}
	}
	//  Need to design How to release memory allocated for the things_resource_s list.
	things_release_resource_inst(target_resource);

	return eh_result;
}
コード例 #15
0
int register_request_handler_cb(st_things_get_request_cb get_cb, st_things_set_request_cb set_cb)
{
	if (NULL == get_cb) {
		THINGS_LOG_E(TAG, "Request callback for GET is NULL.");
		return ST_THINGS_ERROR_INVALID_PARAMETER;
	}

	if (NULL == set_cb) {
		THINGS_LOG_E(TAG, "Request callback for SET is NULL.");
		return ST_THINGS_ERROR_INVALID_PARAMETER;
	}

	g_handle_get_req_cb = get_cb;
	g_handle_set_req_cb = set_cb;

	return ST_THINGS_ERROR_NONE;
}
コード例 #16
0
void register_req_handler(struct things_server_builder_s *builder, request_handler_cb handler)
{
	if (handler == NULL || builder == NULL) {
		THINGS_LOG_E(TAG, "Invalid Param");
		return;
	}
	builder->handler = handler;
}
コード例 #17
0
ファイル: st_things.c プロジェクト: tool3210/TizenRT
int st_things_initialize(const char *json_path, bool *easysetup_complete)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);

	if (STACK_NOT_INITIALIZED != g_stack_status) {
		int ret_val = ST_THINGS_ERROR_OPERATION_FAILED;
		switch (g_stack_status) {
		case STACK_INITIALIZED:
			THINGS_LOG_E(TAG, "Stack initialized already.");
			ret_val = ST_THINGS_ERROR_STACK_ALREADY_INITIALIZED;
			break;
		case STACK_STARTED:
			THINGS_LOG_E(TAG, "Stack is currently running.");
			ret_val = ST_THINGS_ERROR_STACK_RUNNING;
			break;
		default:
			THINGS_LOG_E(TAG, "Invalid stack state: %d.", g_stack_status);
			break;
		}

		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ret_val;
	}

	if (NULL == json_path) {
		THINGS_LOG_E(TAG, "Json file path is NULL");
		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ST_THINGS_ERROR_INVALID_PARAMETER;
	}

	THINGS_LOG_D(TAG, "JSON file path: %s", json_path);

	int result = 0;
	if (1 != (result = things_initialize_stack(json_path, easysetup_complete))) {
		THINGS_LOG_E(TAG, "things_initialize_stack failed (result:%d)", result);
		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ST_THINGS_ERROR_OPERATION_FAILED;
	}

	g_stack_status = STACK_INITIALIZED;

	THINGS_LOG_D(TAG, "Is EasySetup completed : %s", (*easysetup_complete) ? "true" : "false");
	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
	return ST_THINGS_ERROR_NONE;
}
コード例 #18
0
ファイル: things_resource.c プロジェクト: tool3210/TizenRT
void things_set_int_arrayvalue(struct things_representation_s *mother, char *key, int length, int64_t *array)
{
	if (length < 1) {
		THINGS_LOG_E(TAG, "DATA LENGTH IS ZERO!!!!!!");
		return;
	}
	size_t dimensions[MAX_REP_ARRAY_DEPTH] = { length, 0, 0 };

	OCRepPayloadSetIntArray(mother->payload, key, array, dimensions);
}
コード例 #19
0
ファイル: things_resource.c プロジェクト: tool3210/TizenRT
void things_set_byte_value(struct things_representation_s *rep, char *key, uint8_t *value, size_t size)
{
	OCByteString b_val = { value, size };

	if (b_val.len < 1) {
		THINGS_LOG_E(TAG, "No byte value to Set");
	} else {
		OCRepPayloadSetPropByteString(rep->payload, key, b_val);
	}
}
コード例 #20
0
ファイル: things_resource.c プロジェクト: tool3210/TizenRT
void things_set_string_arrayvalue(struct things_representation_s *mother, char *key, int length, char **array)
{
	if (length < 1) {
		THINGS_LOG_E(TAG, "DATA LENGTH IS ZERO!!!!!!");
		return;
	}
	size_t dimensions[MAX_REP_ARRAY_DEPTH] = { length, 0, 0 };

	//    This is codesnippet for creating Array type of value inside the payload..
	OCRepPayloadSetStringArray(mother->payload, key, (const char **)array, dimensions);
}
コード例 #21
0
void delete_resource(struct things_server_builder_s *builder)
{
	iotivity_api_lock();
	for (size_t iter = 0; iter < builder->res_num; iter++) {
		OCStackResult ret = OCDeleteResource((OCResourceHandle)(builder->gres_arr[iter]->resource_handle));
		if (ret != OC_STACK_OK) {
			THINGS_LOG_E(TAG, "Failed to delete the resource");
		}
	}
	iotivity_api_unlock();
}
コード例 #22
0
ファイル: st_things.c プロジェクト: tool3210/TizenRT
int st_things_notify_observers(const char *resource_uri)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);

	if (STACK_STARTED != g_stack_status) {
		int ret_val = ST_THINGS_ERROR_OPERATION_FAILED;
		switch (g_stack_status) {
		case STACK_NOT_INITIALIZED:
			THINGS_LOG_E(TAG, "Stack is not initialized. Before notifying observers, stack should be initialized and started.");
			ret_val = ST_THINGS_ERROR_STACK_NOT_INITIALIZED;
			break;
		case STACK_INITIALIZED:
			THINGS_LOG_E(TAG, "Stack is initialized but not started.");
			ret_val = ST_THINGS_ERROR_STACK_NOT_STARTED;
			break;
		default:
			THINGS_LOG_E(TAG, "Invalid stack state: %d.", g_stack_status);
			break;
		}

		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ret_val;
	}

	if (NULL == resource_uri || 1 > strlen(resource_uri)) {
		THINGS_LOG_E(TAG, "The resource URI is invalid");
		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ST_THINGS_ERROR_INVALID_PARAMETER;
	}

	int result = 0;
	if (1 != (result = things_notify_observers(resource_uri))) {
		THINGS_LOG_E(TAG, "things_notify_observers failed (result:%d)", result);
		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ST_THINGS_ERROR_OPERATION_FAILED;
	}

	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
	return ST_THINGS_ERROR_NONE;
}
コード例 #23
0
static bool get_interface_types(things_resource_s *rsrc, char ***if_types, int *count)
{
	RET_FALSE_IF_PARAM_IS_NULL(TAG, rsrc);
	RET_FALSE_IF_PARAM_IS_NULL(TAG, if_types);
	RET_FALSE_IF_PARAM_IS_NULL(TAG, count);

	int if_count = rsrc->things_get_num_of_inf_types(rsrc);
	THINGS_LOG_D(TAG, "Resource(%s) has %d interface type(s).", rsrc->uri, if_count);
	RET_FALSE_IF_EXPR_IS_TRUE(TAG, if_count < 1, "No interface types in resource.");

	char **types = (char **)things_calloc(if_count, sizeof(char *));
	RET_VAL_IF_NULL(TAG, types, "Failed to allocate memory for inteface types.", false);

	bool result = true;
	const char *if_type = NULL;
	for (int i = 0; i < if_count; i++) {
		if_type = rsrc->things_get_inf_type(rsrc, i);
		if (NULL == if_type || strlen(if_type) < 1) {
			THINGS_LOG_E(TAG, "Interface type at index(%d) is invalid.", i);
			things_free_str_array(types, i);
			result = false;
			break;
		}

		types[i] = things_clone_string(if_type);
		if (NULL == types[i]) {
			THINGS_LOG_E(TAG, "Failed to clone inteface type(%s).", if_type);
			things_free_str_array(types, i);
			result = false;
			break;
		}
	}

	if (result) {
		*count = if_count;
		*if_types = types;
	}

	return result;
}
コード例 #24
0
ファイル: st_things.c プロジェクト: tool3210/TizenRT
int st_things_deinitialize(void)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);

	if (STACK_INITIALIZED != g_stack_status) {
		int ret_val = ST_THINGS_ERROR_OPERATION_FAILED;
		switch (g_stack_status) {
		case STACK_NOT_INITIALIZED:
			THINGS_LOG_E(TAG, "Stack is not initialized.");
			ret_val = ST_THINGS_ERROR_STACK_NOT_INITIALIZED;
			break;
		case STACK_STARTED:
			THINGS_LOG_E(TAG, "Stack is currently running. Stop the stack before deinitializing it.");
			ret_val = ST_THINGS_ERROR_STACK_RUNNING;
			break;
		default:
			THINGS_LOG_E(TAG, "Invalid stack state: %d.", g_stack_status);
			break;
		}

		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ret_val;
	}

	int result = 0;
	if (1 != (result = things_deinitialize_stack())) {
		THINGS_LOG_E(TAG, "things_deinitialize_stack failed (result:%d)", result);
		THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
		return ST_THINGS_ERROR_OPERATION_FAILED;
	}

	g_stack_status = STACK_NOT_INITIALIZED;

	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
	return ST_THINGS_ERROR_NONE;
}
コード例 #25
0
ファイル: things_req_handler.c プロジェクト: tool3210/TizenRT
struct things_request_handler_s *get_handler_instance()
{
	struct things_request_handler_s *handler = (things_request_handler_s *) things_malloc(sizeof(things_request_handler_s));

	if (handler == NULL) {
		THINGS_LOG_E(TAG, "Not Enough Memory");
		return NULL;
	} else {
		handler->entity_handler = &entity_handler;
		handler->init_module = &init_handler;
		handler->deinit_module = &deinit_handler;
		handler->notify_things_observers = &notify_things_observers;
		return handler;
	}
}
コード例 #26
0
void init_builder(struct things_server_builder_s *builder, request_handler_cb cb)
{
	OCTransportAdapter m_transport = (OC_ADAPTER_IP | OC_ADAPTER_TCP);
	if (OC_STACK_OK != OCInit2(OC_CLIENT_SERVER, OC_IP_USE_V4, OC_IP_USE_V4, m_transport)) {
		THINGS_LOG_E(TAG, "RESOURCE SERVER START FAILED");
		return;
	}

	THINGS_LOG_V(TAG, "Resource Server IS NOW STARTING...");

	g_quit_flag = 0;

	pthread_create_rtos(&g_thread_id_server, NULL, server_execute_loop, (void *)NULL, THINGS_STACK_SERVEREXCETUE_LOOP_THREAD);

	register_req_handler(builder, cb);
}
コード例 #27
0
ファイル: fmwup_util_http.c プロジェクト: drashti304/TizenRT
static void callback(struct http_client_response_t *response)
{
	if (response->status != 200) {
		is_link_fail = true;
		THINGS_LOG_E(TAG, "recv callback status %d", response->status);
		return;
	}

	if (download_state == FOTA_DOWNLOAD_STATE_JSON) {
		strncpy(json_str + recv_size, response->entity, response->entity_len);
	} else if (download_state == FOTA_DOWNLOAD_STATE_BINARY) {
		fotahal_write(fotahal_handle, response->entity, response->entity_len);
	}
	recv_size += response->entity_len;
	total_size = response->total_len;
}
コード例 #28
0
ファイル: things_resource.c プロジェクト: tool3210/TizenRT
things_representation_s *things_create_representation_inst(void *rep_payload)
{
	things_representation_s *rep = (things_representation_s *) things_malloc(sizeof(things_representation_s));
	if (NULL == rep) {
		THINGS_LOG_E(TAG, THINGS_MEMORY_ERROR);
		return NULL;
	}

	rep->things_set_value = &things_set_value;
	rep->things_set_bool_value = &things_set_bool_value;
	rep->things_set_double_value = &things_set_double_value;
	rep->things_set_int_value = &things_set_int_value;
	rep->things_set_byte_value = &things_set_byte_value;
	rep->things_set_object_value = &things_set_object_value;

	rep->things_set_arrayvalue = &things_set_arrayvalue;
	rep->things_get_arrayvalue = &things_get_arrayvalue;
	rep->things_set_string_arrayvalue = &things_set_string_arrayvalue;
	rep->things_get_string_arrayvalue = &things_get_string_arrayvalue;

	rep->things_set_double_arrayvalue = &things_set_double_arrayvalue;
	rep->things_get_double_arrayvalue = &things_get_double_arrayvalue;
	rep->things_set_int_arrayvalue = &things_set_int_arrayvalue;
	rep->things_get_int_arrayvalue = &things_get_int_arrayvalue;

	rep->things_get_value = &things_get_value;
	rep->things_get_bool_value = &things_get_bool_value;
	rep->things_get_int_value = &things_get_int_value;
	rep->things_get_double_value = &things_get_double_value;
	rep->things_get_byte_value = &things_get_byte_value;
	rep->things_get_object_value = &things_get_object_value;

	rep->payload = NULL;
	rep->children_payload = NULL;
	rep->children = NULL;
	rep->num_children = 0;

	if (rep_payload != NULL) {
		rep->payload = OCRepPayloadClone((OCRepPayload *) rep_payload);
	} else {
		rep->payload = OCRepPayloadCreate();
	}

	return rep;
}
コード例 #29
0
void *server_execute_loop(void *param)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);

	while (!g_quit_flag) {
		iotivity_api_lock();
		if (OCProcess() != OC_STACK_OK) {
			THINGS_LOG_E(TAG, "OCProcess Error");
			//   need to insert error handling logic from here
		}
		iotivity_api_unlock();
		//   The proper time period for looping need to be decided..
		usleep(10 * 1000);
	}
	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);

	return NULL;
}
コード例 #30
0
void things_bind(struct things_resource_s *res, struct things_resource_s *bind)
{
	if (res == NULL || bind == NULL) {
		THINGS_LOG_E(TAG, "Invalid Resource");
		return;
	}

	if (res->resource_handle == bind->resource_handle) {
		THINGS_LOG_D(TAG, "It's identical resource");
		return;
	}

	iotivity_api_lock();
	OCStackResult ret = OCBindResource((OCResourceHandle)(res->resource_handle),
									   (OCResourceHandle)(bind->resource_handle));
	iotivity_api_unlock();
	if (ret != OC_STACK_OK) {
		THINGS_LOG_V(TAG, "bind Failed ");
	}
}