- Added Light resource creation and discovery.
Change-Id: Ibe923a96d6445c00d7933d109c77bec9b3ac52e2
Signed-off-by: arya.k <arya.kumar@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3817
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
#ifndef RECLIENT_H__
#define RECLIENT_H__
+#include <string>
+
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
#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
#include<iostream>
#include "reclientmain.h"
-
#include "RCSDiscoveryManager.h"
#include "RCSRemoteResourceObject.h"
#include "RCSResourceAttributes.h"
#include "RCSAddress.h"
-
#include "OCPlatform.h"
# define checkResource nullptr == resource?false:true
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<RCSRemoteResourceObject> resource;
std::vector<RCSRemoteResourceObject::Ptr> resourceList;
std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> 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;
resourceList.push_back(foundResource);
- if ("/a/TempSensor" == resourceURI)
+ if (g_resourceUri == resourceURI)
resource = foundResource;
}
}
}
-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)
{
{
try
{
- logMessage = logMessage + "KEY:" + defaultKey.c_str() + "<br>";
- int attrValue = resource->getCachedAttribute(defaultKey).get< int >();
+ logMessage = logMessage + "KEY:" + g_attributeKey.c_str() + "<br>";
+ int attrValue = resource->getCachedAttribute(g_attributeKey).get< int >();
logMessage = logMessage + "VALUE:" + to_string(attrValue) + "<br>";
}
catch (const RCSBadRequestException &e)
while (!discoveryTask)
{
+ resourceList.clear();
+ resource = nullptr;
try
{
discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(
- RCSAddress::multicast(), resourceType, &onResourceDiscovered);
+ RCSAddress::multicast(), g_resourceType, &onResourceDiscovered);
}
catch (const RCSPlatformException &e)
{
else
{
discoveryTask->cancel();
+ discoveryTask = nullptr;
logMessage += "Discovery canceled <br>";
{
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<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL attribute Value");
+ string logMessage = g_attributeKey + " Cannot be NULL<br>";
logMessage += "----------------------<br>";
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 + "<br>";
+ string logMessage = g_attributeKey + " to set : " + attrString + "<br>";
logMessage += "----------------------<br>";
dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
}
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;
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");
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);
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);
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;
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);
+}
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.
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);
}
#ifdef LOG_TAG
#undef LOG_TAG
#endif
-#define LOG_TAG "reservermain"
+#define LOG_TAG "reserver"
#if !defined(PACKAGE)
#define PACKAGE "org.tizen.resampleserver"
#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
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
{
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
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);
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;
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)
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<int>(attributeKey) + 10;
- string tempString = std::to_string(server->getAttribute<int>(attributeKey));
- logMessage = "TEMPERATURE CHANGED : " + tempString + "<br>";
+ server->getAttributes()[g_attributeKey] = server->getAttribute<int>(g_attributeKey) + 1;
+ string tempString = std::to_string(server->getAttribute<int>(g_attributeKey));
+ logMessage = g_attributeKey + " CHANGED : " + tempString + "<br>";
}
else
&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<int>(attributeKey) - 10;
- string tempString = std::to_string(server->getAttribute<int>(attributeKey));
- logMessage = "TEMPERATURE CHANGED : " + tempString + "<br>";
+ server->getAttributes()[g_attributeKey] = server->getAttribute<int>(g_attributeKey) - 1;
+ string tempString = std::to_string(server->getAttribute<int>(g_attributeKey));
+ logMessage = g_attributeKey + " CHANGED : " + tempString + "<br>";
}
else
{
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)
{
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<br>";
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
{
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<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL Value");
+ logMessage = g_attributeKey + "Cannot be NULL<br>";
}
else
{
if (checkServer)
{
RCSResourceObject::LockGuard lock(server);
- int temperate = atoi(temperatureString);
- server->getAttributes()[attributeKey] = temperate;
- logMessage = "TEMPERATURE CHANGED : " + to_string(server->getAttribute<int>
- (attributeKey)) + "<br>";
+ int attributeInt = atoi(attributeString);
+ server->getAttributes()[g_attributeKey] = attributeInt;
+ logMessage = g_attributeKey + " CHANGED : " + to_string(server->getAttribute<int>
+ (g_attributeKey)) + "<br>";
}
else
{
}
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;
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");
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);
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);
}
void start_server(void *data, Evas_Object *obj, void *event_info)
{
server = NULL;
+ serverStarted = true;
string logMessage = "SERVER WITHOUT CALLBACK<br>";
serverCallback = false;
void start_server_cb(void *data, Evas_Object *obj, void *event_info)
{
server = NULL;
+ serverStarted = true;
string logMessage = "SERVER WITH CALLBACK<br>";
serverCallback = true;
&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);
+}