274f2baabcfab4c8f21dee923083e2f4194461f8
[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(double 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
86         /**
87          * DO NOT EDIT: please don't edit the function below.
88          * Access only when modifying internal functions.
89          */
90         controller_init_internal_functions();
91
92         /**
93          * TODO: Creates a connectivity resource and registers the resource in server.
94          */
95
96
97
98
99
100         /**
101          * Creates a timer to call the given function in the given period of time.
102          * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor.
103          */
104         ad->getter_timer = ecore_timer_add(SENSORING_TIME_INTERVAL, _control_sensors_cb, ad);
105         if (!ad->getter_timer) {
106                 _E("Failed to add infrared motion getter timer");
107                 return false;
108         }
109
110         return true;
111 }
112
113 static void service_app_terminate(void *data)
114 {
115         app_data *ad = (app_data *)data;
116
117         if (ad->getter_timer)
118                 ecore_timer_del(ad->getter_timer);
119
120         /**
121          * Releases the resource about connectivity.
122          */
123         connectivity_unset_resource(ad->resource_info);
124
125         /**
126          * DO NOT EDIT: please don't edit the function below.
127          * Access only when modifying internal functions.
128          */
129         controller_fini_internal_functions();
130
131         free(ad);
132 }
133
134 static void service_app_control(app_control_h app_control, void *data)
135 {
136         /*APP_CONTROL*/
137 }
138
139 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
140 {
141         /*APP_EVENT_LANGUAGE_CHANGED*/
142 }
143
144 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
145 {
146         /*APP_EVENT_REGION_FORMAT_CHANGED*/
147 }
148
149 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
150 {
151         /*APP_EVENT_LOW_BATTERY*/
152 }
153
154 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
155 {
156         /*APP_EVENT_LOW_MEMORY*/
157 }
158
159 int main(int argc, char* argv[])
160 {
161         app_data *ad = NULL;
162         int ret = 0;
163         service_app_lifecycle_callback_s event_callback;
164         app_event_handler_h handlers[5] = {NULL, };
165
166         ad = calloc(1, sizeof(app_data));
167         retv_if(!ad, -1);
168
169         event_callback.create = service_app_create;
170         event_callback.terminate = service_app_terminate;
171         event_callback.app_control = service_app_control;
172
173         service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
174         service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
175         service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
176         service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
177
178         ret = service_app_main(argc, argv, &event_callback, ad);
179
180         return ret;
181 }