</method>
<method name="unregisterResource">
<arg type="x" name="resource" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
</method>
<method name="bindInterface">
<arg type="x" name="resource" direction="in"/>
FN_CALL;
int ret;
const gchar *sender;
- OCResourceHandle handle = NULL;
+ OCResourceHandle handle;
handle = icd_ioty_register_resource(uri_path, resource_types, ifaces, properties);
if (handle) {
ret = icd_ioty_unregister_resource(handle);
if (IOTCON_ERROR_NONE != ret)
ERR("icd_ioty_unregister_resource(%u) Fail(%d)", handle, ret);
+
+ handle = NULL;
}
}
_icd_dbus_resource_handle_free(ICD_INT64_TO_POINTER(resource));
- ic_dbus_complete_unregister_resource(object, invocation, ret);
+ ic_dbus_complete_unregister_resource(object, invocation);
return TRUE;
}
OCConnectivityType oic_conn_type;
OCDevAddr dev_addr = {0};
- g_variant_get(resource, "(&s&sba(qs)i)", &uri_path, &host, &is_secure, &options,
+ g_variant_get(resource, "(&s&sba(qs)i)", &uri_path, &host, &is_secure, &options,
&conn_type);
uri = _icd_ioty_resource_generate_uri(uri_path, query);
if (IOTCON_ERROR_NONE != ret) {
return;
}
- ret = iotcon_observers_append(observers, observer_id, &observers);
+ ret = iotcon_observers_insert(observers, observer_id);
if (IOTCON_ERROR_NONE != ret) {
return;
}
if (IOTCON_ERROR_NONE != ret) {
return;
}
- ret = iotcon_observers_remove(observers, observer_id, &observers);
+ ret = iotcon_observers_delete(observers, observer_id);
if (IOTCON_ERROR_NONE != ret) {
return;
}
GError *error = NULL;
int64_t observe_handle;
icl_on_observe_s *cb_container;
- int ret, signal_number, error_code;
+ int ret, signal_number;
char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
arg_query, signal_number, &observe_handle, NULL, &error);
if (error) {
ERR("ic_dbus_call_observer_start_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
g_variant_unref(arg_query);
g_variant_unref(arg_client);
- return error_code;
+ return ret;
}
if (0 == observe_handle) {
_icl_observe_conn_cleanup, _icl_on_observe_cb);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
+ iotcon_client_destroy(cb_container->resource);
+ free(cb_container);
return IOTCON_ERROR_DBUS;
}
resource->observe_sub_id = sub_id;
API int iotcon_observer_stop(iotcon_client_h resource)
{
- int ret, error_code;
+ int ret;
GError *error = NULL;
GVariant *arg_options;
arg_options, &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_observer_stop_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon-daemon Fail(%d)", ret);
{
unsigned int sub_id;
GError *error = NULL;
- int ret, error_code, signal_number;
+ int ret, signal_number;
icl_found_resource_s *cb_container;
char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
ic_utils_dbus_encode_str(resource_type), signal_number, &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_find_resource_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
RETV_IF(NULL == host, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == resource_types, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == client_handle, IOTCON_ERROR_INVALID_PARAMETER);
resource = calloc(1, sizeof(struct icl_remote_resource));
if (NULL == resource) {
#include "icl-client.h"
#include "icl-repr.h"
#include "icl-payload.h"
+#include "icl-observation.h"
#include "icl-dbus-type.h"
const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types)
}
}
- return g_variant_new("a(qs)", builder);
+ return g_variant_builder_end(&builder);
}
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE("ai"));
- for (node = observers; node; node = node->next)
+ for (node = observers->observers_list; node; node = node->next)
g_variant_builder_add(&builder, "i", GPOINTER_TO_INT(node->data));
return g_variant_builder_end(&builder);
}
-inline unsigned int icl_dbus_generate_signal_number()
+unsigned int icl_dbus_generate_signal_number()
{
static unsigned int i = 0;
}
-int icl_dbus_stop()
+void icl_dbus_stop()
{
if (0 == icl_dbus_count) {
- ERR("dbus not initialized");
- return IOTCON_ERROR_DBUS;
+ WARN("dbus not initialized");
+ return;
}
icl_dbus_count--;
if (0 < icl_dbus_count)
- return IOTCON_ERROR_NONE;
+ return;
DBG("All connection is closed");
g_object_unref(icl_dbus_object);
icl_dbus_object = NULL;
- return IOTCON_ERROR_NONE;
+ return;
}
int icl_dbus_convert_dbus_error(int error);
int icl_dbus_start();
-int icl_dbus_stop();
+void icl_dbus_stop();
#endif /* __IOT_CONNECTIVITY_MANAGER_DBUS_H__ */
API int iotcon_register_device_info(const char *device_name)
{
- int ret, error_code;
+ int ret;
GError *error = NULL;
GVariant *arg_info;
NULL, &error);
if (error) {
ERR("ic_dbus_call_register_device_info_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
g_variant_unref(arg_info);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
{
GError *error = NULL;
unsigned int sub_id;
- int ret, signal_number, error_code;
+ int ret, signal_number;
char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
icl_device_info_s *cb_container;
signal_number, &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_get_device_info_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
_icl_device_info_cb);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
+ free(cb_container);
return IOTCON_ERROR_DBUS;
}
* The length of manufacturer_url should be less than and equal to 32. */
API int iotcon_register_platform_info(iotcon_platform_info_s *platform_info)
{
- int ret, error_code;
+ int ret;
GError *error = NULL;
GVariant *arg_info;
NULL, &error);
if (error) {
ERR("ic_dbus_call_register_platform_info_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
g_variant_unref(arg_info);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
gpointer user_data)
{
char *uri_path;
- iotcon_platform_info_s *info = NULL;
+ iotcon_platform_info_s *info;
icl_platform_info_s *cb_container = user_data;
iotcon_platform_info_cb cb = cb_container->cb;
{
GError *error = NULL;
unsigned int sub_id;
- int ret, signal_number, error_code;
+ int ret, signal_number;
char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
icl_platform_info_s *cb_container;
signal_number, &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_get_platform_info_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
_icl_platform_info_cb);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
+ free(cb_container);
return IOTCON_ERROR_DBUS;
}
#include "iotcon-struct.h"
#include "icl.h"
+#include "icl-observation.h"
+
+API int iotcon_observers_create(iotcon_observers_h *ret_observers)
+{
+ RETV_IF(NULL == ret_observers, IOTCON_ERROR_INVALID_PARAMETER);
+
+ iotcon_observers_h observers = calloc(1, sizeof(struct icl_observers));
+ if (NULL == observers) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ *ret_observers = observers;
+
+ return IOTCON_ERROR_NONE;
+}
+
API void iotcon_observers_destroy(iotcon_observers_h observers)
{
RET_IF(NULL == observers);
- g_list_free(observers);
+ g_list_free(observers->observers_list);
+ free(observers);
}
-/* If you want to make a new list, then you should set observers is NULL. */
-API int iotcon_observers_append(iotcon_observers_h observers, int obs_id,
- iotcon_observers_h *ret_observers)
+API int iotcon_observers_insert(iotcon_observers_h observers, int obs_id)
{
- *ret_observers = g_list_append(observers, GUINT_TO_POINTER(obs_id));
+ RETV_IF(NULL == observers, IOTCON_ERROR_INVALID_PARAMETER);
+
+ observers->observers_list = g_list_append(observers->observers_list,
+ GUINT_TO_POINTER(obs_id));
return IOTCON_ERROR_NONE;
}
-API int iotcon_observers_remove(iotcon_observers_h observers, int obs_id,
- iotcon_observers_h *ret_observers)
+API int iotcon_observers_delete(iotcon_observers_h observers, int obs_id)
{
- *ret_observers = g_list_remove(observers, GUINT_TO_POINTER(obs_id));
+ RETV_IF(NULL == observers, IOTCON_ERROR_INVALID_PARAMETER);
+
+ observers->observers_list = g_list_remove(observers->observers_list,
+ GUINT_TO_POINTER(obs_id));
return IOTCON_ERROR_NONE;
}
--- /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_LIBRARY_OBSERVATION_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_OBSERVATION_H__
+
+#include <glib.h>
+
+struct icl_observers {
+ GList *observers_list;
+};
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_OBSERVATION_H__ */
API int iotcon_options_create(iotcon_options_h *ret_options)
{
- iotcon_options_h options = calloc(1, sizeof(struct icl_options));
+ iotcon_options_h options;
+
+ RETV_IF(NULL == ret_options, IOTCON_ERROR_INVALID_PARAMETER);
+
+ options = calloc(1, sizeof(struct icl_options));
if (NULL == options) {
ERR("calloc() Fail(%d)", errno);
return IOTCON_ERROR_OUT_OF_MEMORY;
API int iotcon_options_delete(iotcon_options_h options, unsigned short id)
{
- gboolean ret;
+ gboolean is_removed;
RETV_IF(NULL == options, 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));
- if (FALSE == ret) {
+ is_removed = g_hash_table_remove(options->hash, GUINT_TO_POINTER(id));
+ if (FALSE == is_removed) {
ERR("g_hash_table_remove() Fail");
return IOTCON_ERROR_INVALID_PARAMETER;
}
}
-API int iotcon_options_lookup(iotcon_options_h options, unsigned short id,
- const char **data)
+API int iotcon_options_lookup(iotcon_options_h options, unsigned short id, char **data)
{
- const char *ret;
+ char *value;
RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == data, IOTCON_ERROR_INVALID_PARAMETER);
- ret = g_hash_table_lookup(options->hash, GUINT_TO_POINTER(id));
- if (NULL == ret)
+ value = g_hash_table_lookup(options->hash, GUINT_TO_POINTER(id));
+ if (NULL == value) {
ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
- *data = ret;
+ *data = value;
return IOTCON_ERROR_NONE;
}
#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_OPTIONS_H__
#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_OPTIONS_H__
+#include <glib.h>
#include "iotcon-struct.h"
struct icl_options {
return NULL;
}
- ret = iotcon_representation_set_state(repr, state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
DBG("repr : %s", g_variant_print(var, FALSE));
g_variant_get(var, "(&siasa{sv}av)", &uri_path, &repr->interfaces,
/* attribute */
_icl_state_from_gvariant(state, repr_gvar);
+ ret = iotcon_representation_set_state(repr, state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ iotcon_state_destroy(state);
+ iotcon_representation_destroy(repr);
+ return NULL;
+ }
+ iotcon_state_destroy(state);
+
/* children */
while (g_variant_iter_loop(children, "v", &child)) {
repr->children = g_list_append(repr->children,
}
g_variant_iter_free(children);
- iotcon_state_destroy(state);
-
return repr;
}
API int iotcon_start_presence(unsigned int time_to_live)
{
- int ret, error_code;
+ int ret;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
&error);
if (error) {
ERR("ic_dbus_call_start_presence_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
API int iotcon_stop_presence(void)
{
FN_CALL;
- int ret, error_code;
+ int ret;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
ic_dbus_call_stop_presence_sync(icl_dbus_get_object(), &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_stop_presence_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
FN_CALL;
GError *error = NULL;
unsigned int sub_id;
- int signal_number, error_code;
+ int signal_number, ret;
char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
icl_presence_s *presence_container;
resource_type, signal_number, &(presence_container->handle), NULL, &error);
if (error) {
ERR("ic_dbus_call_subscribe_presence_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
free(presence_container);
- return error_code;
+ return ret;
}
if (0 == presence_container->handle) {
API int iotcon_unsubscribe_presence(iotcon_presence_h presence)
{
FN_CALL;
- int ret, error_code;
+ int ret;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
&ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_unsubscribe_presence_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
API int iotcon_query_create(iotcon_query_h *ret_query)
{
+ RETV_IF(NULL == ret_query, IOTCON_ERROR_INVALID_PARAMETER);
+
iotcon_query_h query = calloc(1, sizeof(struct icl_query));
if (NULL == query) {
ERR("calloc() Fail(%d)", errno);
API int iotcon_query_delete(iotcon_query_h query, const char *key)
{
- gboolean ret;
+ gboolean is_removed;
int query_len;
char *value;
query_len = strlen(key) + strlen(value) + 2;
- ret = g_hash_table_remove(query->hash, key);
- if (FALSE == ret) {
+ is_removed = g_hash_table_remove(query->hash, key);
+ if (FALSE == is_removed) {
ERR("g_hash_table_remove() Fail");
return IOTCON_ERROR_INVALID_PARAMETER;
}
}
-API int iotcon_query_lookup(iotcon_query_h query, const char *key, const char **data)
+API int iotcon_query_lookup(iotcon_query_h query, const char *key, char **data)
{
- const char *value = NULL;
+ char *value = NULL;
RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == data, IOTCON_ERROR_INVALID_PARAMETER);
value = g_hash_table_lookup(query->hash, key);
- if (NULL == value)
+ if (NULL == value) {
ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
*data = value;
#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_QUERY_H__
#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_QUERY_H__
-#include "iotcon-struct.h"
+#include <glib.h>
/**
* @brief The maximum length which can be held in a query.
int ret;
iotcon_list_h list;
+ RETV_IF(NULL == ret_list, IOTCON_ERROR_INVALID_PARAMETER);
+
if (type < IOTCON_TYPE_INT || IOTCON_TYPE_STATE < type) {
ERR("Invalid Type(%d)", type);
- return IOTCON_ERROR_INVALID_PARAMETER;
+ return IOTCON_ERROR_INVALID_TYPE;
}
ret = _icl_list_create(type, &list);
}
-API int iotcon_list_get_nth_str(iotcon_list_h list, int pos, const char **val)
+API int iotcon_list_get_nth_str(iotcon_list_h list, int pos, char **val)
{
int ret;
- const char *strval;
+ char *strval;
iotcon_value_h value;
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
}
-bool icl_state_dec_ref_count(iotcon_state_h val)
+int icl_state_dec_ref_count(iotcon_state_h val)
{
- bool ret;
-
RETV_IF(NULL == val, -1);
- RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
+ RETVM_IF(val->ref_count <= 0, 0, "Invalid Count(%d)", val->ref_count);
val->ref_count--;
- if (0 == val->ref_count)
- ret = true;
- else
- ret = false;
- return ret;
+ return val->ref_count;
}
errno = 0;
iotcon_state_h state;
+ RETV_IF(NULL == ret_state, IOTCON_ERROR_INVALID_PARAMETER);
+
state = calloc(1, sizeof(struct icl_state_s));
if (NULL == state) {
ERR("calloc() Fail(%d)", errno);
{
RET_IF(NULL == state);
- if (false == icl_state_dec_ref_count(state)) {
- return;
+ if (0 == icl_state_dec_ref_count(state)) {
+ g_hash_table_destroy(state->hash_table);
+ free(state);
}
-
- g_hash_table_destroy(state->hash_table);
- free(state);
}
#include "icl-repr-value.h"
void icl_state_inc_ref_count(iotcon_state_h val);
-bool icl_state_dec_ref_count(iotcon_state_h val);
+int icl_state_dec_ref_count(iotcon_state_h val);
int icl_state_del_value(iotcon_state_h state, const char *key,
iotcon_types_e value_type);
return IOTCON_ERROR_NONE;
}
-int icl_value_get_str(iotcon_value_h value, const char **val)
+int icl_value_get_str(iotcon_value_h value, char **val)
{
icl_basic_s *real = (icl_basic_s*)value;
int icl_value_get_int(iotcon_value_h value, int *val);
int icl_value_get_bool(iotcon_value_h value, bool *val);
int icl_value_get_double(iotcon_value_h value, double *val);
-int icl_value_get_str(iotcon_value_h value, const char **val);
+int icl_value_get_str(iotcon_value_h value, char **val);
int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list);
int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state);
errno = 0;
iotcon_representation_h repr;
+ RETV_IF(NULL == ret_repr, IOTCON_ERROR_INVALID_PARAMETER);
+
repr = calloc(1, sizeof(struct icl_representation_s));
if (NULL == repr) {
ERR("calloc() Fail(%d)", errno);
}
-API int iotcon_representation_get_uri_path(iotcon_representation_h repr, const char **uri_path)
+API int iotcon_representation_get_uri_path(iotcon_representation_h repr, char **uri_path)
{
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_NONE;
}
-API int iotcon_representation_set_uri_path(iotcon_representation_h repr, const char *uri_path)
+API int iotcon_representation_set_uri_path(iotcon_representation_h repr,
+ const char *uri_path)
{
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
API int iotcon_resource_types_create(iotcon_resource_types_h *ret_types)
{
- iotcon_resource_types_h types = calloc(1, sizeof(struct icl_resource_types));
+ iotcon_resource_types_h types;
+
+ RETV_IF(NULL == ret_types, IOTCON_ERROR_INVALID_PARAMETER);
+
+ types = calloc(1, sizeof(struct icl_resource_types));
if (NULL == types) {
ERR("calloc() Fail(%d)", errno);
return IOTCON_ERROR_OUT_OF_MEMORY;
static bool _icl_resource_types_duplicate_check(iotcon_resource_types_h types,
const char *type)
{
- GList *ret = NULL;
+ GList *found_node = NULL;
RETV_IF(NULL == types, false);
RETV_IF(NULL == type, false);
- ret = g_list_find_custom(types->type_list, type, _icl_resource_types_strcmp);
- if (NULL == ret)
+ found_node = g_list_find_custom(types->type_list, type, _icl_resource_types_strcmp);
+ if (NULL == found_node)
return false;
return true;
#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_TYPES_H__
#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_TYPES_H__
+#include <glib.h>
#include "iotcon-struct.h"
#include "icl-query.h"
GError *error = NULL;
const gchar **types;
iotcon_resource_h resource;
- int signal_number, error_code;
+ int signal_number, ret;
char sig_name[IC_DBUS_SIGNAL_LENGTH];
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
RETVM_IF(ICL_URI_PATH_LENGTH_MAX < strlen(uri_path),
IOTCON_ERROR_INVALID_PARAMETER, "Invalid uri_path(%s)", uri_path);
properties, signal_number, &(resource->handle), NULL, &error);
if (error) {
ERR("ic_dbus_call_register_resource_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
free(types);
free(resource);
- return error_code;
+ return ret;
}
free(types);
_icl_request_handler);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
+ iotcon_resource_types_destroy(res_types);
+ free(resource->uri_path);
free(resource);
return IOTCON_ERROR_DBUS;
}
API int iotcon_unregister_resource(iotcon_resource_h resource)
{
FN_CALL;
- int ret, error_code;
+ int ret;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
return IOTCON_ERROR_NONE;
}
- ic_dbus_call_unregister_resource_sync(icl_dbus_get_object(), resource->handle,
- &ret, NULL, &error);
+ ic_dbus_call_unregister_resource_sync(icl_dbus_get_object(), resource->handle, NULL,
+ &error);
if (error) {
ERR("ic_dbus_call_unregister_resource_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
resource->handle = 0;
icl_dbus_unsubscribe_signal(resource->sub_id);
API int iotcon_resource_bind_interface(iotcon_resource_h resource, int iface)
{
FN_CALL;
- int ret, error_code;
+ int ret;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
iface, &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_bind_interface_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
API int iotcon_resource_bind_type(iotcon_resource_h resource, const char *resource_type)
{
FN_CALL;
- int ret, error_code;
+ int ret;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
&ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_bind_type_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_h child)
{
GError *error = NULL;
- int i, ret, error_code;
+ int i, ret;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
child->handle, &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_bind_resource_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_h child)
{
GError *error = NULL;
- int i, ret, error_code;
+ int i, ret;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
child->handle, &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_unbind_resource_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
iotcon_notimsg_h msg;
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == notimsg_handle, IOTCON_ERROR_INVALID_PARAMETER);
msg = calloc(1, sizeof(struct icl_notify_msg));
if (NULL == msg) {
API int iotcon_notify_list_of_observers(iotcon_resource_h resource, iotcon_notimsg_h msg,
iotcon_observers_h observers)
{
- int ret, error_code;
+ int ret;
GError *error = NULL;
GVariant *noti_msg;
GVariant *obs;
noti_msg, obs, &ret, NULL, &error);
if (error) {
ERR("ic_dbus_call_notify_list_of_observers_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
g_variant_unref(obs);
g_variant_unref(noti_msg);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
API int iotcon_resource_notify_all(iotcon_resource_h resource)
{
- int ret, error_code;
+ int ret;
GError *error = NULL;
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
&error);
if (error) {
ERR("ic_dbus_call_notify_all_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
{
FN_CALL;
- RETV_IF(NULL == request, TIZEN_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER);
iotcon_response_h resp = calloc(1, sizeof(struct icl_resource_response));
if (NULL == resp) {
API int iotcon_response_send(iotcon_response_h resp)
{
FN_CALL;
- int ret, error_code;
+ int ret;
GError *error = NULL;
GVariant *arg_response;
&error);
if (error) {
ERR("ic_dbus_call_send_response_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
g_variant_unref(arg_response);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
}
-API int iotcon_close(void)
+API void iotcon_close(void)
{
- int ret;
-
- ret = icl_dbus_stop();
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_dbus_stop() Fail(%d)", ret);
-
- return ret;
+ icl_dbus_stop();
}
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
* @see iotcon_representation_destroy()
*/
* @retval iotcon_representation_h Success
* @retval NULL Failure
*/
-int iotcon_representation_clone(const iotcon_representation_h src, iotcon_representation_h *dest);
+int iotcon_representation_clone(const iotcon_representation_h src,
+ iotcon_representation_h *dest);
/**
* @ingroup CAPI_IOT_CONNECTIVITY_MODULE
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_representation_set_uri_path(iotcon_representation_h repr, const char *uri_path);
+int iotcon_representation_set_uri_path(iotcon_representation_h repr,
+ const char *uri_path);
/**
* @brief Gets an URI path from the representation.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_representation_get_uri_path(iotcon_representation_h repr, const char **uri_path);
+int iotcon_representation_get_uri_path(iotcon_representation_h repr, char **uri_path);
/**
* @ingroup CAPI_IOT_CONNECTIVITY_MODULE
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_representation_set_resource_types(iotcon_representation_h repr, iotcon_resource_types_h types);
+int iotcon_representation_set_resource_types(iotcon_representation_h repr,
+ iotcon_resource_types_h types);
/**
* @brief Gets list of resource type from the representation.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_representation_get_resource_types(iotcon_representation_h repr, iotcon_resource_types_h *types);
+int iotcon_representation_get_resource_types(iotcon_representation_h repr,
+ iotcon_resource_types_h *types);
/**
* @brief Sets interfaces to the representation.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr, int ifaces);
+int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
+ int ifaces);
/**
* @brief Gets resource interfaces from the representation.
* @retval #IOTCON_INTERFACE_NONE Not set
* @retval Bitwise OR value which consists of iotcon_interface_e items
*/
-int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr, int *ifaces);
+int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
+ int *ifaces);
/**
* @brief Sets a new state handle into the representation.
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
* @see iotcon_state_destroy()
*/
*
* @see iotcon_children_cb()
*/
-int iotcon_representation_foreach_children(iotcon_representation_h parent, iotcon_children_cb cb,
- void *user_data);
+int iotcon_representation_foreach_children(iotcon_representation_h parent,
+ iotcon_children_cb cb, void *user_data);
/**
* @brief Gets the number of children representation in the parent representation
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_representation_get_children_count(iotcon_representation_h parent, unsigned int *count);
+int iotcon_representation_get_children_count(iotcon_representation_h parent,
+ unsigned int *count);
/**
* @brief Gets the child representation at the given position.
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_NO_DATA No data available
*/
-int iotcon_representation_get_nth_child(iotcon_representation_h parent, int pos, iotcon_representation_h *child);
+int iotcon_representation_get_nth_child(iotcon_representation_h parent, int pos,
+ iotcon_representation_h *child);
/**
* @brief Specifies the type of function passed to iotcon_state_foreach()
* @param[in] type The type of list
* @param[out] list A newly allocated list handle
*
- * @return A newly allocated list handle, otherwise NULL on failure.
- * @retval iotcon_list_h Success
- * @retval NULL Failure
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
int iotcon_list_create(iotcon_types_e type, iotcon_list_h *list);
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_REPRESENTATION Representation errors
*/
-int iotcon_list_get_nth_str(iotcon_list_h list, int pos, const char **val);
+int iotcon_list_get_nth_str(iotcon_list_h list, int pos, char **val);
/**
* @brief Gets the list value at the given position.
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
* @see iotcon_options_destroy()
* @see iotcon_options_insert()
* @see iotcon_options_insert()
* @see iotcon_options_delete()
*/
-int iotcon_options_lookup(iotcon_options_h options, unsigned short id, const char **data);
+int iotcon_options_lookup(iotcon_options_h options, unsigned short id, char **data);
/**
* @brief Specifies the type of function passed to iotcon_options_foreach()
* @see iotcon_query_insert()
* @see iotcon_query_delete()
*/
-int iotcon_query_lookup(iotcon_query_h query, const char *key, const char **data);
+int iotcon_query_lookup(iotcon_query_h query, const char *key, char **data);
/**
* @brief Specifies the type of function passed to iotcon_query_foreach()
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
* @see iotcon_resource_types_destroy()
* @see iotcon_resource_types_insert()
*
* @since_tizen 3.0
*/
-typedef void* iotcon_observers_h;
+typedef struct icl_observers* iotcon_observers_h;
+
+/**
+ * @brief Creates a new observers handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[out] ret_observers A newly allocated list of observers handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see iotcon_observers_destroy()
+ * @see iotcon_observers_insert()
+ * @see iotcon_observers_delete()
+ */
+int iotcon_observers_create(iotcon_observers_h *ret_observers);
/**
* @brief Free a observers handle.
*
* @return void
*
- * @see iotcon_observers_append()
- * @see iotcon_observers_remove()
+ * @see iotcon_observers_create()
+ * @see iotcon_observers_insert()
+ * @see iotcon_observers_delete()
*/
void iotcon_observers_destroy(iotcon_observers_h observers);
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
+ * @see iotcon_observers_create()
* @see iotcon_observers_destroy()
- * @see iotcon_observers_remove()
+ * @see iotcon_observers_delete()
*/
-int iotcon_observers_append(iotcon_observers_h observers, int obs_id,
- iotcon_observers_h *ret_observers);
+int iotcon_observers_insert(iotcon_observers_h observers, int obs_id);
/**
* @brief Remove id from the observers.
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
+ * @see iotcon_observers_create()
* @see iotcon_observers_destroy()
- * @see iotcon_observers_append()
+ * @see iotcon_observers_insert()
*/
-int iotcon_observers_remove(iotcon_observers_h observers, int obs_id,
- iotcon_observers_h *ret_observers);
+int iotcon_observers_delete(iotcon_observers_h observers, int obs_id);
/**
* @brief The handle of resource.
* @see iotcon_request_get_observer_action()
* @see iotcon_request_get_observer_id()
*/
-int iotcon_request_get_representation(iotcon_request_h request, iotcon_representation_h *repr);
+int iotcon_request_get_representation(iotcon_request_h request,
+ iotcon_representation_h *repr);
/**
* @brief Get types of the request
* @see iotcon_response_create()
* @see iotcon_response_destroy()
*/
-int iotcon_response_set_representation(iotcon_response_h resp, iotcon_representation_h repr);
+int iotcon_response_set_representation(iotcon_response_h resp,
+ iotcon_representation_h repr);
/**
* @brief Sets header options into the response
*
* @see iotcon_open()
*/
-int iotcon_close(void);
+void iotcon_close(void);
/**
* @brief Specifies the type of function passed to iotcon_add_connection_changed_cb() and
* @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
* @retval #IOTCON_ERROR_DBUS Dbus errors
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post When the resource receive CRUD request, iotcon_request_handler_cb() will be called.
*
* @privlevel public
* @privilege %http://tizen.org/privilege/internet
*
+ * @remarks When a normal variable is used, there are only dbus error and permission\n
+ * denied error. If the errors of this API are not handled, then you must check\n
+ * whether dbus is running and an application have the privileges for the API.
+ *
* @param[in] resource_handle The handle of the resource to be unregistered
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_register_resource()
* @see iotcon_resource_bind_interface()
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
* @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_resource_bind_type(iotcon_resource_h resource_handle, const char *resource_type);
+int iotcon_resource_bind_type(iotcon_resource_h resource_handle,
+ const char *resource_type);
/**
* @brief Binds a request handler to the resource
* @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_resource_bind_request_handler(iotcon_resource_h resource, iotcon_request_handler_cb cb);
+int iotcon_resource_bind_request_handler(iotcon_resource_h resource,
+ iotcon_request_handler_cb cb);
/**
* @brief Binds a child resource into the parent resource.
* @retval #IOTCON_ERROR_ALREADY Already done
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
* @see iotcon_resource_unbind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_resource_bind_child_resource(iotcon_resource_h parent, iotcon_resource_h child);
+int iotcon_resource_bind_child_resource(iotcon_resource_h parent,
+ iotcon_resource_h child);
/**
* @brief Unbinds a child resource from the parent resource.
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_register_resource()
* @see iotcon_unregister_resource()
* @see iotcon_resource_bind_child_resource()
* @see iotcon_request_handler_cb()
*/
-int iotcon_resource_unbind_child_resource(iotcon_resource_h parent, iotcon_resource_h child);
+int iotcon_resource_unbind_child_resource(iotcon_resource_h parent,
+ iotcon_resource_h child);
/**
* @brief Register device information in a server.
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post iotcon_device_info_cb() will be called when success on getting device information.
*
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post iotcon_platform_info_cb() will be called when success on getting device information.
*
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_stop_presence()
* @see iotcon_subscribe_presence()
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_start_presence()
* @see iotcon_subscribe_presence()
* @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
* @retval #IOTCON_ERROR_DBUS Dbus errors
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post When the resource receive presence, iotcon_presence_cb() will be called.
*
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_start_presence()
* @see iotcon_stop_presence()
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post When the resource is found, iotcon_found_resource_cb() will be called.
*
* @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
* @retval #IOTCON_ERROR_DBUS Dbus errors
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post When the @a resource receive notification message, iotcon_on_observe_cb() will be called.
*
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_on_observe_cb()
* @see iotcon_observer_start()
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*/
int iotcon_response_send(iotcon_response_h resp);
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_REPRESENTATION Representation error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_on_observe_cb()
* @see iotcon_observer_start()
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus error
* @retval #IOTCON_ERROR_SYSTEM System error
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_on_observe_cb()
* @see iotcon_observer_start()
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus errors
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post When the client receive get response, iotcon_on_cru_cb() will be called.
*
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus errors
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post When the client receive put response, iotcon_on_cru_cb() will be called.
*
* @see iotcon_get()
* @see iotcon_post()
*/
-int iotcon_put(iotcon_client_h resource, iotcon_representation_h repr, iotcon_query_h query,
- iotcon_on_cru_cb cb, void *user_data);
+int iotcon_put(iotcon_client_h resource, iotcon_representation_h repr,
+ iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data);
/**
* @brief Posts on a resource
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus errors
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post When the client receive post response, iotcon_on_cru_cb() will be called.
*
* @see iotcon_get()
* @see iotcon_put()
*/
-int iotcon_post(iotcon_client_h resource, iotcon_representation_h repr, iotcon_query_h query,
- iotcon_on_cru_cb cb, void *user_data);
+int iotcon_post(iotcon_client_h resource, iotcon_representation_h repr,
+ iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data);
/**
* @brief Specifies the type of function passed to iotcon_delete()
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_DBUS Dbus errors
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @post When the client receive delete response, iotcon_on_delete_cb() will be called.
*
#include <iotcon.h>
#include "test.h"
-static const char* const door_uri_path = "/a/door";
static char *door_resource_sid;
+static GList *resource_sid_list;
+
+static const char* const door_uri_path = "/a/door";
static void _on_observe(iotcon_client_h resource,
iotcon_representation_h recv_repr,
static void _on_delete(iotcon_client_h resource, iotcon_options_h header_options,
int response_result, void *user_data)
{
+ int ret;
iotcon_client_h door_resource = user_data;
RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result
/* delete callback operations */
- iotcon_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL, _on_observe, NULL);
+ ret = iotcon_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL, _on_observe,
+ NULL);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("iotcon_observer_start() Fail(%d)", ret);
+
iotcon_client_destroy(door_resource);
}
static void _on_post(iotcon_client_h resource, iotcon_representation_h recv_repr,
iotcon_options_h header_options, int response_result, void *user_data)
{
- int ret;
- int ifaces = 0;
+ int ret, ifaces = 0;
iotcon_state_h recv_state;
char *host, *created_uri_path;
iotcon_resource_types_h types = NULL;
"_on_post Response error(%d)", response_result);
INFO("POST request was successful");
- iotcon_representation_get_state(recv_repr, &recv_state);
- iotcon_state_get_str(recv_state, "createduripath", &created_uri_path);
-
- if (NULL == created_uri_path) {
- ERR("created_uri_path is NULL");
+ ret = iotcon_representation_get_state(recv_repr, &recv_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_get_state() Fail(%d)", ret);
return;
}
+ ret = iotcon_state_get_str(recv_state, "createduripath", &created_uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_str() Fail(%d)", ret);
+ return;
+ }
DBG("New resource created : %s", created_uri_path);
ret = iotcon_client_get_host(resource, &host);
return;
}
- iotcon_delete(new_door_resource, _on_delete, door_resource);
+ ret = iotcon_delete(new_door_resource, _on_delete, door_resource);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_delete() Fail(%d)", ret);
+ iotcon_client_destroy(door_resource);
+ iotcon_client_destroy(new_door_resource);
+ return;
+ }
iotcon_client_destroy(new_door_resource);
}
}
/* send POST request */
- iotcon_post(resource, send_repr, NULL, _on_post, NULL);
+ ret = iotcon_post(resource, send_repr, NULL, _on_post, NULL);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("iotcon_post() Fail(%d)", ret);
iotcon_representation_destroy(send_repr);
}
response_result);
INFO("GET request was successful");
- iotcon_representation_get_state(recv_repr, &recv_state);
- iotcon_state_get_bool(recv_state, "opened", &opened);
+ ret = iotcon_representation_get_state(recv_repr, &recv_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ return;
+ }
+
+ ret = iotcon_state_get_bool(recv_state, "opened", &opened);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ return;
+ }
ret = iotcon_representation_create(&send_repr);
if (IOTCON_ERROR_NONE != ret) {
return;
}
- iotcon_state_set_bool(send_state, "opened", true);
+ ret = iotcon_state_set_bool(send_state, "opened", true);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_bool() Fail(%d)", ret);
+ iotcon_state_destroy(send_state);
+ iotcon_representation_destroy(send_repr);
+ return;
+ }
+
+ ret = iotcon_representation_set_state(send_repr, send_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ iotcon_state_destroy(send_state);
+ iotcon_representation_destroy(send_repr);
+ return;
+ }
- iotcon_representation_set_state(send_repr, send_state);
+ iotcon_state_destroy(send_state);
/* send PUT request */
- iotcon_put(resource, send_repr, NULL, _on_put, NULL);
+ ret = iotcon_put(resource, send_repr, NULL, _on_put, NULL);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("iotcon_put() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
iotcon_representation_destroy(send_repr);
}
INFO("host_address : %s", host_address);
}
+static int _sid_compare(const void *a, const void *b)
+{
+ return strcmp(a, b);
+}
+
static void _found_resource(iotcon_client_h resource, void *user_data)
{
int ret;
- char *resource_sid = NULL;
- char *resource_host = NULL;
- char *resource_uri_path = NULL;
+ GList *node;
+ char *resource_sid;
+ char *resource_host;
+ char *resource_uri_path;
+ int resource_interfaces;
iotcon_presence_h presence_handle;
- iotcon_resource_types_h resource_types = NULL;
- int resource_interfaces = 0;
+ iotcon_resource_types_h resource_types;
if (NULL == resource)
return;
}
DBG("[%s] resource server id : %s", resource_uri_path, resource_sid);
- if (door_resource_sid && TEST_STR_EQUAL == strcmp(door_resource_sid, resource_sid)
- && TEST_STR_EQUAL == strcmp(door_uri_path, resource_uri_path)) {
+ node = g_list_find_custom(resource_sid_list, resource_sid, _sid_compare);
+
+ if (node && TEST_STR_EQUAL == strcmp(door_uri_path, resource_uri_path)) {
DBG("uri_path \"%s\" already found. skip !", resource_uri_path);
return;
}
door_resource_sid = strdup(resource_sid);
+ if (NULL == door_resource_sid) {
+ ERR("strdup(door_resource_sid) Fail");
+ return;
+ }
+
+ resource_sid_list = g_list_append(resource_sid_list, door_resource_sid);
/* get the resource host address */
ret = iotcon_client_get_host(resource, &resource_host);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_get_host() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
+ free(door_resource_sid);
return;
}
DBG("[%s] resource host : %s", resource_uri_path, resource_host);
ret = iotcon_client_get_interfaces(resource, &resource_interfaces);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_get_interfaces() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
+ free(door_resource_sid);
return;
}
if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
ret = iotcon_client_get_types(resource, &resource_types);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_get_types() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
+ free(door_resource_sid);
return;
}
resource_uri_path);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
+ free(door_resource_sid);
return;
}
ret = iotcon_query_create(&query);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_query_create() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
+ free(door_resource_sid);
return;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_query_insert() Fail(%d)", ret);
iotcon_query_destroy(query);
+ resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
+ free(door_resource_sid);
return;
}
/* send GET Request */
- iotcon_get(resource, query, _on_get, NULL);
+ ret = iotcon_get(resource, query, _on_get, NULL);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("iotcon_get() Fail(%d)", ret);
+
iotcon_query_destroy(query);
}
+
+ resource_sid_list = g_list_remove(resource_sid_list, door_resource_sid);
+ free(door_resource_sid);
}
int main(int argc, char **argv)
{
FN_CALL;
+ int ret;
GMainLoop *loop;
+
loop = g_main_loop_new(NULL, FALSE);
/* iotcon open */
- iotcon_open();
+ ret = iotcon_open();
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_open() Fail(%d)", ret);
+ return -1;
+ }
/* find door typed resources */
- iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.door", &_found_resource, NULL);
+ ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.door", &_found_resource,
+ NULL);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_find_resource() Fail(%d)", ret);
+ iotcon_close();
+ return -1;
+ }
g_main_loop_run(loop);
g_main_loop_unref(loop);
- free(door_resource_sid);
+ g_list_free_full(resource_sid_list, free);
/* iotcon close */
iotcon_close();
bool state;
char *uri_path;
char *type;
+ int ifaces;
+ int properties;
+ iotcon_resource_h handle;
+ iotcon_observers_h observers;
iotcon_representation_h repr;
} door_resource_s;
-static door_resource_s my_door;
-static bool resource_created = false;
-
-static iotcon_observers_h observers = NULL;
+static bool resource_created;
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data);
-static int _set_door_resource()
+static int _set_door_resource(door_resource_s *door)
{
- my_door.state = false;
- my_door.type = strdup("core.door");
- if (NULL == my_door.type) {
+ int ret;
+
+ door->state = false;
+
+ door->uri_path = strdup("/a/door");
+ if (NULL == door->uri_path) {
+ ERR("strdup(/a/door) Fail");
+ return -1;
+ }
+
+ door->type = strdup("core.door");
+ if (NULL == door->type) {
ERR("strdup(core.door) Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
+ free(door->uri_path);
+ return -1;
}
- my_door.uri_path = strdup("/a/door");
- if (NULL == my_door.uri_path) {
- ERR("strdup(/a/door) Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
+ door->ifaces = IOTCON_INTERFACE_DEFAULT;
+ door->properties = IOTCON_DISCOVERABLE;
+
+ ret = iotcon_observers_create(&door->observers);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_observers_create() Fail");
+ free(door->type);
+ free(door->uri_path);
+ return -1;
}
- return IOTCON_ERROR_NONE;
+ return 0;
+}
+
+static void _free_door_resource(door_resource_s *door)
+{
+ iotcon_observers_destroy(door->observers);
+ free(door->type);
+ free(door->uri_path);
}
-static void _check_door_state()
+static void _check_door_state(door_resource_s door)
{
- if (false == my_door.state)
+ if (false == door.state)
INFO("[Door] closed.");
else
INFO("[Door] opened.");
}
-static iotcon_resource_h _create_door_resource(char *uri_path,
- iotcon_interface_e interfaces, iotcon_resource_property_e properties)
+static iotcon_resource_h _create_door_resource(char *uri_path, char *type, int ifaces,
+ int properties, void *user_data)
{
int ret;
iotcon_resource_h handle;
return NULL;
}
- ret = iotcon_resource_types_insert(resource_types, my_door.type);
+ ret = iotcon_resource_types_insert(resource_types, type);
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_destroy(resource_types);
ERR("iotcon_resource_types_insert() Fail(%d)", ret);
}
/* register door resource */
- ret = iotcon_register_resource(uri_path, resource_types,
- interfaces, properties, _request_handler, NULL, &handle);
+ ret = iotcon_register_resource(uri_path, resource_types, ifaces, properties,
+ _request_handler, user_data, &handle);
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_destroy(resource_types);
ERR("iotcon_register_resource() Fail");
return handle;
}
-static void _send_response(iotcon_response_h response, iotcon_representation_h repr,
+static int _send_response(iotcon_response_h response, iotcon_representation_h repr,
iotcon_response_result_e result)
{
- iotcon_response_set_result(response, result);
- iotcon_response_set_representation(response, repr);
+ int ret;
+
+ ret = iotcon_response_set_result(response, result);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_set_result() Fail(%d)", ret);
+ return -1;
+ }
+
+ ret = iotcon_response_set_representation(response, repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_set_representation() Fail(%d)", ret);
+ return -1;
+ }
/* send Representation to the client */
- iotcon_response_send(response);
+ ret = iotcon_response_send(response);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_send() Fail(%d)", ret);
+ return -1;
+ }
+
+ return 0;
}
-static void _request_handler_get(iotcon_response_h response)
+static void _request_handler_get(door_resource_s *door, iotcon_response_h response)
{
int ret;
iotcon_representation_h resp_repr;
ret = iotcon_state_create(&resp_state);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_state_create() Fail(%d)", ret);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
+
+ ret = iotcon_representation_set_uri_path(resp_repr, door->uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
+ iotcon_state_destroy(resp_state);
+ iotcon_representation_destroy(resp_repr);
return;
}
- iotcon_representation_set_uri_path(resp_repr, my_door.uri_path);
- iotcon_state_set_bool(resp_state, "opened", my_door.state);
+ ret = iotcon_state_set_bool(resp_state, "opened", door->state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_bool() Fail(%d)", ret);
+ iotcon_state_destroy(resp_state);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
+
+ ret = iotcon_representation_set_state(resp_repr, resp_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ iotcon_state_destroy(resp_state);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
- iotcon_representation_set_state(resp_repr, resp_state);
+ iotcon_state_destroy(resp_state);
- _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
+ ret = _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
+ if (0 != ret)
+ ERR("_send_response() Fail(%d)", ret);
iotcon_representation_destroy(resp_repr);
}
-static void _request_handler_put(iotcon_request_h request, iotcon_response_h response)
+static void _request_handler_put(door_resource_s *door, iotcon_request_h request,
+ iotcon_response_h response)
{
- bool bval;
int ret;
+ bool bval;
iotcon_representation_h req_repr, resp_repr;
iotcon_state_h req_state, resp_state;;
INFO("PUT request");
return;
}
- iotcon_representation_get_state(req_repr, &req_state);
+ ret = iotcon_representation_get_state(req_repr, &req_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ return;
+ }
+
+ ret = iotcon_state_get_bool(req_state, "opened", &bval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ return;
+ }
- iotcon_state_get_bool(req_state, "opened", &bval);
- my_door.state = bval;
+ door->state = bval;
- _check_door_state();
+ _check_door_state(*door);
ret = iotcon_representation_create(&resp_repr);
if (IOTCON_ERROR_NONE != ret) {
return;
}
+ ret = iotcon_representation_set_uri_path(resp_repr, door->uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
+
ret = iotcon_state_create(&resp_state);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_state_create() Fail(%d)", ret);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
+
+ ret = iotcon_state_set_bool(resp_state, "opened", door->state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_bool() Fail(%d)", ret);
+ iotcon_state_destroy(resp_state);
+ iotcon_representation_destroy(resp_repr);
return;
}
- iotcon_representation_set_uri_path(resp_repr, my_door.uri_path);
- iotcon_state_set_bool(resp_state, "opened", my_door.state);
+ ret = iotcon_representation_set_state(resp_repr, resp_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ iotcon_state_destroy(resp_state);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
- iotcon_representation_set_state(resp_repr, resp_state);
+ iotcon_state_destroy(resp_state);
- _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
+ ret = _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
+ if (0 != ret)
+ ERR("_send_response() Fail(%d)", ret);
iotcon_representation_destroy(resp_repr);
}
static gboolean _notifier(gpointer user_data)
{
int ret;
- iotcon_representation_h repr;
+ static int i = 0;
iotcon_notimsg_h msg;
+ door_resource_s *door;
+ iotcon_representation_h repr;
- static int i = 0;
- if ((5 == i++) || !(observers))
+ door = user_data;
+
+ if ((5 == i++) || !(door->observers))
return FALSE;
INFO("NOTIFY!");
ret = iotcon_notimsg_create(repr, IOTCON_INTERFACE_DEFAULT, &msg);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_notimsg_create() Fail(%d)", ret);
+ iotcon_representation_destroy(repr);
return FALSE;
}
- iotcon_notify_list_of_observers(user_data, msg, observers);
+ ret = iotcon_notify_list_of_observers(door->handle, msg, door->observers);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_notify_list_of_observers() Fail(%d)", ret);
+ iotcon_notimsg_destroy(msg);
+ iotcon_representation_destroy(repr);
+ return FALSE;
+ }
iotcon_notimsg_destroy(msg);
iotcon_representation_destroy(repr);
return TRUE;
}
-static void _request_handler_post(iotcon_resource_h resource, iotcon_response_h response)
+static void _request_handler_post(door_resource_s *door, iotcon_response_h response)
{
int ret;
iotcon_state_h resp_state;
return;
}
- new_door_handle = _create_door_resource("/a/door1", IOTCON_INTERFACE_DEFAULT,
- (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE));
+ new_door_handle = _create_door_resource("/a/door1", door->type,
+ IOTCON_INTERFACE_DEFAULT, (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), NULL);
if (NULL == new_door_handle) {
ERR("_create_door_resource() Fail");
return;
ret = iotcon_state_create(&resp_state);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_state_create() Fail(%d)", ret);
+ iotcon_representation_destroy(resp_repr);
return;
}
- iotcon_state_set_str(resp_state, "createduripath", "/a/door1");
+ ret = iotcon_state_set_str(resp_state, "createduripath", "/a/door1");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_str() Fail(%d)", ret);
+ iotcon_state_destroy(resp_state);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
+
+ ret = iotcon_representation_set_state(resp_repr, resp_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ iotcon_state_destroy(resp_state);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
- iotcon_representation_set_state(resp_repr, resp_state);
+ iotcon_state_destroy(resp_state);
- _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_RESOURCE_CREATED);
+ ret = _send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_RESOURCE_CREATED);
+ if (0 != ret) {
+ ERR("_send_response() Fail(%d)", ret);
+ iotcon_representation_destroy(resp_repr);
+ return;
+ }
iotcon_representation_destroy(resp_repr);
/* add observe */
- g_timeout_add_seconds(5, _notifier, resource);
+ g_timeout_add_seconds(5, _notifier, door);
}
static void _request_handler_delete(iotcon_resource_h resource,
iotcon_response_result_e result = IOTCON_RESPONSE_RESULT_OK;
INFO("DELETE request");
- iotcon_unregister_resource(resource);
- ret = iotcon_representation_create(&resp_repr);
+ ret = iotcon_unregister_resource(resource);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
+ ERR("iotcon_unregiser_resource() Fail(%d)", ret);
return;
}
result = IOTCON_RESPONSE_RESULT_RESOURCE_DELETED;
- _send_response(response, resp_repr, result);
+ ret = iotcon_representation_create(&resp_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return;
+ }
+
+ ret = _send_response(response, resp_repr, result);
+ if (0 != ret)
+ ERR("_send_response() Fail(%d)", ret);
iotcon_representation_destroy(resp_repr);
}
static int _query_cb(const char *key, const char *value, void *user_data)
{
- INFO("key : %s", key);
- INFO("value : %s", value);
+ INFO("key : %s, value : %s", key, value);
return IOTCON_FUNC_CONTINUE;
}
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data)
{
+ door_resource_s *door;
iotcon_query_h query;
iotcon_response_h response = NULL;
int ret, types, observer_id, observer_action;
RET_IF(NULL == request);
+ door = user_data;
+
ret = iotcon_request_get_query(request, &query);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_query() Fail(%d)", ret);
}
if (IOTCON_REQUEST_GET & types)
- _request_handler_get(response);
+ _request_handler_get(door, response);
else if (IOTCON_REQUEST_PUT & types)
- _request_handler_put(request, response);
+ _request_handler_put(door, request, response);
else if (IOTCON_REQUEST_POST & types)
- _request_handler_post(resource, response);
+ _request_handler_post(door, response);
else if (IOTCON_REQUEST_DELETE & types)
_request_handler_delete(resource, response);
ERR("iotcon_request_get_observer_id() Fail(%d)", ret);
return;
}
- ret = iotcon_observers_append(observers, observer_id, &observers);
+ ret = iotcon_observers_insert(door->observers, observer_id);
} else if (IOTCON_OBSERVE_DEREGISTER == observer_action) {
ret = iotcon_request_get_observer_id(request, &observer_id);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_observer_id() Fail(%d)", ret);
return;
}
- ret = iotcon_observers_remove(observers, observer_id, &observers);
+ ret = iotcon_observers_delete(door->observers, observer_id);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_observers_remove() Fail(%d)", ret);
return;
int main(int argc, char **argv)
{
FN_CALL;
+ int ret;
GMainLoop *loop;
- iotcon_resource_h door_handle;
- iotcon_interface_e door_interfaces = IOTCON_INTERFACE_DEFAULT;
- iotcon_resource_property_e resource_properties = IOTCON_DISCOVERABLE;
- int ret = IOTCON_ERROR_NONE;
+ door_resource_s my_door = {0};
loop = g_main_loop_new(NULL, FALSE);
/* iotcon open */
- iotcon_open();
+ ret = iotcon_open();
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_open() Fail(%d)", ret);
+ return -1;
+ }
/* set local door resource */
- ret = _set_door_resource();
- if (IOTCON_ERROR_NONE != ret) {
+ ret = _set_door_resource(&my_door);
+ if (0 != ret) {
ERR("_set_door_resource() Fail");
+ iotcon_close();
return -1;
}
/* add resource options */
- door_interfaces |= IOTCON_INTERFACE_BATCH;
- resource_properties |= IOTCON_OBSERVABLE;
+ my_door.ifaces |= IOTCON_INTERFACE_BATCH;
+ my_door.properties |= IOTCON_OBSERVABLE;
/* add presence */
g_timeout_add_seconds(10, _presence_timer, NULL);
/* create new door resource */
- door_handle = _create_door_resource("/a/door", door_interfaces, resource_properties);
- if (NULL == door_handle) {
+ my_door.handle = _create_door_resource(my_door.uri_path, my_door.type, my_door.ifaces,
+ my_door.properties, &my_door);
+ if (NULL == my_door.handle) {
ERR("_create_door_resource() Fail");
+ _free_door_resource(&my_door);
+ iotcon_close();
return -1;
}
- _check_door_state();
+ _check_door_state(my_door);
g_main_loop_run(loop);
g_main_loop_unref(loop);
- iotcon_unregister_resource(door_handle);
+ iotcon_unregister_resource(my_door.handle);
+
+ _free_door_resource(&my_door);
/* iotcon close */
iotcon_close();
int main()
{
+ int ret;
GMainLoop *loop;
loop = g_main_loop_new(NULL, FALSE);
/* iotcon open */
- iotcon_open();
+ ret = iotcon_open();
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_open() Fail(%d)", ret);
+ return -1;
+ }
- iotcon_get_platform_info(IOTCON_MULTICAST_ADDRESS, _get_platform_info, NULL);
+ ret = iotcon_get_platform_info(IOTCON_MULTICAST_ADDRESS, _get_platform_info, NULL);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_get_platform_info() Fail(%d)", ret);
+ iotcon_close();
+ return -1;
+ }
- iotcon_get_device_info(IOTCON_MULTICAST_ADDRESS, _get_device_info, NULL);
+ ret = iotcon_get_device_info(IOTCON_MULTICAST_ADDRESS, _get_device_info, NULL);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_get_device_info() Fail(%d)", ret);
+ iotcon_close();
+ return -1;
+ }
g_main_loop_run(loop);
*/
#include <stdlib.h>
+#include <errno.h>
#include <glib.h>
#include <iotcon.h>
#include "test.h"
iotcon_platform_info_s *platform_info = calloc(1, sizeof(iotcon_platform_info_s));
if (NULL == platform_info) {
- ERR("calloc() Fail(%d)", errno);
+ ERR("calloc(platform_info) Fail(%d)", errno);
return -1;
}
loop = g_main_loop_new(NULL, FALSE);
/* iotcon open */
- iotcon_open();
+ ret = iotcon_open();
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_open() Fail(%d)", ret);
+ free(platform_info);
+ return -1;
+ }
ret = iotcon_register_platform_info(platform_info);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_register_platform_info() Fail(%d)", ret);
+ iotcon_close();
free(platform_info);
return -1;
}
ret = iotcon_register_device_info(device_name);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_register_platform_info() Fail(%d)", ret);
+ iotcon_close();
return -1;
}
#include <iotcon.h>
#include "test.h"
-static const char* const room_uri_path = "/a/room";
static char *room_resource_sid;
+static GList *resource_sid_list;
+
+static const char* const room_uri_path = "/a/room";
static int _get_int_list_cb(int pos, const int value, void *user_data)
{
static void _on_get(iotcon_representation_h recv_repr, int response_result)
{
- int i, ret;
- bool is_null;
- iotcon_list_h list;
- const char *uri_path;
+ int i, ret, int_val;
+ bool is_null, bool_val;
+ char *uri_path, *str_val;
+ iotcon_list_h list_val;
iotcon_representation_h child_repr;
iotcon_state_h recv_state, child_state;
unsigned int key_count, children_count;
- RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result,
- "_on_get Response error(%d)", response_result);
+ RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result, "_on_get Response error(%d)",
+ response_result);
INFO("GET request was successful");
DBG("[ parent representation ]");
- iotcon_representation_get_uri_path(recv_repr, &uri_path);
- if (uri_path)
- DBG("uri_path : %s", uri_path);
+ ret = iotcon_representation_get_uri_path(recv_repr, &uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_get_uri_path() Fail(%d)", ret);
+ return;
+ }
+ DBG("uri_path : %s", uri_path);
- iotcon_representation_get_state(recv_repr, &recv_state);
+ ret = iotcon_representation_get_state(recv_repr, &recv_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ return;
+ }
ret = iotcon_state_get_keys_count(recv_state, &key_count);
if (IOTCON_ERROR_NONE != ret) {
}
if (key_count) {
- char *str;
- iotcon_state_get_str(recv_state, "name", &str);
- if (str)
- DBG("name : %s", str);
+ ret = iotcon_state_get_str(recv_state, "name", &str_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_str() Fail(%d)", ret);
+ return;
+ }
+ DBG("name : %s", str_val);
- iotcon_state_get_list(recv_state, "today_temp", &list);
+ ret = iotcon_state_get_list(recv_state, "today_temp", &list_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_list() Fail(%d)", ret);
+ return;
+ }
DBG("today's temperature :");
- iotcon_list_foreach_int(list, _get_int_list_cb, NULL);
+ ret = iotcon_list_foreach_int(list_val, _get_int_list_cb, NULL);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_foreach_int() Fail(%d)", ret);
+ return;
+ }
ret = iotcon_state_is_null(recv_state, "null value", &is_null);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_is_null() Fail(%d)", ret);
+ return;
+ }
+
if (is_null)
DBG("null value is null");
}
for (i = 0; i < children_count; i++) {
DBG("[ child representation ]");
- const char *uri_path;
ret = iotcon_representation_get_nth_child(recv_repr, i, &child_repr);
if (IOTCON_ERROR_NONE != ret) {
continue;
}
- iotcon_representation_get_uri_path(child_repr, &uri_path);
- if (NULL == uri_path)
+ ret = iotcon_representation_get_uri_path(child_repr, &uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_get_uri_path() Fail(%d)", ret);
continue;
-
+ }
DBG("uri_path : %s", uri_path);
- iotcon_representation_get_state(child_repr, &child_state);
+ ret = iotcon_representation_get_state(child_repr, &child_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ continue;
+ }
+
if (TEST_STR_EQUAL == strcmp("/a/light", uri_path)) {
ret = iotcon_state_get_keys_count(child_state, &key_count);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
- return;
+ continue;
}
if (key_count) {
- int brightness;
- iotcon_state_get_int(child_state, "brightness", &brightness);
- DBG("brightness : %d", brightness);
+ ret = iotcon_state_get_int(child_state, "brightness", &int_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_int() Fail(%d)", ret);
+ continue;
+ }
+ DBG("brightness : %d", int_val);
}
} else if (TEST_STR_EQUAL == strcmp("/a/switch", uri_path)) {
ret = iotcon_state_get_keys_count(child_state, &key_count);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
- return;
+ continue;
}
if (key_count) {
- bool bswitch;
- iotcon_state_get_bool(child_state, "switch", &bswitch);
- DBG("switch : %d", bswitch);
+ ret = iotcon_state_get_bool(child_state, "switch", &bool_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ continue;
+ }
+ DBG("switch : %d", bool_val);
}
}
}
return;
}
- iotcon_query_insert(query_params, "if", "oic.if.b");
+ ret = iotcon_query_insert(query_params, "if", "oic.if.b");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_query_insert() Fail(%d)", ret);
+ iotcon_query_destroy(query_params);
+ return;
+ }
/* send GET request again with BATCH interface */
- iotcon_get(resource, query_params, _on_get_2nd, NULL);
+ ret = iotcon_get(resource, query_params, _on_get_2nd, NULL);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_get() Fail(%d)", ret);
+ iotcon_query_destroy(query_params);
+ return;
+ }
iotcon_query_destroy(query_params);
}
return IOTCON_FUNC_CONTINUE;
}
+static int _sid_compare(const void *a, const void *b)
+{
+ return strcmp(a, b);
+}
+
static void _found_resource(iotcon_client_h resource, void *user_data)
{
int ret;
- char *resource_uri_path;
+ GList *node;
+ char *resource_sid;
char *resource_host;
- char *resource_sid = NULL;
- iotcon_resource_types_h resource_types = NULL;
- int resource_interfaces = 0;
+ char *resource_uri_path;
+ int resource_interfaces;
+ iotcon_resource_types_h resource_types;
if (NULL == resource)
return;
}
DBG("[%s] resource server id : %s", resource_uri_path, resource_sid);
- if (room_resource_sid && TEST_STR_EQUAL == strcmp(room_resource_sid, resource_sid)
- && TEST_STR_EQUAL == strcmp(room_uri_path, resource_uri_path)) {
+ node = g_list_find_custom(resource_sid_list, resource_sid, _sid_compare);
+
+ if (node && TEST_STR_EQUAL == strcmp(room_uri_path, resource_uri_path)) {
DBG("uri_path \"%s\" already found. skip !", resource_uri_path);
return;
}
room_resource_sid = strdup(resource_sid);
+ if (NULL == room_resource_sid) {
+ ERR("strdup(room_resource_sid) Fail");
+ return;
+ }
+
+ resource_sid_list = g_list_append(resource_sid_list, room_resource_sid);
/* get the resource host address */
ret = iotcon_client_get_host(resource, &resource_host);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_get_host() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
+ free(room_resource_sid);
return;
}
DBG("[%s] resource host : %s", resource_uri_path, resource_host);
ret = iotcon_client_get_interfaces(resource, &resource_interfaces);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_get_interfaces() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
+ free(room_resource_sid);
return;
}
if (IOTCON_INTERFACE_DEFAULT & resource_interfaces)
ret = iotcon_client_get_types(resource, &resource_types);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_client_get_types() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
+ free(room_resource_sid);
+ return;
+ }
+ ret = iotcon_resource_types_foreach(resource_types, _get_res_type_fn,
+ resource_uri_path);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
+ resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
+ free(room_resource_sid);
return;
}
- iotcon_resource_types_foreach(resource_types, _get_res_type_fn, resource_uri_path);
if (TEST_STR_EQUAL == strcmp(room_uri_path, resource_uri_path)) {
/* send GET request */
- iotcon_get(resource, NULL, _on_get_1st, NULL);
+ ret = iotcon_get(resource, NULL, _on_get_1st, NULL);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("iotcon_get() Fail(%d)", ret);
}
+
+ resource_sid_list = g_list_remove(resource_sid_list, room_resource_sid);
+ free(room_resource_sid);
}
int main(int argc, char **argv)
{
FN_CALL;
+ int ret;
GMainLoop *loop;
+
loop = g_main_loop_new(NULL, FALSE);
/* iotcon open */
- iotcon_open();
+ ret = iotcon_open();
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_open() Fail(%d)", ret);
+ return -1;
+ }
/* find room typed resources */
- iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.room", &_found_resource, NULL);
+ ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.room", &_found_resource,
+ NULL);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_find_resource() Fail(%d)", ret);
+ iotcon_close();
+ return -1;
+ }
g_main_loop_run(loop);
g_main_loop_unref(loop);
+ g_list_free_full(resource_sid_list, free);
+
/* iotcon close */
iotcon_close();
#include <iotcon.h>
#include "test.h"
-static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data);
-
-static void _send_response(iotcon_response_h response, iotcon_representation_h repr,
- iotcon_interface_e interface)
+static int _send_response(iotcon_response_h response, iotcon_representation_h repr,
+ iotcon_interface_e iface)
{
- iotcon_response_set_representation(response, repr);
- iotcon_response_set_interface(response, interface);
- iotcon_response_set_result(response, IOTCON_RESPONSE_RESULT_OK);
+ int ret;
+
+ ret = iotcon_response_set_representation(response, repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_set_representation() Fail(%d)", ret);
+ return -1;
+ }
+
+ ret = iotcon_response_set_interface(response, iface);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_set_interface() Fail(%d)", ret);
+ return -1;
+ }
+
+ ret = iotcon_response_set_result(response, IOTCON_RESPONSE_RESULT_OK);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_set_result() Fail(%d)", ret);
+ return -1;
+ }
/* send Representation to the client */
- iotcon_response_send(response);
+ ret = iotcon_response_send(response);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_response_send() Fail(%d)", ret);
+ return -1;
+ }
+
+ return 0;
}
static void _light_request_handler_get(iotcon_response_h response)
return;
}
- _send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
- iotcon_representation_destroy(resp_repr);
-}
-
-static int _query_foreach_cb(const char *key, const char *value, void *user_data)
-{
- char **interface_str = user_data;
-
- if (TEST_STR_EQUAL == strcmp("if", key))
- *interface_str = (char*)value;
+ ret = _send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
+ if (0 != ret)
+ ERR("_send_response() Fail(%d)", ret);
- return IOTCON_FUNC_CONTINUE;
+ iotcon_representation_destroy(resp_repr);
}
static void _room_request_handler_get(iotcon_request_h request,
iotcon_query_h query;
char *query_str = NULL;
- iotcon_interface_e interface;
+ iotcon_interface_e iface;
INFO("GET request - Room");
return;
}
- iotcon_representation_set_uri_path(room_repr, "/a/room");
- iotcon_state_set_str(room_state, "name", "Michael's Room");
+ ret = iotcon_representation_set_uri_path(room_repr, "/a/room");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ ret = iotcon_state_set_str(room_state, "name", "Michael's Room");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_str() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
/* set null */
- iotcon_state_set_null(room_state, "null value");
+ ret = iotcon_state_set_null(room_state, "null value");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_null() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
ret = iotcon_list_create(IOTCON_TYPE_INT, &temperature_list);
if (IOTCON_ERROR_NONE != ret) {
return;
}
- iotcon_list_insert_int(temperature_list, 22, -1);
- iotcon_list_insert_int(temperature_list, 23, -1);
- iotcon_list_insert_int(temperature_list, 24, -1);
- iotcon_list_insert_int(temperature_list, 25, -1);
- iotcon_list_insert_int(temperature_list, 26, -1);
- iotcon_state_set_list(room_state, "today_temp", temperature_list);
+ ret = iotcon_list_insert_int(temperature_list, 22, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_insert_int() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
- /* Set a room state into room Representation */
- iotcon_representation_set_state(room_repr, room_state);
+ ret = iotcon_list_insert_int(temperature_list, 23, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_insert_int() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ ret = iotcon_list_insert_int(temperature_list, 24, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_insert_int() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ ret = iotcon_list_insert_int(temperature_list, 25, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_insert_int() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ ret = iotcon_list_insert_int(temperature_list, 26, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_insert_int() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
+ ret = iotcon_state_set_list(room_state, "today_temp", temperature_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_list() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
iotcon_list_destroy(temperature_list);
+
+ /* Set a room state into room Representation */
+ ret = iotcon_representation_set_state(room_repr, room_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ iotcon_state_destroy(room_state);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
iotcon_state_destroy(room_state);
/* create a light Representation */
return;
}
+ ret = iotcon_representation_set_uri_path(light_repr, "/a/light");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
+ iotcon_representation_destroy(light_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
/* create a light state */
ret = iotcon_state_create(&light_state);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_state_create() Fail(%d)", ret);
+ iotcon_state_destroy(light_state);
iotcon_representation_destroy(light_repr);
iotcon_representation_destroy(room_repr);
return;
}
- iotcon_representation_set_uri_path(light_repr, "/a/light");
- iotcon_state_set_int(light_state, "brightness", 50);
+ ret = iotcon_state_set_int(light_state, "brightness", 50);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_int() Fail(%d)", ret);
+ iotcon_state_destroy(light_state);
+ iotcon_representation_destroy(light_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
/* Set a light state into light Representation */
- iotcon_representation_set_state(light_repr, light_state);
-
- iotcon_representation_append_child(room_repr, light_repr);
+ ret = iotcon_representation_set_state(light_repr, light_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ iotcon_state_destroy(light_state);
+ iotcon_representation_destroy(light_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
iotcon_state_destroy(light_state);
+
+ ret = iotcon_representation_append_child(room_repr, light_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_append_child() Fail(%d)", ret);
+ iotcon_representation_destroy(light_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
iotcon_representation_destroy(light_repr);
/* create a switch Representation */
return;
}
+ ret = iotcon_representation_set_uri_path(switch_repr, "/a/switch");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
+ iotcon_representation_destroy(switch_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
/* create a switch state */
ret = iotcon_state_create(&switch_state);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_representation_destroy(room_repr);
iotcon_representation_destroy(switch_repr);
+ iotcon_representation_destroy(room_repr);
return;
}
- iotcon_representation_set_uri_path(switch_repr, "/a/switch");
- iotcon_state_set_bool(switch_state, "switch", false);
+ ret = iotcon_state_set_bool(switch_state, "switch", false);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_set_bool() Fail(%d)", ret);
+ iotcon_state_destroy(switch_state);
+ iotcon_representation_destroy(switch_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
/* Set a light state into light Representation */
- iotcon_representation_set_state(switch_repr, switch_state);
- iotcon_representation_append_child(room_repr, switch_repr);
+ ret = iotcon_representation_set_state(switch_repr, switch_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ iotcon_state_destroy(switch_state);
+ iotcon_representation_destroy(switch_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
iotcon_state_destroy(switch_state);
+
+ ret = iotcon_representation_append_child(room_repr, switch_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_append_child() Fail(%d)", ret);
+ iotcon_representation_destroy(switch_repr);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+
iotcon_representation_destroy(switch_repr);
ret = iotcon_request_get_query(request, &query);
iotcon_representation_destroy(room_repr);
return;
}
- if (query)
- iotcon_query_foreach(query, _query_foreach_cb, &query_str);
+
+ if (query) {
+ ret = iotcon_query_lookup(query, "if", &query_str);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_query_lookup() Fail(%d)", ret);
+ iotcon_representation_destroy(room_repr);
+ return;
+ }
+ }
if (query_str && (TEST_STR_EQUAL == strcmp("oic.if.b", query_str))) {
DBG("operation for BATCH interface");
- interface = IOTCON_INTERFACE_BATCH;
+ iface = IOTCON_INTERFACE_BATCH;
} else {
DBG("operation for DEFAULT interface");
- interface = IOTCON_INTERFACE_DEFAULT;
+ iface = IOTCON_INTERFACE_DEFAULT;
}
- _send_response(response, room_repr, interface);
+ ret = _send_response(response, room_repr, iface);
+ if (0 != ret)
+ ERR("_send_response() Fail(%d)", ret);
+
iotcon_representation_destroy(room_repr);
}
/* do PUT operation */
- _send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
+ ret = _send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
+ if (0 != ret)
+ ERR("_send_response() Fail(%d)", ret);
+
iotcon_representation_destroy(resp_repr);
}
/* do POST operation */
- _send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
- iotcon_representation_destroy(resp_repr);
+ ret = _send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
+ if (0 != ret)
+ ERR("_send_response() Fail(%d)", ret);
+ iotcon_representation_destroy(resp_repr);
}
static void _request_handler_delete(iotcon_response_h response)
/* do DELETE operation */
- _send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
- iotcon_representation_destroy(resp_repr);
+ ret = _send_response(response, resp_repr, IOTCON_INTERFACE_DEFAULT);
+ if (0 != ret)
+ ERR("_send_response() Fail(%d)", ret);
+ iotcon_representation_destroy(resp_repr);
}
static void _light_request_handler(iotcon_resource_h resource, iotcon_request_h request,
int ret;
int types;
iotcon_response_h response;
- FN_CALL;
RET_IF(NULL == request);
loop = g_main_loop_new(NULL, FALSE);
/* iotcon open */
- iotcon_open();
+ ret = iotcon_open();
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_open() Fail(%d)", ret);
+ return -1;
+ }
/* register room resource */
ret = iotcon_resource_types_create(&room_rtypes);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_types_create() Fail(%d)", ret);
+ iotcon_close();
+ return -1;
+ }
+ ret = iotcon_resource_types_insert(room_rtypes, "core.room");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_insert(%s) Fail(%d)", "core.room", ret);
+ iotcon_resource_types_destroy(room_rtypes);
+ iotcon_close();
return -1;
}
- iotcon_resource_types_insert(room_rtypes, "core.room");
ret = iotcon_register_resource("/a/room", room_rtypes,
(IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
(IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _room_request_handler,
NULL, &room_handle);
- if (NULL == room_handle) {
- ERR("iotcon_register_resource() Fail");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_register_resource() Fail(%d)", ret);
iotcon_resource_types_destroy(room_rtypes);
+ iotcon_close();
return -1;
}
+ iotcon_resource_types_destroy(room_rtypes);
/* register light resource */
ret = iotcon_resource_types_create(&light_rtypes);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_types_create() Fail(%d)", ret);
- iotcon_resource_types_destroy(room_rtypes);
iotcon_unregister_resource(room_handle);
+ iotcon_close();
+ return -1;
+ }
+ ret = iotcon_resource_types_insert(light_rtypes, "core.light");
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_insert(%s) Fail(%d)", "core.light", ret);
+ iotcon_resource_types_destroy(light_rtypes);
+ iotcon_unregister_resource(room_handle);
+ iotcon_close();
return -1;
}
- iotcon_resource_types_insert(light_rtypes, "core.light");
ret = iotcon_register_resource("/a/light", light_rtypes,
(IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
(IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), _light_request_handler,
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_register_resource() Fail");
iotcon_resource_types_destroy(light_rtypes);
- iotcon_resource_types_destroy(room_rtypes);
iotcon_unregister_resource(room_handle);
+ iotcon_close();
return -1;
}
+ iotcon_resource_types_destroy(light_rtypes);
ret = iotcon_resource_bind_child_resource(room_handle, light_handle);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_bind_child_resource() Fail");
- iotcon_resource_types_destroy(light_rtypes);
iotcon_unregister_resource(light_handle);
- iotcon_resource_types_destroy(room_rtypes);
iotcon_unregister_resource(room_handle);
+ iotcon_close();
return -1;
}
- iotcon_resource_types_destroy(light_rtypes);
- iotcon_resource_types_destroy(room_rtypes);
-
g_main_loop_run(loop);
g_main_loop_unref(loop);