* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <stdbool.h>
#include <stdint.h>
#include <glib.h>
#include <OCApi.h>
return IOTCON_ERROR_NONE;
}
-static int _ic_ioty_generate_interface(iotcon_interface_e iface, string &interface_str)
+extern "C" int ic_ioty_convert_interface_string(const char *src, iotcon_interface_e *dest)
{
- switch (iface) {
+ RETV_IF(NULL == src, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == dest, IOTCON_ERROR_PARAM);
+
+ string interface_str(src);
+
+ if (STR_EQUAL == DEFAULT_INTERFACE.compare(interface_str)) {
+ *dest = IOTCON_INTERFACE_DEFAULT;
+ }
+ else if (STR_EQUAL == LINK_INTERFACE.compare(interface_str)) {
+ *dest = IOTCON_INTERFACE_LINK;
+ }
+ else if (STR_EQUAL == BATCH_INTERFACE.compare(interface_str)) {
+ *dest = IOTCON_INTERFACE_BATCH;
+ }
+ else if (STR_EQUAL == GROUP_INTERFACE.compare(interface_str)) {
+ *dest = IOTCON_INTERFACE_GROUP;
+ }
+ else {
+ ERR("Invalid interface");
+ *dest = IOTCON_INTERFACE_NONE;
+ return IOTCON_ERROR_PARAM;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+static int _ic_ioty_convert_interface_flag(iotcon_interface_e src, string &dest)
+{
+ switch (src) {
case IOTCON_INTERFACE_GROUP:
- interface_str = GROUP_INTERFACE;
+ dest = GROUP_INTERFACE;
break;
case IOTCON_INTERFACE_BATCH:
- interface_str = BATCH_INTERFACE;
+ dest = BATCH_INTERFACE;
break;
case IOTCON_INTERFACE_LINK:
- interface_str = LINK_INTERFACE;
+ dest = LINK_INTERFACE;
break;
case IOTCON_INTERFACE_DEFAULT:
- case IOTCON_INTERFACE_NONE:
- interface_str = DEFAULT_INTERFACE;
+ dest = DEFAULT_INTERFACE;
break;
+ case IOTCON_INTERFACE_NONE:
default:
ERR("Invalid interface");
+ dest = "";
return IOTCON_ERROR_PARAM;
}
return IOTCON_ERROR_NONE;
}
+extern "C" int ic_ioty_convert_interface_flag(iotcon_interface_e src, char **dest)
+{
+ FN_CALL;
+ int ret;
+ string iface_str;
+
+ ret = _ic_ioty_convert_interface_flag(src, iface_str);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_ic_ioty_convert_interface_flag() Fail(%d)", ret);
+ *dest = NULL;
+ return ret;
+ }
+
+ *dest = ic_utils_strdup(iface_str.c_str());
+
+ return IOTCON_ERROR_NONE;
+}
+
extern "C" int ic_ioty_bind_iface_to_res(OCResourceHandle resourceHandle,
iotcon_interface_e iface)
{
OCStackResult ocRet;
string resource_interface;
- ret = _ic_ioty_generate_interface(iface, resource_interface);
+ ret = _ic_ioty_convert_interface_flag(iface, resource_interface);
if (IOTCON_ERROR_NONE != ret) {
- ERR("_ic_ioty_generate_interface() Fail(%d)", ret);
+ ERR("_ic_ioty_convert_interface_flag(%d) Fail(%d)", iface, ret);
return ret;
}
resourceResponse->setErrorCode(msg->error_code);
OCRepresentation ocRep = ic_ioty_repr_parse(msg->repr);
- ret = _ic_ioty_generate_interface(msg->iface, iface);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ic_ioty_generate_interface() Fail(%d)", ret);
- return ret;
+
+ if (IOTCON_INTERFACE_NONE != msg->iface) {
+ ret = _ic_ioty_convert_interface_flag(msg->iface, iface);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_ic_ioty_convert_interface_flag(%d) Fail(%d)", msg->iface, ret);
+ return ret;
+ }
+ }
+ else {
+ iface = DEFAULT_INTERFACE;
}
+
resourceResponse->setResourceRepresentation(ocRep, iface);
ocRet = notifyListOfObservers(resHandle, obsIds, resourceResponse);
pResponse->setErrorCode(resp->error_code);
pResponse->setResponseResult((OCEntityHandlerResult)resp->result);
- ret = _ic_ioty_generate_interface(resp->iface, iface);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ic_ioty_generate_interface() Fail(%d)", ret);
- return ret;
+ if (IOTCON_INTERFACE_NONE != resp->iface) {
+ ret = _ic_ioty_convert_interface_flag(resp->iface, iface);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_ic_ioty_convert_interface_flag(%d) Fail(%d)", resp->iface, ret);
+ return ret;
+ }
+ }
+ else {
+ iface = DEFAULT_INTERFACE;
}
pResponse->setResourceRepresentation(ocRep, iface);
return IOTCON_ERROR_NONE;
}
-static void _ic_ioty_accumulate_options_vector(unsigned short id, const char *data,
+static int _ic_ioty_accumulate_options_vector(unsigned short id, const char *data,
void *user_data)
{
HeaderOptions *options = static_cast<HeaderOptions*>(user_data);
HeaderOption::OCHeaderOption option(id, data);
(*options).push_back(option);
+
+ return IOTCON_FUNC_CONTINUE;
}
static OCResource::Ptr _ic_ioty_create_oc_resource(iotcon_client_h resource)
}
-static void _ic_ioty_accumulate_query_map(const char *key, const char *value,
+static int _ic_ioty_accumulate_query_map(const char *key, const char *value,
void *user_data)
{
QueryParamsMap *queryParams = static_cast<QueryParamsMap*>(user_data);
string keyStr = key;
string valueStr = value;
(*queryParams)[keyStr] = valueStr;
+
+ return IOTCON_FUNC_CONTINUE;
}
int ic_ioty_cancel_observe(iotcon_client_h resource);
+int ic_ioty_convert_interface_flag(iotcon_interface_e src, char **dest);
+int ic_ioty_convert_interface_string(const char *src, iotcon_interface_e *dest);
+
#endif //__IOT_CONNECTIVITY_MANAGER_INTERNAL_IOTIVITY_H__
}
-API void iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb cb,
- void *user_data)
+API int iotcon_options_foreach(iotcon_options_h options,
+ iotcon_options_foreach_cb cb, void *user_data)
{
GHashTableIter iter;
gpointer key, value;
- RET_IF(NULL == options);
- RET_IF(NULL == cb);
+ RETV_IF(NULL == options, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
g_hash_table_iter_init(&iter, options->hash);
- while (g_hash_table_iter_next(&iter, &key, &value))
- cb(GPOINTER_TO_UINT(key), value, user_data);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ if (false == cb(GPOINTER_TO_UINT(key), value, user_data))
+ break;
+ }
+
+ return IOTCON_ERROR_NONE;
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
return ret;
}
-
-API void iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
+API int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
void *user_data)
{
GHashTableIter iter;
gpointer key, value;
- RET_IF(NULL == query);
- RET_IF(NULL == cb);
+ RETV_IF(NULL == query, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
g_hash_table_iter_init(&iter, query->hash);
- while (g_hash_table_iter_next(&iter, &key, &value))
- cb(key, value, user_data);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ if (false == cb(key, value, user_data))
+ break;
+ }
+
+ return IOTCON_ERROR_NONE;
}
return ret;
}
-API iotcon_list_h iotcon_list_new(iotcon_repr_types_e type)
+static iotcon_list_h _ic_list_new(iotcon_types_e type)
{
iotcon_list_h list;
return list;
}
+API iotcon_list_h iotcon_list_new(iotcon_types_e type)
+{
+ if (type < IOTCON_TYPE_INT || IOTCON_TYPE_REPR < type) {
+ ERR("Invalid Type(%d)", type);
+ return NULL;
+ }
+
+ return _ic_list_new(type);
+}
+
-API iotcon_list_h iotcon_list_insert_int(iotcon_list_h list, int val, int pos)
+API int iotcon_list_insert_int(iotcon_list_h list, int val, int pos)
{
iotcon_value_h value;
- RETV_IF(NULL == list, NULL);
- RETVM_IF(IOTCON_TYPE_INT != list->type, list, "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
value = ic_value_new_int(val);
if (NULL == value) {
ERR("ic_value_new_int(%d) Fail", val);
- return list;
+ return IOTCON_ERROR_FAIL;
}
- list = ic_list_insert(list, value, pos);
-
- return list;
+ return ic_list_insert(list, value, pos);
}
-API iotcon_list_h iotcon_list_insert_bool(iotcon_list_h list, bool val, int pos)
+API int iotcon_list_insert_bool(iotcon_list_h list, bool val, int pos)
{
iotcon_value_h value;
- RETV_IF(NULL == list, NULL);
- RETVM_IF(IOTCON_TYPE_BOOL != list->type, list, "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
value = ic_value_new_bool(val);
if (NULL == value) {
ERR("ic_value_new_bool(%d) Fail", val);
- return list;
+ return IOTCON_ERROR_FAIL;
}
- list = ic_list_insert(list, value, pos);
-
- return list;
+ return ic_list_insert(list, value, pos);
}
-API iotcon_list_h iotcon_list_insert_double(iotcon_list_h list, double val, int pos)
+API int iotcon_list_insert_double(iotcon_list_h list, double val, int pos)
{
iotcon_value_h value;
- RETV_IF(NULL == list, NULL);
- RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, list, "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
value = ic_value_new_double(val);
if (NULL == value) {
ERR("ic_value_new_double(%f) Fail", val);
- return list;
+ return IOTCON_ERROR_FAIL;
}
- list = ic_list_insert(list, value, pos);
-
- return list;
+ return ic_list_insert(list, value, pos);
}
-API iotcon_list_h iotcon_list_insert_str(iotcon_list_h list, char *val, int pos)
+API int iotcon_list_insert_str(iotcon_list_h list, char *val, int pos)
{
iotcon_value_h value;
- RETV_IF(NULL == list, NULL);
- RETVM_IF(IOTCON_TYPE_STR != list->type, list, "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
value = ic_value_new_str(val);
if (NULL == value) {
ERR("ic_value_new_str(%s) Fail", val);
- return list;
+ return IOTCON_ERROR_FAIL;
}
- list = ic_list_insert(list, value, pos);
-
- return list;
+ return ic_list_insert(list, value, pos);
}
-API iotcon_list_h iotcon_list_insert_list(iotcon_list_h list, iotcon_list_h val, int pos)
+API int iotcon_list_insert_list(iotcon_list_h list, iotcon_list_h val, int pos)
{
iotcon_value_h value;
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == val, NULL);
- RETVM_IF(IOTCON_TYPE_LIST != list->type, list, "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
value = ic_value_new_list(val);
if (NULL == value) {
ERR("ic_value_new_list(%p) Fail", val);
- return list;
+ return IOTCON_ERROR_FAIL;
}
ic_list_inc_ref_count(val);
- list = ic_list_insert(list, value, pos);
-
- return list;
+ return ic_list_insert(list, value, pos);
}
-API iotcon_list_h iotcon_list_insert_repr(iotcon_list_h list, iotcon_repr_h val, int pos)
+API int iotcon_list_insert_repr(iotcon_list_h list, iotcon_repr_h val, int pos)
{
iotcon_value_h value;
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == val, NULL);
- RETVM_IF(IOTCON_TYPE_REPR != list->type, list, "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_REPR != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
value = ic_value_new_repr(val);
if (NULL == value) {
ERR("ic_value_new_repr(%p) Fail", val);
- return list;
+ return IOTCON_ERROR_FAIL;
}
ic_repr_inc_ref_count(val);
- list = ic_list_insert(list, value, pos);
-
- return list;
+ return ic_list_insert(list, value, pos);
}
-API int iotcon_list_get_nth_int(iotcon_list_h list, int index)
+API int iotcon_list_get_nth_int(iotcon_list_h list, int index, int *val)
{
+ int ival, ret;
iotcon_value_h value;
- RETV_IF(NULL == list, 0);
- RETV_IF(NULL == list->list, 0);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = g_list_nth_data(list->list, index);
if (NULL == value) {
ERR("g_list_nth_data() Fail");
- return 0;
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = ic_value_get_int(value, &ival);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_int() Fail(%d)", ret);
+ return IOTCON_ERROR_FAIL;
}
- return ic_value_get_int(value);
+ *val = ival;
+
+ return IOTCON_ERROR_NONE;
}
-API bool iotcon_list_get_nth_bool(iotcon_list_h list, int index)
+API int iotcon_list_get_nth_bool(iotcon_list_h list, int index, bool *val)
{
+ int ret;
+ bool bval;
iotcon_value_h value;
- RETV_IF(NULL == list, false);
- RETV_IF(NULL == list->list, false);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = g_list_nth_data(list->list, index);
if (NULL == value) {
ERR("g_list_nth_data() Fail");
- return false;
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = ic_value_get_bool(value, &bval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_bool() Fail(%d)", ret);
+ return IOTCON_ERROR_FAIL;
}
- return ic_value_get_bool(value);
+ *val = bval;
+
+ return IOTCON_ERROR_NONE;
}
-API double iotcon_list_get_nth_double(iotcon_list_h list, int index)
+API int iotcon_list_get_nth_double(iotcon_list_h list, int index, double *val)
{
+ int ret;
+ double dbval;
iotcon_value_h value;
- RETV_IF(NULL == list, 0.0);
- RETV_IF(NULL == list->list, 0.0);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = g_list_nth_data(list->list, index);
if (NULL == value) {
ERR("g_list_nth_data() Fail");
- return 0.0;
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = ic_value_get_double(value, &dbval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_double() Fail(%d)", ret);
+ return IOTCON_ERROR_FAIL;
}
- return ic_value_get_double(value);
+ *val = dbval;
+
+ return IOTCON_ERROR_NONE;
}
-API const char* iotcon_list_get_nth_str(iotcon_list_h list, int index)
+API int iotcon_list_get_nth_str(iotcon_list_h list, int index, const char **val)
{
+ int ret;
+ const char *strval;
iotcon_value_h value;
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == list->list, NULL);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = g_list_nth_data(list->list, index);
if (NULL == value) {
ERR("g_list_nth_data() Fail");
- return NULL;
+ return IOTCON_ERROR_NO_DATA;
}
- return ic_value_get_str(value);
+ ret = ic_value_get_str(value, &strval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_str() Fail(%d)", ret);
+ return IOTCON_ERROR_FAIL;
+ }
+
+ *val = strval;
+
+ return IOTCON_ERROR_NONE;
}
-API iotcon_list_h iotcon_list_get_nth_list(iotcon_list_h list, int index)
+API int iotcon_list_get_nth_list(iotcon_list_h src, int index, iotcon_list_h *dest)
{
+ int ret;
iotcon_value_h value;
+ iotcon_list_h list_val;
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == list->list, NULL);
+ RETV_IF(NULL == src, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == src->list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == dest, IOTCON_ERROR_PARAM);
- value = g_list_nth_data(list->list, index);
+ value = g_list_nth_data(src->list, index);
if (NULL == value) {
ERR("g_list_nth_data() Fail");
- return NULL;
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = ic_value_get_list(value, &list_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_list() Fail(%d)", ret);
+ return IOTCON_ERROR_FAIL;
}
- return ic_value_get_list(value);
+ *dest = list_val;
+
+ return IOTCON_ERROR_NONE;
}
-API iotcon_repr_h iotcon_list_get_nth_repr(iotcon_list_h list, int index)
+API int iotcon_list_get_nth_repr(iotcon_list_h list, int index, iotcon_repr_h *repr)
{
+ int ret;
iotcon_value_h value;
+ iotcon_repr_h repr_val;
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == list->list, NULL);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
value = g_list_nth_data(list->list, index);
if (NULL == value) {
ERR("g_list_nth_data() Fail");
- return NULL;
+ return IOTCON_ERROR_NO_DATA;
}
- return ic_value_get_repr(value);
+ ret = ic_value_get_repr(value, &repr_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_list() Fail(%d)", ret);
+ return IOTCON_ERROR_FAIL;
+ }
+
+ *repr = repr_val;
+
+ return IOTCON_ERROR_NONE;
}
-static int _ic_list_del_nth_value(iotcon_list_h list, int pos, iotcon_repr_types_e value_type)
+static int _ic_list_del_nth_value(iotcon_list_h list, int pos, iotcon_types_e value_type)
{
iotcon_value_h value;
}
-API int iotcon_list_get_type(iotcon_list_h list)
+API int iotcon_list_get_type(iotcon_list_h list, int *type)
{
RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == type, IOTCON_ERROR_PARAM);
- return list->type;
+ *type = list->type;
+
+ return IOTCON_ERROR_NONE;
}
-API int iotcon_list_get_length(iotcon_list_h list)
+API unsigned int iotcon_list_get_length(iotcon_list_h list)
{
- RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
- RETV_IF(NULL == list->list, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == list, 0);
+ RETV_IF(NULL == list->list, 0);
return g_list_length(list->list);
}
}
-iotcon_list_h ic_list_insert(iotcon_list_h list, iotcon_value_h value, int pos)
+int ic_list_insert(iotcon_list_h list, iotcon_value_h value, int pos)
{
- RETV_IF(NULL == list, NULL);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
list->list = g_list_insert(list->list, value, pos);
- if (NULL == list->list) {
- ERR("g_list_insert() Fail");
- return list;
- }
- return list;
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_fn fn, void *user_data)
+API int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_fn fn,
+ void *user_data)
{
GList *cur;
int index = 0;
ic_basic_s *real = NULL;
- RETM_IF(NULL == list, "IOTCON_ERROR_PARAM(NULL == list)");
- RETM_IF(NULL == fn, "IOTCON_ERROR_PARAM(NULL == fn)");
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
+ RETV_IF(NULL == fn, IOTCON_ERROR_PARAM);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- (*fn)(index, real->val.i, user_data);
+ if (IOTCON_FUNC_STOP == fn(index, real->val.i, user_data))
+ break;
index++;
cur = next;
}
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_fn fn, void *user_data)
+API int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_fn fn,
+ void *user_data)
{
GList *cur;
int index = 0;
ic_basic_s *real = NULL;
- RETM_IF(NULL == list, "IOTCON_ERROR_PARAM(NULL == list)");
- RETM_IF(NULL == fn, "IOTCON_ERROR_PARAM(NULL == fn)");
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
+ RETV_IF(NULL == fn, IOTCON_ERROR_PARAM);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- (*fn)(index, real->val.b, user_data);
+ if (IOTCON_FUNC_STOP == fn(index, real->val.b, user_data))
+ break;
index++;
cur = next;
}
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_fn fn, void *user_data)
+API int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_fn fn,
+ void *user_data)
{
GList *cur;
int index = 0;
ic_basic_s *real = NULL;
- RETM_IF(NULL == list, "IOTCON_ERROR_PARAM(NULL == list)");
- RETM_IF(NULL == fn, "IOTCON_ERROR_PARAM(NULL == fn)");
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
+ RETV_IF(NULL == fn, IOTCON_ERROR_PARAM);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- (*fn)(index, real->val.d, user_data);
+ if (IOTCON_FUNC_STOP == fn(index, real->val.d, user_data))
+ break;
index++;
cur = next;
}
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_fn fn, void *user_data)
+API int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_fn fn,
+ void *user_data)
{
GList *cur;
int index = 0;
ic_basic_s *real = NULL;
- RETM_IF(NULL == list, "IOTCON_ERROR_PARAM(NULL == list)");
- RETM_IF(NULL == fn, "IOTCON_ERROR_PARAM(NULL == fn)");
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
+ RETV_IF(NULL == fn, IOTCON_ERROR_PARAM);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- (*fn)(index, real->val.s, user_data);
+ if (IOTCON_FUNC_STOP == fn(index, real->val.s, user_data))
+ break;
index++;
cur = next;
}
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_list_list_foreach(iotcon_list_h list, iotcon_list_list_fn fn, void *user_data)
+API int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_fn fn,
+ void *user_data)
{
int index = 0;
GList *cur = NULL;
ic_val_list_s *real = NULL;
- RETM_IF(NULL == list, "IOTCON_ERROR_PARAM(NULL == list)");
- RETM_IF(NULL == fn, "IOTCON_ERROR_PARAM(NULL == fn)");
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
+ RETV_IF(NULL == fn, IOTCON_ERROR_PARAM);
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- (*fn)(index, real->list, user_data);
+ if (IOTCON_FUNC_STOP == fn(index, real->list, user_data))
+ break;
index++;
cur = next;
}
+
+ return IOTCON_ERROR_NONE;
}
-API void iotcon_list_foreach_repr(iotcon_list_h list, iotcon_list_repr_fn fn, void *user_data)
+API int iotcon_list_foreach_repr(iotcon_list_h list, iotcon_list_repr_fn fn, void *user_data)
{
int index = 0;
GList *cur = NULL;
ic_val_repr_s *real = NULL;
- RETM_IF(NULL == list, "IOTCON_ERROR_PARAM(NULL == list)");
- RETM_IF(NULL == fn, "IOTCON_ERROR_PARAM(NULL == fn)");
+
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_REPR != list->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ list->type);
+ RETV_IF(NULL == fn, IOTCON_ERROR_PARAM);;
cur = list->list;
while (cur) {
GList *next = cur->next;
real = cur->data;
- (*fn)(index, real->repr, user_data);
+ if (IOTCON_FUNC_STOP == fn(index, real->repr, user_data))
+ break;
index++;
cur = next;
}
+
+ return IOTCON_ERROR_NONE;
}
*/
JsonArray* ic_list_to_json(iotcon_list_h list)
{
- int i;
- int count = 0;
+ int i, ret, count;
JsonArray *parray = NULL;
JsonNode *child_node = NULL;
JsonObject *child_obj = NULL;
json_array_add_element(parray, child_node);
break;
case IOTCON_TYPE_LIST:
- child_list = ic_value_get_list(child_value);
+ ret = ic_value_get_list(child_value, &child_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_list() Fail(%d)", ret);
+ json_array_unref(parray);
+ return NULL;
+ }
+
child_array = ic_list_to_json(child_list);
if (NULL == child_array) {
ERR("ic_list_to_json(child_list) Fail");
json_array_add_element(parray, child_node);
break;
case IOTCON_TYPE_REPR:
- child_repr = ic_value_get_repr(child_value);
+ ret = ic_value_get_repr(child_value, &child_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_repr() Fail(%d)", ret);
+ json_array_unref(parray);
+ return NULL;
+ }
+
child_obj = ic_obj_to_json(child_repr);
if (NULL == child_obj) {
ERR("ic_obj_to_json(child_repr) Fail");
*/
iotcon_list_h ic_list_from_json(JsonArray *parray)
{
- int i;
+ int i, ret;
int count = json_array_get_length(parray);
- iotcon_list_h list = iotcon_list_new(IOTCON_TYPE_NONE);
+ iotcon_list_h list = _ic_list_new(IOTCON_TYPE_NONE);
/* DBG("array count(%d)", count); */
for (i = 0; i < count; i++) {
return NULL;
}
- list = ic_list_insert(list, value, -1);
+ ret = ic_list_insert(list, value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_list_insert() Fail(%d)", ret);
+ ic_value_free(value);
+ iotcon_list_free(list);
+ return NULL;
+ }
list->type = real->type;
}
else if (JSON_NODE_HOLDS_ARRAY(child_node)) {
return NULL;
}
- list = ic_list_insert(list, value, -1);
+ ret = ic_list_insert(list, value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_list_insert() Fail(%d)", ret);
+ iotcon_list_free(parsed_list);
+ iotcon_list_free(list);
+ return NULL;
+ }
list->type = IOTCON_TYPE_LIST;
}
else if (JSON_NODE_HOLDS_OBJECT(child_node)) {
ERR("ic_value_new_repr(%p) Fail", ret_repr);
iotcon_repr_free(ret_repr);
iotcon_list_free(list);
+ return NULL;
}
- list = ic_list_insert(list, value, -1);
+ ret = ic_list_insert(list, value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_list_insert() Fail(%d)", ret);
+ iotcon_repr_free(ret_repr);
+ iotcon_list_free(list);
+ return NULL;
+ }
list->type = IOTCON_TYPE_REPR;
}
}
static int _ic_list_clone_value(iotcon_list_h list, iotcon_list_h ret_list)
{
- int i, count;
+ int i, ret, count;
iotcon_value_h value, copied_value;
count = g_list_length(list->list);
return IOTCON_ERROR_FAIL;
}
- ic_list_insert(ret_list, copied_value, -1);
+ ret = ic_list_insert(ret_list, copied_value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_list_insert() Fail");
+ ic_value_free(copied_value);
+ return IOTCON_ERROR_FAIL;
+ }
}
return IOTCON_ERROR_NONE;
static int _ic_list_clone_list(iotcon_list_h list, iotcon_list_h ret_list)
{
- int i, count;
+ int i, ret, count;
+
iotcon_value_h value;
iotcon_list_h list_val, copied_list;
count = g_list_length(list->list);
for (i = 0; i < count; i++) {
- list_val = iotcon_list_get_nth_list(list, i);
- if (NULL != list_val) {
- ERR("iotcon_list_get_nth_list() Fail");
+ ret = iotcon_list_get_nth_list(list, i, &list_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_get_nth_list() Fail(%d)", ret);
return IOTCON_ERROR_FAIL;
}
return IOTCON_ERROR_FAIL;
}
- ret_list = ic_list_insert(ret_list, value, -1);
+ ret = ic_list_insert(ret_list, value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_list_insert(%d) Fail", ret);
+ ic_value_free(value);
+ return IOTCON_ERROR_FAIL;
+ }
}
return IOTCON_ERROR_NONE;
static int _ic_list_clone_repr(iotcon_list_h list, iotcon_list_h ret_list)
{
- int i, count;
+ int i, ret, count;
iotcon_value_h value;
iotcon_repr_h repr_val, copied_repr;
count = g_list_length(list->list);
for (i = 0; i < count; i++) {
- repr_val = iotcon_list_get_nth_repr(list, i);
- if (NULL == repr_val) {
+ ret = iotcon_list_get_nth_repr(list, i, &repr_val);
+ if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_list_get_nth_repr() Fail");
return IOTCON_ERROR_FAIL;
}
return IOTCON_ERROR_FAIL;
}
- ret_list = ic_list_insert(ret_list, value, -1);
+ ret = ic_list_insert(ret_list, value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_list_insert(%d) Fail", ret);
+ ic_value_free(value);
+ return IOTCON_ERROR_FAIL;
+ }
}
return IOTCON_ERROR_NONE;
struct ic_list_s {
int type;
+ int ref_count;
GList *list;
};
int ic_list_remove(iotcon_list_h list, iotcon_value_h val);
-iotcon_list_h ic_list_insert(iotcon_list_h list, iotcon_value_h value, int pos);
+int ic_list_insert(iotcon_list_h list, iotcon_value_h value, int pos);
JsonArray* ic_list_to_json(iotcon_list_h list);
iotcon_list_h ic_list_from_json(JsonArray *parray);
#include "ic-repr-obj.h"
int ic_obj_del_value(iotcon_repr_h repr, const char *key,
- iotcon_repr_types_e value_type)
+ iotcon_types_e value_type)
{
gboolean ret = FALSE;
iotcon_value_h value = NULL;
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_get_int(iotcon_repr_h repr, const char *key)
+API int iotcon_repr_get_int(iotcon_repr_h repr, const char *key, int *val)
{
iotcon_value_h value;
- RETV_IF(NULL == repr, 0);
- RETV_IF(NULL == key, 0);
+ RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = g_hash_table_lookup(repr->hash_table, key);
if (NULL == value) {
ERR("g_hash_table_lookup() Fail");
- return 0;
+ return IOTCON_ERROR_NO_DATA;
}
ic_basic_s *real = (ic_basic_s*)value;
- RETV_IF(IOTCON_TYPE_INT != real->type, 0);
+ RETV_IF(IOTCON_TYPE_INT != real->type, IOTCON_ERROR_FAIL);
- return real->val.i;
+ *val = real->val.i;
+
+ return IOTCON_ERROR_NONE;
}
API int iotcon_repr_set_int(iotcon_repr_h repr, const char *key, int val)
return ret;
}
-API bool iotcon_repr_get_bool(iotcon_repr_h repr, const char *key)
+API int iotcon_repr_get_bool(iotcon_repr_h repr, const char *key, bool *val)
{
ic_basic_s *real = NULL;
iotcon_value_h value = NULL;
- RETV_IF(NULL == repr, false);
- RETV_IF(NULL == key, false);
+ RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = g_hash_table_lookup(repr->hash_table, key);
if (NULL == value) {
ERR("g_hash_table_lookup() Fail");
- return false;
+ return IOTCON_ERROR_NO_DATA;
}
real = (ic_basic_s*)value;
- RETV_IF(IOTCON_TYPE_BOOL != real->type, false);
+ RETV_IF(IOTCON_TYPE_BOOL != real->type, IOTCON_ERROR_FAIL);
+
+ *val = real->val.b;
- return real->val.b;
+ return IOTCON_ERROR_NONE;
}
API int iotcon_repr_set_bool(iotcon_repr_h repr, const char *key, bool val)
return ret;
}
-API double iotcon_repr_get_double(iotcon_repr_h repr, const char *key)
+API int iotcon_repr_get_double(iotcon_repr_h repr, const char *key, double *val)
{
ic_basic_s *real = NULL;
iotcon_value_h value = NULL;
- RETV_IF(NULL == repr, 0.0);
- RETV_IF(NULL == key, 0.0);
+ RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = g_hash_table_lookup(repr->hash_table, key);
if (NULL == value) {
ERR("g_hash_table_lookup() Fail");
- return 0;
+ return IOTCON_ERROR_NO_DATA;
}
real = (ic_basic_s*)value;
- RETV_IF(IOTCON_TYPE_DOUBLE != real->type, 0.0);
+ RETV_IF(IOTCON_TYPE_DOUBLE != real->type, IOTCON_ERROR_FAIL);
+
+ *val = real->val.d;
- return real->val.d;
+ return IOTCON_ERROR_NONE;
}
API int iotcon_repr_set_double(iotcon_repr_h repr, const char *key, double val)
return ret;
}
-API char* iotcon_repr_get_str(iotcon_repr_h repr, const char *key)
+API int iotcon_repr_get_str(iotcon_repr_h repr, const char *key, char **val)
{
ic_basic_s *real = NULL;
iotcon_value_h value = NULL;
- RETV_IF(NULL == repr, NULL);
- RETV_IF(NULL == key, NULL);
+ RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = g_hash_table_lookup(repr->hash_table, key);
if (NULL == value) {
ERR("g_hash_table_lookup() Fail");
- return NULL;
+ return IOTCON_ERROR_NO_DATA;
}
real = (ic_basic_s*)value;
- RETV_IF(IOTCON_TYPE_STR != real->type, NULL);
+ RETV_IF(IOTCON_TYPE_STR != real->type, IOTCON_ERROR_FAIL);
- return real->val.s;
+ *val = real->val.s;
+
+ return IOTCON_ERROR_NONE;
}
API int iotcon_repr_set_str(iotcon_repr_h repr, const char *key, char *val)
RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == val, IOTCON_ERROR_PARAM);
value = ic_value_new_str(val);
if (NULL == value) {
return ret;
}
-API iotcon_list_h iotcon_repr_get_list(iotcon_repr_h repr, const char *key)
+API int iotcon_repr_get_list(iotcon_repr_h repr, const char *key, iotcon_list_h *list)
{
iotcon_value_h value = NULL;
ic_val_list_s *real = NULL;
- RETV_IF(NULL == repr, NULL);
- RETV_IF(NULL == key, NULL);
+ RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
value = g_hash_table_lookup(repr->hash_table, key);
if (NULL == value) {
ERR("g_hash_table_lookup() Fail");
- return NULL;
+ return IOTCON_ERROR_NO_DATA;
}
real = (ic_val_list_s*)value;
- RETV_IF(IOTCON_TYPE_LIST != real->type, NULL);
+ RETV_IF(IOTCON_TYPE_LIST != real->type, IOTCON_ERROR_FAIL);
- return real->list;
+ *list = real->list;
+
+ return IOTCON_ERROR_NONE;
}
API int iotcon_repr_set_list(iotcon_repr_h repr, const char *key, iotcon_list_h list)
RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == list, IOTCON_ERROR_PARAM);
value = ic_value_new_list(list);
if (NULL == value) {
return ret;
}
-API iotcon_repr_h iotcon_repr_get_repr(iotcon_repr_h repr, const char *key)
+
+API int iotcon_repr_get_repr(iotcon_repr_h src, const char *key, iotcon_repr_h *dest)
{
ic_val_repr_s *real = NULL;
iotcon_value_h value = NULL;
- RETV_IF(NULL == repr, NULL);
- RETV_IF(NULL == key, NULL);
+ RETV_IF(NULL == src, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == dest, IOTCON_ERROR_PARAM);
- value = g_hash_table_lookup(repr->hash_table, key);
+ value = g_hash_table_lookup(src->hash_table, key);
if (NULL == value) {
ERR("g_hash_table_lookup() Fail");
- return NULL;
+ return IOTCON_ERROR_NO_DATA;
}
real = (ic_val_repr_s*)value;
- RETV_IF(IOTCON_TYPE_REPR != real->type, NULL);
+ RETV_IF(IOTCON_TYPE_REPR != real->type, IOTCON_ERROR_FAIL);
+
+ *dest = real->repr;
- return real->repr;
+ return IOTCON_ERROR_NONE;
}
API int iotcon_repr_set_repr(iotcon_repr_h repr, const char *key, iotcon_repr_h val)
return ret;
}
+API int iotcon_repr_get_type(iotcon_repr_h repr, const char *key, int *type)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == type, IOTCON_ERROR_PARAM);
+
+ value = g_hash_table_lookup(repr->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+ *type = value->type;
+
+ return IOTCON_ERROR_NONE;
+}
+
int ic_obj_set_value(iotcon_repr_h repr, const char *key, iotcon_value_h value)
{
RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
unsigned int index, JsonObject *json_obj)
{
FN_CALL;
- int type;
+ int type, ret;
const char *key;
iotcon_repr_h child_repr = NULL;
iotcon_list_h child_list = NULL;
json_object_set_member(json_obj, key, child_node);
break;
case IOTCON_TYPE_LIST:
- child_list = ic_value_get_list(value);
+ ret = ic_value_get_list(value, &child_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_list() Fail(%d)", ret);
+ return IOTCON_ERROR_FAIL;
+ }
+
child_array = ic_list_to_json(child_list);
if (NULL == child_array) {
ERR("ic_list_to_json() Fail");
json_object_set_member(json_obj, key, child_node);
break;
case IOTCON_TYPE_REPR:
- child_repr = ic_value_get_repr(value);
+ ret = ic_value_get_repr(value, &child_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_repr() Fail(%d)", ret);
+ return IOTCON_ERROR_FAIL;
+ }
+
child_obj = ic_obj_to_json(child_repr);
if (NULL == child_obj) {
ERR("ic_obj_to_json() Fail");
#include "iotcon-constant.h"
int ic_obj_del_value(iotcon_repr_h repr, const char *key,
- iotcon_repr_types_e value_type);
+ iotcon_types_e value_type);
int ic_repr_obj_get_value(iotcon_repr_h repr, const char *key, iotcon_value_h *retval);
int ic_obj_set_value(iotcon_repr_h repr, const char *key, iotcon_value_h value);
return (iotcon_value_h)value;
}
-int ic_value_get_int(iotcon_value_h value)
+int ic_value_get_int(iotcon_value_h value, int *val)
{
ic_basic_s *real = (ic_basic_s*)value;
- RETV_IF(NULL == value, 0);
- RETVM_IF(IOTCON_TYPE_INT != real->type, 0, "IOTCON_ERROR_PARAM(%d)", real->type);
+ RETV_IF(NULL == value, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_INT != real->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ real->type);
- return real->val.i;
+ *val = real->val.i;
+
+ return IOTCON_ERROR_NONE;
}
-bool ic_value_get_bool(iotcon_value_h value)
+int ic_value_get_bool(iotcon_value_h value, bool *val)
{
ic_basic_s *real = (ic_basic_s*)value;
- RETV_IF(NULL == value, false);
- RETVM_IF(IOTCON_TYPE_BOOL != real->type, false, "IOTCON_ERROR_PARAM(%d)", real->type);
+ RETV_IF(NULL == value, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_BOOL != real->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ real->type);
+
+ *val = real->val.b;
- return real->val.b;
+ return IOTCON_ERROR_NONE;
}
-double ic_value_get_double(iotcon_value_h value)
+int ic_value_get_double(iotcon_value_h value, double *val)
{
ic_basic_s *real = (ic_basic_s*)value;
- RETV_IF(NULL == value, 0.0);
- RETVM_IF(IOTCON_TYPE_DOUBLE != real->type, 0.0, "IOTCON_ERROR_PARAM(%d)", real->type);
+ RETV_IF(NULL == value, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_DOUBLE != real->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ real->type);
- return real->val.d;
+ *val = real->val.d;
+
+ return IOTCON_ERROR_NONE;
}
-const char* ic_value_get_str(iotcon_value_h value)
+int ic_value_get_str(iotcon_value_h value, const char **val)
{
ic_basic_s *real = (ic_basic_s*)value;
- RETV_IF(NULL == value, NULL);
- RETVM_IF(IOTCON_TYPE_STR != real->type, NULL, "IOTCON_ERROR_PARAM(%d)", real->type);
+ RETV_IF(NULL == value, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_STR != real->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ real->type);
- return real->val.s;
+ *val = real->val.s;
+
+ return IOTCON_ERROR_NONE;
}
-iotcon_list_h ic_value_get_list(iotcon_value_h value)
+int ic_value_get_list(iotcon_value_h value, iotcon_list_h *list)
{
ic_val_list_s *real = (ic_val_list_s*)value;
- RETV_IF(NULL == value, NULL);
- RETVM_IF(IOTCON_TYPE_LIST != real->type, NULL, "IOTCON_ERROR_PARAM(%d)", real->type);
+ RETV_IF(NULL == value, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_LIST != real->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ real->type);
- return real->list;
-}
+ *list = real->list;
+ return IOTCON_ERROR_NONE;
+}
-iotcon_repr_h ic_value_get_repr(iotcon_value_h value)
+int ic_value_get_repr(iotcon_value_h value, iotcon_repr_h *repr)
{
ic_val_repr_s *real = (ic_val_repr_s*)value;
- RETV_IF(NULL == value, NULL);
- RETVM_IF(IOTCON_TYPE_REPR != real->type, NULL, "IOTCON_ERROR_PARAM(%d)", real->type);
+ RETV_IF(NULL == value, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_TYPE_REPR != real->type, IOTCON_ERROR_PARAM, "Invalid Type(%d)",
+ real->type);
- return real->repr;
+ *repr = real->repr;
+
+ return IOTCON_ERROR_NONE;
}
/*
* A general result : 1
* : true
-* : 5.5
+* : 5.5
* : "Hello"
*/
JsonNode* ic_value_to_json(iotcon_value_h value)
void ic_value_free(gpointer data)
{
+ FN_CALL;
+ int ret;
+ const char *str;
iotcon_value_h value;
+ iotcon_list_h list;
+ iotcon_repr_h repr;
RET_IF(NULL == data);
int type = value->type;
switch (type) {
case IOTCON_TYPE_STR:
- free((char*)ic_value_get_str(value));
+ ret = ic_value_get_str(value, &str);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_str() Fail(%d)", ret);
+ break;
+ }
+ free((char*)str);
case IOTCON_TYPE_INT:
case IOTCON_TYPE_BOOL:
case IOTCON_TYPE_DOUBLE:
case IOTCON_TYPE_NULL:
break;
case IOTCON_TYPE_LIST:
- iotcon_list_free(ic_value_get_list(value));
+ DBG("value is list");
+ ret = ic_value_get_list(value, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_list() Fail(%d)", ret);
+ break;
+ }
+ iotcon_list_free(list);
break;
case IOTCON_TYPE_REPR:
- iotcon_repr_free(ic_value_get_repr(value));
+ DBG("value is Repr");
+ ret = ic_value_get_repr(value, &repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_repr() Fail(%d)", ret);
+ break;
+ }
+ iotcon_repr_free(repr);
break;
default:
ERR("Invalid type(%d)", type);
iotcon_value_h ic_value_new_repr(iotcon_repr_h val);
-int ic_value_get_int(iotcon_value_h value);
-bool ic_value_get_bool(iotcon_value_h value);
-double ic_value_get_double(iotcon_value_h value);
-const char* ic_value_get_str(iotcon_value_h value);
-iotcon_list_h ic_value_get_list(iotcon_value_h value);
-iotcon_repr_h ic_value_get_repr(iotcon_value_h value);
+int ic_value_get_int(iotcon_value_h value, int *val);
+int ic_value_get_bool(iotcon_value_h value, bool *val);
+int ic_value_get_double(iotcon_value_h value, double *val);
+int ic_value_get_str(iotcon_value_h value, const char **val);
+int ic_value_get_list(iotcon_value_h value, iotcon_list_h *list);
+int ic_value_get_repr(iotcon_value_h value, iotcon_repr_h *repr);
JsonNode* ic_value_to_json(iotcon_value_h value);
#include "iotcon-representation.h"
#include "ic-common.h"
#include "ic-utils.h"
+#include "ic-ioty.h"
#include "ic-repr-list.h"
#include "ic-repr-value.h"
#include "ic-repr-obj.h"
return NULL;
}
- ret_val->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+ ret_val->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
ic_value_free);
ic_repr_inc_ref_count(ret_val);
return ret_val;
}
-API const char* iotcon_repr_get_uri(iotcon_repr_h repr)
-{
- RETV_IF(NULL == repr, NULL);
-
- return repr->uri;
-}
-
-API int iotcon_repr_set_uri(iotcon_repr_h repr, const char *uri)
+API int iotcon_repr_get_uri(iotcon_repr_h repr, const char **uri)
{
RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
RETV_IF(NULL == uri, IOTCON_ERROR_PARAM);
- repr->uri = ic_utils_strdup(uri);
- if (NULL == repr->uri) {
- ERR("ic_utils_strdup() Fail");
- return IOTCON_ERROR_MEMORY;
- }
+ *uri = repr->uri;
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_del_uri(iotcon_repr_h repr)
+API int iotcon_repr_set_uri(iotcon_repr_h repr, const char *uri)
{
RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
free(repr->uri);
repr->uri = NULL;
- return IOTCON_ERROR_NONE;
-}
-
-API void iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_resourcetype_fn fn,
- void *user_data)
-{
- RET_IF(NULL == repr);
-
- /* (GFunc) : fn needs to use "const" qualifier */
- g_list_foreach(repr->res_types, (GFunc)fn, user_data);
-}
-
-API int iotcon_repr_get_resource_types_count(iotcon_repr_h repr)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
-
- return g_list_length(repr->res_types);
-}
-
-API int iotcon_repr_append_resource_types(iotcon_repr_h repr, const char *type)
-{
- char *res_type = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
- RETV_IF(NULL == type, IOTCON_ERROR_PARAM);
-
- res_type = ic_utils_strdup(type);
- if (NULL == res_type) {
- ERR("ic_utils_strdup() Fail");
- return IOTCON_ERROR_MEMORY;
+ if (NULL != uri) {
+ repr->uri = ic_utils_strdup(uri);
+ if (NULL == repr->uri) {
+ ERR("ic_utils_strdup() Fail");
+ return IOTCON_ERROR_MEMORY;
+ }
}
- repr->res_types = g_list_append(repr->res_types, res_type);
-
return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_del_resource_types(iotcon_repr_h repr, const char *type)
+API int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_str_list_s **types)
{
- GList *cur = NULL;
RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
- RETV_IF(NULL == type, IOTCON_ERROR_PARAM);
- RETV_IF(NULL == repr->res_types, IOTCON_ERROR_PARAM);
-
- cur = g_list_find_custom(repr->res_types, type, (GCompareFunc)g_strcmp0);
- if (NULL == cur) {
- WARN("g_list_find(%s) returns NULL", type);
- return IOTCON_ERROR_NO_DATA;
- }
+ RETV_IF(NULL == types, IOTCON_ERROR_PARAM);
- repr->res_types = g_list_delete_link(repr->res_types, cur);
+ *types = repr->res_types;
return IOTCON_ERROR_NONE;
}
-API void iotcon_repr_get_resource_interfaces(iotcon_repr_h repr, iotcon_interface_fn fn,
- void *user_data)
+API int iotcon_repr_set_resource_types(iotcon_repr_h repr, iotcon_str_list_s *types)
{
- RET_IF(NULL == repr);
+ RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
- /* (GFunc) : fn needs to use "const" qualifier */
- g_list_foreach(repr->interfaces, (GFunc)fn, user_data);
-}
+ iotcon_str_list_free(repr->res_types);
+ repr->res_types = NULL;
-API int iotcon_repr_get_resource_interfaces_count(iotcon_repr_h repr)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
+ if (NULL != types)
+ repr->res_types = iotcon_str_list_clone(types);
- return g_list_length(repr->interfaces);
+ return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_append_resource_interfaces(iotcon_repr_h repr, const char *iface)
+API int iotcon_repr_get_resource_interfaces(iotcon_repr_h repr)
{
- char *res_interface = NULL;
-
- RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
- RETV_IF(NULL == iface, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == repr, IOTCON_INTERFACE_NONE);
- res_interface = ic_utils_strdup(iface);
- if (NULL == res_interface) {
- ERR("ic_utils_strdup() Fail");
- return IOTCON_ERROR_MEMORY;
- }
-
- repr->interfaces = g_list_append(repr->interfaces, res_interface);
- return IOTCON_ERROR_NONE;
+ return repr->interfaces;
}
-API int iotcon_repr_del_resource_interface(iotcon_repr_h repr, const char *iface)
+API int iotcon_repr_set_resource_interfaces(iotcon_repr_h repr, int ifaces)
{
- GList *cur = NULL;
RETV_IF(NULL == repr, IOTCON_ERROR_PARAM);
- RETV_IF(NULL == iface, IOTCON_ERROR_PARAM);
- RETV_IF(NULL == repr->interfaces, IOTCON_ERROR_PARAM);
- cur = g_list_find_custom(repr->interfaces, iface, (GCompareFunc)g_strcmp0);
- if (NULL == cur) {
- WARN("g_list_find(%s) returns NULL", iface);
- return IOTCON_ERROR_NO_DATA;
- }
-
- repr->interfaces = g_list_delete_link(repr->interfaces, cur);
+ repr->interfaces = ifaces;
return IOTCON_ERROR_NONE;
}
return IOTCON_ERROR_NONE;
}
-API void iotcon_repr_get_children(iotcon_repr_h parent, iotcon_children_fn fn,
+API int iotcon_repr_get_children(iotcon_repr_h parent, iotcon_children_fn fn,
void *user_data)
{
- RET_IF(NULL == parent);
+ GList *list, *next;
+
+ RETV_IF(NULL == parent, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == fn, IOTCON_ERROR_PARAM);
+
+ list = parent->children;
+ while (list) {
+ next = list->next;
+ if (IOTCON_FUNC_STOP == fn(list->data, user_data))
+ break;
+ list = next;
+ }
- /* (GFunc) : fn needs to use "const" qualifier */
- g_list_foreach(parent->children, (GFunc)fn, user_data);
+ return IOTCON_ERROR_NONE;
}
-API int iotcon_repr_get_children_count(iotcon_repr_h parent)
+API unsigned int iotcon_repr_get_children_count(iotcon_repr_h parent)
{
- RETV_IF(NULL == parent, IOTCON_ERROR_PARAM);
- RETV_IF(NULL == parent->children, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == parent, 0);
+ RETV_IF(NULL == parent->children, 0);
return g_list_length(parent->children);
}
-API iotcon_repr_h iotcon_repr_get_nth_child(iotcon_repr_h parent, int index)
+API int iotcon_repr_get_nth_child(iotcon_repr_h parent, int index, iotcon_repr_h *child)
{
- RETV_IF(NULL == parent, NULL);
- RETV_IF(NULL == parent->children, NULL);
+ RETV_IF(NULL == parent, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == parent->children, IOTCON_ERROR_PARAM);
+ RETV_IF(NULL == child, IOTCON_ERROR_PARAM);
- return g_list_nth_data(parent->children, index);
+ *child = g_list_nth_data(parent->children, index);
+ if (NULL == *child) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ return IOTCON_ERROR_NONE;
}
API iotcon_str_list_s* iotcon_repr_get_key_list(iotcon_repr_h repr)
return g_hash_table_size(repr->hash_table);
}
-void _ic_repr_get_res_type_fn(const char *res_type, void *user_data)
+static int _ic_repr_get_res_type_fn(const char *res_type, void *user_data)
{
JsonArray *rt_array = user_data;
json_array_add_string_element(rt_array, res_type);
- DBG("res_type(%s)", res_type);
-}
-void _ic_repr_get_res_interface_fn(const char *res_if, void *user_data)
-{
- JsonArray *if_array = user_data;
- json_array_add_string_element(if_array, res_if);
- DBG("res_if(%s)", res_if);
+ return IOTCON_FUNC_CONTINUE;
}
/*
static JsonObject* _ic_repr_data_generate_json(iotcon_repr_h cur_repr,
unsigned int child_index)
{
- FN_CALL;
+ int i, ret, ifaces;
+ char *iface_str;
+ const char *uri;
JsonObject *repr_obj = NULL;
unsigned int rt_count = 0;
- unsigned int if_count = 0;
JsonObject *prop_obj = NULL;
+ iotcon_str_list_s *resource_types = NULL;
RETV_IF(NULL == cur_repr, NULL);
if (0 < iotcon_repr_get_keys_count(cur_repr)) {
repr_obj = ic_obj_to_json(cur_repr);
if (NULL == repr_obj) {
- ERR("ic_obj_to_json() Fail()");
+ ERR("ic_obj_to_json() Fail");
json_object_unref(repr_obj);
return NULL;
}
}
- else
+ else {
repr_obj = json_object_new();
+ }
if (cur_repr->uri) {
- const char *uri = iotcon_repr_get_uri(cur_repr);
+ iotcon_repr_get_uri(cur_repr, &uri);
json_object_set_string_member(repr_obj, IOTCON_KEY_URI, uri);
}
- if (cur_repr->res_types) {
- rt_count = iotcon_repr_get_resource_types_count(cur_repr);
- }
- if (cur_repr->interfaces) {
- if_count = iotcon_repr_get_resource_interfaces_count(cur_repr);
- }
+ if (cur_repr->res_types)
+ rt_count = iotcon_str_list_length(cur_repr->res_types);
- if (0 < rt_count || 0 < if_count) {
+ if (0 < rt_count || IOTCON_INTERFACE_NONE != cur_repr->interfaces) {
prop_obj = json_object_new();
json_object_set_object_member(repr_obj, IOTCON_KEY_PROPERTY, prop_obj);
}
if (0 < rt_count) {
JsonArray *rt_array = json_array_new();
- iotcon_repr_get_resource_types(cur_repr, _ic_repr_get_res_type_fn, rt_array);
+
+ ret = iotcon_repr_get_resource_types(cur_repr, &resource_types);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_repr_get_resource_types() Fail(%d)", ret);
+ json_object_unref(repr_obj);
+ return NULL;
+ }
+
+ ret = iotcon_str_list_foreach(resource_types, _ic_repr_get_res_type_fn,
+ rt_array);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_str_list_foreach() Fail");
+ json_object_unref(repr_obj);
+ return NULL;
+ }
json_object_set_array_member(prop_obj, IOTCON_KEY_RESOURCETYPES, rt_array);
}
- if (0 < if_count) {
+ if (IOTCON_INTERFACE_NONE != cur_repr->interfaces) {
JsonArray *if_array = json_array_new();
- iotcon_repr_get_resource_interfaces(cur_repr, _ic_repr_get_res_interface_fn,
- if_array);
+ ifaces = iotcon_repr_get_resource_interfaces(cur_repr);
+ for (i = 1; i < IOTCON_INTERFACE_MAX; i = i << 1) {
+ if (IOTCON_INTERFACE_NONE == (ifaces & i)) /* this interface not exist */
+ continue;
+ ret = ic_ioty_convert_interface_flag((ifaces & i), &iface_str);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_ioty_convert_interface_flag(%d) Fail(%d)", i, ret);
+ json_object_unref(repr_obj);
+ json_array_unref(if_array);
+ return NULL;
+ }
+ json_array_add_string_element(if_array, iface_str);
+ }
+
json_object_set_array_member(prop_obj, IOTCON_KEY_INTERFACES, if_array);
}
static JsonObject* _ic_repr_data_generate_parent(iotcon_repr_h cur_repr,
unsigned int child_index)
{
+ FN_CALL;
JsonObject *obj = _ic_repr_data_generate_json(cur_repr, child_index);
if (NULL == obj) {
ERR("_ic_repr_data_generate_json() Fail");
static JsonObject* _ic_repr_data_generate_child(iotcon_repr_h cur_repr,
unsigned int child_index)
{
+ FN_CALL;
JsonObject *obj = _ic_repr_data_generate_json(cur_repr, child_index);
if (NULL == obj) {
ERR("_ic_repr_data_generate_json() Fail");
json_array_add_object_element(root_array, repr_obj);
for (child_index = 0; child_index < child_count; child_index++) {
- child_repr = iotcon_repr_get_nth_child(repr, child_index);
+ iotcon_repr_get_nth_child(repr, child_index, &child_repr);
repr_obj = _ic_repr_data_generate_child(child_repr, child_index);
if (NULL == repr_obj) {
ERR("_ic_repr_data_generate_child() Fali(NULL == repr_obj)");
*/
iotcon_repr_h ic_repr_parse_json(const char *json_string)
{
+ const char *iface_str = NULL;
+ const char *rtype_str = NULL;
const char *uri_value = NULL;
+ iotcon_interface_e iface_flag;
RETV_IF(NULL == json_string, NULL);
IOTCON_KEY_PROPERTY);
if (json_object_has_member(property_obj, IOTCON_KEY_RESOURCETYPES)) {
+ iotcon_str_list_s *res_types = NULL;
JsonArray *rt_array = json_object_get_array_member(property_obj,
IOTCON_KEY_RESOURCETYPES);
- unsigned int rt_count = json_array_get_length(rt_array);
unsigned int rt_index = 0;
+ unsigned int rt_count = json_array_get_length(rt_array);
+
for (rt_index = 0; rt_index < rt_count; rt_index++) {
- iotcon_repr_append_resource_types(repr,
- json_array_get_string_element(rt_array, rt_index));
+ rtype_str = json_array_get_string_element(rt_array, rt_index);
+ res_types = iotcon_str_list_append(res_types, rtype_str);
}
+ iotcon_repr_set_resource_types(repr, res_types);
}
if (json_object_has_member(property_obj, IOTCON_KEY_INTERFACES)) {
JsonArray *if_array = json_object_get_array_member(property_obj,
IOTCON_KEY_INTERFACES);
unsigned int if_count = json_array_get_length(if_array);
- unsigned int if_index = 0;
- for (if_index = 0; if_index < if_count; if_index++)
- iotcon_repr_append_resource_interfaces(repr,
- json_array_get_string_element(if_array, if_index));
+ unsigned int if_index;
+ int ifaces = IOTCON_INTERFACE_NONE;
+
+ for (if_index = 0; if_index < if_count; if_index++) {
+ iface_str = json_array_get_string_element(if_array, if_index);
+ ret = ic_ioty_convert_interface_string(iface_str, &iface_flag);
+ ifaces |= iface_flag;
+ }
+ iotcon_repr_set_resource_interfaces(repr, ifaces);
+
}
}
return repr;
}
+
API void iotcon_repr_free(iotcon_repr_h repr)
{
FN_CALL;
- int ref_count;
RET_IF(NULL == repr);
if (false == _ic_repr_dec_ref_count(repr))
/* (GDestroyNotify) : iotcon_repr_h is proper type than gpointer */
g_list_free_full(repr->children, (GDestroyNotify)iotcon_repr_free);
- g_list_free_full(repr->interfaces, g_free);
- g_list_free_full(repr->res_types, g_free);
+
+ /* repr->res_types COULD be not null */
+ if (repr->res_types)
+ iotcon_str_list_free(repr->res_types);
g_hash_table_destroy(repr->hash_table);
free(repr);
static void _ic_repr_obj_clone(char *key, iotcon_value_h src_val, iotcon_repr_h dest_repr)
{
FN_CALL;
- int type = IOTCON_TYPE_NONE;
+ int type, ret;
iotcon_value_h value, copied_val;
iotcon_list_h child_list, copied_list;
iotcon_repr_h child_repr, copied_repr;
ic_obj_set_value(dest_repr, ic_utils_strdup(key), copied_val);
break;
case IOTCON_TYPE_LIST:
- child_list = ic_value_get_list(src_val);
+ ret = ic_value_get_list(src_val, &child_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_list() Fail(%d)", ret);
+ return;
+ }
+
copied_list = ic_list_clone(child_list);
if (NULL == copied_list) {
ERR("ic_list_clone() Fail");
ic_obj_set_value(dest_repr, key, value);
break;
case IOTCON_TYPE_REPR:
- child_repr = ic_value_get_repr(src_val);
+ ret = ic_value_get_repr(src_val, &child_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_value_get_repr() Fail(%d)", ret);
+ return;
+ }
+
copied_repr = iotcon_repr_clone(child_repr);
if (NULL == copied_repr) {
ERR("ic_list_clone() Fail");
}
}
-static gpointer _ic_repr_copy_str(gconstpointer src, gpointer data)
-{
- FN_CALL;
- return ic_utils_strdup(src);
-}
-
static gpointer _ic_repr_copy_repr(gconstpointer src, gpointer data)
{
FN_CALL;
dest = iotcon_repr_new();
if (src->uri)
dest->uri = strdup(src->uri);
- dest->interfaces = g_list_copy_deep(src->interfaces, _ic_repr_copy_str, NULL);
- dest->res_types = g_list_copy_deep(src->res_types, _ic_repr_copy_str, NULL);
+ dest->interfaces = src->interfaces;
+ dest->res_types = iotcon_str_list_clone(src->res_types);
dest->children = g_list_copy_deep(src->children, _ic_repr_copy_repr, NULL);
g_hash_table_foreach(src->hash_table, (GHFunc)_ic_repr_obj_clone, dest);
struct ic_repr_s {
char *uri;
+ int ref_count;
+ int interfaces;
GHashTable *hash_table;
GList *children;
- GList *res_types;
- GList *interfaces;
+ iotcon_str_list_s *res_types;
};
/**
#include <string.h>
#include <errno.h>
-#include "iotcon-struct.h"
+#include "iotcon.h"
#include "ic-common.h"
#include "ic-utils.h"
return length;
}
-
-API void iotcon_str_list_foreach(iotcon_str_list_s *str_list,
- iotcon_string_foreach_cb cb, void *user_data)
+API int iotcon_str_list_foreach(iotcon_str_list_s *str_list, iotcon_string_foreach_cb cb,
+ void *user_data)
{
- RET_IF(NULL == str_list);
+ RETV_IF(NULL == str_list, IOTCON_ERROR_PARAM);
while (str_list) {
- cb(str_list->string, user_data);
+ if (false == cb(str_list->string, user_data))
+ break;
str_list = str_list->next;
}
+
+ return IOTCON_ERROR_NONE;
}
#define IOTCON_CONTAINED_RESOURCES_MAX 5
*/
+#define IOTCON_FUNC_STOP 0
+#define IOTCON_FUNC_CONTINUE 1
+
/**
* @brief Action associated with observation
*/
IOTCON_TYPE_NULL,
IOTCON_TYPE_LIST,
IOTCON_TYPE_REPR,
-} iotcon_repr_types_e;
+} iotcon_types_e;
#endif /* __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__ */
void iotcon_repr_free(iotcon_repr_h repr);
iotcon_repr_h iotcon_repr_clone(const iotcon_repr_h src);
-int iotcon_repr_set_uri(iotcon_repr_h repr, const char *uri);
-const char* iotcon_repr_get_uri(iotcon_repr_h repr);
-int iotcon_repr_del_uri(iotcon_repr_h repr);
-
/**
* @ingroup CAPI_IOT_CONNECTIVITY_MODULE
* @brief Appends resource type name.
* @since_tizen 3.0
- * @remarks Duplicate type names are allowed.
+ * @remarks Stored string is replaced with @a uri. If @a uri is NULL, stored string is set
+ * by NULL.
*
* @param[in] repr The handle to the Representation
- * @param[in] type The resource type
+ * @param[in] uri The URI of resource
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_MEMORY Out of memory
* @retval #IOTCON_ERROR_PARAM Invalid parameter
*/
-int iotcon_repr_append_resource_types(iotcon_repr_h repr, const char *type);
-typedef void (*iotcon_resourcetype_fn)(const char *res_type, void *user_data);
-void iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_resourcetype_fn fn,
- void *user_data);
-int iotcon_repr_get_resource_types_count(iotcon_repr_h repr);
-int iotcon_repr_del_resource_types(iotcon_repr_h repr, const char *type);
+int iotcon_repr_set_uri(iotcon_repr_h repr, const char *uri);
+int iotcon_repr_get_uri(iotcon_repr_h repr, const char **uri);
-int iotcon_repr_append_resource_interfaces(iotcon_repr_h repr, const char *iface);
-typedef void (*iotcon_interface_fn)(const char *res_if, void *user_data);
-void iotcon_repr_get_resource_interfaces(iotcon_repr_h repr, iotcon_interface_fn fn,
- void *user_data);
-int iotcon_repr_get_resource_interfaces_count(iotcon_repr_h repr);
-int iotcon_repr_del_resource_interfaces(iotcon_repr_h repr, const char *type);
+/**
+ * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
+ * @brief Sets resource type list to the Representation.
+ * @since_tizen 3.0
+ * @remarks Stored list is replaced with @a types. If @a types is NULL, stored list is set
+ * by NULL.
+ * @param[in] repr The handle to the Representation
+ * @param[in] types The resource type list
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_PARAM Invalid parameter
+ */
+int iotcon_repr_set_resource_types(iotcon_repr_h repr, iotcon_str_list_s *types);
+int iotcon_repr_get_resource_types(iotcon_repr_h repr, iotcon_str_list_s **types);
+
+int iotcon_repr_set_resource_interfaces(iotcon_repr_h repr, int ifaces);
+int iotcon_repr_get_resource_interfaces(iotcon_repr_h repr);
/**
* @ingroup CAPI_IOT_CONNECTIVITY_MODULE
* @brief Sets int value.
* @since_tizen 3.0
- * @remarks Stored value is replaced with @a ival.
+ * @remarks Stored value is replaced with @a val.
*
* @param[in] repr The handle to the Representation
* @param[in] type The resource type
int iotcon_repr_set_repr(iotcon_repr_h dest, const char *key, iotcon_repr_h src);
int iotcon_repr_set_null(iotcon_repr_h repr, const char *key);
-int iotcon_repr_get_int(iotcon_repr_h repr, const char *key);
-bool iotcon_repr_get_bool(iotcon_repr_h repr, const char *key);
-double iotcon_repr_get_double(iotcon_repr_h repr, const char *key);
-char* iotcon_repr_get_str(iotcon_repr_h repr, const char *key);
-iotcon_list_h iotcon_repr_get_list(iotcon_repr_h repr, const char *key);
-iotcon_repr_h iotcon_repr_get_repr(iotcon_repr_h repr, const char *key);
+int iotcon_repr_get_int(iotcon_repr_h repr, const char *key, int *val);
+int iotcon_repr_get_bool(iotcon_repr_h repr, const char *key, bool *val);
+int iotcon_repr_get_double(iotcon_repr_h repr, const char *key, double *val);
+int iotcon_repr_get_str(iotcon_repr_h repr, const char *key, char **val);
+int iotcon_repr_get_list(iotcon_repr_h repr, const char *key, iotcon_list_h *list);
+int iotcon_repr_get_repr(iotcon_repr_h src, const char *key, iotcon_repr_h *dest);
bool iotcon_repr_is_null(iotcon_repr_h repr, const char *key);
int iotcon_repr_del_int(iotcon_repr_h repr, const char *key);
int iotcon_repr_del_repr(iotcon_repr_h repr, const char *key);
int iotcon_repr_del_null(iotcon_repr_h repr, const char *key);
+int iotcon_repr_get_type(iotcon_repr_h repr, const char *key, int *type);
+
int iotcon_repr_append_child(iotcon_repr_h parent, iotcon_repr_h child);
-typedef void (*iotcon_children_fn)(iotcon_repr_h child, void *user_data);
-void iotcon_repr_get_children(iotcon_repr_h parent, iotcon_children_fn fn,
+typedef bool (*iotcon_children_fn)(iotcon_repr_h child, void *user_data);
+int iotcon_repr_get_children(iotcon_repr_h parent, iotcon_children_fn fn,
void *user_data);
-int iotcon_repr_get_children_count(iotcon_repr_h parent);
-iotcon_repr_h iotcon_repr_get_nth_child(iotcon_repr_h parent, int index);
+unsigned int iotcon_repr_get_children_count(iotcon_repr_h parent);
+int iotcon_repr_get_nth_child(iotcon_repr_h parent, int index, iotcon_repr_h *child);
iotcon_str_list_s* iotcon_repr_get_key_list(iotcon_repr_h repr);
int iotcon_repr_get_keys_count(iotcon_repr_h repr);
char* iotcon_repr_generate_json(iotcon_repr_h repr);
-iotcon_list_h iotcon_list_new(iotcon_repr_types_e type);
+iotcon_list_h iotcon_list_new(iotcon_types_e type);
void iotcon_list_free(iotcon_list_h list);
/**
*
* @return the (possibly changed) start of the list, otherwise a null pointer on failure
*/
-iotcon_list_h iotcon_list_insert_int(iotcon_list_h list, int val, int pos);
-iotcon_list_h iotcon_list_insert_bool(iotcon_list_h list, bool val, int pos);
-iotcon_list_h iotcon_list_insert_double(iotcon_list_h list, double val, int pos);
-iotcon_list_h iotcon_list_insert_str(iotcon_list_h list, char *val, int pos);
-iotcon_list_h iotcon_list_insert_list(iotcon_list_h list, iotcon_list_h val, int pos);
-iotcon_list_h iotcon_list_insert_repr(iotcon_list_h list, iotcon_repr_h val, int pos);
-
-int iotcon_list_get_nth_int(iotcon_list_h list, int index);
-bool iotcon_list_get_nth_bool(iotcon_list_h list, int index);
-double iotcon_list_get_nth_double(iotcon_list_h list, int index);
-const char* iotcon_list_get_nth_str(iotcon_list_h list, int index);
-iotcon_list_h iotcon_list_get_nth_list(iotcon_list_h list, int index);
-iotcon_repr_h iotcon_list_get_nth_repr(iotcon_list_h list, int index);
+int iotcon_list_insert_int(iotcon_list_h list, int val, int pos);
+int iotcon_list_insert_bool(iotcon_list_h list, bool val, int pos);
+int iotcon_list_insert_double(iotcon_list_h list, double val, int pos);
+int iotcon_list_insert_str(iotcon_list_h list, char *val, int pos);
+int iotcon_list_insert_list(iotcon_list_h list, iotcon_list_h val, int pos);
+int iotcon_list_insert_repr(iotcon_list_h list, iotcon_repr_h val, int pos);
+
+int iotcon_list_get_nth_int(iotcon_list_h list, int index, int *val);
+int iotcon_list_get_nth_bool(iotcon_list_h list, int index, bool *val);
+int iotcon_list_get_nth_double(iotcon_list_h list, int index, double *val);
+int iotcon_list_get_nth_str(iotcon_list_h list, int index, const char **val);
+int iotcon_list_get_nth_list(iotcon_list_h src, int index, iotcon_list_h *dest);
+int iotcon_list_get_nth_repr(iotcon_list_h list, int index, iotcon_repr_h *repr);
int iotcon_list_del_nth_int(iotcon_list_h list, int pos);
int iotcon_list_del_nth_bool(iotcon_list_h list, int pos);
int iotcon_list_del_nth_list(iotcon_list_h list, int pos);
int iotcon_list_del_nth_repr(iotcon_list_h list, int pos);
-int iotcon_list_get_type(iotcon_list_h list);
-int iotcon_list_get_length(iotcon_list_h list);
-
-typedef void (*iotcon_list_int_fn)(int index, const int value, void *user_data);
-void iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_fn fn, void *user_data);
-typedef void (*iotcon_list_bool_fn)(int index, const bool value, void *user_data);
-void iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_fn fn, void *user_data);
-typedef void (*iotcon_list_double_fn)(int index, const double value, void *user_data);
-void iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_fn fn, void *user_data);
-typedef void (*iotcon_list_str_fn)(int index, const char *value, void *user_data);
-void iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_fn fn, void *user_data);
-typedef void (*iotcon_list_list_fn)(int index, iotcon_list_h value, void *user_data);
-void iotcon_list_list_foreach(iotcon_list_h list, iotcon_list_list_fn fn, void *user_data);
-typedef void (*iotcon_list_repr_fn)(int index, iotcon_repr_h value, void *user_data);
-void iotcon_list_foreach_repr(iotcon_list_h list, iotcon_list_repr_fn fn, void *user_data);
+int iotcon_list_get_type(iotcon_list_h list, int *type);
+unsigned int iotcon_list_get_length(iotcon_list_h list);
+
+typedef int (*iotcon_list_int_fn)(int index, const int value,
+ void *user_data);
+int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_fn fn, void *user_data);
+typedef int (*iotcon_list_bool_fn)(int index, const bool value,
+ void *user_data);
+int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_fn fn, void *user_data);
+typedef int (*iotcon_list_double_fn)(int index, const double value,
+ void *user_data);
+int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_fn fn,
+ void *user_data);
+typedef int (*iotcon_list_str_fn)(int index, const char *value,
+ void *user_data);
+int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_fn fn, void *user_data);
+typedef int (*iotcon_list_list_fn)(int index, iotcon_list_h value,
+ void *user_data);
+int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_fn fn, void *user_data);
+typedef int (*iotcon_list_repr_fn)(int index, iotcon_repr_h value,
+ void *user_data);
+int iotcon_list_foreach_repr(iotcon_list_h list, iotcon_list_repr_fn fn, void *user_data);
#endif /* __IOT_CONNECTIVITY_MANAGER_REPRESENTATION_H__ */
#define __IOT_CONNECTIVITY_MANAGER_STRUCT_H__
#include <stdint.h>
-#include <iotcon-constant.h>
+#include <stdbool.h>
+
+#include "iotcon-constant.h"
typedef struct ic_value_s* iotcon_value_h;
typedef struct ic_list_s* iotcon_list_h;
const char *data);
int iotcon_options_delete(iotcon_options_h options, unsigned short id);
const char* iotcon_options_lookup(iotcon_options_h options, unsigned short id);
-typedef void (*iotcon_options_foreach_cb)(unsigned short id, const char *data,
+typedef int (*iotcon_options_foreach_cb)(unsigned short id, const char *data,
+ void *user_data);
+int iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb cb,
void *user_data);
-void iotcon_options_foreach(iotcon_options_h options,
- iotcon_options_foreach_cb cb, void *user_data);
typedef struct ic_query* iotcon_query_h;
int iotcon_query_insert(iotcon_query_h query, const char *key, const char *value);
int iotcon_query_delete(iotcon_query_h query, const char *key);
const char* iotcon_query_lookup(iotcon_query_h query, const char *key);
-typedef void (*iotcon_query_foreach_cb)(const char *key, const char *value,
+typedef int (*iotcon_query_foreach_cb)(const char *key, const char *value,
void *user_data);
-void iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
+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);
const char *string);
iotcon_str_list_s* iotcon_str_list_clone(iotcon_str_list_s *str_list);
unsigned int iotcon_str_list_length(iotcon_str_list_s *str_list);
-typedef void (*iotcon_string_foreach_cb)(const char *string, void *user_data);
-void iotcon_str_list_foreach(iotcon_str_list_s *str_list,
- iotcon_string_foreach_cb cb, void *user_data);
+typedef int (*iotcon_string_foreach_cb)(const char *string, void *user_data);
+int iotcon_str_list_foreach(iotcon_str_list_s *str_list, iotcon_string_foreach_cb cb,
+ void *user_data);
const char* iotcon_str_list_nth_data(iotcon_str_list_s *str_list, unsigned int n);
#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#include <stdbool.h>
#include <stdlib.h>
#include <glib.h>
_print_repr_info(recv_repr);
- created_uri = iotcon_repr_get_str(recv_repr, "createduri");
+ iotcon_repr_get_str(recv_repr, "createduri", &created_uri);
if (created_uri) {
DBG("New resource created : %s", created_uri);
iotcon_query_free(query_params);
}
-static void _get_res_type_fn(const char *string, void *user_data)
+static int _get_res_type_fn(const char *string, void *user_data)
{
char *resource_uri = user_data;
DBG("[%s] resource type : %s", resource_uri, string);
+
+ return IOTCON_FUNC_CONTINUE;
}
static void _presence_handler(int result, unsigned int nonce,
static void _found_resource(iotcon_client_h resource, void *user_data)
{
+ int ret;
const char *resource_uri = NULL;
const char *resource_host = NULL;
iotcon_str_list_s *resource_types = NULL;
/* get the resource types */
resource_types = iotcon_client_get_types(resource);
- iotcon_str_list_foreach(resource_types, _get_res_type_fn,
+ ret = iotcon_str_list_foreach(resource_types, _get_res_type_fn,
(void *)resource_uri);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_str_list_foreach() Fail(%d)", ret);
+ return;
+ }
iotcon_subscribe_presence(resource_host, "core.door", _presence_handler, NULL);
static void _request_handler_put(iotcon_request_h request, iotcon_response_h response)
{
+ bool bval;
iotcon_repr_h req_repr = NULL;
iotcon_repr_h resp_repr = NULL;
INFO("PUT request");
req_repr = iotcon_request_get_representation(request);
- my_door.state = iotcon_repr_get_bool(req_repr, "opened");
+ iotcon_repr_get_bool(req_repr, "opened", &bval);
+ my_door.state = bval;
_check_door_state();
g_timeout_add_seconds(5, _notifier, door_handle);
}
-static void query_cb(const char *key, const char *value, void *user_data)
+static int _query_cb(const char *key, const char *value, void *user_data)
{
INFO("key : %s", key);
INFO("value : %s", value);
+
+ return IOTCON_FUNC_CONTINUE;
}
static void _request_handler(iotcon_request_h request, void *user_data)
query = iotcon_request_get_query(request);
if (query)
- iotcon_query_foreach(query, query_cb, NULL);
+ iotcon_query_foreach(query, _query_cb, NULL);
request_type = iotcon_request_get_request_type(request);
if (NULL == request_type) {
iotcon_client_h room_resource = NULL;
-void _get_int_list_fn(int index, const int value, void *user_data)
+static int _get_int_list_fn(int index, const int value, void *user_data)
{
DBG("%d°C", value);
+
+ return IOTCON_FUNC_CONTINUE;
}
static void _on_get(iotcon_repr_h recv_repr, int response_result)
{
- int i, children_count;
+ int i, ret;
+ unsigned int children_count;
+ const char *uri;
iotcon_repr_h child_repr;
iotcon_list_h list;
iotcon_str_list_s *key_list = NULL;
- RETM_IF(IOTCON_RESPONSE_RESULT_OK != response_result, "_on_get_1st 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 ]");
- DBG("uri : %s", iotcon_repr_get_uri(recv_repr));
+ iotcon_repr_get_uri(recv_repr, &uri);
+ if (uri)
+ DBG("uri : %s", uri);
key_list = iotcon_repr_get_key_list(recv_repr);
if (key_list) {
- DBG("name : %s", iotcon_repr_get_str(recv_repr, "name"));
+ char *str;
+ iotcon_repr_get_str(recv_repr, "name", &str);
+ if (str)
+ DBG("name : %s", str);
- list = iotcon_repr_get_list(recv_repr, "today_temp");
+ iotcon_repr_get_list(recv_repr, "today_temp", &list);
DBG("today's temperature :");
iotcon_list_foreach_int(list, _get_int_list_fn, NULL);
DBG("[ child representation ]");
const char *uri;
- child_repr = iotcon_repr_get_nth_child(recv_repr, i);
- uri = iotcon_repr_get_uri(child_repr);
- DBG("uri : %s", uri);
+ ret = iotcon_repr_get_nth_child(recv_repr, i, &child_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_repr_get_nth_child(%d) Fail(%d)", i, ret);
+ continue;
+ }
+
+ iotcon_repr_get_uri(child_repr, &uri);
+ if (uri)
+ DBG("uri : %s", uri);
if (!strcmp("/a/light", uri)) {
key_list = iotcon_repr_get_key_list(child_repr);
if (key_list) {
- DBG("brightness : %d", iotcon_repr_get_int(child_repr, "brightness"));
+ int brightness;
+ iotcon_repr_get_int(child_repr, "brightness", &brightness);
+ DBG("brightness : %d", brightness);
iotcon_str_list_free(key_list);
}
}
else if (!strcmp("/a/switch", uri)) {
key_list = iotcon_repr_get_key_list(child_repr);
if (key_list) {
- DBG("switch : %d", iotcon_repr_get_bool(child_repr, "switch"));
+ bool bswitch;
+ iotcon_repr_get_bool(child_repr, "switch", &bswitch);
+ DBG("switch : %d", bswitch);
iotcon_str_list_free(key_list);
}
}
iotcon_query_free(query_params);
}
-static void _get_res_type_fn(const char *string, void *user_data)
+static int _get_res_type_fn(const char *string, void *user_data)
{
char *resource_uri = user_data;
DBG("[%s] resource type : %s", resource_uri, string);
+
+ return IOTCON_FUNC_CONTINUE;
}
static void _found_resource(iotcon_client_h resource, void *user_data)
iotcon_repr_free(resp_repr);
}
-void _query_foreach_cb(const char *key, const char *value, void *user_data)
+static int _query_foreach_cb(const char *key, const char *value, void *user_data)
{
char **interface_str = user_data;
if (!strcmp("if", key)) {
*interface_str = (char*)value;
}
+ return IOTCON_FUNC_CONTINUE;
}
static void _room_request_handler_get(iotcon_request_h request,