summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJin Yoon <jinny.yoon@samsung.com>2017-09-12 09:50:02 +0900
committerJin Yoon <jinny.yoon@samsung.com>2017-09-12 09:50:02 +0900
commit0ac403760ad74cea3372a69dc03f3a78aef7148a (patch)
tree955bc8ae82cb15d3bf010ba32dc6a62e6d225435 /src
parent3e9be00dba2ea9e5abd0aaec1aa8f17f710ef3c6 (diff)
downloadposition-finder-server-0ac403760ad74cea3372a69dc03f3a78aef7148a.tar.gz
position-finder-server-0ac403760ad74cea3372a69dc03f3a78aef7148a.tar.bz2
position-finder-server-0ac403760ad74cea3372a69dc03f3a78aef7148a.zip
Use a conf file to get 'path' and 'address'
Change-Id: I35d7aa41ae3a01b98071e3dd73cdff2c12b23115
Diffstat (limited to 'src')
-rw-r--r--src/connectivity.c35
-rw-r--r--src/controller.c4
-rw-r--r--src/controller_internal.c2
-rw-r--r--src/controller_util.c110
-rw-r--r--src/resource/resource_infrared_obstacle_avoidance_sensor.c2
-rw-r--r--src/webutil.c37
6 files changed, 124 insertions, 66 deletions
diff --git a/src/connectivity.c b/src/connectivity.c
index a6b0350..3154e2d 100644
--- a/src/connectivity.c
+++ b/src/connectivity.c
@@ -455,28 +455,6 @@ void connectivity_unset_resource(connectivity_resource_s *resource_info)
free(resource_info);
}
-static int _get_default_path_in_conf(char *buf, int size)
-{
- FILE *in = NULL;
- size_t nread = 0;
-
- in = fopen(CONF_FILE, "r");
- retv_if(!in, -1);
-
- nread = fread(buf, 1, size, in);
- if (nread <= 0) {
- _I("No contents in the conf.");
- return -1;
- }
-
- if (buf[nread - 1] == '\n')
- buf[nread - 1] = '\0';
-
- fclose(in);
-
- return 0;
-}
-
int connectivity_set_resource(const char *path, const char *type, connectivity_resource_s **out_resource_info)
{
iotcon_resource_types_h resource_types = NULL;
@@ -484,18 +462,15 @@ int connectivity_set_resource(const char *path, const char *type, connectivity_r
connectivity_resource_s *resource_info = NULL;
uint8_t policies;
int ret = -1;
- char default_path[URI_PATH_LEN] = { 0, };
+
+ retv_if(!path, -1);
+ retv_if(!type, -1);
+ retv_if(!out_resource_info, -1);
resource_info = calloc(1, sizeof(connectivity_resource_s));
retv_if(!resource_info, -1);
- if (path) {
- resource_info->path = strdup(path);
- } else {
- ret = _get_default_path_in_conf(default_path, URI_PATH_LEN);
- retv_if(ret < 0, -1);
- resource_info->path = strdup(default_path);
- }
+ resource_info->path = strdup(path);
goto_if(!resource_info->path, error);
_D("Path : [%s]", resource_info->path);
diff --git a/src/controller.c b/src/controller.c
index e6e4ae3..c80090e 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -29,9 +29,11 @@
#include "resource.h"
#include "connectivity.h"
#include "controller.h"
+#include "controller_util.h"
+#include "webutil.h"
#define CONNECTIVITY_KEY "opened"
-#define SENSORING_TIME_INTERVAL 5.0f
+#define SENSORING_TIME_INTERVAL 1.0f
typedef struct app_data_s {
Ecore_Timer *getter_timer;
diff --git a/src/controller_internal.c b/src/controller_internal.c
index cd24bad..28002f7 100644
--- a/src/controller_internal.c
+++ b/src/controller_internal.c
@@ -24,6 +24,7 @@
#include "log.h"
#include "connectivity.h"
#include "resource.h"
+#include "controller_util.h"
void controller_init_internal_functions(void)
{
@@ -35,4 +36,5 @@ void controller_fini_internal_functions(void)
_I("Terminating...");
resource_close_all();
connectivity_fini();
+ controller_util_free();
}
diff --git a/src/controller_util.c b/src/controller_util.c
new file mode 100644
index 0000000..b894f76
--- /dev/null
+++ b/src/controller_util.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ * Geunsun Lee <gs86.lee@samsung.com>
+ * Eunyoung Lee <ey928.lee@samsung.com>
+ * Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <glib.h>
+
+#include "log.h"
+
+#define CONF_GROUP_DEFAULT_NAME "default"
+#define CONF_KEY_PATH_NAME "path"
+#define CONF_KEY_ADDRESS_NAME "address"
+
+struct controller_util_s {
+ char *path;
+ char *address;
+};
+
+struct controller_util_s controller_util = { 0, };
+
+static int _read_conf_file(void)
+{
+ GKeyFile *gkf = NULL;
+
+ gkf = g_key_file_new();
+ retv_if(!gkf, -1);
+
+ if (!g_key_file_load_from_file(gkf, CONF_FILE, G_KEY_FILE_NONE, NULL)) {
+ _E("could not read config file %s", CONF_FILE);
+ return -1;
+ }
+
+ controller_util.path = g_key_file_get_string(gkf,
+ CONF_GROUP_DEFAULT_NAME,
+ CONF_KEY_PATH_NAME,
+ NULL);
+ if (!controller_util.path)
+ _E("could not get the key string");
+
+ controller_util.address = g_key_file_get_string(gkf,
+ CONF_GROUP_DEFAULT_NAME,
+ CONF_KEY_ADDRESS_NAME,
+ NULL);
+ if (!controller_util.address)
+ _E("could not get the key string");
+
+ g_key_file_free(gkf);
+
+ return 0;
+}
+
+int controller_util_get_path(const char **path)
+{
+ retv_if(!path, -1);
+
+ if (!controller_util.path) {
+ int ret = -1;
+ ret = _read_conf_file();
+ retv_if(-1 == ret, -1);
+ }
+
+ *path = controller_util.path;
+
+ return 0;
+}
+
+int controller_util_get_address(const char **address)
+{
+ retv_if(!address, -1);
+
+ if (!controller_util.address) {
+ int ret = -1;
+ ret = _read_conf_file();
+ retv_if(-1 == ret, -1);
+ }
+
+ *address = controller_util.address;
+
+ return 0;
+}
+
+void controller_util_free(void)
+{
+ if (controller_util.path) {
+ free(controller_util.path);
+ controller_util.path = NULL;
+ }
+
+ if (controller_util.address) {
+ free(controller_util.address);
+ controller_util.address = NULL;
+ }
+}
diff --git a/src/resource/resource_infrared_obstacle_avoidance_sensor.c b/src/resource/resource_infrared_obstacle_avoidance_sensor.c
index 29ef463..1bbfb38 100644
--- a/src/resource/resource_infrared_obstacle_avoidance_sensor.c
+++ b/src/resource/resource_infrared_obstacle_avoidance_sensor.c
@@ -56,5 +56,7 @@ int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value
_I("Infrared Obstacle Avoidance Sensor Value : %d", *out_value);
+ *out_value = !*out_value;
+
return 0;
}
diff --git a/src/webutil.c b/src/webutil.c
index 55fd071..d1fed79 100644
--- a/src/webutil.c
+++ b/src/webutil.c
@@ -175,28 +175,6 @@ int web_util_json_data_array_end(void)
return 0;
}
-static int _get_default_path_in_conf(char *buf, int size)
-{
- FILE *in = NULL;
- size_t nread = 0;
-
- in = fopen(CONF_FILE, "r");
- retv_if(!in, -1);
-
- nread = fread(buf, 1, size, in);
- if (nread <= 0) {
- _I("No contents in the conf.");
- return -1;
- }
-
- if (buf[nread - 1] == '\n')
- buf[nread - 1] = '\0';
-
- fclose(in);
-
- return 0;
-}
-
int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_s *sensor_data)
{
const char n_id[] = "SensorPiID";
@@ -217,10 +195,8 @@ int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_
const char n_gas[] = "Gas";
const char n_e_sensor[] = "SensorEnabled";
const char n_hash[] = "Hash";
- const char *path = NULL;
- char default_path[URI_PATH_LEN] = { 0, };
- int ret = -1;
+ retv_if(!sensorpi_id, -1);
retv_if(Json_h.builder == NULL, -1);
retv_if(Json_h.is_begin == false, -1);
retv_if(Json_h.is_end == true, -1);
@@ -249,20 +225,11 @@ int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_
}
*/
- if (sensorpi_id) {
- path = sensorpi_id;
- } else {
- ret = _get_default_path_in_conf(default_path, URI_PATH_LEN);
- retv_if(ret < 0, -1);
- path = default_path;
- }
- retv_if(!path, -1);
- retv_if(0 == strlen(path), -1);
json_builder_begin_object(Json_h.builder);
json_builder_set_member_name(Json_h.builder, n_id);
- json_builder_add_string_value(Json_h.builder, path);
+ json_builder_add_string_value(Json_h.builder, sensorpi_id);
if (sensor_data->enabled_sensor & WEB_UTIL_SENSOR_MOTION) {
json_builder_set_member_name(Json_h.builder, n_motion);