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 "controller.h"
31 #include "connectivity.h"
33 #define GPIO_INFRARED_MOTION_NUM 20
34 #define CONNECTIVITY_KEY "opened"
36 typedef struct app_data_s {
37 Ecore_Timer *getter_timer;
38 connectivity_resource_s *resource_info;
41 static Eina_Bool control_sensors_cb(void *data)
47 * Infrared motion sensor outputs 1 if motion is detected, or 0 if motion is detected.
49 if (resource_read_infrared_motion_sensor(GPIO_INFRARED_MOTION_NUM, &value) == -1)
50 _E("Failed to get Infrared Motion value [GPIO:%d]", GPIO_INFRARED_MOTION_NUM);
53 * Notifies specific clients that resource's attributes have changed.
55 if (connectivity_notify_bool(ad->resource_info, CONNECTIVITY_KEY, value) == -1)
56 _E("Cannot notify message");
58 return ECORE_CALLBACK_RENEW;
61 static bool service_app_create(void *data)
67 * No modification required!!!
68 * Access only when modifying internal functions.
70 controller_init_internal_functions();
73 * Create a connectivity resource and registers the resource in server.
75 ret = connectivity_set_resource("/door/1", "org.tizen.door", &ad->resource_info);
76 if (ret == -1) _E("Cannot broadcast resource");
79 * Creates a timer to call the given function in the given period of time.
80 * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor.
82 ad->getter_timer = ecore_timer_add(0.5f, control_sensors_cb, ad);
83 if (!ad->getter_timer) {
84 _E("Failed to add infrared motion getter timer");
91 static void service_app_terminate(void *data)
93 app_data *ad = (app_data *)data;
95 for (int i = 0; i < PIN_MAX; i++) {
96 if (ad->getter_timer) {
97 ecore_timer_del(ad->getter_timer);
102 * Releases the resource about connectivity.
104 connectivity_unset_resource(ad->resource_info);
107 * No modification required!!!
108 * Access only when modifying internal functions.
110 controller_fini_internal_functions();
115 static void service_app_control(app_control_h app_control, void *data)
117 // Todo: add your code here.
120 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
122 /*APP_EVENT_LANGUAGE_CHANGED*/
125 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
127 /*APP_EVENT_REGION_FORMAT_CHANGED*/
130 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
132 /*APP_EVENT_LOW_BATTERY*/
135 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
137 /*APP_EVENT_LOW_MEMORY*/
140 int main(int argc, char* argv[])
144 service_app_lifecycle_callback_s event_callback;
145 app_event_handler_h handlers[5] = {NULL, };
147 ad = calloc(1, sizeof(app_data));
150 event_callback.create = service_app_create;
151 event_callback.terminate = service_app_terminate;
152 event_callback.app_control = service_app_control;
154 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
155 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
156 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
157 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
159 ret = service_app_main(argc, argv, &event_callback, ad);