YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#include "mainwindow.h"
7#include <QApplication>
8
9#include <yarp/os/Network.h>
10#include <yarp/os/Property.h>
11#include <yarp/os/Os.h>
12#include <yarp/os/Log.h>
14#include <string>
16
17
18#define HELP_MESSAGE "\
19Usage:\n\
20 yarpmanager [option]\n\n\
21Options:\n\
22 --load_application Path to application to load in the main window\n\
23 --from Configuration file name\n\
24 --application Path to application to open\n\
25 --ymanagerini_dir \n\
26 --apppath \n\
27 --modpath \n\
28 --respath \n\
29 --templpath \n\
30 --load_subfolders \n\
31 --watchdog \n\
32 --module_failure \n\
33 --connection_failure \n\
34 --auto_connect \n\
35 --auto_dependency \n\
36 --add_current_dir add the current dir to the search path\n\
37 --elapsed_time if present the time stamp for log messages will be relative to the GUI start time\n\
38 --disable_autoreload if present it will disable applications autoreload on loaded files modifications\n\
39"
40
41#define DEF_CONFIG_FILE "ymanager.ini"
42
43
44#if defined(_WIN32)
45//#include <csignal>
46#include <windows.h>
47
48#else
49
50#include <cerrno>
51#include <sys/types.h>
52#include <csignal>
53#endif
54
55void onSignal(int signum);
56
57int main(int argc, char *argv[])
58{
59
60#if defined(_WIN32)
61 // We create a console. This is inherited by console processes created by the localhost broker.
62 // It is useful because new processes can receive ctrl+brk signals and shutdown cleanly.
63 // This console is not actually needed for printing so we hide it. In principle we could
64 // redirect the output of all processes to this console, in practice this would be end up
65 // soon in a big mess.
66 AllocConsole();
67 HWND hwnd = GetConsoleWindow();
68 HWND hide = FindWindowA("ConsoleWindowClass",NULL);
69 ShowWindow(hide, 0);
70#endif
71 QApplication a(argc, argv);
72
73 // Setup resource finder
74
76 rf.setDefaultContext("yarpmanager");
78 rf.configure(argc, argv);
79
81
82 yarp::os::Property config;
83 config.fromString(rf.toString());
84
85 if(config.check("help"))
86 {
87 yInfo("%s",HELP_MESSAGE);
88 return 0;
89 }
90
94 bool add_curr_dir = false;
95 if(config.check("add_current_dir"))
96 {
97 add_curr_dir=true;
98 }
99 const int cur_dir_max_size=512;
100 char current_dir[cur_dir_max_size]; current_dir[0]=0;
101 yarp::os::getcwd(current_dir,cur_dir_max_size);
102 config.put("current_dir", current_dir);
103
104 std::string inifile=rf.findFile("from");
105 std::string inipath;
106 size_t lastSlash=inifile.rfind('/');
107 if (lastSlash!=std::string::npos){
108 inipath=inifile.substr(0, lastSlash+1);
109 }else{
110 lastSlash=inifile.rfind('\\');
111 if (lastSlash!=std::string::npos){
112 inipath=inifile.substr(0, lastSlash+1);
113 }
114 }
115
116 if(!config.check("ymanagerini_dir")){
117 config.put("ymanagerini_dir", inipath);
118 }
119
120 yarp::os::Bottle appPaths;
121 if(!config.check("apppath")){
122
123 appPaths= rf.findPaths("applications");
124
125 yarp::os::ResourceFinderOptions findRobotScripts;
127 yarp::os::Bottle appPaths2=rf.findPaths("scripts", findRobotScripts);
128// yarp::os::Bottle appPaths2=rf.findPaths("scripts");
129// std::cout << "app path : " << appPaths.toString()<< std::endl;
130 QString appPathsStr="";
131 for (size_t ind=0; ind < appPaths.size(); ++ind){
132 appPathsStr += (appPaths.get(ind).asString() + ";").c_str();
133 }
134 for (size_t ind=0; ind < appPaths2.size(); ++ind){
135 appPathsStr += (appPaths2.get(ind).asString() + ";").c_str();
136 }
137 if (add_curr_dir)
138 {
139 appPathsStr += (current_dir + std::string(";")).c_str();
140 }
141 std::string sss= appPathsStr.toLatin1().data();
142 config.put("apppath", appPathsStr.toLatin1().data());
143 }
144
145 if(!config.check("modpath")){
146 appPaths=rf.findPaths("modules");
147 //std::cout << "mod path : " << appPaths.toString()<< std::endl;
148 QString modPathsStr="";
149 for (size_t ind=0; ind < appPaths.size(); ++ind){
150 modPathsStr += (appPaths.get(ind).asString() + ";").c_str();
151 }
152 if (add_curr_dir)
153 {
154 modPathsStr += (current_dir + std::string(";")).c_str();
155 }
156 config.put("modpath", modPathsStr.toLatin1().data());
157 }
158
159 if(!config.check("respath")){
160 appPaths=rf.findPaths("resources");
161 //std::cout << "res path : " << appPaths.toString()<< std::endl;
162 QString resPathsStr="";
163 for (size_t ind=0; ind < appPaths.size(); ++ind){
164 resPathsStr += (appPaths.get(ind).asString() + ";").c_str();
165 }
166 if (add_curr_dir)
167 {
168 resPathsStr += (current_dir + std::string(";")).c_str();
169 }
170 config.put("respath", resPathsStr.toLatin1().data());
171 }
172
173 if(!config.check("templpath")){
174 appPaths=rf.findPaths("templates/applications");
175 // std::cout << "templ path : " << appPaths.toString()<< std::endl;
176 QString templPathsStr="";
177 for (size_t ind=0; ind < appPaths.size(); ++ind){
178 templPathsStr += (appPaths.get(ind).asString() + ";").c_str();
179 }
180 if (add_curr_dir)
181 {
182 templPathsStr += (current_dir + std::string(";")).c_str();
183 }
184 config.put("templpath", templPathsStr.toLatin1().data());
185
186 }
187
188 if(!config.check("load_subfolders")){
189 config.put("load_subfolders", "yes");
190 }
191
192 if(!config.check("watchdog")){
193 config.put("watchdog", "no");
194 }
195
196 if(!config.check("module_failure")){
197 config.put("module_failure", "prompt");
198 }
199
200 if(!config.check("connection_failure")){
201 config.put("connection_failure", "prompt");
202 }
203
204 if(!config.check("auto_connect")){
205 config.put("auto_connect", "no");
206 }
207
208 if(!config.check("auto_dependency")){
209 config.put("auto_dependency", "no");
210 }
211
212 if(!config.check("elapsed_time"))
213 {
215 clock.setStartTime("00:00:00");
216 }
217
218#if defined(_WIN32)
219 //setup signal handler for windows
220// signal(SIGINT, onSignal);
221// signal(SIGBREAK, onSignal);
222// signal(SIGTERM, onSignal);
223
224#else
225 // Set up the structure to specify the new action.
226// struct sigaction new_action, old_action;
227// new_action.sa_handler = onSignal;
228// sigemptyset (&new_action.sa_mask);
229// new_action.sa_flags = 0;
230// sigaction (SIGINT, NULL, &old_action);
231// if (old_action.sa_handler != SIG_IGN)
232// sigaction (SIGINT, &new_action, NULL);
233// sigaction (SIGHUP, NULL, &old_action);
234// if (old_action.sa_handler != SIG_IGN)
235// sigaction (SIGHUP, &new_action, NULL);
236// sigaction (SIGTERM, NULL, &old_action);
237// if (old_action.sa_handler != SIG_IGN)
238// sigaction (SIGTERM, &new_action, NULL);
239#endif
240
241 MainWindow w;
242 w.init(config);
243 w.show();
244
245 return a.exec();
246}
247
248// void onSignal(int signum)
249// {
250// qDebug("Use <quit> menu to exit!");
251// }
#define yInfo(...)
Definition Log.h:319
MainWindow class.
Definition display.h:22
void init(yarp::os::Property config)
Init the application with the current configuration.
Singleton class For storing execution start time.
Definition utility.h:86
void setStartTime(std::string startTimeStr)
Set the starting time from a string in HH:MM:SS format.
Definition utility.h:110
static ClockStart & getInstance()
Definition utility.h:88
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:252
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:247
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
A class for storing options and configuration information.
Definition Property.h:32
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:980
bool check(const std::string &key) const override
Check if there exists a property of the given name.
These options are loosely based on http://wiki.icub.org/wiki/YARP_ResourceFinder.
Helper class for finding config files and other external resources.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
std::string toString() const override
Return a standard text representation of the content of the object.
static ResourceFinder & getResourceFinderSingleton()
Access a ResourceFinder singleton whose lifetime will match that of the YARP library.
yarp::os::Bottle findPaths(const std::string &name)
Expand a partial path to a list of paths.
std::string findFile(const std::string &name)
Find the full path to a file.
bool setDefaultConfigFile(const std::string &fname)
Provide a default value for the configuration file (can be overridden from command line with the –fro...
virtual std::string asString() const
Get string value.
Definition Value.cpp:240
int main(int argc, char *argv[])
Definition main.cpp:596
#define HELP_MESSAGE
Definition main.cpp:18
void onSignal(int signum)
#define DEF_CONFIG_FILE
Definition main.cpp:41
char * getcwd(char *buf, size_t size)
Portable wrapper for the getcwd() function.
Definition Os.cpp:105
@ YARP_CLOCK_SYSTEM
Definition Time.h:28
The main, catch-all namespace for YARP.
Definition dirs.h:16