3 * \brief SmartDeviceLink main application sources
4 * Copyright (c) 2013, Ford Motor Company
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided with the
18 * Neither the name of the Ford Motor Company nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
41 #include <iostream> // cpplint: Streams are highly discouraged.
42 #include <fstream> // cpplint: Streams are highly discouraged.
44 // ----------------------------------------------------------------------------
46 #include "./life_cycle.h"
48 #include "utils/signals.h"
49 #include "utils/system.h"
50 #include "config_profile/profile.h"
52 #if defined(EXTENDED_MEDIA_MODE)
56 #include "media_manager/media_manager_impl.h"
57 // ----------------------------------------------------------------------------
58 // Third-Party includes
59 #include "networking.h" // cpplint: Include the directory when naming .h files
61 // ----------------------------------------------------------------------------
63 #ifndef SDL_LOG4CXX_PROPERTIES_FILE
64 #define SDL_LOG4CXX_PROPERTIES_FILE "log4cxx.properties"
67 #ifndef SDL_HMI_LINK_FILE
68 #define SDL_HMI_LINK_FILE "hmi_link"
71 #ifndef SDL_HMI_BROWSER_PATH
72 #define SDL_HMI_BROWSER_PATH "/usr/bin/chromium-browser"
73 #define SDL_HMI_BROWSER_ARG0 "chromium-browser"
74 #define SDL_HMI_BROWSER_ARG1 "--auth-schemes=basic,digest,ntlm"
77 CREATE_LOGGERPTR_GLOBAL(logger, "appMain")
80 const std::string kBrowser = SDL_HMI_BROWSER_PATH;
81 const std::string kBrowserName = SDL_HMI_BROWSER_ARG0;
83 #ifdef SDL_HMI_BROWSER_ARG1
84 const std::string kBrowserParams = SDL_HMI_BROWSER_ARG1;
87 const std::string kLocalHostAddress = "127.0.0.1";
88 const std::string kApplicationVersion = "SDL_RB_B3.5";
92 * Initialize HTML based HMI.
93 * @return true if success otherwise false.
98 if (stat(SDL_HMI_LINK_FILE, &sb) == -1) {
99 LOG4CXX_FATAL(logger, "File with HMI link doesn't exist!");
103 std::ifstream file_str;
104 file_str.open(SDL_HMI_LINK_FILE);
106 if (!file_str.is_open()) {
107 LOG4CXX_FATAL(logger, "File with HMI link was not opened!");
111 file_str.seekg(0, std::ios::end);
112 int32_t length = file_str.tellg();
113 file_str.seekg(0, std::ios::beg);
115 std::string hmi_link;
116 std::getline(file_str, hmi_link);
120 "Input string:" << hmi_link << " length = " << hmi_link.size());
123 if (stat(hmi_link.c_str(), &sb) == -1) {
124 LOG4CXX_INFO(logger, "HMI index.html doesn't exist!");
125 // The hmi_link file in Tizen contains the Crosswalk application ID,
126 // not a top-level HMI web page such as index.html, since we're
127 // launching the HMI through xwalk-launcher. Ignore the fact that
128 // such a file doesn't exist.
132 return utils::System(kBrowser, kBrowserName)
133 #ifdef SDL_HMI_BROWSER_ARG1
136 .Add(hmi_link).Execute();
142 * Initialize HTML based HMI.
143 * @return true if success otherwise false.
146 std::string kStartHmi = "./start_hmi.sh";
148 if (stat(kStartHmi.c_str(), &sb) == -1) {
149 LOG4CXX_FATAL(logger, "HMI start script doesn't exist!");
153 return utils::System(kStartHmi).Execute();
160 * \brief Entry point of the program.
161 * \param argc number of argument
162 * \param argv array of arguments
163 * \return EXIT_SUCCESS or EXIT_FAILURE
165 int32_t main(int32_t argc, char** argv) {
167 // --------------------------------------------------------------------------
168 // Logger initialization
169 INIT_LOGGER(SDL_LOG4CXX_PROPERTIES_FILE);
171 threads::Thread::SetNameForId(threads::Thread::CurrentId(), "MainThread");
173 LOG4CXX_INFO(logger, "Application started!");
174 LOG4CXX_INFO(logger, "Application version " << kApplicationVersion);
176 // Initialize gstreamer. Needed to activate debug from the command line.
177 #if defined(EXTENDED_MEDIA_MODE)
178 gst_init(&argc, &argv);
181 // --------------------------------------------------------------------------
182 // Components initialization
183 if ((argc > 1)&&(0 != argv)) {
184 profile::Profile::instance()->config_file_name(argv[1]);
186 profile::Profile::instance()->config_file_name(SDL_CONFIG_FILE);
190 if (!profile::Profile::instance()->policy_turn_off()) {
191 if (!utils::System("./init_policy.sh").Execute(true)) {
192 LOG4CXX_ERROR(logger, "Failed initialization of policy database");
199 main_namespace::LifeCycle::instance()->StartComponents();
201 // --------------------------------------------------------------------------
202 // Third-Party components initialization.
204 if (!main_namespace::LifeCycle::instance()->InitMessageSystem()) {
205 main_namespace::LifeCycle::instance()->StopComponents();
209 LOG4CXX_INFO(logger, "InitMessageBroker successful");
211 if (profile::Profile::instance()->launch_hmi()) {
212 if (profile::Profile::instance()->server_address() == kLocalHostAddress) {
213 LOG4CXX_INFO(logger, "Start HMI on localhost");
217 main_namespace::LifeCycle::instance()->StopComponents();
221 LOG4CXX_INFO(logger, "InitHmi successful");
222 #endif // #ifndef NO_HMI
225 // --------------------------------------------------------------------------
227 utils::SubscribeToTerminateSignal(
228 &main_namespace::LifeCycle::StopComponentsOnSignal);