2 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <service_app.h>
26 #include "connectivity.h"
28 #define MAX_QUEUE_ELEMENTS 20
30 static void _start_internal_function(void);
31 static void _stop_internal_function(void);
33 void _observe_resource_cb(connectivity_resource_s *resource_info, void *resource_data, void *user_data)
35 int detected = (int) resource_data;
36 static int queue[MAX_QUEUE_ELEMENTS] = { 0, };
41 if (detected) _I("Detected.");
42 else _I("Nothing detected.");
44 queue[i++] = detected;
45 if (i == MAX_QUEUE_ELEMENTS) i = 0;
47 for (j = 0; j < MAX_QUEUE_ELEMENTS && !result; j++) {
51 _I("Result value is [%d]\n", result);
54 bool service_app_create(void *data)
58 _start_internal_function();
60 ret = connectivity_observe_resource(_observe_resource_cb, NULL);
61 retv_if(ret == -1, false);
66 void service_app_terminate(void *data)
68 _stop_internal_function();
71 void service_app_control(app_control_h app_control, void *data)
73 // Todo: add your code here.
76 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
78 /*APP_EVENT_LANGUAGE_CHANGED*/
81 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
83 /*APP_EVENT_REGION_FORMAT_CHANGED*/
86 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
88 /*APP_EVENT_LOW_BATTERY*/
91 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
93 /*APP_EVENT_LOW_MEMORY*/
96 int main(int argc, char* argv[])
99 service_app_lifecycle_callback_s event_callback;
100 app_event_handler_h handlers[5] = {NULL, };
103 event_callback.create = service_app_create;
104 event_callback.terminate = service_app_terminate;
105 event_callback.app_control = service_app_control;
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);
112 ret = service_app_main(argc, argv, &event_callback, ad);
117 /* Do not modify codes under this comment */
118 static void _start_internal_function(void)
121 ret = connectivity_init();
122 ret_if(IOTCON_ERROR_NONE != ret);
125 static void _stop_internal_function(void)
127 _I("Terminating...");