From: arya.k Date: Mon, 12 Oct 2015 15:17:24 +0000 (+0530) Subject: [RE][TIZEN] Fix for application crash when Back Button is pressed. X-Git-Tag: 1.0.1~50 X-Git-Url: http://review.tizen.org/git/?p=contrib%2Fiotivity.git;a=commitdiff_plain;h=73a98e07c61ecf161011be3da34bb2fe12acd81f [RE][TIZEN] Fix for application crash when Back Button is pressed. - Added Light resource creation and discovery. Change-Id: Ibe923a96d6445c00d7933d109c77bec9b3ac52e2 Signed-off-by: arya.k Reviewed-on: https://gerrit.iotivity.org/gerrit/3817 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/resource-encapsulation/examples/tizen/RESampleClientApp/inc/reclient.h b/service/resource-encapsulation/examples/tizen/RESampleClientApp/inc/reclient.h index c8734dc..5177093 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleClientApp/inc/reclient.h +++ b/service/resource-encapsulation/examples/tizen/RESampleClientApp/inc/reclient.h @@ -21,9 +21,20 @@ #ifndef RECLIENT_H__ #define RECLIENT_H__ +#include + typedef void(*ClientMenuHandler)(); typedef int ReturnValue; +const std::string TEMPERATURE_URI = "/a/TempSensor"; +const std::string LIGHT_URI = "/a/light"; +const std::string TEMPERATURE_RT = "oic.r.temperaturesensor"; +const std::string LIGHT_RT = "oic.r.light"; +const std::string TEMPERATURE_AK = "Temperature"; +const std::string LIGHT_AK = "Brightness"; + +void client_cb(void *data); + void *showClientAPIs(void *data); #endif // RECLIENT_H__ \ No newline at end of file diff --git a/service/resource-encapsulation/examples/tizen/RESampleClientApp/inc/reclientmain.h b/service/resource-encapsulation/examples/tizen/RESampleClientApp/inc/reclientmain.h index 0c947a0..55bd6ce 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleClientApp/inc/reclientmain.h +++ b/service/resource-encapsulation/examples/tizen/RESampleClientApp/inc/reclientmain.h @@ -43,6 +43,8 @@ using namespace OC; #define ELM_DEMO_EDJ "opt/usr/apps/org.tizen.resampleclient/res/ui_controls.edj" -void client_cb(void *data, Evas_Object *obj, void *event_info); +void discoverTempSensor(void *data, Evas_Object *obj, void *event_info); + +void discoverLight(void *data, Evas_Object *obj, void *event_info); #endif // RECLIENTMAIN_H__ \ No newline at end of file diff --git a/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclient.cpp b/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclient.cpp index d01f195..8761e1d 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclient.cpp +++ b/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclient.cpp @@ -23,12 +23,10 @@ #include #include "reclientmain.h" - #include "RCSDiscoveryManager.h" #include "RCSRemoteResourceObject.h" #include "RCSResourceAttributes.h" #include "RCSAddress.h" - #include "OCPlatform.h" # define checkResource nullptr == resource?false:true @@ -37,16 +35,13 @@ using namespace std; using namespace OC; using namespace OIC::Service; -constexpr int CORRECT_INPUT = 1; -constexpr int INCORRECT_INPUT = 2; -constexpr int QUIT_INPUT = 3; - std::shared_ptr resource; std::vector resourceList; std::unique_ptr discoveryTask; -const std::string defaultKey = "Temperature"; -const std::string resourceType = "oic.r.temperaturesensor"; +std::string g_resourceUri; +std::string g_resourceType; +std::string g_attributeKey; static Evas_Object *log_entry = NULL; static Evas_Object *list = NULL; @@ -93,7 +88,7 @@ void onResourceDiscovered(std::shared_ptr foundResource resourceList.push_back(foundResource); - if ("/a/TempSensor" == resourceURI) + if (g_resourceUri == resourceURI) resource = foundResource; } @@ -260,13 +255,12 @@ static void getAttributeFromRemoteServer(void *data, Evas_Object *obj, void *eve } } -static void setAttributeToRemoteServer(int setTemperature) +static void setAttributeToRemoteServer(int setValue) { - string key = "Temperature"; string logMessage = ""; RCSResourceAttributes setAttribute; - setAttribute[key] = setTemperature; + setAttribute[g_attributeKey] = setValue; if (checkResource) { @@ -421,8 +415,8 @@ static void getCachedAttribute(void *data, Evas_Object *obj, void *event_info) { try { - logMessage = logMessage + "KEY:" + defaultKey.c_str() + "
"; - int attrValue = resource->getCachedAttribute(defaultKey).get< int >(); + logMessage = logMessage + "KEY:" + g_attributeKey.c_str() + "
"; + int attrValue = resource->getCachedAttribute(g_attributeKey).get< int >(); logMessage = logMessage + "VALUE:" + to_string(attrValue) + "
"; } catch (const RCSBadRequestException &e) @@ -478,10 +472,12 @@ void discoverResource() while (!discoveryTask) { + resourceList.clear(); + resource = nullptr; try { discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType( - RCSAddress::multicast(), resourceType, &onResourceDiscovered); + RCSAddress::multicast(), g_resourceType, &onResourceDiscovered); } catch (const RCSPlatformException &e) { @@ -504,6 +500,7 @@ void cancelDiscoverResource() else { discoveryTask->cancel(); + discoveryTask = nullptr; logMessage += "Discovery canceled
"; @@ -538,31 +535,31 @@ popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info) { temperature_popup_fields *popup_fields = (temperature_popup_fields *)data; Evas_Object *entry = popup_fields->entry; - const char *temperatureString = elm_entry_entry_get(entry); + const char *attributeString = elm_entry_entry_get(entry); // Remove white spaces(if any) at the beginning int beginning = 0; - while (temperatureString[beginning] == ' ') + while (attributeString[beginning] == ' ') { (beginning)++; } - int len = strlen(temperatureString); - if (NULL == temperatureString || 1 > len) + int len = strlen(attributeString); + if (NULL == attributeString || 1 > len) { - dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL Temperature Value"); - string logMessage = "Temperature Cannot be NULL
"; + dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL attribute Value"); + string logMessage = g_attributeKey + " Cannot be NULL
"; logMessage += "----------------------
"; dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str()); ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage); } else { - int temperate = atoi(temperatureString); - string tempString(temperatureString); - setAttributeToRemoteServer(temperate); - dlog_print(DLOG_INFO, LOG_TAG, "#### Temperature to set : %d", temperate); + int attributeValue = atoi(attributeString); + string attrString(attributeString); + setAttributeToRemoteServer(attributeValue); + dlog_print(DLOG_INFO, LOG_TAG, "#### Attribute to set : %d", attributeValue); - string logMessage = "Temperature to set : " + tempString + "
"; + string logMessage = g_attributeKey + " to set : " + attrString + "
"; logMessage += "----------------------
"; dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str()); ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, @@ -573,7 +570,7 @@ popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info) } static void -list_scheduled_actionset_cb(void *data, Evas_Object *obj, void *event_info) +list_get_attribute_value_cb(void *data, Evas_Object *obj, void *event_info) { Evas_Object *popup, *btn; Evas_Object *nf = naviframe; @@ -585,7 +582,14 @@ list_scheduled_actionset_cb(void *data, Evas_Object *obj, void *event_info) elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0); eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL); evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_object_part_text_set(popup, "title,text", "Enter the temperature"); + if (LIGHT_RT == g_resourceType) + { + elm_object_part_text_set(popup, "title,text", "Enter the brightness"); + } + else + { + elm_object_part_text_set(popup, "title,text", "Enter the temperature"); + } layout = elm_layout_add(popup); elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_datetime_text"); @@ -598,7 +602,14 @@ list_scheduled_actionset_cb(void *data, Evas_Object *obj, void *event_info) evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL); eext_entry_selection_back_event_allow_set(entry, EINA_TRUE); - elm_object_part_text_set(entry, "elm.guide", "in degree celsius"); + if (LIGHT_RT == g_resourceType) + { + elm_object_part_text_set(entry, "elm.guide", "RANGE (0 - 50)"); + } + else + { + elm_object_part_text_set(entry, "elm.guide", "in degree celsius"); + } elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER); elm_object_part_content_set(layout, "elm.swallow.content", entry); @@ -676,7 +687,7 @@ void *showClientAPIs(void *data) getAttributeFromRemoteServer, NULL); elm_list_item_append(list, "4. Set Attribute", NULL, NULL, - list_scheduled_actionset_cb, NULL); + list_get_attribute_value_cb, NULL); elm_list_item_append(list, "5. Start Caching - No update", NULL, NULL, startCachingWithoutCallback, NULL); @@ -716,8 +727,7 @@ naviframe_pop_cb(void *data, Elm_Object_Item *it) return EINA_TRUE; } -// Method to be called when the Group APIs UI Button is selected -void client_cb(void *data, Evas_Object *obj, void *event_info) +void client_cb(void *data) { Evas_Object *layout; Evas_Object *scroller; @@ -771,3 +781,21 @@ void client_cb(void *data, Evas_Object *obj, void *event_info) nf_it = elm_naviframe_item_push(nf, "Resource Encapsulation", NULL, NULL, scroller, NULL); elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL); } + +void discoverTempSensor(void *data, Evas_Object *obj, void *event_info) +{ + g_resourceUri = TEMPERATURE_URI; + g_resourceType = TEMPERATURE_RT; + g_attributeKey = TEMPERATURE_AK; + + client_cb(data); +} + +void discoverLight(void *data, Evas_Object *obj, void *event_info) +{ + g_resourceUri = LIGHT_URI; + g_resourceType = LIGHT_RT; + g_attributeKey = LIGHT_AK; + + client_cb(data); +} diff --git a/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclientmain.cpp b/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclientmain.cpp index dfbbbf5..4e53fad 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclientmain.cpp +++ b/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclientmain.cpp @@ -69,6 +69,11 @@ create_list_view(appdata_s *ad) evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL); // Main Menu Items Here + elm_list_item_append(list, "Discover Temperature Sensor Resource", NULL, NULL, discoverTempSensor, + nf); + + elm_list_item_append(list, "Discover Light Resource", NULL, NULL, discoverLight, nf); + elm_list_go(list); // This button is set for devices which doesn't have H/W back key. @@ -76,8 +81,6 @@ create_list_view(appdata_s *ad) elm_object_style_set(btn, "naviframe/end_btn/default"); nf_it = elm_naviframe_item_push(nf, "Resource Encapsulation", btn, NULL, list, NULL); elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, ad->win); - - client_cb(nf, NULL, NULL); } diff --git a/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/remain.h b/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/remain.h index 1e5a899..99b5784 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/remain.h +++ b/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/remain.h @@ -35,7 +35,7 @@ using namespace OC; #ifdef LOG_TAG #undef LOG_TAG #endif -#define LOG_TAG "reservermain" +#define LOG_TAG "reserver" #if !defined(PACKAGE) #define PACKAGE "org.tizen.resampleserver" @@ -43,6 +43,8 @@ using namespace OC; #define ELM_DEMO_EDJ "opt/usr/apps/org.tizen.resampleserver/res/ui_controls.edj" -void serverCreateUI(void *data, Evas_Object *obj, void *event_info); +void temperatureResource(void *data, Evas_Object *obj, void *event_info); + +void lightResource(void *data, Evas_Object *obj, void *event_info); #endif // REMAIN_H__ \ No newline at end of file diff --git a/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/reserver.h b/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/reserver.h index a8386d1..8aed849 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/reserver.h +++ b/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/reserver.h @@ -36,11 +36,13 @@ constexpr int DEFALUT_VALUE = 0; constexpr int PRESENCE_ON = 1; constexpr int PRESENCE_OFF = 2; -std::string resourceUri = "/a/TempSensor"; -std::string resourceType = "oic.r.temperaturesensor"; -std::string resourceInterface = "oic.if."; -std::string attributeKey = "Temperature"; -int isPresenceOn = PRESENCE_ON; +const std::string TEMPERATURE_URI = "/a/TempSensor"; +const std::string LIGHT_URI = "/a/light"; +const std::string TEMPERATURE_RT = "oic.r.temperaturesensor"; +const std::string LIGHT_RT = "oic.r.light"; +const std::string TEMPERATURE_AK = "Temperature"; +const std::string LIGHT_AK = "Brightness"; +const std::string RESOURCE_INTERFACE = "oic.if."; enum class Control { @@ -54,6 +56,6 @@ void start_server(void *data, Evas_Object *obj, void *event_info); void start_server_cb(void *data, Evas_Object *obj, void *event_info); -void *showGroupAPIs(void *data); +void *showAPIs(void *data); #endif // RESERVER_H__ \ No newline at end of file diff --git a/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/remain.cpp b/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/remain.cpp index 849734a..57fb281 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/remain.cpp +++ b/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/remain.cpp @@ -66,7 +66,10 @@ create_list_view(appdata_s *ad) evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL); // Main Menu Items Here - elm_list_item_append(list, "Start Temperature Sensor", NULL, NULL, serverCreateUI, nf); + elm_list_item_append(list, "Start Temperature Sensor Resource", NULL, NULL, temperatureResource, + nf); + + elm_list_item_append(list, "Start Light Resource", NULL, NULL, lightResource, nf); elm_list_go(list); diff --git a/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/reserver.cpp b/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/reserver.cpp index 6f837c5..4e74617 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/reserver.cpp +++ b/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/reserver.cpp @@ -30,10 +30,16 @@ using namespace std; using namespace OC; using namespace OIC::Service; +# define checkServer NULL!=server?true:false + RCSResourceObject::Ptr server; +static bool serverStarted = false; static bool serverCallback = false; +int isPresenceOn = PRESENCE_ON; -# define checkServer NULL!=server?true:false +std::string g_resourceUri; +std::string g_resourceType; +std::string g_attributeKey; static Evas_Object *log_entry = NULL; static Evas_Object *list = NULL; @@ -70,17 +76,18 @@ void printAttribute(const RCSResourceAttributes &attrs) static void onDestroy() { - server = NULL; string logMessage = "SERVER DESTROYED"; - if(isPresenceOn == PRESENCE_ON) + if(true == serverStarted) { - OCPlatform::stopPresence(); - } + server = nullptr; + if(isPresenceOn == PRESENCE_ON) + { + OCPlatform::stopPresence(); + } - dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str()); - ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, - &logMessage); + serverStarted = false; + } } //hander for get request (if developer choose second option for resource Creation) @@ -129,16 +136,16 @@ static void list_selected_cb(void *data, Evas_Object *obj, void *event_info) elm_list_item_selected_set(it, EINA_FALSE); } -static void increaseTemp(void *data, Evas_Object *obj, void *event_info) +static void increaseAttribute(void *data, Evas_Object *obj, void *event_info) { string logMessage = ""; if (checkServer) { RCSResourceObject::LockGuard lock(server); - server->getAttributes()[attributeKey] = server->getAttribute(attributeKey) + 10; - string tempString = std::to_string(server->getAttribute(attributeKey)); - logMessage = "TEMPERATURE CHANGED : " + tempString + "
"; + server->getAttributes()[g_attributeKey] = server->getAttribute(g_attributeKey) + 1; + string tempString = std::to_string(server->getAttribute(g_attributeKey)); + logMessage = g_attributeKey + " CHANGED : " + tempString + "
"; } else @@ -152,16 +159,16 @@ static void increaseTemp(void *data, Evas_Object *obj, void *event_info) &logMessage); } -static void decreaseTemp(void *data, Evas_Object *obj, void *event_info) +static void decreaseAttribute(void *data, Evas_Object *obj, void *event_info) { string logMessage = ""; if (checkServer) { RCSResourceObject::LockGuard lock(server); - server->getAttributes()[attributeKey] = server->getAttribute(attributeKey) - 10; - string tempString = std::to_string(server->getAttribute(attributeKey)); - logMessage = "TEMPERATURE CHANGED : " + tempString + "
"; + server->getAttributes()[g_attributeKey] = server->getAttribute(g_attributeKey) - 1; + string tempString = std::to_string(server->getAttribute(g_attributeKey)); + logMessage = g_attributeKey + " CHANGED : " + tempString + "
"; } else { @@ -180,8 +187,8 @@ static void initServer() try { - server = RCSResourceObject::Builder(resourceUri, resourceType, - resourceInterface).setDiscoverable(true).setObservable(true).build(); + server = RCSResourceObject::Builder(g_resourceUri, g_resourceType, + RESOURCE_INTERFACE).setDiscoverable(true).setObservable(true).build(); } catch (const RCSPlatformException &e) { @@ -190,14 +197,14 @@ static void initServer() server->setAutoNotifyPolicy(RCSResourceObject::AutoNotifyPolicy::UPDATED); server->setSetRequestHandlerPolicy(RCSResourceObject::SetRequestHandlerPolicy::NEVER); - server->setAttribute(attributeKey, DEFALUT_VALUE); + server->setAttribute(g_attributeKey, DEFALUT_VALUE); string logMessage = "SERVER CREATED
"; dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str()); ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage); - ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showGroupAPIs, NULL); + ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showAPIs, NULL); } static void @@ -213,30 +220,30 @@ popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info) { datetime_popup_fields *popup_fields = (datetime_popup_fields *)data; Evas_Object *entry = popup_fields->entry; - const char *temperatureString = elm_entry_entry_get(entry); + const char *attributeString = elm_entry_entry_get(entry); // Remove white spaces(if any) at the beginning string logMessage = ""; int beginning = 0; - while (temperatureString[beginning] == ' ') + while (attributeString[beginning] == ' ') { (beginning)++; } - int len = strlen(temperatureString); - if (NULL == temperatureString || 1 > len) + int len = strlen(attributeString); + if (NULL == attributeString || 1 > len) { - dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL Temperature Value"); - logMessage = "Temperature Cannot be NULL
"; + dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL Value"); + logMessage = g_attributeKey + "Cannot be NULL
"; } else { if (checkServer) { RCSResourceObject::LockGuard lock(server); - int temperate = atoi(temperatureString); - server->getAttributes()[attributeKey] = temperate; - logMessage = "TEMPERATURE CHANGED : " + to_string(server->getAttribute - (attributeKey)) + "
"; + int attributeInt = atoi(attributeString); + server->getAttributes()[g_attributeKey] = attributeInt; + logMessage = g_attributeKey + " CHANGED : " + to_string(server->getAttribute + (g_attributeKey)) + "
"; } else { @@ -253,7 +260,7 @@ popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info) } static void -list_get_temperaure_cb(void *data, Evas_Object *obj, void *event_info) +list_get_attribute_cb(void *data, Evas_Object *obj, void *event_info) { Evas_Object *popup, *btn; Evas_Object *nf = naviframe; @@ -265,7 +272,14 @@ list_get_temperaure_cb(void *data, Evas_Object *obj, void *event_info) elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0); eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL); evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_object_part_text_set(popup, "title,text", "Enter the temperature"); + if (LIGHT_RT == g_resourceType) + { + elm_object_part_text_set(popup, "title,text", "Enter the brightness"); + } + else + { + elm_object_part_text_set(popup, "title,text", "Enter the temperature"); + } layout = elm_layout_add(popup); elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_datetime_text"); @@ -278,7 +292,15 @@ list_get_temperaure_cb(void *data, Evas_Object *obj, void *event_info) evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL); eext_entry_selection_back_event_allow_set(entry, EINA_TRUE); - elm_object_part_text_set(entry, "elm.guide", "in degree celsius"); + if (LIGHT_RT == g_resourceType) + { + elm_object_part_text_set(entry, "elm.guide", "RANGE (0 - 50)"); + } + else + { + elm_object_part_text_set(entry, "elm.guide", "in degree celsius"); + } + elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER); elm_object_part_content_set(layout, "elm.swallow.content", entry); @@ -311,21 +333,36 @@ list_get_temperaure_cb(void *data, Evas_Object *obj, void *event_info) evas_object_show(popup); } -void *showGroupAPIs(void *data) +void *showAPIs(void *data) { // Add items to the list only if the list is empty const Eina_List *eina_list = elm_list_items_get(list); int count = eina_list_count(eina_list); if (!count) { - elm_list_item_append(list, "1. Increase Temperature", NULL, NULL, - increaseTemp, NULL); + if (LIGHT_RT == g_resourceType) + { + elm_list_item_append(list, "1. Increase Brightness", NULL, NULL, + increaseAttribute, NULL); + + elm_list_item_append(list, "2. Decrease Brightness", NULL, NULL, + decreaseAttribute, NULL); - elm_list_item_append(list, "2. Decrease Temperature", NULL, NULL, - decreaseTemp, NULL); + elm_list_item_append(list, "3. Set Brightness", NULL, NULL, + list_get_attribute_cb, NULL); + } + else + { + elm_list_item_append(list, "1. Increase Temperature", NULL, NULL, + increaseAttribute, NULL); + + elm_list_item_append(list, "2. Decrease Temperature", NULL, NULL, + decreaseAttribute, NULL); + + elm_list_item_append(list, "3. Set Temperature", NULL, NULL, + list_get_attribute_cb, NULL); + } - elm_list_item_append(list, "3. Set Temperature", NULL, NULL, - list_get_temperaure_cb, NULL); elm_list_go(list); } @@ -408,6 +445,7 @@ void serverCreateUI(void *data, Evas_Object *obj, void *event_info) void start_server(void *data, Evas_Object *obj, void *event_info) { server = NULL; + serverStarted = true; string logMessage = "SERVER WITHOUT CALLBACK
"; serverCallback = false; @@ -421,6 +459,7 @@ void start_server(void *data, Evas_Object *obj, void *event_info) void start_server_cb(void *data, Evas_Object *obj, void *event_info) { server = NULL; + serverStarted = true; string logMessage = "SERVER WITH CALLBACK
"; serverCallback = true; @@ -442,3 +481,21 @@ void start_server_cb(void *data, Evas_Object *obj, void *event_info) &logMessage); } + +void temperatureResource(void *data, Evas_Object *obj, void *event_info) +{ + g_resourceUri = TEMPERATURE_URI; + g_resourceType = TEMPERATURE_RT; + g_attributeKey = TEMPERATURE_AK; + + serverCreateUI(data, NULL, NULL); +} + +void lightResource(void *data, Evas_Object *obj, void *event_info) +{ + g_resourceUri = LIGHT_URI; + g_resourceType = LIGHT_RT; + g_attributeKey = LIGHT_AK; + + serverCreateUI(data, NULL, NULL); +}