diff options
author | Jin Yoon <jinny.yoon@samsung.com> | 2017-08-08 19:55:39 +0900 |
---|---|---|
committer | Jin Yoon <jinny.yoon@samsung.com> | 2017-08-08 19:55:39 +0900 |
commit | d86a718678c2dc8a5ee557c08c11f301c8e47d59 (patch) | |
tree | 11c2283f081bfff285c39639638ec04c129dfb96 /src | |
parent | 385e0d94669178e257daced33990597d22bfa7e8 (diff) | |
download | rcc-d86a718678c2dc8a5ee557c08c11f301c8e47d59.tar.gz rcc-d86a718678c2dc8a5ee557c08c11f301c8e47d59.tar.bz2 rcc-d86a718678c2dc8a5ee557c08c11f301c8e47d59.zip |
Copy CBOR file from res dir to data dir for protecting crash
Change-Id: I02d9d726a3827c348d23f151a53fb1e03980d6f5
Diffstat (limited to 'src')
-rw-r--r-- | src/connectivity.c | 45 | ||||
-rw-r--r-- | src/controller.c | 6 | ||||
-rw-r--r-- | src/resource/resource_infrared_motion_sensor.c | 2 |
3 files changed, 47 insertions, 6 deletions
diff --git a/src/connectivity.c b/src/connectivity.c index eb281f1..9165cb9 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -19,6 +19,7 @@ * limitations under the License. */ +#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <glib.h> @@ -32,6 +33,9 @@ #define ULTRASONIC_RESOURCE_1_URI "/door/1" #define ULTRASONIC_RESOURCE_2_URI "/door/2" #define ULTRASONIC_RESOURCE_TYPE "org.tizen.door" +#define BUFSIZE 1024 +#define CBOR_FILE_IN_RES "/home/owner/apps_rw/org.tizen.position-finder-server/res/iotcon-test-svr-db-server.dat" +#define CBOR_FILE_IN_DATA "/home/owner/apps_rw/org.tizen.position-finder-server/data/iotcon-test-svr-db-server.dat" static void _request_resource_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data); @@ -302,12 +306,16 @@ static int _handle_observer(iotcon_request_h request, iotcon_observers_h observe ret = iotcon_request_get_observe_id(request, &observe_id); retv_if(IOTCON_ERROR_NONE != ret, -1); + _I("Add an observer : %d", observe_id); + ret = iotcon_observers_add(observers, observe_id); retv_if(IOTCON_ERROR_NONE != ret, -1); } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) { ret = iotcon_request_get_observe_id(request, &observe_id); retv_if(IOTCON_ERROR_NONE != ret, -1); + _I("Remove an observer : %d", observe_id); + ret = iotcon_observers_remove(observers, observe_id); retv_if(IOTCON_ERROR_NONE != ret, -1); } @@ -343,11 +351,46 @@ error: _send_response(request, NULL, IOTCON_RESPONSE_ERROR); } +static void _copy_file(const char *in_filename, const char *out_filename) +{ + char buf[BUFSIZE] = { 0, }; + size_t nread = 0; + FILE *in = NULL; + FILE *out = NULL; + + ret_if(!in_filename); + ret_if(!out_filename); + + in = fopen(in_filename, "r"); + ret_if(!in); + + out = fopen(out_filename, "w"); + goto_if(!out, error); + + rewind(in); + while ((nread = fread(buf, 1, sizeof(buf), in)) > 0) { + if (fwrite (buf, 1, nread, out) < nread) { + _E("critical error to copy a file"); + break; + } + } + + fclose(in); + fclose(out); + + return; + +error: + fclose(out); +} + int connectivity_init(void) { int ret = -1; - ret = iotcon_initialize("/home/owner/apps_rw/org.tizen.position-finder-server/data/iotcon-test-svr-db-server.dat"); + _copy_file(CBOR_FILE_IN_RES, CBOR_FILE_IN_DATA); + + ret = iotcon_initialize(CBOR_FILE_IN_DATA); retv_if(IOTCON_ERROR_NONE != ret, -1); ret = iotcon_set_device_name(ULTRASONIC_RESOURCE_TYPE); diff --git a/src/controller.c b/src/controller.c index 20388a7..e662a99 100644 --- a/src/controller.c +++ b/src/controller.c @@ -19,11 +19,11 @@ * limitations under the License. */ -#include <tizen.h> -#include <Ecore.h> -#include <service_app.h> #include <unistd.h> #include <glib.h> +#include <Ecore.h> +#include <tizen.h> +#include <service_app.h> #include <iotcon.h> // Please remove this after test diff --git a/src/resource/resource_infrared_motion_sensor.c b/src/resource/resource_infrared_motion_sensor.c index d20664f..40308a3 100644 --- a/src/resource/resource_infrared_motion_sensor.c +++ b/src/resource/resource_infrared_motion_sensor.c @@ -53,7 +53,5 @@ int resource_read_infrared_motion_sensor(int pin_num, int *out_value) ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value); retv_if(ret < 0, -1); - _I("Infrared Motion Sensor Value : %d", *out_value); - return 0; } |