1 /*--------------------------------------------------------------------------*/
4 // This file is part of ruwai.
6 // If you use ruwai_parser in any program or publication, please inform and
7 // acknowledge its author Stefan Mertl (stefan@mertl-research.at).
9 // ruwai is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /*--------------------------------------------------------------------------*/
28 handle_sig_term(int signum
)
30 if ((signum
== SIGTERM
) || (signum
== SIGINT
))
32 LCDDisplay display
= LCDDisplay(66, 67, 45, 23, 47, 27);
36 display
.print("STOPPED", "RUWAICOM");
37 syslog(LOG_WARNING
, "Stopped ruwaicom (SIGTERM, SIGINT).");
44 int main(int argc
, char* argv
[])
46 signal(SIGTERM
, handle_sig_term
);
47 signal(SIGINT
, handle_sig_term
);
48 std::string config_file
= "";
49 std::string debug_level
= "";
52 std::cout
<< "usage: " << argv
[0] << " CONFIG_FILENAME" << std::endl
;
56 if (strcmp(argv
[1], "--version") == 0)
58 std::cout
<< "version " << RUWAI_RECORD_VERSION
<< std::endl
;
62 // TODO: Add an exception handling if the config file can't be read.
63 config_file
= (std::string
)argv
[1];
65 boost::property_tree::ptree pt
;
66 boost::property_tree::ini_parser::read_ini(config_file
, pt
);
67 debug_level
= pt
.get
<std::string
>("log.level");
69 int log_level
= LOG_NOTICE
;
70 if(debug_level
== "emerg")
72 log_level
= LOG_EMERG
;
74 else if(debug_level
== "alert")
76 log_level
= LOG_ALERT
;
78 else if(debug_level
== "critical")
82 else if(debug_level
== "error")
86 else if(debug_level
== "warning")
88 log_level
= LOG_WARNING
;
90 else if(debug_level
== "notice")
92 log_level
= LOG_NOTICE
;
94 else if(debug_level
== "info")
98 else if(debug_level
== "debug")
100 log_level
= LOG_DEBUG
;
103 setlogmask(LOG_UPTO(log_level
));
104 openlog("ruwaicom", LOG_CONS
| LOG_PID
| LOG_NDELAY
, LOG_LOCAL1
);
105 syslog(LOG_NOTICE
, "Starting ruwaicom version %s.", RUWAI_RECORD_VERSION
);
106 syslog(LOG_NOTICE
, "Git revision: %s.", GIT_VERSION
);
108 Root root
= Root(config_file
);
109 syslog(LOG_NOTICE
, "Starting the root...");
111 if (root
.storage_mode
== "sd")
113 syslog(LOG_NOTICE
, "Initial check for the SD card.");
114 if (root
.is_sd_dev_available())
116 if (!root
.is_sd_mounted())
118 syslog(LOG_NOTICE
, "Mounting the SD card....");
119 // Try to mount the SD card.
122 syslog(LOG_ERR
, "Couldn't mount the SD card. No place to write the data to.");
130 root
.clear_tmp_dir();
135 syslog(LOG_ERR
, "The root is not ready. Can't start it. Good bye.");
136 root
.display
->print("Had a problem.", "Check log.");
139 syslog(LOG_NOTICE
, "Exiting ruwaicom.");
141 return(EXIT_SUCCESS
);