Show the file size of the files in the tmp_dir on the LCD.
[ruwai.git] / software / c++ / ruwaicom / src / ruwaicom.cpp
blobab7849e2d0b22188aef12a66731ab89ef652a3ae
1 /*--------------------------------------------------------------------------*/
2 // LICENSE
3 //
4 // This file is part of ruwai.
5 //
6 // If you use ruwai_parser in any program or publication, please inform and
7 // acknowledge its author Stefan Mertl (stefan@mertl-research.at).
8 //
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 /*--------------------------------------------------------------------------*/
22 #include <signal.h>
23 #include "ruwaicom.h"
24 #include "root.h"
27 void
28 handle_sig_term(int signum)
30 if ((signum == SIGTERM) || (signum == SIGINT))
32 LCDDisplay display = LCDDisplay(66, 67, 45, 23, 47, 27);
33 display.init();
34 display.clear();
35 display.home();
36 display.print("STOPPED", "RUWAICOM");
39 std::exit(signum);
43 int main(int argc, char* argv[])
45 signal(SIGTERM, handle_sig_term);
46 signal(SIGINT, handle_sig_term);
47 std::string config_file = "";
48 std::string debug_level = "";
49 if (argc != 2)
51 std::cout << "usage: " << argv[0] << " CONFIG_FILENAME" << std::endl;
52 return(EXIT_SUCCESS);
55 if (strcmp(argv[1], "--version") == 0)
57 std::cout << "version " << RUWAI_RECORD_VERSION << std::endl;
58 return(EXIT_SUCCESS);
61 // TODO: Add an exception handling if the config file can't be read.
62 config_file = (std::string)argv[1];
64 boost::property_tree::ptree pt;
65 boost::property_tree::ini_parser::read_ini(config_file, pt);
66 debug_level = pt.get<std::string>("log.level");
68 int log_level = LOG_NOTICE;
69 if(debug_level == "emerg")
71 log_level = LOG_EMERG;
73 else if(debug_level == "alert")
75 log_level = LOG_ALERT;
77 else if(debug_level == "critical")
79 log_level = LOG_CRIT;
81 else if(debug_level == "error")
83 log_level = LOG_ERR;
85 else if(debug_level == "warning")
87 log_level = LOG_WARNING;
89 else if(debug_level == "notice")
91 log_level = LOG_NOTICE;
93 else if(debug_level == "info")
95 log_level = LOG_INFO;
97 else if(debug_level == "debug")
99 log_level = LOG_DEBUG;
102 setlogmask(LOG_UPTO(log_level));
103 openlog("ruwaicom", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
104 syslog(LOG_NOTICE, "Starting ruwaicom version %s.", RUWAI_RECORD_VERSION);
105 syslog(LOG_NOTICE, "Git revision: %s.", GIT_VERSION);
107 Root root = Root(config_file);
108 syslog(LOG_NOTICE, "Starting the root...");
110 if (root.storage_mode == "sd")
112 syslog(LOG_NOTICE, "Initial check for the SD card.");
113 if (root.is_sd_dev_available())
115 if (!root.is_sd_mounted())
117 syslog(LOG_NOTICE, "Mounting the SD card....");
118 // Try to mount the SD card.
119 if(!root.mount_sd())
121 syslog(LOG_ERR, "Couldn't mount the SD card. No place to write the data to.");
127 if (root.ready())
129 root.clear_tmp_dir();
130 root.run();
132 else
134 syslog(LOG_ERR, "The root is not ready. Can't start it. Good bye.");
135 root.display->print("Had a problem.", "Check log.");
138 syslog(LOG_NOTICE, "Exiting ruwaicom.");
139 closelog();
140 return(EXIT_SUCCESS);