19#if defined(YARP_HAS_EXECINFO_H) && !defined(__APPLE__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__PPC__)
35#if defined(YARP_HAS_EXECINFO_H) && !defined(__APPLE__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__PPC__)
37 static void sigsegv_handler(
int nSignum, siginfo_t* si,
void* vcontext);
49#if defined(YARP_HAS_EXECINFO_H) && !defined(__APPLE__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__PPC__)
63#if defined(YARP_HAS_EXECINFO_H) && !defined(__APPLE__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__PPC__)
66 auto context =
reinterpret_cast<ucontext_t*
>(vcontext);
67#if defined(__x86_64__)
68 context->uc_mcontext.gregs[REG_RIP]++;
70 context->uc_mcontext.gregs[REG_EIP]++;
73 const size_t max_depth = 100;
75 void* stack_addrs[max_depth];
77 stack_depth = backtrace(stack_addrs, max_depth);
78 stack_strings = backtrace_symbols(stack_addrs, stack_depth);
80 yError(
"yarprobotinterface intercepted a segmentation fault caused by a faulty plugin:");
81 yError(
"%s\n", stack_strings[2]);
95#if defined(YARP_HAS_EXECINFO_H) && !defined(__APPLE__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__PPC__)
96 struct sigaction action;
97 memset(&action, 0,
sizeof(
struct sigaction));
99 action.sa_flags = SA_SIGINFO;
112 if (!rf.
check(
"config")) {
113 yFatal() <<
"Missing \"config\" argument";
116 const std::string& filename = rf.
findFile(
"config");
117 yTrace() <<
"Reading robot config file" << filename;
119 bool verbosity = rf.
check(
"verbose");
120 bool deprecated = rf.
check(
"allow-deprecated-dtd");
121 bool dryrun = rf.
check(
"dryrun");
122 mPriv->autocloseAfterStart = rf.
check(
"autocloseAfterStart");
133 config.
unput(
"config");
138 yFatal() <<
"Config file " << filename <<
" not parsed correctly.";
147 setName(mPriv->robot.portprefix().c_str());
149 mPriv->robot.setVerbose(verbosity);
150 mPriv->robot.setAllowDeprecatedDevices(rf.
check(
"allow-deprecated-devices"));
151 mPriv->robot.setDryRun(dryrun);
153 std::string portprefix = mPriv->robot.portprefix();
154 if (portprefix[0] !=
'/') {
156 "*************************************************************************************\n"
157 "* yarprobotinterface 'portprefix' parameter does not follow convention, *\n"
158 "* it MUST start with a leading '/' since it is used as the full prefix port name *\n"
159 "* name: full port prefix name with leading '/', e.g. /robotName *\n"
160 "* A temporary automatic fix will be done for you, but please fix your config file *\n"
161 "*************************************************************************************";
162 portprefix =
"/" + portprefix;
165 std::string rpcPortName(portprefix +
"/yarprobotinterface");
166 mPriv->rpcPort.open(rpcPortName);
167 attach(mPriv->rpcPort);
172 yError() <<
"Error in" << ActionPhaseToString(mPriv->robot.currentPhase()) <<
"phase... see previous messages for more info";
193 yCDebug(YRI) <<
"yarprobotinterface running happily";
196 yCInfo(YRI) <<
"`autocloseAfterStart` option selected. Calling close()";
206 mPriv->interruptReceived++;
208 yCWarning(YRI) <<
"Interrupt #" << mPriv->interruptReceived <<
"# received.";
210 mPriv->robot.interrupt();
220 switch (mPriv->interruptReceived) {
245 return mPriv->closeOk;
247 mPriv->closed =
true;
251 switch (mPriv->interruptReceived) {
255 mPriv->closeOk =
false;
262 mPriv->closeOk =
false;
268 mPriv->closeOk =
false;
271 mPriv->rpcPort.interrupt();
272 mPriv->rpcPort.close();
273 return mPriv->closeOk;
278 return this->
yarp().attachAsServer(source);
284 return ActionPhaseToString(mPriv->robot.currentPhase());
289 return mPriv->robot.currentLevel();
299 return mPriv->robot.name();
void yarp_print_trace(FILE *out, const char *file, unsigned int line)
Low level function for printing a stack trace, if implemented (ACE or gcc/Linux).
A class for storing options and configuration information.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
std::string toString() const override
Return a standard text representation of the content of the object.
std::string findFile(const std::string &name)
Find the full path to a file.
A port that is specialized as an RPC server.
Result of the parsing of yarp::robotinterface::XMLReader.
bool parsingIsSuccessful
True if the parsing was successful, false otherwise.
Robot robot
If parsingIsSuccessful is true, contains a valid robot instance.
Class to read an XML file.
XMLReaderResult getRobotFromFile(const std::string &filename, const yarp::os::Searchable &config=yarp::os::Property())
Parse the XML description of a robotinterface from a file.
void setEnableDeprecated(bool enab)
void setVerbose(bool verbose)
static void sigsegv_handler(int nSignum, siginfo_t *si, void *vcontext)
static struct sigaction old_action
yarp::os::RpcServer rpcPort
yarp::robotinterface::Robot robot
std::string get_robot() override
Returns robot name.
bool updateModule() override
Override this to do whatever your module needs to do.
std::string get_phase() override
Returns current phase.
double getPeriod() override
You can override this to control the approximate periodicity at which updateModule() is called by run...
bool close() override
Close function.
bool attach(yarp::os::RpcServer &source) override
Make any input from an RpcServer object go to the respond() method.
bool configure(yarp::os::ResourceFinder &rf) override
Configure the module, pass a ResourceFinder object to the module.
int32_t get_level() override
Returns current level.
bool is_ready() override
Returns true if yarprobotinterface is ready (all startup actions performed and no interrupt called).
std::string quit() override
Closes yarprobotinterface.
bool interruptModule() override
Try to halt any ongoing operations by threads managed by the module.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
The main, catch-all namespace for YARP.