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}")
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
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
--- /dev/null
+/*
+ * 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__ */
%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"
%files
%{_pkg_res_dir}/*.dat
+%{_pkg_res_dir}/*.conf
%manifest %{alias}.manifest
%defattr(-,root,root,-)
%{_pkg_rw_data_dir}
--- /dev/null
+[default]
+path=/door/1
+address=http://tizentalks.xyz:3000/api/bang/data
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;
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);
#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;
#include "log.h"
#include "connectivity.h"
#include "resource.h"
+#include "controller_util.h"
void controller_init_internal_functions(void)
{
_I("Terminating...");
resource_close_all();
connectivity_fini();
+ controller_util_free();
}
--- /dev/null
+/*
+ * 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;
+ }
+}
_I("Infrared Obstacle Avoidance Sensor Value : %d", *out_value);
+ *out_value = !*out_value;
+
return 0;
}
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";
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);
}
*/
- 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);