apply connectivity function name changes
[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 typedef struct app_data_s {
34         Ecore_Timer *getter_timer;
35         connectivity_resource_s *resource_info;
36 } app_data;
37
38
39 static Eina_Bool _control_sensors_cb(void *data)
40 {
41         app_data *ad = data;
42         int value = -1;
43         int ret = -1;
44
45 #if 0
46         ret = resource_read_infrared_motion_sensor(PIN_NUMBER, &value);
47         if (ret != 0) _E("Cannot read sensor value");
48
49         _D("Detected value : %d", value);
50 #endif
51
52 #if 0
53         ret = connectivity_notify_int(ad->resource_info, KEY, value);
54         if (ret != 0) _E("Cannot notify value");
55 #endif
56
57         return ECORE_CALLBACK_RENEW;
58 }
59
60 static bool service_app_create(void *data)
61 {
62         app_data *ad = data;
63         int ret = -1;
64
65         /**
66          * DO NOT EDIT: please don't edit the function below.
67          * Access only when modifying internal functions.
68          */
69         controller_init_internal_functions();
70
71 #if 0
72         ret = connectivity_set_protocol(CONNECTIVITY_PROTOCOL);
73         if (ret != 0) _E("Cannot set connectivity type");
74 #endif
75
76 #if 0
77         ret = connectivity_set_resource("/door/0", "org.tizen.door", &ad->resource_info);
78         if (ret != 0) _E("Cannot set connectivity resource");
79 #endif
80
81         /**
82          * Creates a timer to call the given function in the given period of time.
83          * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor.
84          */
85 #if 0
86         ad->getter_timer = ecore_timer_add(Duration , _control_sensors_cb, ad);
87         if (!ad->getter_timer) {
88                 _E("Failed to add getter timer");
89                 return false;
90         }
91 #endif
92
93     return true;
94 }
95
96 static void service_app_terminate(void *data)
97 {
98         app_data *ad = (app_data *)data;
99
100         if (ad->getter_timer) {
101                 ecore_timer_del(ad->getter_timer);
102         }
103
104         connectivity_unset_resource(ad->resource_info);
105
106         /**
107          * DO NOT EDIT: please don't edit the function below.
108          * Access only when modifying internal functions.
109          */
110         controller_fini_internal_functions();
111
112         free(ad);
113 }
114
115 static void service_app_control(app_control_h app_control, void *data)
116 {
117     /* APP_CONTROL */
118 }
119
120 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
121 {
122         /*APP_EVENT_LANGUAGE_CHANGED*/
123 }
124
125 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
126 {
127         /*APP_EVENT_REGION_FORMAT_CHANGED*/
128 }
129
130 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
131 {
132         /*APP_EVENT_LOW_BATTERY*/
133 }
134
135 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
136 {
137         /*APP_EVENT_LOW_MEMORY*/
138 }
139
140 int main(int argc, char* argv[])
141 {
142         app_data *ad = NULL;
143         int ret = 0;
144         service_app_lifecycle_callback_s event_callback;
145         app_event_handler_h handlers[5] = {NULL, };
146
147         ad = calloc(1, sizeof(app_data));
148         retv_if(!ad, -1);
149
150         event_callback.create = service_app_create;
151         event_callback.terminate = service_app_terminate;
152         event_callback.app_control = service_app_control;
153
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);
158
159         ret = service_app_main(argc, argv, &event_callback, ad);
160
161         return ret;
162 }