/* null COULD be allowed */
if (resource->header_options)
- ic_options_free(resource->header_options);
+ iotcon_options_free(resource->header_options);
iotcon_resource_types_free(resource->types);
free(resource);
}
if (resource->header_options)
iotcon_options_free(resource->header_options);
- if (NULL == header_options) {
- resource->header_options = NULL;
- return IOTCON_ERROR_NONE;
- }
-
- if (true == header_options->has_parent)
+ if (header_options)
resource->header_options = ic_options_ref(header_options);
else
- resource->header_options = header_options;
- if (NULL == resource->header_options) {
- ERR("header_options is NULL");
- return IOTCON_ERROR_NO_DATA;
- }
-
- resource->header_options->has_parent = true;
+ resource->header_options = NULL;
return IOTCON_ERROR_NONE;
}
#include "icl-utils.h"
#include "icl-options.h"
+iotcon_options_h ic_options_ref(iotcon_options_h options)
+{
+ RETV_IF(NULL == options, NULL);
+ RETV_IF(options->ref_count <= 0, NULL);
+
+ options->ref_count++;
+
+ return options;
+}
+
+
API iotcon_options_h iotcon_options_new()
{
iotcon_options_h options = calloc(1, sizeof(struct ic_options));
}
options->hash = 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);
+ options->ref_count = 1;
- g_hash_table_unref(options->hash);
- free(options);
+ return 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);
+ options->ref_count--;
+
+ if (0 == options->ref_count) {
+ g_hash_table_unref(options->hash);
+ free(options);
+ }
}
API int iotcon_options_insert(iotcon_options_h options, unsigned short id,
const char *data)
{
- FN_CALL;
-
RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(options->has_parent, IOTCON_ERROR_INVALID_PARAMETER,
+ RETVM_IF(1 < options->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
"Don't modify it. It is already set.");
RETVM_IF(IOTCON_OPTIONS_MAX <= g_hash_table_size(options->hash),
IOTCON_ERROR_OUT_OF_MEMORY, "Options already have maximum elements.");
gboolean ret;
RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(options->has_parent, IOTCON_ERROR_INVALID_PARAMETER,
+ RETVM_IF(1 < options->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
"Don't modify it. It is already set.");
ret = g_hash_table_remove(options->hash, GUINT_TO_POINTER(id));
return IOTCON_ERROR_NONE;
}
-
-
-iotcon_options_h ic_options_ref(iotcon_options_h options)
-{
- iotcon_options_h ref;
-
- RETV_IF(NULL == options, NULL);
-
- ref = calloc(1, sizeof(struct ic_options));
- if (NULL == ref) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
-
- ref->hash = g_hash_table_ref(options->hash);
-
- return ref;
-}
-
#include "iotcon-struct.h"
struct ic_options {
- bool has_parent;
+ int ref_count;
GHashTable *hash;
};
-void ic_options_free(iotcon_options_h options);
iotcon_options_h ic_options_ref(iotcon_options_h options);
#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_OPTIONS_H__ */
if (resp->new_uri)
free(resp->new_uri);
if (resp->header_options)
- ic_options_free(resp->header_options);
+ iotcon_options_free(resp->header_options);
free(resp);
}
value = va_arg(args, int);
if (value < IOTCON_RESPONSE_RESULT_OK || IOTCON_RESPONSE_RESULT_MAX <= value) {
ERR("Invalid value(%d)", value);
+ va_end(args);
return IOTCON_ERROR_INVALID_PARAMETER;
}
resp->result = value;
if (resp->new_uri)
free(resp->new_uri);
- if (new_resource_uri)
- resp->new_uri = ic_utils_strdup(new_resource_uri);
- else
+ if (new_resource_uri) {
+ resp->new_uri = strdup(new_resource_uri);
+ if (NULL == resp->new_uri) {
+ ERR("strdup() Fail(%d)", errno);
+ va_end(args);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+ } else {
resp->new_uri = NULL;
+ }
break;
case IOTCON_RESPONSE_HEADER_OPTIONS:
options = va_arg(args, iotcon_options_h);
if (resp->header_options)
- ic_options_free(resp->header_options);
- if (NULL == options) {
- resp->header_options = NULL;
- break;
- }
- if (true == options->has_parent)
+ iotcon_options_free(resp->header_options);
+
+ if (options)
resp->header_options = ic_options_ref(options);
else
- resp->header_options = options;
- if (NULL == resp->header_options) {
- ERR("header_options is NULL");
- return IOTCON_ERROR_NO_DATA;
- }
-
- resp->header_options->has_parent = true;
+ resp->header_options = NULL;
break;
- case IOTCON_RESPONSE_NONE:
default:
+ ERR("Invalid Response Property(%d)", prop);
break;
}
} iotcon_resource_property_e;
typedef enum {
- IOTCON_RESPONSE_NONE = 0,
IOTCON_RESPONSE_RESOURCE_URI = 1,
IOTCON_RESPONSE_RESULT = 2,
IOTCON_RESPONSE_REPRESENTATION = 3,
void *user_data);
int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
void *user_data);
-iotcon_query_h iotcon_query_clone(iotcon_query_h query);
/**
iotcon_repr_h send_repr = iotcon_repr_new();
- iotcon_query_h query_params = iotcon_query_new();
/* send POST request */
- iotcon_post(door_resource, send_repr, query_params, _on_post, NULL);
+ iotcon_post(door_resource, send_repr, NULL, _on_post, NULL);
iotcon_repr_free(send_repr);
- iotcon_query_free(query_params);
-
}
static void _on_get(iotcon_options_h header_options, iotcon_repr_h recv_repr,
iotcon_repr_h send_repr = iotcon_repr_new();
iotcon_repr_set_bool(send_repr, "opened", true);
- iotcon_query_h query_params = iotcon_query_new();
/* send PUT request */
- iotcon_put(door_resource, send_repr, query_params, _on_put, NULL);
+ iotcon_put(door_resource, send_repr, NULL, _on_put, NULL);
iotcon_repr_free(send_repr);
- iotcon_query_free(query_params);
}
static int _get_res_type_fn(const char *string, void *user_data)
light_repr = iotcon_repr_new();
iotcon_repr_set_uri(light_repr, "/a/light");
iotcon_repr_set_int(light_repr, "brightness", 50);
+ iotcon_repr_append_child(room_repr, light_repr);
+ iotcon_repr_free(light_repr);
/* create a switch Representation */
switch_repr = iotcon_repr_new();
iotcon_repr_set_uri(switch_repr, "/a/switch");
iotcon_repr_set_bool(switch_repr, "switch", false);
-
- iotcon_repr_append_child(room_repr, light_repr);
iotcon_repr_append_child(room_repr, switch_repr);
- iotcon_repr_free(light_repr);
iotcon_repr_free(switch_repr);
ret = iotcon_request_get_query(request, &query);