Analyzer Queue for checking proper values
[apps/native/position-finder-client.git] / src / control.c
1 /*
2  * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdlib.h>
18 #include <glib.h>
19
20 #include <tizen.h>
21 #include <service_app.h>
22 #include <iotcon.h>
23 #include <Eina.h>
24
25 #include "log.h"
26 #include "connectivity.h"
27
28 #define MAX_QUEUE_ELEMENTS 20
29
30 static void _start_internal_function(void);
31 static void _stop_internal_function(void);
32
33 void _observe_resource_cb(connectivity_resource_s *resource_info, void *resource_data, void *user_data)
34 {
35         int detected = (int) resource_data;
36         static int queue[MAX_QUEUE_ELEMENTS] = { 0, };
37         static int i = 0;
38         int j = 0;
39         int result = 0;
40
41         if (detected) _I("Detected.");
42         else _I("Nothing detected.");
43
44         queue[i++] = detected;
45         if (i == MAX_QUEUE_ELEMENTS) i = 0;
46
47         for (j = 0; j < MAX_QUEUE_ELEMENTS && !result; j++) {
48                 result |= queue[j];
49         }
50
51         _I("Result value is [%d]\n", result);
52 }
53
54 bool service_app_create(void *data)
55 {
56         int ret = -1;
57
58         _start_internal_function();
59
60         ret = connectivity_observe_resource(_observe_resource_cb, NULL);
61         retv_if(ret == -1, false);
62
63     return true;
64 }
65
66 void service_app_terminate(void *data)
67 {
68         _stop_internal_function();
69 }
70
71 void service_app_control(app_control_h app_control, void *data)
72 {
73     // Todo: add your code here.
74 }
75
76 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
77 {
78         /*APP_EVENT_LANGUAGE_CHANGED*/
79 }
80
81 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
82 {
83         /*APP_EVENT_REGION_FORMAT_CHANGED*/
84 }
85
86 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
87 {
88         /*APP_EVENT_LOW_BATTERY*/
89 }
90
91 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
92 {
93         /*APP_EVENT_LOW_MEMORY*/
94 }
95
96 int main(int argc, char* argv[])
97 {
98     char ad[50] = {0, };
99         service_app_lifecycle_callback_s event_callback;
100         app_event_handler_h handlers[5] = {NULL, };
101         int ret = 0;
102
103         event_callback.create = service_app_create;
104         event_callback.terminate = service_app_terminate;
105         event_callback.app_control = service_app_control;
106
107         service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
108         service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
109         service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
110         service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
111
112         ret = service_app_main(argc, argv, &event_callback, ad);
113
114         return ret;
115 }
116
117 /* Do not modify codes under this comment */
118 static void _start_internal_function(void)
119 {
120         int ret = -1;
121         ret = connectivity_init();
122         ret_if(IOTCON_ERROR_NONE != ret);
123 }
124
125 static void _stop_internal_function(void)
126 {
127         _I("Terminating...");
128         connectivity_fini();
129 }