Use ELM_MAIN macro for main function
[platform/upstream/csr-framework.git] / src / framework / ui / popup / main.cpp
1 /*
2  * Copyright (c) 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  * @file        main.cpp
18  * @author      Janusz Kozerski (j.kozerski@samsung.com)
19  *              Kyungwook Tak (k.tak@samsung.com)
20  * @version     1.0
21  * @brief       Popup service main
22  */
23 #include <stdexcept>
24
25 #include <vconf.h>
26 #include <Elementary.h>
27 #include <Ecore.h>
28 #include <memory>
29 #include <csignal>
30 #include <cstring>
31
32 #include "common/audit/logger.h"
33 #include "popup-service.h"
34
35 namespace {
36
37 void updateLanguage(void)
38 {
39         std::unique_ptr<char> lang(new char);
40
41         lang.reset(vconf_get_str(VCONFKEY_LANGSET));
42         if (!lang) {
43                 WARN("Cannot get language_set.");
44         } else {
45                 setenv("LANG", lang.get(), 1);
46                 setenv("LC_MESSAGES", lang.get(), 1);
47         }
48
49         setlocale(LC_ALL, "");
50 }
51
52 } // namespace anonymous
53
54 int elm_main(int, char **)
55 {
56         try {
57                 Csr::Audit::Logger::setTag("CSR_POPUP");
58
59                 INFO("CSR popup service start!");
60
61                 std::signal(SIGTERM, [](int signal) {
62                         WARN("Popup is terminated by signal[" << strsignal(signal) << "]");
63                         /* cleanup and close up stuff here */
64                         exit(signal);
65                 });
66
67                 updateLanguage();
68
69                 Csr::Ui::PopupService service;
70
71                 // If timeout time is too small and popup service wakes up repeatedly too quickly,
72                 // it can be kept out to start by systemd.
73                 service.start(POPUP_SERVICE_IDLE_TIMEOUT_TIME);
74
75                 return 0;
76         } catch (const std::exception &e) {
77                 ERROR("std exception: " << e.what());
78                 return -1;
79         } catch (...) {
80                 ERROR("Unhandled exception occured!");
81                 return -1;
82         }
83 }
84 ELM_MAIN()