summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCMakeLists.txt4
-rw-r--r--inc/controller_util.h29
-rw-r--r--packaging/org.tizen.position-finder-server.spec3
-rw-r--r--res/pi.conf3
-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
10 files changed, 161 insertions, 68 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f86c5a1..041fa7c 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,7 +25,7 @@ pkg_check_modules(APP_PKGS REQUIRED
ADD_DEFINITIONS(-DCBOR_FILE_IN_RES="${INSTALL_RESDIR}/${CBOR_FILE}")
ADD_DEFINITIONS(-DCBOR_FILE_IN_DATA="${INSTALL_OWNER_DATADIR}/${CBOR_FILE}")
-ADD_DEFINITIONS(-DCONF_FILE="${INSTALL_OWNER_DATADIR}/${CONF_FILE}")
+ADD_DEFINITIONS(-DCONF_FILE="${INSTALL_RESDIR}/${CONF_FILE}")
FOREACH (flag ${APP_PKGS_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -40,6 +40,7 @@ INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc)
ADD_EXECUTABLE(${PROJECT_NAME}
${PROJECT_ROOT_DIR}/src/controller.c
${PROJECT_ROOT_DIR}/src/controller_internal.c
+ ${PROJECT_ROOT_DIR}/src/controller_util.c
${PROJECT_ROOT_DIR}/src/connectivity.c
${PROJECT_ROOT_DIR}/src/webutil.c
${PROJECT_ROOT_DIR}/src/resource.c
@@ -69,5 +70,6 @@ INSTALL(DIRECTORY DESTINATION ${INSTALL_OWNER_DATADIR})
INSTALL(FILES ${ORG_PREFIX}.${PROJECT_NAME}.xml DESTINATION ${SYS_PACKAGES_DIR})
INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/default_icon.png DESTINATION ${SYS_ICONS_DIR} RENAME ${PROJECT_NAME}.png)
INSTALL(FILES ${PROJECT_ROOT_DIR}/res/${CBOR_FILE} DESTINATION ${INSTALL_RESDIR})
+INSTALL(FILES ${PROJECT_ROOT_DIR}/res/${CONF_FILE} DESTINATION ${INSTALL_RESDIR})
# End of a file
diff --git a/inc/controller_util.h b/inc/controller_util.h
new file mode 100644
index 0000000..29b5e46
--- /dev/null
+++ b/inc/controller_util.h
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+#ifndef __POSITION_FINDER_CONTROLLER_UTIL_H__
+#define __POSITION_FINDER_CONTROLLER_UTIL_H__
+
+int controller_util_get_path(const char **path);
+int controller_util_get_address(const char **address);
+void controller_util_free(void);
+
+#endif /* __POSITION_FINDER_CONTROLLER_UTIL_H__ */
diff --git a/packaging/org.tizen.position-finder-server.spec b/packaging/org.tizen.position-finder-server.spec
index 666094b..a1bb673 100644
--- a/packaging/org.tizen.position-finder-server.spec
+++ b/packaging/org.tizen.position-finder-server.spec
@@ -44,7 +44,7 @@ Server for Position Finder
%define _sys_packages_dir %{TZ_SYS_RO_PACKAGES}
%define _sys_license_dir %{TZ_SYS_SHARE}/license
%define _cbor_file iotcon-test-svr-db-server.dat
-%define _conf_file .dev_id
+%define _conf_file pi.conf
%ifarch %{arm}
export CFLAGS="$CFLAGS -DTIZEN_BUILD_TARGET"
@@ -97,6 +97,7 @@ chmod 666 %{_pkg_rw_data_dir}/*.dat
%files
%{_pkg_res_dir}/*.dat
+%{_pkg_res_dir}/*.conf
%manifest %{alias}.manifest
%defattr(-,root,root,-)
%{_pkg_rw_data_dir}
diff --git a/res/pi.conf b/res/pi.conf
new file mode 100644
index 0000000..84627d9
--- /dev/null
+++ b/res/pi.conf
@@ -0,0 +1,3 @@
+[default]
+path=/door/1
+address=http://tizentalks.xyz:3000/api/bang/data
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);