Modify comments&logs on template
[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
33 #define CONNECTIVITY_KEY "opened"
34
35 typedef struct app_data_s {
36         Ecore_Timer *getter_timer;
37         connectivity_resource_s *resource_info;
38 } app_data;
39
40 static Eina_Bool control_sensors_cb(void *data)
41 {
42         int value = 0;
43         app_data *ad = data;
44
45         /**
46          * Infrared motion sensor outputs 1 if motion is detected, or 0 if motion is not detected.
47          */
48         /*
49         if (resource_read_infrared_motion_sensor(Pin Number, &value) == -1)
50                 _E("Failed to get Infrared Motion value [GPIO:%d]", GPIO_INFRARED_MOTION_NUM);
51         */
52
53         /**
54          * Notifies specific clients that resource's attributes have changed.
55          */
56         /*
57         if (connectivity_notify_bool(ad->resource_info, KEY, VALUE) == -1)
58                 _E("Cannot notify message");
59         */
60
61         return ECORE_CALLBACK_RENEW;
62 }
63
64 static bool service_app_create(void *data)
65 {
66         app_data *ad = data;
67         int ret = -1;
68
69         /**
70          * No modification required!!!
71          * Access only when modifying internal functions.
72          */
73         //controller_init_internal_functions();
74
75         /**
76          * Create a connectivity resource and registers the resource in server.
77          */
78         /*
79         ret = connectivity_set_resource("/door/1", "org.tizen.door", &ad->resource_info);
80         if (ret == -1) _E("Cannot broadcast resource");
81         */
82
83         /**
84          * Creates a timer to call the given function in the given period of time.
85          * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor.
86          */
87         /*
88         ad->getter_timer = ecore_timer_add(Duration, control_sensors_cb, ad);
89         if (!ad->getter_timer) {
90                 _E("Failed to add infrared motion getter timer");
91                 return false;
92         }
93         */
94
95     return true;
96 }
97
98 static void service_app_terminate(void *data)
99 {
100         app_data *ad = (app_data *)data;
101
102         for (int i = 0; i < PIN_MAX; i++) {
103                 if (ad->getter_timer) {
104                         ecore_timer_del(ad->getter_timer);
105                 }
106         }
107
108         /**
109          * Releases the resource about connectivity.
110          */
111         connectivity_unset_resource(ad->resource_info);
112
113         /**
114          * No modification required!!!
115          * Access only when modifying internal functions.
116          */
117         controller_fini_internal_functions();
118
119         free(ad);
120 }
121
122 static void service_app_control(app_control_h app_control, void *data)
123 {
124     // Todo: add your code here.
125 }
126
127 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
128 {
129         /*APP_EVENT_LANGUAGE_CHANGED*/
130 }
131
132 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
133 {
134         /*APP_EVENT_REGION_FORMAT_CHANGED*/
135 }
136
137 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
138 {
139         /*APP_EVENT_LOW_BATTERY*/
140 }
141
142 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
143 {
144         /*APP_EVENT_LOW_MEMORY*/
145 }
146
147 int main(int argc, char* argv[])
148 {
149         app_data *ad = NULL;
150         int ret = 0;
151         service_app_lifecycle_callback_s event_callback;
152         app_event_handler_h handlers[5] = {NULL, };
153
154         ad = calloc(1, sizeof(app_data));
155         retv_if(!ad, -1);
156
157         event_callback.create = service_app_create;
158         event_callback.terminate = service_app_terminate;
159         event_callback.app_control = service_app_control;
160
161         service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
162         service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
163         service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
164         service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
165
166         ret = service_app_main(argc, argv, &event_callback, ad);
167
168         return ret;
169 }