-
Notifications
You must be signed in to change notification settings - Fork 204
added device for synchronization #2772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ste93
wants to merge
6
commits into
robotology:master
Choose a base branch
from
ste93:time_devices
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
systemReady {#master} | ||
----------------------- | ||
|
||
### yarp | ||
#### devices | ||
* added systemReady device that opens some ports when called. It is useful for synchronize processes opened with yarprobotinterface and yarpmanager to avoid crashes when some processes are not started | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/devices/awaitSystemReady/AwaitSystemReady_nws_yarp.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
|
||
#include "AwaitSystemReady_nws_yarp.h" | ||
#include <yarp/os/Network.h> | ||
#include <yarp/os/LogComponent.h> | ||
#include <yarp/os/LogStream.h> | ||
|
||
YARP_LOG_COMPONENT(AWAITSYSTEMREADY_NWS_YARP, "yarp.devices.AwaitSystemReady_nws_yarp") | ||
|
||
AwaitSystemReady_nws_yarp::AwaitSystemReady_nws_yarp() | ||
{ | ||
} | ||
|
||
bool AwaitSystemReady_nws_yarp::open(yarp::os::Searchable &config) | ||
{ | ||
if (config.check("PORT_LIST")) { | ||
// skips the first one since it is PORT_LIST | ||
yarp::os::Bottle port_list = config.findGroup("PORT_LIST").tail(); | ||
for (int index = 0; index < port_list.size(); index++) { | ||
std::string current_port_property = port_list.get(index).toString(); | ||
std::string token; | ||
int pos; | ||
char delimiter = ' '; | ||
pos = current_port_property.find(delimiter); | ||
token = current_port_property.substr(0, pos); | ||
std::string current_port_name = port_list.find(token).asString(); | ||
yarp::os::NetworkBase::waitPort(current_port_name); | ||
} | ||
return true; | ||
} | ||
yCError(AWAITSYSTEMREADY_NWS_YARP) << "missing PORT_LIST group"; | ||
return false; | ||
} | ||
|
||
|
||
bool AwaitSystemReady_nws_yarp::close() | ||
{ | ||
return true; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#ifndef YARP_AWAITSYSTEMREADY_NWS_YARP_H | ||
|
||
#include <yarp/dev/DeviceDriver.h> | ||
|
||
|
||
/** | ||
* @ingroup dev_impl_network_servers | ||
* | ||
* \section AwaitSystemReady_nws_yarp Device description | ||
* \brief `AwaitSystemReady_nws_yarp`: A yarp nws to wait port for synchronization: | ||
* it waits for the specified ports inside the PORT_LIST group. | ||
* Related to SystemReady_nws_yarp. | ||
* | ||
* Parameters required by this device are: | ||
* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | | ||
* |:-------------------:|:-----------------------:|:-------:|:--------------:|:-------------:|:-----------------------------: |:-----------------------------------------------------| | ||
* | PORT_NAME | - | group | | | Yes | the group inside which port names are located | | ||
* | ||
* example of xml file with a fake odometer | ||
* | ||
* \code{.unparsed} | ||
* <?xml version="1.0" encoding="UTF-8" ?> | ||
* <!DOCTYPE robot PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd"> | ||
* <robot name="awaitSystemReady" build="2" portprefix="test" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
* <devices> | ||
* <device xmlns:xi="http://www.w3.org/2001/XInclude" name="awaitSystemReady_nws_yarp" type="awaitSystemReady_nws_yarp"> | ||
* <group name="PORT_LIST"> | ||
* <param name="pippo_port">/pippo</param> | ||
* <param name="pluto_port">/pluto</param> | ||
* </group> | ||
* </device> | ||
* </devices> | ||
* </robot> | ||
* \endcode | ||
* | ||
*/ | ||
|
||
class AwaitSystemReady_nws_yarp : | ||
public yarp::dev::DeviceDriver | ||
{ | ||
public: | ||
AwaitSystemReady_nws_yarp(); | ||
|
||
// DeviceDriver | ||
bool open(yarp::os::Searchable ¶ms) override; | ||
bool close() override; | ||
|
||
}; | ||
|
||
#endif // YARP_AWAITSYSTEMREADY_NWS_YARP_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
yarp_prepare_plugin(awaitSystemReady_nws_yarp | ||
CATEGORY device | ||
TYPE AwaitSystemReady_nws_yarp | ||
INCLUDE AwaitSystemReady_nws_yarp.h | ||
EXTRA_CONFIG | ||
WRAPPER=awaitSystemReady_nws_yarp | ||
DEFAULT ON | ||
) | ||
|
||
if(NOT SKIP_awaitSystemReady_nws_yarp) | ||
yarp_add_plugin(yarp_awaitSystemReady_nws_yarp) | ||
|
||
target_sources(yarp_awaitSystemReady_nws_yarp | ||
PRIVATE | ||
AwaitSystemReady_nws_yarp.cpp | ||
AwaitSystemReady_nws_yarp.h | ||
) | ||
|
||
target_link_libraries(yarp_awaitSystemReady_nws_yarp | ||
PRIVATE | ||
YARP::YARP_os | ||
YARP::YARP_sig | ||
YARP::YARP_dev | ||
) | ||
list(APPEND YARP_${YARP_PLUGIN_MASTER}_PRIVATE_DEPS | ||
YARP_os | ||
YARP_sig | ||
YARP_dev | ||
) | ||
|
||
yarp_install( | ||
TARGETS yarp_awaitSystemReady_nws_yarp | ||
EXPORT YARP_${YARP_PLUGIN_MASTER} | ||
COMPONENT ${YARP_PLUGIN_MASTER} | ||
LIBRARY DESTINATION ${YARP_DYNAMIC_PLUGINS_INSTALL_DIR} | ||
ARCHIVE DESTINATION ${YARP_STATIC_PLUGINS_INSTALL_DIR} | ||
YARP_INI DESTINATION ${YARP_PLUGIN_MANIFESTS_INSTALL_DIR} | ||
) | ||
|
||
set(YARP_${YARP_PLUGIN_MASTER}_PRIVATE_DEPS ${YARP_${YARP_PLUGIN_MASTER}_PRIVATE_DEPS} PARENT_SCOPE) | ||
|
||
set_property(TARGET yarp_awaitSystemReady_nws_yarp PROPERTY FOLDER "Plugins/Device/NWS") | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
yarp_prepare_plugin(systemReady_nws_yarp | ||
CATEGORY device | ||
TYPE SystemReady_nws_yarp | ||
INCLUDE SystemReady_nws_yarp.h | ||
EXTRA_CONFIG | ||
WRAPPER=systemReady_nws_yarp | ||
DEFAULT ON | ||
) | ||
|
||
if(NOT SKIP_systemReady_nws_yarp) | ||
yarp_add_plugin(yarp_systemReady_nws_yarp) | ||
|
||
target_sources(yarp_systemReady_nws_yarp | ||
PRIVATE | ||
SystemReady_nws_yarp.cpp | ||
SystemReady_nws_yarp.h | ||
) | ||
|
||
target_link_libraries(yarp_systemReady_nws_yarp | ||
PRIVATE | ||
YARP::YARP_os | ||
YARP::YARP_sig | ||
YARP::YARP_dev | ||
) | ||
list(APPEND YARP_${YARP_PLUGIN_MASTER}_PRIVATE_DEPS | ||
YARP_os | ||
YARP_sig | ||
YARP_dev | ||
) | ||
|
||
yarp_install( | ||
TARGETS yarp_systemReady_nws_yarp | ||
EXPORT YARP_${YARP_PLUGIN_MASTER} | ||
COMPONENT ${YARP_PLUGIN_MASTER} | ||
LIBRARY DESTINATION ${YARP_DYNAMIC_PLUGINS_INSTALL_DIR} | ||
ARCHIVE DESTINATION ${YARP_STATIC_PLUGINS_INSTALL_DIR} | ||
YARP_INI DESTINATION ${YARP_PLUGIN_MANIFESTS_INSTALL_DIR} | ||
) | ||
|
||
set(YARP_${YARP_PLUGIN_MASTER}_PRIVATE_DEPS ${YARP_${YARP_PLUGIN_MASTER}_PRIVATE_DEPS} PARENT_SCOPE) | ||
|
||
set_property(TARGET yarp_systemReady_nws_yarp PROPERTY FOLDER "Plugins/Device/NWS") | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
|
||
#include "SystemReady_nws_yarp.h" | ||
#include <yarp/os/LogComponent.h> | ||
#include <yarp/os/LogStream.h> | ||
|
||
YARP_LOG_COMPONENT(SYSTEMREADY_NWS_YARP, "yarp.devices.SystemReady_nws_yarp") | ||
|
||
SystemReady_nws_yarp::SystemReady_nws_yarp() | ||
{ | ||
} | ||
|
||
bool SystemReady_nws_yarp::open(yarp::os::Searchable &config) | ||
{ | ||
if (config.check("PORT_LIST")) { | ||
// skips the first one since it is PORT_LIST | ||
yarp::os::Bottle port_list = config.findGroup("PORT_LIST").tail(); | ||
for (int index = 0; index < port_list.size(); index++) { | ||
std::string current_port_property = port_list.get(index).toString(); | ||
std::string token; | ||
int pos; | ||
char delimiter = ' '; | ||
pos = current_port_property.find(delimiter); | ||
token = current_port_property.substr(0, pos); | ||
std::string current_port_name = port_list.find(token).asString(); | ||
yarp::os::Port* current_port = new yarp::os::Port; | ||
port_pointers_list.push_back(current_port); | ||
if(!current_port->open(current_port_name)){ | ||
yCError(SYSTEMREADY_NWS_YARP) << "error opening " << current_port_name; | ||
close(); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
yCError(SYSTEMREADY_NWS_YARP) << "missing PORT_LIST group"; | ||
return false; | ||
} | ||
|
||
|
||
bool SystemReady_nws_yarp::close() | ||
{ | ||
for (auto elem: port_pointers_list){ | ||
elem->close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There used to be a |
||
delete elem; | ||
} | ||
ste93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
port_pointers_list.clear(); | ||
return true; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#ifndef YARP_SYSTEMREADY_NWS_YARP_H | ||
#define YARP_SYSTEMREADY_NWS_YARP_H | ||
|
||
#include <vector> | ||
#include <yarp/os/Port.h> | ||
#include <yarp/dev/DeviceDriver.h> | ||
|
||
|
||
/** | ||
* @ingroup dev_impl_network_servers | ||
* | ||
* \section SystemReady_nws_yarp_parameters Device description | ||
* \brief `SystemReady_nws_yarp`: A yarp nws to open port for synchronization: | ||
* it opens the specified ports inside the PORT_LIST group. | ||
* Related to awaitSystemReady_nws_yarp. | ||
* | ||
* Parameters required by this device are: | ||
* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | | ||
* |:-------------------:|:-----------------------:|:-------:|:--------------:|:-------------:|:-----------------------------: |:-----------------------------------------------------| | ||
* | PORT_NAME | - | group | | | Yes | the group inside which port names are located | | ||
* | ||
* example of xml file with a fake odometer | ||
* | ||
* \code{.unparsed} | ||
* <?xml version="1.0" encoding="UTF-8" ?> | ||
* <!DOCTYPE robot PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd"> | ||
* <robot name="fakeOdometry" build="2" portprefix="test" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
* <devices> | ||
* <device xmlns:xi="http://www.w3.org/2001/XInclude" name="systemReady_nws_yarp" type="systemReady_nws_yarp"> | ||
* <group name="PORT_LIST"> | ||
* <param name="pippo_port">/pippo</param> | ||
* <param name="pluto_port">/pluto</param> | ||
* </group> | ||
* </device> | ||
* </devices> | ||
* </robot> | ||
* \endcode | ||
* | ||
*/ | ||
|
||
class SystemReady_nws_yarp : | ||
public yarp::dev::DeviceDriver | ||
{ | ||
public: | ||
SystemReady_nws_yarp(); | ||
|
||
// DeviceDriver | ||
bool open(yarp::os::Searchable ¶ms) override; | ||
bool close() override; | ||
|
||
private: | ||
std::vector<yarp::os::Port*> port_pointers_list; | ||
|
||
}; | ||
|
||
#endif // YARP_SYSTEMREADY_NWS_YARP_H |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.