*******************************************************************************/
/**
* @file tbt-iotcon-view.c
- * @brief covers IoTvitiy connection reiotconed apis
+ * @brief covers IoT Connectivity apis
* @since_tizen 3.0
* @author A. B. M. Nazibullah(nazib.ullah@samsung.com)
* @date October, 2016
/* Door Resource */
-typedef struct _door_resource_s {
+typedef struct _door_resource_s
+{
bool attributes;
char *uri_path;
char *type;
Evas_Object *iotcon_label;
Evas_Object *iotcon_btn;
-
Evas_Object* get_btn;
Evas_Object* post_btn;
Evas_Object* put_btn;
Evas_Object* del_btn;
-
Evas_Object* info_list;
GList *device_id_list;
-
door_resource_s my_door;
iotcon_query_h query;
-
iotcon_remote_resource_h resource_clone;
bool opened;
-
char *host;
char *created_uri_path;
iotcon_connectivity_type_e connectivity_type;
static void _app_destroy_cb(void* this);
static char* get_iotcon_error(iotcon_error_e err);
-
static int _set_door_resource(door_resource_s *door);
static iotcon_resource_h _create_door_resource(char *uri_path, char *type, iotcon_resource_interfaces_h ifaces, uint8_t policies, void *user_data);
static void _iotcon_server_change_state_btn_pressed_cb(void *data, Evas_Object *obj, void *event_info);
static int _send_response(iotcon_request_h request, iotcon_representation_h repr, iotcon_response_result_e result);
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data);
static int _request_handler_delete(iotcon_resource_h resource, iotcon_request_h request);
-static int _request_handler_post(door_resource_s *door, iotcon_request_h request);
+static int _request_handler_post(door_resource_s *door, iotcon_request_h request, void *user_data);
static int _request_handler_put(door_resource_s *door, iotcon_request_h request);
-
static bool _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data);
static void _on_response(iotcon_remote_resource_h resource, iotcon_error_e err, iotcon_request_type_e request_type, iotcon_response_h response, void *user_data);
static void disable_control_button(iotcon_view *this, bool get, bool post, bool put, bool del);
static void discovered_resource_list_show(iotcon_view *this);
static void _resource_selected_cb(void *data, Evas_Object *obj, void *event_info);
+#define USE_GENLIST
+
+#ifdef USE_GENLIST
+typedef struct
+{
+ int index;
+ Elm_Object_Item *item;
+ char* text;
+}item_data;
+
+static void _gl_del_cb(void *data, Evas_Object *obj EINA_UNUSED);
+static char *_gl_text_get_cb(void *data, Evas_Object *obj, const char *part);
+Elm_Object_Item* _iotcon_elm_genlist_item_append(Evas_Object* list, char *item_text, Evas_Smart_Cb func, void* data);
+#endif
+
+#ifdef USE_GENLIST
+static void _gl_del_cb(void *data, Evas_Object *obj EINA_UNUSED)
+{
+ DBG("_gl_del_cb");
+ item_data *id = data;
+ RETM_IF(!id, "item is NULL");
+ SAFE_DELETE(id);
+}
+
+static char *_gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ DBG("_gl_text_get_cb");
+ item_data *id = data;
+ if(part && !strcmp(part, "elm.text"))
+ {
+ char buf[1024];
+ snprintf(buf, 1023,"%s", id->text);
+ return strdup(buf);
+ }
+ return NULL;
+}
+
+Elm_Object_Item* _iotcon_elm_genlist_item_append(Evas_Object* list, char *item_text, Evas_Smart_Cb func, void* data)
+{
+
+ DBG("_pick_elm_genlist_item_append%s:", item_text);
+ static int index = 1;
+ Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
+
+ itc->item_style = "default";
+ itc->func.text_get = _gl_text_get_cb;
+ itc->func.content_get = NULL;
+ itc->func.del = _gl_del_cb;
+
+ item_data *id = calloc(sizeof(item_data), 1);
+ id->index = index++;
+ id->text = strdup(item_text);
+
+ elm_scroller_single_direction_set(list, ELM_SCROLLER_SINGLE_DIRECTION_HARD);
+
+ //HOMOGENEOUS MODE
+ //If item height is same when each style name is same, Use homogeneous mode.
+ elm_genlist_homogeneous_set(list, EINA_TRUE);
+
+ //COMPRESS MODE
+ //For the Mobile view, because it has full window, compresse mode should be used.
+ elm_genlist_mode_set(list, ELM_LIST_COMPRESS);
+
+ Elm_Object_Item *item = elm_genlist_item_append(list, itc,id, NULL, ELM_GENLIST_ITEM_NONE, func, data);
+ id->item = item;
+
+ elm_genlist_item_class_free(itc);
+
+ return item;
+}
+#endif
+
/**
* @function iotcon_view_add
RETVM_IF(NULL == this->view, NULL, "navi is null");
this->iotcon_label = ui_utils_label_add(this->view->layout, "");
- ui_utils_label_set_text(this->iotcon_label, "Info: ", "left");
+ ui_utils_label_set_text(this->iotcon_label, "", "left");
elm_object_part_content_set(this->view->layout, "iotcon_text", this->iotcon_label);
+#ifdef USE_GENLIST
+ this->info_list = elm_genlist_add(this->view->layout);
+ RETVM_IF(!this->info_list, NULL, "elm_genlist_add failed");
+#else
this->info_list = elm_list_add(this->view->layout);
RETVM_IF(!this->info_list, NULL, "elm_list_add failed");
+#endif
+
evas_object_data_set(this->info_list, "view_data", this);
elm_object_part_content_set(this->view->layout, "iotcon_info_view", this->info_list);
+#ifndef USE_GENLIST
elm_list_go(this->info_list);
+#endif
evas_object_show(this->info_list);
char db_file_path[256]={'\0',};
-
if(this->view->tbt_info->apptype == TBT_APP_IOTCON_BASIC_SERVER)
{
- this->iotcon_btn = ui_utils_push_button_add(this, this->view->layout, "Open/Close", _iotcon_server_change_state_btn_pressed_cb);
+ this->iotcon_btn = ui_utils_push_button_add(this, this->view->layout, "Open/Close Door", _iotcon_server_change_state_btn_pressed_cb);
elm_object_part_content_set(this->view->layout, "iotcon_btn", this->iotcon_btn);
elm_object_disabled_set(this->iotcon_btn, true);
view = (iotcon_view*)this;
RETM_IF(NULL == view, "view is NULL");
+ int ret;
+
if(view->view->tbt_info->apptype == TBT_APP_IOTCON_BASIC_SERVER)
{
- iotcon_stop_presence();
- iotcon_resource_destroy(view->my_door.handle);
+ ret = iotcon_stop_presence();
+ DBG("iotcon_stop_presence : %s", get_iotcon_error(ret));
+ ret = iotcon_resource_destroy(view->my_door.handle);
+ DBG("iotcon_resource_destroy : %s", get_iotcon_error(ret));
_free_door_resource(&view->my_door);
_resource_created = false;
}
if(view->view->tbt_info->apptype == TBT_APP_IOTCON_BASIC_CLIENT)
{
- iotcon_query_destroy(view->query);
+ ret = iotcon_query_destroy(view->query);
+ DBG("iotcon_query_destroy : %s", get_iotcon_error(ret));
+ ret = iotcon_remote_resource_observe_deregister(view->resource_clone);
+ DBG("iotcon_remote_resource_observe_deregister : %s", get_iotcon_error(ret));
}
/* deinitialize iotcon */
- iotcon_deinitialize();
+ ret = iotcon_deinitialize();
+ DBG("iotcon_deinitialize : %s", get_iotcon_error(ret));
SAFE_DELETE(view->view);
SAFE_DELETE(view);
}
{
iotcon_observers_destroy(door->observers);
iotcon_resource_interfaces_destroy(door->ifaces);
- free(door->type);
- free(door->uri_path);
+ SAFE_DELETE(door->type);
+ SAFE_DELETE(door->uri_path);
}
static void _get_button_pressed_cb(void *data, Evas_Object *obj, void *event_info)
iotcon_query_h query;
int result;
-
- result = iotcon_remote_resource_observe_register(this->resource_clone, IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER, NULL, _on_observe, this);
- RETM_IF(IOTCON_ERROR_NONE != result, "iotcon_remote_resource_observe_register result(%s)", get_iotcon_error(result));
-
result = iotcon_query_create(&query);
RETM_IF(IOTCON_ERROR_NONE != result, "iotcon_query_create result(%s)", get_iotcon_error(result));
ret = iotcon_representation_create(&send_repr);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
+ ERR("iotcon_representation_create() Fail(%s)", get_iotcon_error(ret));
return;
}
/* send POST request */
ret = iotcon_remote_resource_post(this->resource_clone, send_repr, NULL, _on_response, this);
if (IOTCON_ERROR_NONE != ret)
- ERR("iotcon_remote_resource_post() Fail(%d)", ret);
+ ERR("iotcon_remote_resource_post() Fail(%s)", get_iotcon_error(ret));
iotcon_representation_destroy(send_repr);
}
RETM_IF(IOTCON_ERROR_NONE != ret, "iotcon_representation_create result(%s)", get_iotcon_error(ret));
ret = iotcon_attributes_create(&send_attributes);
- if (IOTCON_ERROR_NONE != ret) {
+ if (IOTCON_ERROR_NONE != ret)
+ {
ERR("iotcon_attributes_create() Fail(%d)", ret);
iotcon_representation_destroy(send_repr);
return;
}
ret = iotcon_attributes_add_bool(send_attributes, "opened", !this->opened);
- if (IOTCON_ERROR_NONE != ret) {
+ if (IOTCON_ERROR_NONE != ret)
+ {
ERR("iotcon_attributes_add_bool() Fail(%d)", ret);
iotcon_attributes_destroy(send_attributes);
iotcon_representation_destroy(send_repr);
}
ret = iotcon_representation_set_attributes(send_repr, send_attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_representation_set_attributes() Fail(%s)", get_iotcon_error(ret));
iotcon_attributes_destroy(send_attributes);
iotcon_representation_destroy(send_repr);
return;
ret = iotcon_remote_resource_create(this->host, this->connectivity_type, this->created_uri_path,
IOTCON_RESOURCE_SECURE, this->types, this->ifaces, &new_door_resource);
- if (IOTCON_ERROR_NONE != ret) {
+ if (IOTCON_ERROR_NONE != ret)
+ {
ERR("iotcon_remote_resource_create() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_remote_resource_delete(new_door_resource, _on_response, this);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_delete() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_remote_resource_delete() Fail(%s)", get_iotcon_error(ret));
iotcon_remote_resource_destroy(new_door_resource);
return;
}
+
+ int result = iotcon_remote_resource_observe_register(this->resource_clone, IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER, NULL, _on_observe, this);
+ RETM_IF(IOTCON_ERROR_NONE != result, "iotcon_remote_resource_observe_register result(%s)", get_iotcon_error(result));
}
static void disable_control_button(iotcon_view *this, bool get, bool put, bool post, bool del)
this->post_btn = ui_utils_push_button_add(this, table, "POST", _post_button_pressed_cb);
elm_table_pack(table, this->post_btn, 2, 0, 1, 1);
- this->del_btn = ui_utils_push_button_add(this, table, "DEL", _del_button_pressed_cb);
+ this->del_btn = ui_utils_push_button_add(this, table, "DELETE", _del_button_pressed_cb);
elm_table_pack(table, this->del_btn, 3, 0, 1, 1);
disable_control_button(this, true, true, true, true);
return table;
}
-
-///////////////////////////////////////////client///////////////////////////////////////////////////
static void _on_observe(iotcon_remote_resource_h resource, iotcon_error_e err,
int sequence_number, iotcon_response_h response, void *user_data)
{
iotcon_representation_h repr;
iotcon_response_result_e response_result;
- RETM_IF(IOTCON_ERROR_NONE != err, "_on_observe error(%d)", err);
+ if(i==0)
+ {
+ #ifdef USE_GENLIST
+ elm_genlist_clear(this->info_list);
+ #else
+ elm_list_clear(this->info_list);
+ #endif
+ i=1;
+ }
+
+ RETM_IF(IOTCON_ERROR_NONE != err, "_on_observe error(%s)", get_iotcon_error(err));
ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_get_result() Fail(%s)", get_iotcon_error(ret));
return;
}
- if (IOTCON_RESPONSE_OK != response_result) {
+ if (IOTCON_RESPONSE_OK != response_result)
+ {
ERR("_on_response_observe Response error(%d)", response_result);
return;
}
ret = iotcon_response_get_representation(response, &repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_representation() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_get_representation() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_representation_get_attributes(repr, &attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_representation_get_attributes() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_attributes_get_bool(attributes, "opened", &opened);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_attributes_get_bool() Fail(%s)", get_iotcon_error(ret));
return;
}
DBG("notify_cb information");
- switch ((int)opened) {
+ switch ((int)opened)
+ {
case true:
DBG("[Door] opened.");
- elm_list_item_append(this->info_list,"[Door] opened.", NULL, NULL, NULL, NULL);
+#ifdef USE_GENLIST
+ _iotcon_elm_genlist_item_append(this->info_list, "[Door] opened.",NULL,NULL);
+#else
+ elm_list_item_append(this->info_list, "[Door] opened.", NULL, NULL, NULL, NULL);
+#endif
break;
case false:
DBG("[Door] closed.");
- elm_list_item_append(this->info_list,"[Door] closed.", NULL, NULL, NULL, NULL);
+#ifdef USE_GENLIST
+ _iotcon_elm_genlist_item_append(this->info_list, "[Door] closed.",NULL,NULL);
+#else
+ elm_list_item_append(this->info_list, "[Door] closed.", NULL, NULL, NULL, NULL);
+#endif
break;
default:
break;
}
-// if (5 == i++) {
-// iotcon_remote_resource_observe_deregister(resource);
-// iotcon_remote_resource_destroy(resource);
-// }
-
+#ifndef USE_GENLIST
elm_list_go(this->info_list);
+#endif
}
static void _on_response_delete(iotcon_remote_resource_h resource,
iotcon_response_result_e response_result;
ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_get_result() Fail(%s)", get_iotcon_error(ret));
return;
}
- if (IOTCON_RESPONSE_OK != response_result
- && IOTCON_RESPONSE_RESOURCE_DELETED != response_result) {
+ if (IOTCON_RESPONSE_OK != response_result && IOTCON_RESPONSE_RESOURCE_DELETED != response_result)
+ {
ERR("_on_response_delete Response error(%d)", response_result);
return;
}
- iotcon_remote_resource_observe_deregister(resource);
- DBG("DELETE request was successful");
disable_control_button(this, true, true, true, true);
-
/* delete callback operations */
-
iotcon_remote_resource_destroy(resource);
}
-static void _on_response_post(iotcon_remote_resource_h resource,
- iotcon_response_h response, void *user_data)
+static void _on_response_post(iotcon_remote_resource_h resource, iotcon_response_h response, void *user_data)
{
RETM_IF(NULL == user_data, "data is NULL");
this->ifaces = NULL;
ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_get_result() Fail(%s)", get_iotcon_error(ret));
return;
}
- if (IOTCON_RESPONSE_RESOURCE_CREATED != response_result) {
+ if (IOTCON_RESPONSE_RESOURCE_CREATED != response_result)
+ {
ERR("_on_response_post Response error(%d)", response_result);
return;
}
DBG("POST request was successful");
ret = iotcon_response_get_representation(response, &recv_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_representation() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_get_representation() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_representation_get_attributes(recv_repr, &recv_attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_representation_get_attributes() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_attributes_get_str(recv_attributes, "createduripath", &created_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_attributes_get_str() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_attributes_get_str() Fail(%s)", get_iotcon_error(ret));
return;
}
this->created_uri_path = strdup(created_uri_path);
DBG("New resource created : %s", this->created_uri_path);
ret = iotcon_remote_resource_get_host_address(resource, &this->host);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_host_address() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_remote_resource_get_host_address() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_remote_resource_get_connectivity_type(resource, &this->connectivity_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_connectivity_type() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_remote_resource_get_connectivity_type() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_remote_resource_get_types(resource, &this->types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_types() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_remote_resource_get_types() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_remote_resource_get_interfaces(resource, &this->ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_remote_resource_get_interfaces() Fail(%s)", get_iotcon_error(ret));
return;
}
iotcon_response_result_e response_result;
ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_get_result() Fail(%s)", get_iotcon_error(ret));
return;
}
- if (IOTCON_RESPONSE_RESOURCE_CHANGED != response_result) {
+ if (IOTCON_RESPONSE_RESOURCE_CHANGED != response_result)
+ {
ERR("_on_response_put Response error(%d)", response_result);
return;
}
return IOTCON_FUNC_CONTINUE;
}
-static void _presence_handler(iotcon_presence_h presence, iotcon_error_e err,
- iotcon_presence_response_h response, void *user_data)
+static void _presence_handler(iotcon_presence_h presence, iotcon_error_e err, iotcon_presence_response_h response, void *user_data)
{
char *host_address;
char *resource_type;
iotcon_presence_trigger_e trigger;
iotcon_connectivity_type_e connectivity_type;
- RETM_IF(IOTCON_ERROR_NONE != err, "_presence_handler error(%d)", err);
+ RETM_IF(IOTCON_ERROR_NONE != err, "_presence_handler error(%s)", get_iotcon_error(err));
ret = iotcon_presence_response_get_result(response, &result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_result() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_presence_response_get_result() Fail(%s)", get_iotcon_error(ret));
return;
}
- if (IOTCON_PRESENCE_OK == result) {
+ if (IOTCON_PRESENCE_OK == result)
+ {
ret = iotcon_presence_response_get_trigger(response, &trigger);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_trigger() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_presence_response_get_trigger() Fail(%s)", get_iotcon_error(ret));
return;
}
}
ret = iotcon_presence_response_get_host_address(response, &host_address);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_host_address() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_presence_response_get_host_address() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_presence_response_get_connectivity_type(response, &connectivity_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_connectivity_type() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_presence_response_get_connectivity_type() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_presence_response_get_resource_type(response, &resource_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_resource_type() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_presence_response_get_resource_type() Fail(%s)", get_iotcon_error(ret));
return;
}
this = (iotcon_view*)user_data;
RETM_IF(NULL == this, "view is NULL");
- RETM_IF(IOTCON_ERROR_NONE != err, "_on_response error(%d)", err);
+ RETM_IF(IOTCON_ERROR_NONE != err, "_on_response error(%s)", get_iotcon_error(err));
DBG("request(%d) was successful", request_type);
- switch (request_type) {
+ switch (request_type)
+ {
case IOTCON_REQUEST_GET:
_on_response_get(resource, response, this);
break;
RETVM_IF(IOTCON_ERROR_NONE != result, IOTCON_FUNC_STOP, "Invalid result(%s)", get_iotcon_error(result));
RETVM_IF(NULL == resource, IOTCON_FUNC_CONTINUE, "NULL == resource");
-
DBG("===== resource found =====");
-
/* get the resource URI */
ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
RETVM_IF(IOTCON_ERROR_NONE != ret, IOTCON_FUNC_CONTINUE, "iotcon_remote_resource_get_uri_path result(%s)", get_iotcon_error(ret));
{
DBG(" discovered_resource_list_show ");
RETM_IF(NULL == this, "view is NULL");
-
+#ifdef USE_GENLIST
+ elm_genlist_clear(this->info_list);
+#else
elm_list_clear(this->info_list);
+#endif
GList *l;
iotcon_remote_resource_h resource;
for(l = this->device_id_list; l != NULL; l = l->next)
{
-
char* resource_uri_path = NULL;
resource = (iotcon_remote_resource_h)l->data;
-
int result;
-
result = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
RETM_IF(IOTCON_ERROR_NONE != result, "iotcon_remote_resource_get_uri_path result(%s)", get_iotcon_error(result));
-
-
if (!strncmp(DOOR_RESOURCE_URI_PREFIX, resource_uri_path,strlen(DOOR_RESOURCE_URI_PREFIX)))
{
char* resource_device_id;
result = iotcon_remote_resource_get_device_id(resource, &resource_device_id);
RETM_IF(IOTCON_ERROR_NONE != result, "iotcon_remote_resource_get_device_id result(%s)", get_iotcon_error(result));
-
- elm_list_item_append(this->info_list,resource_device_id, NULL, NULL, _resource_selected_cb, resource);
+#ifdef USE_GENLIST
+ _iotcon_elm_genlist_item_append(this->info_list, resource_device_id,_resource_selected_cb, resource);
+#else
+ elm_list_item_append(this->info_list,resource_device_id, NULL, NULL, _resource_selected_cb, resource);
+#endif
}
-
}
+#ifndef USE_GENLIST
elm_list_go(this->info_list);
+#endif
evas_object_show(this->info_list);
}
DBG("resource_device_id: %s", resource_device_id);
}
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-static iotcon_resource_h _create_door_resource(char *uri_path, char *type,
- iotcon_resource_interfaces_h ifaces, uint8_t policies, void *user_data)
+static iotcon_resource_h _create_door_resource(char *uri_path, char *type, iotcon_resource_interfaces_h ifaces, uint8_t policies, void *user_data)
{
RETVM_IF(NULL == user_data, false, "data is NULL");
iotcon_resource_types_h resource_types;
ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_create() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_resource_types_create() Fail(%s)", get_iotcon_error(ret));
return NULL;
}
ret = iotcon_resource_types_add(resource_types, type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_add() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_resource_types_add() Fail(%s)", get_iotcon_error(ret));
iotcon_resource_types_destroy(resource_types);
return NULL;
}
/* register door resource */
- ret = iotcon_resource_create(uri_path, resource_types, ifaces, policies,
- _request_handler, this, &handle);
- if (IOTCON_ERROR_NONE != ret) {
+ ret = iotcon_resource_create(uri_path, resource_types, ifaces, policies, _request_handler, this, &handle);
+ if (IOTCON_ERROR_NONE != ret)
+ {
ERR("iotcon_resource_create() Fail");
iotcon_resource_types_destroy(resource_types);
return NULL;
ret = iotcon_resource_notify(door->handle, repr, door->observers, IOTCON_QOS_HIGH);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_notify() Fail(%d)", ret);
+ ERR("iotcon_resource_notify() Fail(%s)", get_iotcon_error(ret));
iotcon_representation_destroy(repr);
return;
}
/* create a door Representation */
ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_representation_create() Fail(%s)", get_iotcon_error(ret));
return NULL;
}
/* create a door attributes */
ret = iotcon_attributes_create(&attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_attributes_create() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_attributes_create() Fail(%s)", get_iotcon_error(ret));
iotcon_representation_destroy(repr);
return NULL;
}
ret = iotcon_representation_set_uri_path(repr, door->uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_representation_set_uri_path() Fail(%s)", get_iotcon_error(ret));
iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
ret = iotcon_attributes_add_bool(attributes, "opened", door->attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_attributes_add_bool() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_attributes_add_bool() Fail(%s)", get_iotcon_error(ret));
iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
ret = iotcon_representation_set_attributes(repr, attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_representation_set_attributes() Fail(%s)", get_iotcon_error(ret));
iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
iotcon_attributes_h attributes;
ret = iotcon_representation_get_attributes(repr, &attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_representation_get_attributes() Fail(%s)", get_iotcon_error(ret));
return -1;
}
ret = iotcon_attributes_get_bool(attributes, "opened", &bval);
- if (IOTCON_ERROR_NONE != ret) {
+ if (IOTCON_ERROR_NONE != ret)
+ {
ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
return -1;
}
static bool _query_cb(const char *key, const char *value, void *user_data)
{
DBG("key : %s, value : %s", key, value);
-
return IOTCON_FUNC_CONTINUE;
}
RETM_IF(NULL == request, "request is NULL");
ret = iotcon_request_get_host_address(request, &host_address);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_host_address() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_request_get_host_address() Fail(%s)", get_iotcon_error(ret));
_send_response(request, NULL, IOTCON_RESPONSE_ERROR);
return;
}
DBG("host_address : %s", host_address);
ret = iotcon_request_get_query(request, &query);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_query() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_request_get_query() Fail(%s)", get_iotcon_error(ret));
_send_response(request, NULL, IOTCON_RESPONSE_ERROR);
return;
}
iotcon_query_foreach(query, _query_cb, NULL);
ret = iotcon_request_get_request_type(request, &type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_request_type() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_request_get_request_type() Fail(%s)", get_iotcon_error(ret));
_send_response(request, NULL, IOTCON_RESPONSE_ERROR);
return;
}
if (IOTCON_REQUEST_GET == type)
{
ret = _request_handler_get(door, request);
+ if(ret == -1)return;
str = format_string("%s", "GET");
- elm_list_item_append(this->info_list, str, NULL, NULL, NULL, NULL);
+#ifdef USE_GENLIST
+ _iotcon_elm_genlist_item_append(this->info_list, str,NULL,NULL);
+#else
+ elm_list_item_append(this->info_list, str, NULL, NULL, NULL, NULL);
+#endif
SAFE_DELETE(str);
}
else if (IOTCON_REQUEST_PUT == type)
{
ret = _request_handler_put(door, request);
+ if(ret == -1)return;
str = format_string("%s", "PUT");
- elm_list_item_append(this->info_list, str, NULL, NULL, NULL, NULL);
+#ifdef USE_GENLIST
+ _iotcon_elm_genlist_item_append(this->info_list, str,NULL,NULL);
+#else
+ elm_list_item_append(this->info_list, str, NULL, NULL, NULL, NULL);
+#endif
SAFE_DELETE(str);
}
else if (IOTCON_REQUEST_POST == type)
{
- ret = _request_handler_post(door, request);
+ ret = _request_handler_post(door, request, this);
+ if(ret == -1)return;
str = format_string("%s", "POST");
- elm_list_item_append(this->info_list, str, NULL, NULL, NULL, NULL);
+#ifdef USE_GENLIST
+ _iotcon_elm_genlist_item_append(this->info_list, str,NULL,NULL);
+#else
+ elm_list_item_append(this->info_list, str, NULL, NULL, NULL, NULL);
+#endif
SAFE_DELETE(str);
}
-
else if (IOTCON_REQUEST_DELETE == type)
{
ret = _request_handler_delete(resource, request);
+ if(ret == -1)return;
str = format_string("%s", "DELETE");
- elm_list_item_append(this->info_list, str, NULL, NULL, NULL, NULL);
+#ifdef USE_GENLIST
+ _iotcon_elm_genlist_item_append(this->info_list, str,NULL,NULL);
+#else
+ elm_list_item_append(this->info_list, str, NULL, NULL, NULL, NULL);
+#endif
SAFE_DELETE(str);
elm_object_disabled_set(this->iotcon_btn, false);
DBG("Delete Request get");
}
-
+#ifndef USE_GENLIST
elm_list_go(this->info_list);
-// evas_object_show(this->info_list);
-
- if (0 != ret) {
+#endif
+ if (0 != ret)
+ {
_send_response(request, NULL, IOTCON_RESPONSE_ERROR);
return;
}
ret = iotcon_request_get_observe_type(request, &observe_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_type() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_request_get_observe_type() Fail(%s)", get_iotcon_error(ret));
return;
}
- if (IOTCON_OBSERVE_REGISTER == observe_type) {
+ if (IOTCON_OBSERVE_REGISTER == observe_type)
+ {
ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_id() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_request_get_observe_id() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_observers_add(door->observers, observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_observers_add() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_observers_add() Fail(%s)", get_iotcon_error(ret));
return;
}
- } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
+ }
+ else if (IOTCON_OBSERVE_DEREGISTER == observe_type)
+ {
ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_id() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_request_get_observe_id() Fail(%s)", get_iotcon_error(ret));
return;
}
ret = iotcon_observers_remove(door->observers, observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_observers_remove() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_observers_remove() Fail(%s)", get_iotcon_error(ret));
return;
}
}
-
}
-static int _request_handler_delete(iotcon_resource_h resource,
- iotcon_request_h request)
+static int _request_handler_delete(iotcon_resource_h resource, iotcon_request_h request)
{
int ret;
DBG("DELETE request");
ret = iotcon_resource_destroy(resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_destroy() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_resource_destroy() Fail(%s)", get_iotcon_error(ret));
return -1;
}
ret = _send_response(request, NULL, IOTCON_RESPONSE_RESOURCE_DELETED);
- if (0 != ret) {
+ if (0 != ret)
+ {
ERR("_send_response() Fail(%d)", ret);
return -1;
}
}
-static int _request_handler_post(door_resource_s *door, iotcon_request_h request)
+static int _request_handler_post(door_resource_s *door, iotcon_request_h request, void* user_data)
{
int ret;
iotcon_attributes_h resp_attributes;
iotcon_representation_h resp_repr = NULL;
iotcon_resource_h new_door_handle;
DBG("POST request");
+ RETVM_IF(NULL == user_data,-1, "data is NULL");
+ iotcon_view *this = NULL;
+ this = (iotcon_view*)user_data;
+ RETVM_IF(NULL == this,-1, "view is NULL");
+
- if (_resource_created) {
+ if (_resource_created)
+ {
ERR("Resource(%s) is already created", DOOR_RESOURCE_URI2);
return -1;
}
- new_door_handle = _create_door_resource(DOOR_RESOURCE_URI2, door->type,
- door->ifaces, IOTCON_RESOURCE_SECURE, door);
- if (NULL == new_door_handle) {
+ new_door_handle = _create_door_resource(DOOR_RESOURCE_URI2, door->type, door->ifaces, IOTCON_RESOURCE_SECURE, this);
+ if (NULL == new_door_handle)
+ {
ERR("_create_door_resource() Fail");
return -1;
}
/* send information that new resource was created */
ret = iotcon_representation_create(&resp_repr);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
+ ERR("iotcon_representation_create() Fail(%s)", get_iotcon_error(ret));
return -1;
}
ret = iotcon_attributes_create(&resp_attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_attributes_create() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_attributes_create() Fail(%s)", get_iotcon_error(ret));
iotcon_representation_destroy(resp_repr);
return -1;
}
ret = iotcon_attributes_add_str(resp_attributes, "createduripath", DOOR_RESOURCE_URI2);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_attributes_add_str() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_attributes_add_str() Fail(%s)", get_iotcon_error(ret));
iotcon_attributes_destroy(resp_attributes);
iotcon_representation_destroy(resp_repr);
return -1;
}
ret = iotcon_representation_set_attributes(resp_repr, resp_attributes);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_representation_set_attributes() Fail(%s)", get_iotcon_error(ret));
iotcon_attributes_destroy(resp_attributes);
iotcon_representation_destroy(resp_repr);
return -1;
iotcon_attributes_destroy(resp_attributes);
ret = _send_response(request, resp_repr, IOTCON_RESPONSE_RESOURCE_CREATED);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
+ if (0 != ret)
+ {
+ ERR("_send_response() Fail(%s)", get_iotcon_error(ret));
iotcon_representation_destroy(resp_repr);
return -1;
}
DBG("PUT request");
ret = iotcon_request_get_representation(request, &req_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_representation() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_request_get_representation() Fail(%s)", get_iotcon_error(ret));
return -1;
}
ret = _set_door_representation(door, req_repr);
- if (0 != ret) {
- ERR("_set_door_representation() Fail(%d)", ret);
+ if (0 != ret)
+ {
+ ERR("_set_door_representation() Fail(%s)", get_iotcon_error(ret));
return -1;
}
_check_door_attributes(*door);
resp_repr = _get_door_representation(door);
- if (NULL == resp_repr) {
+ if (NULL == resp_repr)
+ {
ERR("_get_door_representation() Fail");
return -1;
}
ret = _send_response(request, resp_repr, IOTCON_RESPONSE_OK);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
+ if (0 != ret)
+ {
+ ERR("_send_response() Fail(%s)", get_iotcon_error(ret));
iotcon_representation_destroy(resp_repr);
return -1;
}
/* notify */
ret = iotcon_resource_notify(door->handle, resp_repr, door->observers, IOTCON_QOS_HIGH);
if (IOTCON_ERROR_NONE != ret)
- ERR("iotcon_resource_notify() Fail(%d)", ret);
+ ERR("iotcon_resource_notify() Fail(%s)", get_iotcon_error(ret));
iotcon_representation_destroy(resp_repr);
DBG("GET request");
resp_repr = _get_door_representation(door);
- if (NULL == resp_repr) {
+ if (NULL == resp_repr)
+ {
ERR("_get_door_representation() Fail");
return -1;
}
ret = _send_response(request, resp_repr, IOTCON_RESPONSE_OK);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
+ if (0 != ret)
+ {
+ ERR("_send_response() Fail(%s)", get_iotcon_error(ret));
iotcon_representation_destroy(resp_repr);
return -1;
}
iotcon_response_h response;
ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_create() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_create() Fail(%s)", get_iotcon_error(ret));
return -1;
}
ret = iotcon_response_set_result(response, result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_set_result() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_set_result() Fail(%s)", get_iotcon_error(ret));
iotcon_response_destroy(response);
return -1;
}
ret = iotcon_response_set_representation(response, repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_set_representation() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_set_representation() Fail(%s)", get_iotcon_error(ret));
iotcon_response_destroy(response);
return -1;
}
/* send Representation to the client */
ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_send() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_response_send() Fail(%s)", get_iotcon_error(ret));
iotcon_response_destroy(response);
return -1;
}
iotcon_response_destroy(response);
-
return 0;
}
door->attributes = false;
door->uri_path = strdup(DOOR_RESOURCE_URI);
- if (NULL == door->uri_path) {
+ if (NULL == door->uri_path)
+ {
ERR("strdup(%s) Fail", DOOR_RESOURCE_URI);
return -1;
}
door->type = strdup(DOOR_RESOURCE_TYPE);
- if (NULL == door->type) {
+ if (NULL == door->type)
+ {
ERR("strdup(%s) Fail", DOOR_RESOURCE_TYPE);
SAFE_DELETE(door->uri_path);
return -1;
}
ret = iotcon_resource_interfaces_create(&door->ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_resource_interfaces_create() Fail(%s)", get_iotcon_error(ret));
SAFE_DELETE(door->type);
SAFE_DELETE(door->uri_path);
return ret;
}
ret = iotcon_resource_interfaces_add(door->ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
+ if (IOTCON_ERROR_NONE != ret)
+ {
+ ERR("iotcon_resource_interfaces_add() Fail(%s)", get_iotcon_error(ret));
iotcon_resource_interfaces_destroy(door->ifaces);
SAFE_DELETE(door->type);
SAFE_DELETE(door->uri_path);
| IOTCON_RESOURCE_SECURE;
ret = iotcon_observers_create(&door->observers);
- if (IOTCON_ERROR_NONE != ret) {
+ if (IOTCON_ERROR_NONE != ret)
+ {
ERR("iotcon_observers_create() Fail");
iotcon_resource_interfaces_destroy(door->ifaces);
SAFE_DELETE(door->type);
{
char* err_msg;
- switch (err) {
+ switch (err)
+ {
case IOTCON_ERROR_NONE:
err_msg = "IOTCON_ERROR_NONE";
break;