2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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>
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
13 * http://floralicense.org/license/
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.
26 #include <service_app.h>
30 #include "connectivity.h"
31 #include "controller.h"
32 #include "controller_util.h"
37 * DO NOT EDIT: please don't edit the time interval.
39 #define SENSORING_TIME_INTERVAL 2.0f
42 * TODO: You have to use the pin numbers below.
43 * You can change the pin numbers freely.
45 #define TRIG_PIN_NUMBER 20
46 #define ECHO_PIN_NUMBER 21
48 typedef struct app_data_s {
49 Ecore_Timer *getter_timer;
50 connectivity_resource_s *resource_info;
53 static void _ultrasonic_sensor_read_cb(double value, void *data)
58 * TODO: Send the value of the ultrasonic sensor to the Client.
67 static Eina_Bool _control_sensors_cb(void *data)
72 * TODO: Prepare to read the value of the ultrasonic sensor.
79 return ECORE_CALLBACK_RENEW;
82 static bool service_app_create(void *data)
87 * DO NOT EDIT: please don't edit the function below.
88 * Access only when modifying internal functions.
90 controller_init_internal_functions();
93 * TODO: Creates a connectivity resource and registers the resource in server.
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.
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");
113 static void service_app_terminate(void *data)
115 app_data *ad = (app_data *)data;
117 if (ad->getter_timer)
118 ecore_timer_del(ad->getter_timer);
121 * Releases the resource about connectivity.
123 connectivity_unset_resource(ad->resource_info);
126 * DO NOT EDIT: please don't edit the function below.
127 * Access only when modifying internal functions.
129 controller_fini_internal_functions();
134 static void service_app_control(app_control_h app_control, void *data)
139 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
141 /*APP_EVENT_LANGUAGE_CHANGED*/
144 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
146 /*APP_EVENT_REGION_FORMAT_CHANGED*/
149 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
151 /*APP_EVENT_LOW_BATTERY*/
154 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
156 /*APP_EVENT_LOW_MEMORY*/
159 int main(int argc, char* argv[])
163 service_app_lifecycle_callback_s event_callback;
164 app_event_handler_h handlers[5] = {NULL, };
166 ad = calloc(1, sizeof(app_data));
169 event_callback.create = service_app_create;
170 event_callback.terminate = service_app_terminate;
171 event_callback.app_control = service_app_control;
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);
178 ret = service_app_main(argc, argv, &event_callback, ad);