Change resource_ultrasonic_sensor for Soscon2017
[apps/native/position-finder-server.git] / src / controller.c
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Contact: Jin Yoon <jinny.yoon@samsung.com>
5  *          Geunsun Lee <gs86.lee@samsung.com>
6  *          Eunyoung Lee <ey928.lee@samsung.com>
7  *          Junkyu Han <junkyu.han@samsung.com>
8  *
9  * Licensed under the Flora License, Version 1.1 (the License);
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://floralicense.org/license/
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an AS IS BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 #include <unistd.h>
23 #include <glib.h>
24 #include <Ecore.h>
25 #include <tizen.h>
26 #include <service_app.h>
27
28 #include "log.h"
29 #include "resource.h"
30 #include "connectivity.h"
31 #include "controller.h"
32 #include "controller_util.h"
33 #include "webutil.h"
34
35
36 /**
37  * DO NOT EDIT: please don't edit the time interval.
38  */
39 #define SENSORING_TIME_INTERVAL 2.0f
40
41 /**
42  * TODO: You have to use the pin numbers below.
43  * You can change the pin numbers freely.
44  */
45 #define TRIG_PIN_NUMBER 20
46 #define ECHO_PIN_NUMBER 21
47
48 typedef struct app_data_s {
49         Ecore_Timer *getter_timer;
50         connectivity_resource_s *resource_info;
51 } app_data;
52
53 static void _ultrasonic_sensor_read_cb(float value, void *data)
54 {
55         app_data *ad = data;
56
57         /**
58          * TODO: Send the value of the ultrasonic sensor to the Client.
59          */
60
61
62
63
64
65 }
66
67 static Eina_Bool _control_sensors_cb(void *data)
68 {
69         app_data *ad = data;
70
71         /**
72          * TODO: Prepare to read the value of the ultrasonic sensor.
73          */
74
75
76
77
78
79         return ECORE_CALLBACK_RENEW;
80 }
81
82 static bool service_app_create(void *data)
83 {
84         app_data *ad = data;
85         const char *path = NULL;
86
87         /**
88          * DO NOT EDIT: please don't edit the function below.
89          * Access only when modifying internal functions.
90          */
91         controller_init_internal_functions();
92
93         /**
94          * TODO: Get a path of the box.
95          * Get a predefined path based on where the box is placed.(e.g. "/door/1")
96          * The path is a string value that is passed as the first argument to the connectivity_set_resource().
97          */
98
99
100
101
102
103         /**
104          * Creates a connectivity resource and registers the resource in server.
105          */
106
107
108
109
110
111         /**
112          * Creates a timer to call the given function in the given period of time.
113          * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor.
114          */
115         ad->getter_timer = ecore_timer_add(SENSORING_TIME_INTERVAL, _control_sensors_cb, ad);
116         if (!ad->getter_timer) {
117                 _E("Failed to add infrared motion getter timer");
118                 return false;
119         }
120
121         return true;
122 }
123
124 static void service_app_terminate(void *data)
125 {
126         app_data *ad = (app_data *)data;
127
128         if (ad->getter_timer)
129                 ecore_timer_del(ad->getter_timer);
130
131         /**
132          * Releases the resource about connectivity.
133          */
134         connectivity_unset_resource(ad->resource_info);
135
136         /**
137          * DO NOT EDIT: please don't edit the function below.
138          * Access only when modifying internal functions.
139          */
140         controller_fini_internal_functions();
141
142         free(ad);
143 }
144
145 static void service_app_control(app_control_h app_control, void *data)
146 {
147         /*APP_CONTROL*/
148 }
149
150 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
151 {
152         /*APP_EVENT_LANGUAGE_CHANGED*/
153 }
154
155 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
156 {
157         /*APP_EVENT_REGION_FORMAT_CHANGED*/
158 }
159
160 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
161 {
162         /*APP_EVENT_LOW_BATTERY*/
163 }
164
165 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
166 {
167         /*APP_EVENT_LOW_MEMORY*/
168 }
169
170 int main(int argc, char* argv[])
171 {
172         app_data *ad = NULL;
173         int ret = 0;
174         service_app_lifecycle_callback_s event_callback;
175         app_event_handler_h handlers[5] = {NULL, };
176
177         ad = calloc(1, sizeof(app_data));
178         retv_if(!ad, -1);
179
180         event_callback.create = service_app_create;
181         event_callback.terminate = service_app_terminate;
182         event_callback.app_control = service_app_control;
183
184         service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
185         service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
186         service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
187         service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
188
189         ret = service_app_main(argc, argv, &event_callback, ad);
190
191         return ret;
192 }