RTXI
2.4
The Real-Time eXperiment Interface Documentation
src
main.cpp
Go to the documentation of this file.
1
/*
2
The Real-Time eXperiment Interface (RTXI)
3
Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
*/
19
20
#include <QApplication>
21
#include <QtWidgets>
22
23
#include <iostream>
24
#include <cstdlib>
25
#include <dirent.h>
26
#include <errno.h>
27
#include <getopt.h>
28
#include <signal.h>
29
#include <string>
30
#include <unistd.h>
31
#include <ctype.h>
32
#include <
daq.h
>
33
#include <
debug.h
>
34
#include <
main_window.h
>
35
#include <
plugin.h
>
36
37
#if XENOMAI
38
#include <rtdk.h>
39
#endif
40
41
static
pid_t parentThread;
42
43
struct
cli_options_t
44
{
45
std::string
config_file
;
46
std::string
plugins_path
;
47
};
48
49
static
bool
parse_cli_options(
int
,
char
*[],
cli_options_t
*);
50
static
void
signal_handler(
int
);
51
52
int
main
(
int
argc,
char
*argv[])
53
{
54
int
retval = 0;
55
56
#if XENOMAI
57
/* Initialize rtdk */
58
rt_print_auto_init(1);
59
#endif
60
61
/* Try to Exit Cleanly on Signals */
62
parentThread = getpid();
63
signal(SIGINT,signal_handler);
64
signal(SIGABRT,signal_handler);
65
signal(SIGSEGV,signal_handler);
66
67
/* Handle Command-Line Options */
68
cli_options_t
cli_options;
69
if
(!parse_cli_options(argc,argv,&cli_options))
70
return
-EINVAL;
71
72
/* Find Configuration File */
73
std::string config_file;
74
if
(cli_options.
config_file
.length())
75
config_file = cli_options.
config_file
;
76
else
if
(getenv(
"RTXI_CONF"
))
77
config_file = getenv(
"RTXI_CONF"
);
78
else
79
config_file =
"/usr/local/share/rtxi/rtxi.conf"
;
80
81
/************************************************************
82
* Create Main System Components *
83
* *
84
* These need to be created early because they should have *
85
* Settings::IDs of 0 and 1. *
86
************************************************************/
87
88
/* Create GUI Objects */
89
QApplication::setDesktopSettingsAware(
false
);
90
QApplication *app =
new
QApplication(argc,argv);
91
app->connect(app,SIGNAL(lastWindowClosed()),app,SLOT(quit()));
92
MainWindow::getInstance
()->
loadWindow
();;
93
94
RT::System::getInstance
();
95
IO::Connector::getInstance
();
96
97
/* Bootstrap the System */
98
Settings::Manager::getInstance
()->
load
(config_file);
99
retval = app->exec();
100
101
Plugin::Manager::getInstance
()->
unloadAll
();
102
return
retval;
103
}
104
105
static
void
error_msg(
const
std::string &
self
)
106
{
107
std::cout <<
"Try \'"
<<
self
<<
" --help\' for more information.\n"
;
108
}
109
110
static
void
help_msg(
const
std::string &
self
)
111
{
112
std::cout <<
"Usage: "
<<
self
<<
" [options]\n"
;
113
std::cout <<
" where options include:\n"
;
114
std::cout <<
" --help, -h - Displays this message\n"
;
115
std::cout <<
" --config-file, -c - Pick a custom configuration file\n"
;
116
std::cout <<
" --plugins-path, -p - Specify a plugins directory\n"
;
117
}
118
119
static
bool
parse_cli_options(
int
argc,
char
*argv[],
cli_options_t
*cli_options)
120
{
121
int
opt, index;
122
123
struct
option options[] =
124
{
125
{
"help"
, no_argument, 0,
'h'
},
126
{
"config-file"
, required_argument, 0,
'c'
},
127
{
"plugins-path"
, required_argument, 0,
'p'
},
128
{
"models-path"
, required_argument, 0,
'm'
},
129
{ 0,0,0,0 }
130
};
131
132
for
(;;)
133
{
134
opt = getopt_long(argc,argv,
"hc:p:m:"
,options,&index);
135
136
if
(opt < 0)
break
;
137
138
switch
(opt)
139
{
140
case
'c'
:
141
cli_options->
config_file
= optarg;
142
break
;
143
case
'h'
:
144
help_msg(argv[0]);
145
return
false
;
146
case
'p'
:
147
cli_options->
plugins_path
= optarg;
148
break
;
149
default
:
150
error_msg(argv[0]);
151
return
false
;
152
}
153
}
154
155
return
true
;
156
}
157
158
static
void
signal_handler(
int
signum)
159
{
160
static
int
count = 0;
161
162
/* Only handler handle signals in the parent */
163
if
(getpid() != parentThread)
return
;
164
165
ERROR_MSG
(
"signal_handler : signal type %i received\n"
, signum);
166
PRINT_BACKTRACE
();
167
168
if
(count++) _exit(-EFAULT);
169
170
//DEBUG_MSG("signal_handler : finished\n");
171
exit(0);
172
}
ERROR_MSG
void ERROR_MSG(const std::string &errmsg,...)
Definition:
debug.cpp:27
Settings::Manager::getInstance
static Manager * getInstance(void)
Definition:
settings.cpp:534
IO::Connector::getInstance
static Connector * getInstance(void)
Definition:
io.cpp:421
plugin.h
cli_options_t
Definition:
main.cpp:43
RT::System::getInstance
static System * getInstance(void)
Definition:
rt.cpp:361
daq.h
cli_options_t::config_file
std::string config_file
Definition:
main.cpp:45
MainWindow::loadWindow
void loadWindow(void)
Definition:
main_window.cpp:296
cli_options_t::plugins_path
std::string plugins_path
Definition:
main.cpp:46
Settings::Manager::load
int load(const std::string &)
Definition:
settings.cpp:230
Plugin::Manager::getInstance
static Manager * getInstance(void)
Definition:
plugin.cpp:188
PRINT_BACKTRACE
void PRINT_BACKTRACE(void)
Prints a backtrace to standard error.
Definition:
debug.cpp:22
MainWindow::getInstance
static MainWindow * getInstance(void)
Definition:
main_window.cpp:454
Plugin::Manager::unloadAll
void unloadAll(void)
Definition:
plugin.cpp:117
debug.h
main
int main(int argc, char *argv[])
Definition:
main.cpp:52
main_window.h
Generated on Thu Apr 21 2022 16:58:34 for RTXI by
1.8.17