resource_s.resource_uri = ic_utils_strdup(resource->uri().c_str());
resource_s.resource_host = ic_utils_strdup(resource->host().c_str());
resource_s.is_observable = resource->isObservable();
- resource_s.resource_types = iotcon_new_resource_types();
- resource_s.resource_interfaces = iotcon_new_resource_interfaces();
+ resource_s.resource_types = iotcon_resource_types_new();
+ resource_s.resource_interfaces = iotcon_resource_interfaces_new();
vector<string> resource_types = resource->getResourceTypes();
for (string &resource_type : resource_types)
resource_s.resource_types
- = iotcon_add_resource_types(resource_s.resource_types,
+ = iotcon_resource_types_insert(resource_s.resource_types,
ic_utils_strdup(resource_type.c_str()));
vector<string> resource_interfaces = resource->getResourceInterfaces();
free(resource_s.resource_uri);
free(resource_s.resource_host);
- iotcon_delete_resource_types(resource_s.resource_types);
- iotcon_delete_resource_interfaces(resource_s.resource_interfaces);
+ iotcon_resource_types_free(resource_s.resource_types);
+ iotcon_resource_interfaces_free(resource_s.resource_interfaces);
}
};
{
FN_CALL;
int res;
- iotcon_header_options header_options;
+ iotcon_options_h options;
iotcon_repr_h repr = NULL;
if (OC_STACK_OK == eCode)
else
res = IOTCON_ERR_IOTIVITY;
- header_options = iotcon_new_header_options();
+ options = iotcon_options_new();
for (HeaderOption::OCHeaderOption option : headerOptions) {
- iotcon_add_header_option(header_options, option.getOptionID(),
+ iotcon_options_insert(options, option.getOptionID(),
option.getOptionData().c_str());
}
repr = ic_ioty_repr_generate_repr(ocRep);
if (on_get)
- on_get(header_options, repr, res, cb_data);
+ on_get(options, repr, res, cb_data);
- iotcon_delete_header_options(header_options);
+ iotcon_options_free(options);
}
};
{
FN_CALL;
int res;
- iotcon_header_options header_options;
+ iotcon_options_h options;
iotcon_repr_h repr = NULL;
if (OC_STACK_OK == eCode)
else
res = IOTCON_ERR_IOTIVITY;
- header_options = iotcon_new_header_options();
+ options = iotcon_options_new();
for (HeaderOption::OCHeaderOption option : headerOptions) {
- iotcon_add_header_option(header_options, option.getOptionID(),
+ iotcon_options_insert(options, option.getOptionID(),
option.getOptionData().c_str());
}
repr = ic_ioty_repr_generate_repr(ocRep);
if (on_put)
- on_put(header_options, repr, res, cb_data);
+ on_put(options, repr, res, cb_data);
- iotcon_delete_header_options(header_options);
+ iotcon_options_free(options);
}
};
{
FN_CALL;
int res;
- iotcon_header_options header_options;
+ iotcon_options_h options;
iotcon_repr_h repr = NULL;
if (OC_STACK_OK == eCode)
else
res = IOTCON_ERR_IOTIVITY;
- header_options = iotcon_new_header_options();
+ options = iotcon_options_new();
for (HeaderOption::OCHeaderOption option : headerOptions) {
- iotcon_add_header_option(header_options, option.getOptionID(),
+ iotcon_options_insert(options, option.getOptionID(),
option.getOptionData().c_str());
}
repr = ic_ioty_repr_generate_repr(ocRep);
if (on_post)
- on_post(header_options, repr, res, cb_data);
+ on_post(options, repr, res, cb_data);
- iotcon_delete_header_options(header_options);
+ iotcon_options_free(options);
}
};
void onDelete(const HeaderOptions& headerOptions, const int eCode)
{
int res;
- iotcon_header_options header_options;
+ iotcon_options_h options;
if (OC_STACK_OK == eCode)
res = IOTCON_ERR_NONE;
else
res = IOTCON_ERR_IOTIVITY;
- header_options = iotcon_new_header_options();
+ options = iotcon_options_new();
for (HeaderOption::OCHeaderOption option : headerOptions) {
- iotcon_add_header_option(header_options, option.getOptionID(),
+ iotcon_options_insert(options, option.getOptionID(),
option.getOptionData().c_str());
}
if (on_delete)
- on_delete(header_options, res, cb_data);
+ on_delete(options, res, cb_data);
- iotcon_delete_header_options(header_options);
+ iotcon_options_free(options);
}
};
{
FN_CALL;
int res;
- iotcon_header_options header_options;
+ iotcon_options_h options;
iotcon_repr_h repr = NULL;
if (OC_STACK_OK == eCode)
else
res = IOTCON_ERR_IOTIVITY;
- header_options = iotcon_new_header_options();
+ options = iotcon_options_new();
for (HeaderOption::OCHeaderOption option : headerOptions) {
- iotcon_add_header_option(header_options, option.getOptionID(),
+ iotcon_options_insert(options, option.getOptionID(),
option.getOptionData().c_str());
}
repr = ic_ioty_repr_generate_repr(ocRep);
if (on_observe)
- on_observe(header_options, repr, res, sequenceNumber, cb_data);
+ on_observe(options, repr, res, sequenceNumber, cb_data);
- iotcon_delete_header_options(header_options);
+ iotcon_options_free(options);
}
};
}
return OC_EH_ERROR;
}
- request_s.query_params = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
- if (NULL == request_s.query_params) {
+ request_s.query = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+ if (NULL == request_s.query) {
ERR("g_hash_table_new_full() Fail");
return OC_EH_ERROR;
}
queryParams = request->getQueryParameters();
for (it = queryParams.begin(); it != queryParams.end(); ++it) {
DBG("key=%s value=%s", it->first.c_str(), it->second.c_str());
- g_hash_table_insert(request_s.query_params, ic_utils_strdup(it->first.c_str()),
+ g_hash_table_insert(request_s.query, ic_utils_strdup(it->first.c_str()),
ic_utils_strdup(it->second.c_str()));
}
- request_s.header_opts = iotcon_new_header_options();
- if (NULL == request_s.header_opts) {
- ERR("iot_new_header_options() Fail");
+ request_s.header_options = iotcon_options_new();
+ if (NULL == request_s.header_options) {
+ ERR("iotcon_options_new() Fail");
return OC_EH_ERROR;
}
for (auto it1 = headerOptions.begin(); it1 != headerOptions.end(); ++it1) {
DBG("OptionID=%d, OptionData=%s",
it1->getOptionID(), it1->getOptionData().c_str());
- iotcon_add_header_option(request_s.header_opts,
- it1->getOptionID(),
+ iotcon_options_insert(request_s.header_options, it1->getOptionID(),
it1->getOptionData().c_str());
}
}
request_s.request_type = ic_utils_strdup(request->getRequestType().c_str());
if (NULL == request_s.request_type) {
ERR("ic_utils_strdup() Fail");
- g_hash_table_destroy(request_s.header_opts);
- g_hash_table_destroy(request_s.query_params);
+ iotcon_options_free(request_s.header_options);
+ iotcon_query_free(request_s.query);
return OC_EH_ERROR;
}
if (NULL == request_s.request_type) {
ERR("ic_utils_strdup() Fail");
free(request_s.request_type);
- g_hash_table_destroy(request_s.header_opts);
- g_hash_table_destroy(request_s.query_params);
+ iotcon_options_free(request_s.header_options);
+ iotcon_query_free(request_s.query);
return OC_EH_ERROR;
}
free(request_s.res_uri);
if (request_s.repr) /* To avoid unnecessary ERR log (repr could be NULL) */
iotcon_repr_free(request_s.repr);
- g_hash_table_destroy(request_s.header_opts);
- g_hash_table_destroy(request_s.query_params);
+ iotcon_options_free(request_s.header_options);
+ iotcon_query_free(request_s.query);
return OC_EH_OK;
}
shared_ptr<icIotivityHandler::presenceObject> object
= make_shared<icIotivityHandler::presenceObject>(presence_handler_cb, user_data);
SubscribeCallback subscribeCallback
- = bind(&icIotivityHandler::presenceObject::presenceHandler, object,
+ = bind(&icIotivityHandler::presenceObject::presenceHandler, object,
placeholders::_1, placeholders::_2, placeholders::_3);
ret = subscribePresence(presence_handle, host_address, subscribeCallback);
shared_ptr<icIotivityHandler::findObject> object
= make_shared<icIotivityHandler::findObject>(found_resource_cb, user_data);
FindCallback findCallback = bind(&icIotivityHandler::findObject::foundResource,
- object, placeholders::_1);
+ object, placeholders::_1);
ret = findResource(host, resource_name, findCallback);
if (OC_STACK_OK != ret) {
return IOTCON_ERR_NONE;
}
-static OCResource::Ptr _create_oc_resource(iotcon_resource_s resource)
+static void _change_options(unsigned short id, char *data, void *user_data)
{
- RETV_IF(NULL == resource.resource_host, NULL);
- RETV_IF(NULL == resource.resource_uri, NULL);
+ HeaderOptions *options = static_cast<HeaderOptions *>(user_data);
+ HeaderOption::OCHeaderOption option(id, data);
+ (*options).push_back(option);
+}
+static OCResource::Ptr _create_oc_resource(iotcon_resource_s resource)
+{
string host = resource.resource_host;
string uri = resource.resource_uri;
vector<string> resource_types;
vector<string> resource_ifs;
HeaderOptions header_options;
- GHashTableIter iter;
- gpointer key = NULL;
- gpointer value = NULL;
+
+ RETV_IF(NULL == resource.resource_host, NULL);
+ RETV_IF(NULL == resource.resource_uri, NULL);
GList *node = resource.resource_types;
- for (node = g_list_first(node); NULL != node; node = g_list_next(node)) {
+ for (node = g_list_first(node); node; node = g_list_next(node)) {
string resource_type_str = (char *)node->data;
resource_types.push_back(resource_type_str);
}
node = resource.resource_interfaces;
- for (node = g_list_first(node); NULL != node; node = g_list_next(node)) {
+ for (node = g_list_first(node); node; node = g_list_next(node)) {
string resource_if_str = (char *)node->data;
resource_ifs.push_back(resource_if_str);
}
OCResource::Ptr ocResource = constructResourceObject(host, uri,
resource.is_observable, resource_types, resource_ifs);
- if (NULL != resource.header_options) {
- g_hash_table_iter_init(&iter, resource.header_options);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- HeaderOption::OCHeaderOption header_option(
- GPOINTER_TO_UINT(key), (const char *)value);
- header_options.push_back(header_option);
- }
+ if (resource.header_options) {
+ iotcon_options_foreach(resource.header_options, _change_options,
+ (void *)&header_options);
ocResource->setHeaderOptions(header_options);
}
}
extern "C" int ic_ioty_get(iotcon_resource_s resource,
- iotcon_query_parameters query_params, iotcon_on_get_cb on_get_cb, void *user_data)
+ iotcon_query query, iotcon_on_get_cb on_get_cb, void *user_data)
{
FN_CALL;
OCStackResult ret;
OCResource::Ptr ocResource = NULL;
- QueryParamsMap query;
+ QueryParamsMap queryParams;
+
GHashTableIter iter;
gpointer key, value;
- if (NULL != query_params) {
- g_hash_table_iter_init(&iter, query_params);
+ if (query) {
+ g_hash_table_iter_init(&iter, query);
while (g_hash_table_iter_next(&iter, &key, &value)) {
string keyStr = (char *)key;
string valueStr = (char *)value;
- query[keyStr] = valueStr;
+ queryParams[keyStr] = valueStr;
}
}
= make_shared<icIotivityHandler::getObject>(on_get_cb, user_data);
GetCallback getCallback = bind(&icIotivityHandler::getObject::onGet, object,
placeholders::_1, placeholders::_2, placeholders::_3);
- ret = ocResource->get(query, getCallback);
+ ret = ocResource->get(queryParams, getCallback);
if (OC_STACK_OK != ret) {
ERR("get() Fail(%d)", ret);
return IOTCON_ERR_IOTIVITY;
extern "C" int ic_ioty_put(iotcon_resource_s resource,
iotcon_repr_h repr,
- iotcon_query_parameters query_params,
+ iotcon_query query,
iotcon_on_put_cb on_put_cb,
void *user_data)
{
OCResource::Ptr ocResource = NULL;
OCRepresentation ocRep;
- QueryParamsMap query;
+ QueryParamsMap queryParams;
GHashTableIter iter;
gpointer key, value;
- if (NULL != query_params) {
- g_hash_table_iter_init(&iter, query_params);
+ if (query) {
+ g_hash_table_iter_init(&iter, query);
while (g_hash_table_iter_next(&iter, &key, &value)) {
string keyStr = (char *)key;
string valueStr = (char *)value;
- query[keyStr] = valueStr;
+ queryParams[keyStr] = valueStr;
}
}
PutCallback putCallback = bind(&icIotivityHandler::putObject::onPut, object,
placeholders::_1, placeholders::_2, placeholders::_3);
- ret = ocResource->put(ocRep, query, putCallback);
+ ret = ocResource->put(ocRep, queryParams, putCallback);
if (OC_STACK_OK != ret) {
ERR("put() Fail(%d)", ret);
return IOTCON_ERR_IOTIVITY;
extern "C" int ic_ioty_post(iotcon_resource_s resource,
iotcon_repr_h repr,
- iotcon_query_parameters query_params,
+ iotcon_query query,
iotcon_on_post_cb on_post_cb,
void *user_data)
{
OCStackResult ret;
GHashTableIter iter;
gpointer key, value;
- QueryParamsMap query;
+ QueryParamsMap queryParams;
OCRepresentation ocRep;
OCResource::Ptr ocResource = NULL;
- if (NULL != query_params) {
- g_hash_table_iter_init(&iter, query_params);
+ if (query) {
+ g_hash_table_iter_init(&iter, query);
while (g_hash_table_iter_next(&iter, &key, &value)) {
string keyStr = (char *)key;
string valueStr = (char *)value;
- query[keyStr] = valueStr;
+ queryParams[keyStr] = valueStr;
}
}
PostCallback postCallback = bind(&icIotivityHandler::postObject::onPost, object,
placeholders::_1, placeholders::_2, placeholders::_3);
- ret = ocResource->post(ocRep, query, postCallback);
+ ret = ocResource->post(ocRep, queryParams, postCallback);
if (OC_STACK_OK != ret) {
ERR("post() Fail(%d)", ret);
return IOTCON_ERR_IOTIVITY;
shared_ptr<icIotivityHandler::deleteObject> object
= make_shared<icIotivityHandler::deleteObject>(on_delete_cb, user_data);
DeleteCallback deleteCallback = bind(&icIotivityHandler::deleteObject::onDelete,
- object, placeholders::_1, placeholders::_2);
+ object, placeholders::_1, placeholders::_2);
ret = ocResource->deleteResource(deleteCallback);
if (OC_STACK_OK != ret) {
extern "C" int ic_ioty_observe(iotcon_resource_s *resource,
iotcon_observe_type_e observe_type,
- iotcon_query_parameters query_params,
+ iotcon_query query,
iotcon_on_observe_cb on_observe_cb,
void *user_data)
{
OCResource::Ptr ocResource = NULL;
ObserveType observeType;
- QueryParamsMap query;
+ QueryParamsMap queryParams;
GHashTableIter iter;
gpointer key, value;
- if (NULL != query_params) {
- g_hash_table_iter_init(&iter, query_params);
+ if (query) {
+ g_hash_table_iter_init(&iter, query);
while (g_hash_table_iter_next(&iter, &key, &value)) {
string keyStr = (char *)key;
string valueStr = (char *)value;
- query[keyStr] = valueStr;
+ queryParams[keyStr] = valueStr;
}
}
shared_ptr<icIotivityHandler::observeObject> object
= make_shared<icIotivityHandler::observeObject>(on_observe_cb, user_data);
ObserveCallback observeCallback = bind(&icIotivityHandler::observeObject::onObserve,
- object, placeholders::_1, placeholders::_2, placeholders::_3,
+ object, placeholders::_1, placeholders::_2, placeholders::_3,
placeholders::_4);
- ret = ocResource->observe(observeType, query, observeCallback);
+ ret = ocResource->observe(observeType, queryParams, observeCallback);
if (OC_STACK_OK != ret) {
ERR("observe() Fail(%d)", ret);
return IOTCON_ERR_IOTIVITY;
int ic_ioty_find_resource(const char *host, const char *resource_name,
iotcon_found_resource_cb found_resource_cb, void *user_data);
-int ic_ioty_get(iotcon_resource_s resource, iotcon_query_parameters query_params,
+int ic_ioty_get(iotcon_resource_s resource, iotcon_query query,
iotcon_on_get_cb on_get_cb, void *user_data);
-int ic_ioty_put(iotcon_resource_s resource,
- iotcon_repr_h repr,
- iotcon_query_parameters query_params,
- iotcon_on_put_cb on_put_cb,
- void *user_data);
+int ic_ioty_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+ iotcon_on_put_cb on_put_cb, void *user_data);
-int ic_ioty_post(iotcon_resource_s resource,
- iotcon_repr_h repr,
- iotcon_query_parameters query_params,
- iotcon_on_put_cb on_post_cb,
- void *user_data);
+int ic_ioty_post(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+ iotcon_on_put_cb on_post_cb, void *user_data);
int ic_ioty_delete_res(iotcon_resource_s resource,
iotcon_on_delete_cb on_delete_cb, void *user_data);
-int ic_ioty_observe(iotcon_resource_s *resource,
- iotcon_observe_type_e observe_type,
- iotcon_query_parameters query_params,
- iotcon_on_observe_cb on_observe_cb,
- void *user_data);
+int ic_ioty_observe(iotcon_resource_s *resource, iotcon_observe_type_e observe_type,
+ iotcon_query query, iotcon_on_observe_cb on_observe_cb, void *user_data);
int ic_ioty_cancel_observe(iotcon_resource_s resource);
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdlib.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+
+#include "ic-common.h"
+#include "ic-utils.h"
+#include "ic-struct.h"
+#include "ic-ioty.h"
+#include "ic-options.h"
+
+API iotcon_options_h iotcon_options_new()
+{
+ iotcon_options_h options = calloc(1, sizeof(struct ic_options_s));
+ if (NULL == options) {
+ ERR("calloc() Fail(%d)", errno);
+ return NULL;
+ }
+
+ options->options = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free);
+ return options;
+}
+
+void ic_options_free(iotcon_options_h options)
+{
+ RET_IF(NULL == options);
+
+ g_hash_table_unref(options->options);
+ free(options);
+}
+
+API void iotcon_options_free(iotcon_options_h options)
+{
+ RET_IF(NULL == options);
+ RETM_IF(true == options->has_parent, "iotcon_options has parent");
+
+ ic_options_free(options);
+}
+
+API int iotcon_options_insert(iotcon_options_h options, const unsigned short id,
+ const char *data)
+{
+ FN_CALL;
+ gpointer value;
+
+ RETVM_IF(((id < IOTCON_OPTIONID_MIN) || (IOTCON_OPTIONID_MAX < id)), IOTCON_ERR_PARAM,
+ "Invalid id(%d)", id);
+
+ value = ic_utils_strdup(data);
+
+ g_hash_table_insert(options->options, GUINT_TO_POINTER(id), value);
+
+ return IOTCON_ERR_NONE;
+}
+
+API int iotcon_options_delete(iotcon_options_h options, const unsigned short id)
+{
+ gboolean ret;
+
+ RETV_IF(NULL == options, IOTCON_ERR_PARAM);
+
+ ret = g_hash_table_remove(options->options, GUINT_TO_POINTER(id));
+ if (FALSE == ret) {
+ ERR("g_hash_table_remove() Fail");
+ return IOTCON_ERR_PARAM;
+ }
+ return IOTCON_ERR_NONE;
+}
+
+API const char* iotcon_options_lookup(iotcon_options_h options, const unsigned short id)
+{
+ const char *ret;
+
+ RETV_IF(NULL == options, NULL);
+
+ ret = g_hash_table_lookup(options->options, GUINT_TO_POINTER(id));
+ if (NULL == ret)
+ ERR("g_hash_table_lookup() Fail");
+
+ return ret;
+}
+
+API void iotcon_options_foreach(iotcon_options_h options,
+ iotcon_options_foreach_cb foreach_cb, void *user_data)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ RET_IF(NULL == options);
+
+ g_hash_table_iter_init(&iter, options->options);
+ while (g_hash_table_iter_next(&iter, &key, &value))
+ foreach_cb(GPOINTER_TO_UINT(key), value, user_data);
+}
+
+API iotcon_options_h iotcon_options_clone(iotcon_options_h options)
+{
+ iotcon_options_h clone = NULL;
+
+ RETV_IF(NULL == options, NULL);
+
+ clone = calloc(1, sizeof(struct ic_options_s));
+ if (NULL == clone) {
+ ERR("calloc() Fail(%d)", errno);
+ return NULL;
+ }
+
+ clone->options = g_hash_table_ref(options->options);
+
+ return clone;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_OPTIONS_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_OPTIONS_H__
+
+#include "iotcon-struct.h"
+
+void ic_options_free(iotcon_options_h options);
+
+#endif //__IOT_CONNECTIVITY_MANAGER_INTERNAL_OPTIONS_H__
struct ic_repr_s *repr;
} ic_val_repr_s;
+struct ic_options_s {
+ bool has_parent;
+ GHashTable *options;
+};
+
/* related with iotcon_response_property_e */
struct ic_res_response_s {
char *new_resource_uri;
int error_code;
- iotcon_header_options header_options;
+ iotcon_options_h header_options;
iotcon_interface_e interface;
iotcon_request_h request_handle;
iotcon_resource_h resource_handle;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <glib.h>
#include "ic-utils.h"
#include "ic-struct.h"
#include "ic-ioty.h"
+#include "ic-options.h"
/**
* @brief global context
_set_iotcon_init(FALSE);
}
-API iotcon_response_h iotcon_create_response(iotcon_request_h req_h,
+API iotcon_response_h iotcon_response_new(iotcon_request_h req_h,
iotcon_resource_h res_h)
{
FN_CALL;
{
int value;
va_list args;
+ char *new_resource_uri = NULL;
+ iotcon_options_h options = NULL;
va_start(args, prop);
resp->error_code = va_arg(args, int);
break;
case IOTCON_RESP_RES_URI:
- resp->new_resource_uri = va_arg(args, char*);
+ new_resource_uri = va_arg(args, char*);
+ if (resp->new_resource_uri)
+ free(resp->new_resource_uri);
+
+ if (new_resource_uri)
+ resp->new_resource_uri = ic_utils_strdup(new_resource_uri);
+ else
+ resp->new_resource_uri = NULL;
+ break;
+ case IOTCON_RESP_HEADER_OPTIONS:
+ options = va_arg(args, iotcon_options_h);
+ if (resp->header_options)
+ ic_options_free(resp->header_options);
+
+ if (true == options->has_parent)
+ resp->header_options = iotcon_options_clone(options);
+ else
+ resp->header_options = options;
+ resp->header_options->has_parent = true;
break;
case IOTCON_RESP_NONE:
default:
return IOTCON_ERR_NONE;
}
-API void iotcon_delete_response(iotcon_response_h resp)
+API void iotcon_response_free(iotcon_response_h resp)
{
FN_CALL;
struct ic_res_response_s *data = resp;
RET_IF(NULL == resp);
free(data->new_resource_uri);
- iotcon_delete_header_options(data->header_options);
+ ic_options_free(resp->header_options);
iotcon_repr_free(resp->repr);
free(data);
}
resource_s.resource_host = ic_utils_strdup(host);
resource_s.resource_uri = ic_utils_strdup(uri);
resource_s.is_observable = is_observable;
- resource_s.resource_types = iotcon_new_resource_types();
- resource_s.resource_interfaces = iotcon_new_resource_interfaces();
+ resource_s.resource_types = iotcon_resource_types_new();
+ resource_s.resource_interfaces = iotcon_resource_interfaces_new();
- for (node = g_list_first(resource_type); NULL != node; node = g_list_next(node)) {
+ for (node = g_list_first(resource_type); node; node = g_list_next(node)) {
resource_s.resource_types = g_list_append(resource_s.resource_types,
ic_utils_strdup(node->data));
}
- for (node = g_list_first(resource_if); NULL != node; node = g_list_next(node)) {
+ for (node = g_list_first(resource_if); node; node = g_list_next(node)) {
resource_s.resource_interfaces = g_list_append(resource_s.resource_interfaces,
ic_utils_strdup(node->data));
}
free(resource->resource_uri);
free(resource->resource_host);
- iotcon_delete_header_options(resource->header_options);
- iotcon_delete_resource_types(resource->resource_types);
- iotcon_delete_resource_interfaces(resource->resource_interfaces);
+ iotcon_options_free(resource->header_options);
+ iotcon_resource_types_free(resource->resource_types);
+ iotcon_resource_interfaces_free(resource->resource_interfaces);
}
API iotcon_resource_s iotcon_copy_resource(iotcon_resource_s resource)
resource_s.resource_host = ic_utils_strdup(resource.resource_host);
resource_s.resource_uri = ic_utils_strdup(resource.resource_uri);
resource_s.is_observable = resource.is_observable;
- resource_s.resource_types = iotcon_new_resource_types();
- resource_s.resource_interfaces = iotcon_new_resource_interfaces();
+ resource_s.resource_types = iotcon_resource_types_new();
+ resource_s.resource_interfaces = iotcon_resource_interfaces_new();
resource_s.observe_handle = resource.observe_handle;
- for (node = g_list_first(resource.resource_types); NULL != node;
- node = g_list_next(node)) {
+ for (node = g_list_first(resource.resource_types); node; node = g_list_next(node)) {
resource_s.resource_types = g_list_append(resource_s.resource_types,
ic_utils_strdup(node->data));
}
- for (node = g_list_first(resource.resource_interfaces); NULL != node;
+ for (node = g_list_first(resource.resource_interfaces); node;
node = g_list_next(node)) {
resource_s.resource_interfaces = g_list_append(resource_s.resource_interfaces,
ic_utils_strdup(node->data));
return resource_s;
}
-API int iotcon_get(iotcon_resource_s resource, iotcon_query_parameters query_params,
+API int iotcon_get(iotcon_resource_s resource, iotcon_query query,
iotcon_on_get_cb on_get_cb, void *user_data)
{
FN_CALL;
int ret = IOTCON_ERR_NONE;
- ret = ic_ioty_get(resource, query_params, on_get_cb, user_data);
+ ret = ic_ioty_get(resource, query, on_get_cb, user_data);
if (IOTCON_ERR_NONE != ret)
ERR("ic_ioty_get() Fail(%d)", ret);
return ret;
}
-API int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr,
- iotcon_query_parameters query_params, iotcon_on_put_cb on_put_cb, void *user_data)
+API int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+ iotcon_on_put_cb on_put_cb, void *user_data)
{
FN_CALL;
RETV_IF(NULL == repr, IOTCON_ERR_PARAM);
- ret = ic_ioty_put(resource, repr, query_params, on_put_cb, user_data);
+ ret = ic_ioty_put(resource, repr, query, on_put_cb, user_data);
if (IOTCON_ERR_NONE != ret)
ERR("ic_ioty_put() Fail(%d)", ret);
API int iotcon_post(iotcon_resource_s resource,
iotcon_repr_h repr,
- iotcon_query_parameters query_params,
+ iotcon_query query,
iotcon_on_post_cb on_post_cb,
void *user_data)
{
RETV_IF(NULL == repr, IOTCON_ERR_PARAM);
- ret = ic_ioty_post(resource, repr, query_params, on_post_cb, user_data);
+ ret = ic_ioty_post(resource, repr, query, on_post_cb, user_data);
if (IOTCON_ERR_NONE != ret)
ERR("ic_ioty_post() Fail(%d)", ret);
API int iotcon_observe(iotcon_observe_type_e observe_type,
iotcon_resource_s *resource,
- iotcon_query_parameters query_params,
+ iotcon_query query,
iotcon_on_observe_cb on_observe_cb,
void *user_data)
{
int ret = IOTCON_ERR_NONE;
- ret = ic_ioty_observe(resource, observe_type, query_params, on_observe_cb,
+ ret = ic_ioty_observe(resource, observe_type, query, on_observe_cb,
user_data);
if (IOTCON_ERR_NONE != ret)
ERR("ic_ioty_observe() Fail(%d)", ret);
return ret;
}
-API iotcon_resource_types iotcon_new_resource_types()
+API iotcon_resource_types iotcon_resource_types_new()
{
return NULL;
}
-API iotcon_resource_types iotcon_add_resource_types(iotcon_resource_types resource_types,
- const char *resource_type)
+API iotcon_resource_types iotcon_resource_types_insert(
+ iotcon_resource_types resource_types, const char *resource_type)
{
FN_CALL;
return resource_types;
}
-API void iotcon_delete_resource_types(iotcon_resource_types resource_types)
+API void iotcon_resource_types_free(iotcon_resource_types resource_types)
{
FN_CALL;
- g_list_free_full(resource_types, g_free);
+ g_list_free_full(resource_types, free);
}
-API iotcon_resource_interfaces iotcon_new_resource_interfaces()
+API iotcon_resource_interfaces iotcon_resource_interfaces_new()
{
FN_CALL;
return NULL;
}
-API iotcon_resource_interfaces iotcon_add_resource_interfaces(
+API iotcon_resource_interfaces iotcon_resource_interfaces_insert(
iotcon_resource_interfaces resource_interfaces, iotcon_interface_e interface)
{
FN_CALL;
return resource_interfaces;
}
-API void iotcon_delete_resource_interfaces(iotcon_resource_interfaces resource_interfaces)
-{
- FN_CALL;
-
- g_list_free_full(resource_interfaces, g_free);
-}
-
-API iotcon_header_options iotcon_new_header_options()
-{
- iotcon_header_options options = NULL;
- options = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
- return options;
-}
-
-API iotcon_error_e iotcon_add_header_option(iotcon_header_options options,
- const unsigned short id, const char *data)
+API void iotcon_resource_interfaces_free(iotcon_resource_interfaces resource_interfaces)
{
FN_CALL;
- RETV_IF(((id < IOTCON_HEADER_OPTIONID_MIN)
- || (IOTCON_HEADER_OPTIONID_MAX < id)), IOTCON_ERR_PARAM);
-
- gpointer value = ic_utils_strdup(data);
-
- g_hash_table_insert(options, GUINT_TO_POINTER(id), value);
-
- return IOTCON_ERR_NONE;
-}
-
-API void iotcon_delete_header_options(iotcon_header_options options)
-{
- RET_IF(NULL == options);
-
- g_hash_table_destroy(options);
+ g_list_free_full(resource_interfaces, free);
}
-API iotcon_query_parameters iotcon_new_query_params()
+API iotcon_query iotcon_query_new()
{
- iotcon_query_parameters query_params = NULL;
+ iotcon_query query = NULL;
- query_params = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ query = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
- return query_params;
+ return query;
}
-API void iotcon_add_query_param(iotcon_query_parameters query_params, const char *key,
- const char *value)
+API void iotcon_query_insert(iotcon_query query, const char *key, const char *value)
{
- g_hash_table_insert(query_params, ic_utils_strdup(key), ic_utils_strdup(value));
+ g_hash_table_insert(query, ic_utils_strdup(key), ic_utils_strdup(value));
}
-API void iotcon_delete_query_params(iotcon_query_parameters query_params)
+API void iotcon_query_free(iotcon_query query)
{
- RET_IF(NULL == query_params);
+ RET_IF(NULL == query);
- g_hash_table_destroy(query_params);
+ g_hash_table_destroy(query);
}
-API char* iotcon_find_query_param(iotcon_query_parameters query_params, const char *key)
+API char* iotcon_query_lookup(iotcon_query query, const char *key)
{
- return g_hash_table_lookup(query_params, key);
+ return g_hash_table_lookup(query, key);
}
-API iotcon_observers iotcon_new_observation()
+API iotcon_observers iotcon_observation_new()
{
return NULL;
}
-API iotcon_observers iotcon_add_observation(iotcon_observers observers,
+API iotcon_observers iotcon_observation_insert(iotcon_observers observers,
iotcon_observation_info_s obs)
{
iotcon_observation_info_s *obs_node = calloc(1, sizeof(iotcon_observation_info_s));
return observers;
}
-API iotcon_observers iotcon_delete_observation(iotcon_observers observers,
+API iotcon_observers iotcon_observation_delete(iotcon_observers observers,
iotcon_observation_info_s obs)
{
GList *node = NULL;
return observers;
}
-API void iotcon_free_observation(iotcon_observers observers)
+API void iotcon_observation_free(iotcon_observers observers)
{
- g_list_free_full(observers, g_free);
+ g_list_free_full(observers, free);
}
-API char* iotcon_get_resource_uri(iotcon_resource_s resource_s)
+API char* iotcon_resource_get_uri(iotcon_resource_s resource_s)
{
return resource_s.resource_uri;
}
-API char* iotcon_get_resource_host(iotcon_resource_s resource_s)
+API char* iotcon_resource_get_host(iotcon_resource_s resource_s)
{
return resource_s.resource_host;
}
-API iotcon_resource_types iotcon_get_resource_types(iotcon_resource_s resource_s)
+API iotcon_resource_types iotcon_resource_get_types(iotcon_resource_s resource_s)
{
return resource_s.resource_types;
}
-API iotcon_resource_interfaces iotcon_get_resource_interfaces(
- iotcon_resource_s resource_s)
+API iotcon_resource_interfaces iotcon_resource_get_interfaces(iotcon_resource_s resource_s)
{
return resource_s.resource_interfaces;
}
-API void iotcon_set_header_options(iotcon_resource_s *resource_s,
- iotcon_header_options options)
+API void iotcon_resource_set_options(iotcon_resource_s *resource,
+ iotcon_options_h header_options)
{
- iotcon_header_options header_options;
- GHashTableIter iter;
- gpointer key = NULL;
- gpointer value = NULL;
+ RET_IF(NULL == resource);
- RET_IF(NULL == resource_s);
- RET_IF(NULL == options);
+ if (resource->header_options)
+ iotcon_options_free(resource->header_options);
- header_options = iotcon_new_header_options();
- g_hash_table_iter_init(&iter, options);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- iotcon_add_header_option(header_options, GPOINTER_TO_UINT(key), value);
- }
- resource_s->header_options = header_options;
+ resource->header_options = header_options;
}
-API void iotcon_unset_header_options(iotcon_resource_s *resource_s)
+API iotcon_options_h iotcon_request_get_options(iotcon_request_s request)
{
- RET_IF(NULL == resource_s);
- iotcon_delete_header_options(resource_s->header_options);
- resource_s->header_options = NULL;
+ return request.header_options;
}
* range of 2048 to 3000 inclusive of lower and upper bound.
* HeaderOptions instance creation fails if above condition is not satisfied.
*/
-#define IOTCON_HEADER_OPTIONID_MIN 2048
-#define IOTCON_HEADER_OPTIONID_MAX 3000
+#define IOTCON_OPTIONID_MIN 2048
+#define IOTCON_OPTIONID_MAX 3000
/**
IOTCON_RESP_ERR_CODE = 2,
IOTCON_RESP_RESULT = 3,
IOTCON_RESP_REPRESENTATION = 4,
+ IOTCON_RESP_HEADER_OPTIONS = 5
} iotcon_response_property_e;
typedef enum {
typedef GList* iotcon_observers;
typedef unsigned char iotcon_observation_id;
-typedef GHashTable* iotcon_header_options;
-typedef GHashTable* iotcon_query_parameters;
+
+typedef struct ic_options_s* iotcon_options_h;
+typedef GHashTable* iotcon_query;
typedef GList *iotcon_resource_types;
typedef GList *iotcon_resource_interfaces;
typedef struct ic_res_response_s* iotcon_response_h;
/**
- * @brief These are used in setting header options.
- */
-typedef struct {
- unsigned short option_id;
- char *option_data;
-} iotcon_header_option;
-
-
-/**
* @brief observation information structure
*/
typedef struct {
char *resource_host;
bool is_observable;
bool is_collection;
- iotcon_header_options header_options;
+ iotcon_options_h header_options;
iotcon_resource_types resource_types;
iotcon_resource_interfaces resource_interfaces;
iotcon_observe_h observe_handle;
typedef struct {
char *request_type;
char *res_uri;
- iotcon_header_options header_opts;
- iotcon_query_parameters query_params;
+ iotcon_options_h header_options;
+ iotcon_query query;
int request_handler_flag;
iotcon_request_h request_handle;
iotcon_resource_h resource_handle;
void iotcon_initialize(const char *addr, unsigned short port);
void iotcon_deinitialize();
-iotcon_response_h iotcon_create_response(iotcon_request_h req_h,
+iotcon_response_h iotcon_response_new(iotcon_request_h req_h,
iotcon_resource_h res_h);
-void iotcon_delete_response(iotcon_response_h resp);
+void iotcon_response_free(iotcon_response_h resp);
typedef void (*iotcon_rest_api_handle_cb)(const iotcon_request_s *request);
int iotcon_find_resource(const char *host, const char *resource_name,
iotcon_found_resource_cb found_resource_cb, void *user_data);
-typedef void (*iotcon_on_get_cb)(const iotcon_header_options header_options,
+typedef void (*iotcon_on_get_cb)(const iotcon_options_h header_options,
const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_put_cb)(const iotcon_header_options header_options,
+typedef void (*iotcon_on_put_cb)(const iotcon_options_h header_options,
const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_post_cb)(const iotcon_header_options header_options,
+typedef void (*iotcon_on_post_cb)(const iotcon_options_h header_options,
const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_observe_cb)(const iotcon_header_options header_options,
- const iotcon_repr_h repr, const int e_code, const int sequence_number,
+typedef void (*iotcon_on_observe_cb)(const iotcon_options_h header_options,
+ const iotcon_repr_h repr, const int e_code, const int sequence_number,
void *user_data);
-typedef void (*iotcon_on_delete_cb)(const iotcon_header_options header_options,
+typedef void (*iotcon_on_delete_cb)(const iotcon_options_h header_options,
const int e_code, void *user_data);
iotcon_resource_s iotcon_construct_resource_object(const char *host,
void iotcon_destruct_resource_object(iotcon_resource_s *resource);
iotcon_resource_s iotcon_copy_resource(iotcon_resource_s resource);
-int iotcon_get(iotcon_resource_s resource, iotcon_query_parameters query_params,
+int iotcon_get(iotcon_resource_s resource, iotcon_query query,
iotcon_on_get_cb on_get_cb, void *user_data);
-int iotcon_put(iotcon_resource_s resource,
- iotcon_repr_h repr,
- iotcon_query_parameters query_params,
- iotcon_on_put_cb on_put_cb,
- void *user_data);
-int iotcon_post(iotcon_resource_s resource,
- iotcon_repr_h repr,
- iotcon_query_parameters query_params,
- iotcon_on_post_cb on_post_cb,
- void *user_data);
-int iotcon_delete_resource(iotcon_resource_s resource,
- iotcon_on_delete_cb on_delete_cb,
+int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+ iotcon_on_put_cb on_put_cb, void *user_data);
+int iotcon_post(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+ iotcon_on_post_cb on_post_cb, void *user_data);
+int iotcon_delete_resource(iotcon_resource_s resource, iotcon_on_delete_cb on_delete_cb,
void *user_data);
int iotcon_observe(iotcon_observe_type_e observe_type,
iotcon_resource_s *resource,
- iotcon_query_parameters query_params,
+ iotcon_query query,
iotcon_on_observe_cb on_observe_cb,
void *user_data);
int iotcon_cancel_observe(iotcon_resource_s resource);
-iotcon_resource_types iotcon_new_resource_types();
-iotcon_resource_types iotcon_add_resource_types(iotcon_resource_types resource_types,
+iotcon_resource_types iotcon_resource_types_new();
+iotcon_resource_types iotcon_resource_types_insert(iotcon_resource_types resource_types,
const char *resource_type);
-void iotcon_delete_resource_types(iotcon_resource_types resource_types);
+void iotcon_resource_types_free(iotcon_resource_types resource_types);
-iotcon_resource_interfaces iotcon_new_resource_interfaces();
-iotcon_resource_interfaces iotcon_add_resource_interfaces(
+iotcon_resource_interfaces iotcon_resource_interfaces_new();
+iotcon_resource_interfaces iotcon_resource_interfaces_insert(
iotcon_resource_interfaces resource_interfaces, iotcon_interface_e interface);
-void iotcon_delete_resource_interfaces(iotcon_resource_interfaces resource_interfaces);
-
-iotcon_header_options iotcon_new_header_options();
-iotcon_error_e iotcon_add_header_option(iotcon_header_options options,
- const unsigned short id, const char *data);
-void iotcon_delete_header_options(iotcon_header_options options);
+void iotcon_resource_interfaces_free(iotcon_resource_interfaces resource_interfaces);
+
+iotcon_options_h iotcon_options_new();
+void iotcon_options_free(iotcon_options_h options);
+int iotcon_options_insert(iotcon_options_h options, const unsigned short id,
+ const char *data);
+int iotcon_options_delete(iotcon_options_h options, const unsigned short id);
+const char* iotcon_options_lookup(iotcon_options_h options, const unsigned short id);
+typedef void (*iotcon_options_foreach_cb)(unsigned short id, char *data, void *user_data);
+void iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb foreach_cb,
+ void *user_data);
+iotcon_options_h iotcon_options_clone(iotcon_options_h options);
-iotcon_query_parameters iotcon_new_query_params();
-void iotcon_add_query_param(iotcon_query_parameters query_params, const char *key,
- const char *value);
-void iotcon_delete_query_params(iotcon_query_parameters query_params);
-char* iotcon_find_query_param(iotcon_query_parameters query_params, const char *key);
+iotcon_query iotcon_query_new();
+void iotcon_query_insert(iotcon_query query, const char *key, const char *value);
+void iotcon_query_free(iotcon_query query);
+char* iotcon_query_lookup(iotcon_query query, const char *key);
-iotcon_observers iotcon_new_observation();
-iotcon_observers iotcon_add_observation(iotcon_observers observers,
+iotcon_observers iotcon_observation_new();
+iotcon_observers iotcon_observation_insert(iotcon_observers observers,
iotcon_observation_info_s obs);
-iotcon_observers iotcon_delete_observation(iotcon_observers observers,
+iotcon_observers iotcon_observation_delete(iotcon_observers observers,
iotcon_observation_info_s obs);
-void iotcon_free_observation(iotcon_observers observers);
-
-char* iotcon_get_resource_uri(iotcon_resource_s resource_s);
-char* iotcon_get_resource_host(iotcon_resource_s resource_s);
-iotcon_resource_types iotcon_get_resource_types(iotcon_resource_s resource_s);
-iotcon_resource_interfaces iotcon_get_resource_interfaces(iotcon_resource_s resource_s);
-void iotcon_set_header_options(iotcon_resource_s *resource_s,
- iotcon_header_options options);
-void iotcon_unset_header_options(iotcon_resource_s *resource_s);
+void iotcon_observation_free(iotcon_observers observers);
+
+char* iotcon_resource_get_uri(iotcon_resource_s resource_s);
+char* iotcon_resource_get_host(iotcon_resource_s resource_s);
+iotcon_resource_types iotcon_resource_get_types(iotcon_resource_s resource_s);
+iotcon_resource_interfaces iotcon_resource_get_interfaces(iotcon_resource_s resource_s);
+
+void iotcon_resource_set_options(iotcon_resource_s *resource,
+ iotcon_options_h header_options);
iotcon_repr_h iotcon_repr_new();
const char* iotcon_repr_get_uri(iotcon_repr_h repr);
}
-static void _on_put(const iotcon_header_options header_options, iotcon_repr_h repr,
+static void _on_put(const iotcon_options_h header_options, iotcon_repr_h repr,
const int e_code, void *user_data)
{
FN_CALL;
/* set the flag for receiving response succesfully */
}
-void _on_get(const iotcon_header_options header_options, iotcon_repr_h repr,
+void _on_get(const iotcon_options_h header_options, iotcon_repr_h repr,
const int e_code, void *user_data)
{
FN_CALL;
iotcon_repr_h repr = iotcon_repr_new();
iotcon_repr_set_bool(repr, "opened", true);
- iotcon_query_parameters query_params = iotcon_new_query_params();
- iotcon_put(door_resource, repr, query_params, _on_put, NULL);
+ iotcon_query query = iotcon_query_new();
+ iotcon_put(door_resource, repr, query, _on_put, NULL);
}
else {
INFO("===== resource found =====");
/* Get the resource URI */
- resource_uri = iotcon_get_resource_uri(*resource);
+ resource_uri = iotcon_resource_get_uri(*resource);
if (NULL == resource_uri) {
ERR("uri is NULL");
return;
}
/* Get the resource host address */
- resource_host = iotcon_get_resource_host(*resource);
+ resource_host = iotcon_resource_get_host(*resource);
DBG("[%s] resource host : %s", resource_uri, resource_host);
/* Get the resource interfaces */
- resource_interfaces = iotcon_get_resource_interfaces(*resource);
+ resource_interfaces = iotcon_resource_get_interfaces(*resource);
if (resource_interfaces) {
interfaces_str = _alloc_str_from_glist(resource_interfaces);
DBG("[%s] resource interfaces : %s", resource_uri, interfaces_str);
}
/* Get the resource types */
- resource_types = iotcon_get_resource_types(*resource);
+ resource_types = iotcon_resource_get_types(*resource);
if (resource_types) {
res_types_str = _alloc_str_from_glist(resource_types);
DBG("[%s] resource types : %s", resource_uri, res_types_str);
if (!strcmp(door_uri, resource_uri)) {
door_resource = iotcon_copy_resource(*resource);
- iotcon_query_parameters query_params = iotcon_new_query_params();
+ iotcon_query query = iotcon_query_new();
/* send GET Request */
- iotcon_get(*resource, query_params, _on_get, NULL);
+ iotcon_get(*resource, query, _on_get, NULL);
- iotcon_delete_query_params(query_params);
+ iotcon_query_free(query);
}
}
}
int requestFlag = request_s->request_handler_flag;
if (requestFlag & IOTCON_REQUEST_FLAG) {
- iotcon_response_h pResponse = iotcon_create_response(request_s->request_handle,
+ iotcon_response_h pResponse = iotcon_response_new(request_s->request_handle,
request_s->resource_handle);
if (NULL == pResponse) {
ERR("pResponse is NULL");