Modify rules for compatibility
[apps/native/sample/sample-core-components.git] / rule / service / project / src / main.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 <service_app.h>
18 #include <system_settings.h>
19 #include <Elementary.h>
20 #include <dlog.h>
21 #include "$(appName).h"
22 #include "data.h"
23
24 /**
25  * @brief Hook to take necessary actions before main event loop starts.
26  * Initialize the service's data.
27  * If this function returns true, the main loop of the sertvice starts.
28  * If this function returns false, the service is terminated.
29  */
30 static bool srv_create(void *user_data)
31 {
32         return true;
33 }
34
35 /**
36  * @brief This callback function is called when another application.
37  * sends the launch request to the service.
38  */
39 static void srv_control(app_control_h app_control, void *user_data)
40 {
41         /* Handle the launch request. */
42 }
43
44 /**
45  * @brief This callback function is called once after the main loop.
46  * of the service exits.
47  */
48 static void srv_terminate(void *user_data)
49 {
50         /* Release all resources. */
51 }
52
53 /**
54  * @brief This function will be called when the language is changed.
55  */
56 static void service_lang_changed(app_event_info_h event_info, void *user_data)
57 {
58         char *locale = NULL;
59
60         system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
61
62         if (locale != NULL) {
63                 elm_language_set(locale);
64                 free(locale);
65         }
66         return;
67 }
68
69 /**
70  * @brief Main function of the service.
71  */
72 int main(int argc, char *argv[])
73 {
74         int ret;
75
76         service_app_lifecycle_callback_s event_callback = {0, };
77         app_event_handler_h handlers[5] = {NULL, };
78
79         event_callback.create = srv_create;
80         event_callback.terminate = srv_terminate;
81         event_callback.app_control = srv_control;
82
83         /*
84          * If you want to handling more events,
85          * please check the service's lifecycle guide.
86          */
87         service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_lang_changed, NULL);
88
89         ret = service_app_main(argc, argv, &event_callback, NULL);
90         if (ret != APP_ERROR_NONE)
91                 dlog_print(DLOG_ERROR, LOG_TAG, "service_app_main() is failed. err = %d", ret);
92
93         return ret;
94 }