Disable gcov
[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         char *lang = vconf_get_str(VCONFKEY_LANGSET);
40         if (lang == nullptr) {
41                 WARN("Cannot get language_set.");
42                 return;
43         }
44
45         ::setenv("LANG", lang, 1);
46         ::setenv("LC_MESSAGES", lang, 1);
47         ::setlocale(LC_ALL, "");
48
49         ::free(lang);
50 }
51
52 struct ElmRaii {
53         ElmRaii(int argc, char **argv)
54         {
55                 DEBUG("elm_init()");
56                 elm_init(argc, argv);
57         }
58
59         virtual ~ElmRaii()
60         {
61                 DEBUG("elm_shutdown()");
62                 /* TODO: do shutdown.
63                  *   shutdown generates segmentation fault by unknown reason.
64                  */
65                 //      elm_shutdown();
66         }
67 };
68
69 } // namespace anonymous
70
71 int main(int argc, char **argv)
72 {
73 #ifdef TIZEN_TEST_GCOV
74         ::setenv("GCOV_PREFIX", "/tmp", 1);
75 #endif
76         try {
77                 Csr::Audit::Logger::setTag("CSR_POPUP");
78
79                 INFO("CSR popup service start!");
80
81                 /* init/shutdown elm automatically */
82                 ElmRaii elmRaii(argc, argv);
83
84                 std::signal(SIGTERM, [](int signal) {
85                         WARN("Popup is terminated by signal[" << strsignal(signal) << "]");
86                         /* cleanup and close up stuff here */
87                         exit(signal);
88                 });
89
90                 updateLanguage();
91
92                 Csr::Ui::PopupService service;
93
94                 // If timeout time is too small and popup service wakes up repeatedly too quickly,
95                 // it can be kept out to start by systemd.
96                 service.start(POPUP_SERVICE_IDLE_TIMEOUT_TIME);
97
98                 return 0;
99         } catch (const std::exception &e) {
100                 ERROR("std exception: " << e.what());
101                 return -1;
102         } catch (...) {
103                 ERROR("Unhandled exception occured!");
104                 return -1;
105         }
106 }