#define ULTRASONIC_RESOURCE_TYPE "org.tizen.door"
#define BUFSIZE 1024
#define URI_PATH_LEN 64
+#define URI_PATH "/door/1"
+#define PATH "path"
static void _request_resource_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data);
iotcon_representation_destroy(representation);
}
-static iotcon_representation_h _create_representation_with_bool(iotcon_resource_h res, const char *key, bool value)
+static iotcon_representation_h _create_representation_with_bool(connectivity_resource_s *resource_info, const char *key, bool value)
{
iotcon_attributes_h attributes = NULL;
iotcon_representation_h representation = NULL;
char *uri_path = NULL;
int ret = -1;
- ret = iotcon_resource_get_uri_path(res, &uri_path);
+ ret = iotcon_resource_get_uri_path(resource_info->res, &uri_path);
retv_if(IOTCON_ERROR_NONE != ret, NULL);
ret = iotcon_representation_create(&representation);
ret = iotcon_representation_set_uri_path(representation, uri_path);
goto_if(IOTCON_ERROR_NONE != ret, error);
+ ret = iotcon_attributes_add_str(attributes, PATH, resource_info->path);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
ret = iotcon_attributes_add_bool(attributes, key, value);
goto_if(IOTCON_ERROR_NONE != ret, error);
return NULL;
}
-static iotcon_representation_h _create_representation_with_int(iotcon_resource_h res, const char *key, int value)
+static iotcon_representation_h _create_representation_with_int(connectivity_resource_s *resource_info, const char *key, int value)
{
iotcon_attributes_h attributes = NULL;
iotcon_representation_h representation = NULL;
char *uri_path = NULL;
int ret = -1;
- ret = iotcon_resource_get_uri_path(res, &uri_path);
+ ret = iotcon_resource_get_uri_path(resource_info->res, &uri_path);
retv_if(IOTCON_ERROR_NONE != ret, NULL);
ret = iotcon_representation_create(&representation);
ret = iotcon_representation_set_uri_path(representation, uri_path);
goto_if(IOTCON_ERROR_NONE != ret, error);
- ret = iotcon_attributes_add_int(attributes, "opened", value);
+ ret = iotcon_attributes_add_str(attributes, PATH, resource_info->path);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ ret = iotcon_attributes_add_int(attributes, key, value);
goto_if(IOTCON_ERROR_NONE != ret, error);
ret = iotcon_representation_set_attributes(representation, attributes);
return NULL;
}
-static iotcon_representation_h _create_representation_with_double(iotcon_resource_h res, const char *key, double value)
+static iotcon_representation_h _create_representation_with_double(connectivity_resource_s *resource_info, const char *key, double value)
{
iotcon_attributes_h attributes = NULL;
iotcon_representation_h representation = NULL;
char *uri_path = NULL;
int ret = -1;
- ret = iotcon_resource_get_uri_path(res, &uri_path);
+ ret = iotcon_resource_get_uri_path(resource_info->res, &uri_path);
retv_if(IOTCON_ERROR_NONE != ret, NULL);
ret = iotcon_representation_create(&representation);
ret = iotcon_representation_set_uri_path(representation, uri_path);
goto_if(IOTCON_ERROR_NONE != ret, error);
- ret = iotcon_attributes_add_double(attributes, "opened", value);
+ ret = iotcon_attributes_add_str(attributes, PATH, resource_info->path);
+ goto_if(IOTCON_ERROR_NONE != ret, error);
+
+ ret = iotcon_attributes_add_double(attributes, key, value);
goto_if(IOTCON_ERROR_NONE != ret, error);
ret = iotcon_representation_set_attributes(representation, attributes);
_D("Notify the value[%d]", value);
- representation = _create_representation_with_bool(resource_info->res, key, value);
+ representation = _create_representation_with_bool(resource_info, key, value);
retv_if(!representation, -1);
ret = iotcon_resource_notify(resource_info->res, representation, resource_info->observers, IOTCON_QOS_HIGH);
_D("Notify the value[%d]", value);
- representation = _create_representation_with_int(resource_info->res, key, value);
+ representation = _create_representation_with_int(resource_info, key, value);
retv_if(!representation, -1);
ret = iotcon_resource_notify(resource_info->res, representation, resource_info->observers, IOTCON_QOS_HIGH);
_D("Notify the value[%f]", value);
- representation = _create_representation_with_double(resource_info->res, key, value);
+ representation = _create_representation_with_double(resource_info, key, value);
retv_if(!representation, -1);
ret = iotcon_resource_notify(resource_info->res, representation, resource_info->observers, IOTCON_QOS_HIGH);
ret_if(!resource_info);
if (resource_info->observers) iotcon_observers_destroy(resource_info->observers);
if (resource_info->res) iotcon_resource_destroy(resource_info->res);
+ if (resource_info->path) free(resource_info->path);
free(resource_info);
}
-static int _get_default_uri_path_in_conf(char *buf, int size)
+static int _get_default_path_in_conf(char *buf, int size)
{
FILE *in = NULL;
size_t nread = 0;
return 0;
}
-int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info)
+int connectivity_set_resource(const char *path, const char *type, connectivity_resource_s **out_resource_info)
{
iotcon_resource_types_h resource_types = NULL;
iotcon_resource_interfaces_h ifaces = NULL;
connectivity_resource_s *resource_info = NULL;
uint8_t policies;
int ret = -1;
- const char *final_uri_path = NULL;
- char default_uri_path[URI_PATH_LEN] = { 0, };
+ char default_path[URI_PATH_LEN] = { 0, };
+
+ resource_info = calloc(1, sizeof(connectivity_resource_s));
+ retv_if(!resource_info, -1);
- if (uri_path) {
- final_uri_path = uri_path;
+ if (path) {
+ resource_info->path = strdup(path);
} else {
- ret = _get_default_uri_path_in_conf(default_uri_path, URI_PATH_LEN);
+ ret = _get_default_path_in_conf(default_path, URI_PATH_LEN);
retv_if(ret < 0, -1);
- final_uri_path = default_uri_path;
+ resource_info->path = strdup(default_path);
}
+ goto_if(!resource_info->path, error);
- _D("uri path : [%s]", final_uri_path);
-
- resource_info = calloc(1, sizeof(connectivity_resource_s));
- retv_if(!resource_info, -1);
- *out_resource_info = resource_info;
+ _D("Path : [%s]", resource_info->path);
ret = iotcon_resource_types_create(&resource_types);
goto_if(IOTCON_ERROR_NONE != ret, error);
IOTCON_RESOURCE_OBSERVABLE |
IOTCON_RESOURCE_SECURE;
- ret = iotcon_resource_create(final_uri_path,
+ ret = iotcon_resource_create(URI_PATH,
resource_types,
ifaces,
policies,
iotcon_resource_types_destroy(resource_types);
iotcon_resource_interfaces_destroy(ifaces);
+ *out_resource_info = resource_info;
return 0;
if (ifaces) iotcon_resource_interfaces_destroy(ifaces);
if (resource_types) iotcon_resource_types_destroy(resource_types);
if (resource_info->res) iotcon_resource_destroy(resource_info->res);
+ if (resource_info->path) free(resource_info->path);
if (resource_info) free(resource_info);
return -1;
#include "connectivity.h"
#include "controller.h"
-#define GPIO_ULTRASONIC_TRIG_NUM_1 20
-#define GPIO_ULTRASONIC_ECHO_NUM_1 21
-#define MULTIPLE_SENSOR_NUMBER 5
#define CONNECTIVITY_KEY "opened"
+#define SENSORING_TIME_INTERVAL 1.0f
typedef struct app_data_s {
Ecore_Timer *getter_timer;
static Eina_Bool control_sensors_cb(void *data)
{
- int value[MULTIPLE_SENSOR_NUMBER] = { 0, };
- int total = 0;
- int gpio_num[MULTIPLE_SENSOR_NUMBER] = { 5, 6, 13, 19, 26 };
- int i = 0;
app_data *ad = data;
- /**
- * This is the case when a number of the same sensors are installed.
- * Each of the five infrared motion sensors will receive the value.
- */
- for (i = 0; i < MULTIPLE_SENSOR_NUMBER; i++) {
- /**
- * Infrared motion sensor outputs 1 if motion is detected, or 0 if motion is not detected.
- */
- if (resource_read_infrared_motion_sensor(gpio_num[i], &value[i]) == -1) {
- _E("Failed to get Infrared Motion value [GPIO:%d]", gpio_num[i]);
- continue;
- }
- /**
- * If at least one of the five infrared motion sensors detects motion (1),
- * it is judged that there is a person (total == 1).
- */
- total |= value[i];
- }
- _I("[5:%d] | [6:%d] | [13:%d] | [19:%d] | [26:%d] = [Total:%d]", value[0], value[1], value[2], value[3], value[4], total);
-
- /**
- * Notifies specific clients that resource's attributes have changed.
- */
- if (connectivity_notify_bool(ad->resource_info, CONNECTIVITY_KEY, total) == -1)
+ if (connectivity_notify_bool(ad->resource_info, CONNECTIVITY_KEY, true) == -1)
_E("Cannot notify message");
return ECORE_CALLBACK_RENEW;
/**
* Create a connectivity resource and registers the resource in server.
*/
- ret = connectivity_set_resource("/door/1", "org.tizen.door", &ad->resource_info);
+ ret = connectivity_set_resource(NULL, "org.tizen.door", &ad->resource_info);
if (ret == -1) _E("Cannot broadcast resource");
/**
* Creates a timer to call the given function in the given period of time.
* In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor.
*/
- ad->getter_timer = ecore_timer_add(0.5f, control_sensors_cb, ad);
+ ad->getter_timer = ecore_timer_add(SENSORING_TIME_INTERVAL, control_sensors_cb, ad);
if (!ad->getter_timer) {
_E("Failed to add infrared motion getter timer");
return false;