36 #define BOOST_FILESYSTEM_VERSION 3 37 #include <boost/filesystem.hpp> 50 if (!g_packages.count(pkg))
return PackagePtr();
51 return g_packages[pkg].lock();
61 if (data_type ==
"Header")
return g_messages_by_name[ros::message_traits::datatype<std_msgs::Header>()].lock();
62 if (!g_messages_by_name.count(data_type))
return MessagePtr();
63 return g_messages_by_name[data_type].lock();
68 if (!g_messages_by_md5sum.count(md5sum))
return MessagePtr();
69 return g_messages_by_md5sum[md5sum].lock();
73 if (!g_messages_by_typeid.count(&type_info))
return MessagePtr();
74 return g_messages_by_typeid[&type_info].lock();
79 if (g_packages.count(package->getName()))
return g_packages[package->getName()].lock();
80 g_repository.push_back(package);
81 g_packages[package->getName()] =
package;
87 std::vector<std::string> messages;
88 for(std::vector<MessagePtr>::const_iterator it =
messages_.begin(); it !=
messages_.end(); ++it)
89 messages.push_back((*it)->getName());
101 if (g_messages_by_name.count(message->getDataType()))
return g_messages_by_name[message->getDataType()].lock();
103 g_messages_by_name[message->getDataType()] =
message;
104 g_messages_by_md5sum[message->getMD5Sum()] =
message;
105 g_messages_by_typeid[&(message->getTypeId())] = message;
118 for(std::size_t j = 0; j < field->size(); j++) {
119 std::string field_name = (!prefix.empty() ? prefix + separator_ :
"") + field->getName();
120 if (field->isContainer()) field_name += boost::lexical_cast<std::string>(j);
122 if (field->isMessage()) {
125 ROS_WARN(
"Expansion of %s failed: Could not expand field %s with unknown type %s", getDataType(), field->getName(), field->getDataType());
128 expand(expanded, field_name);
131 fields_.push_back(expanded);
132 fields_by_name_[field_name] = expanded;
133 field_names_.push_back(expanded->getName());
142 return getFields(fields, expand, separator, prefix);
149 std::string base(prefix + field->getName());
151 for (std::size_t index = 0; index < field->size(); ++index) {
152 std::string name(base);
153 if (field->isArray()) name = name + boost::lexical_cast<std::string>(index);
155 if (expand && field->isMessage()) {
158 ROS_WARN(
"Expansion of %s failed: Could not expand field %s with unknown type %s", getDataType(), field->getName(), field->getDataType());
161 expanded->getFields(fields, expand, separator, name + separator);
164 fields.push_back(name);
175 return getTypes(types, expand);
183 for (std::size_t index = 0; index < field->size(); ++index) {
184 if (expand && field->isMessage()) {
187 ROS_WARN(
"Expansion of %s failed: Could not expand field %s with unknown type %s", getDataType(), field->getName(), field->getDataType());
190 expanded->getTypes(types, expand);
193 types.push_back(field->isArray() ? field->getValueType() : field->getDataType());
203 std::vector<boost::any> values;
204 return getValues(values, expand);
209 if (!hasInstance())
return values;
214 for (std::size_t index = 0; index < field->size(); ++index) {
215 if (expand && field->isMessage()) {
218 ROS_WARN(
"Expansion of %s failed: Could not expand field %s with unknown type %s", getDataType(), field->getName(), field->getDataType());
221 expanded->getValues(values, expand);
224 values.push_back(field->get(index));
241 return load(
"libintrospection_" + package_name +
".so");
247 path path(package_or_library_or_path);
248 if (is_directory(path)) {
250 for(directory_iterator entry(path); entry != directory_iterator(); ++entry) {
252 if (is_regular_file(entry->path()))
load(entry->path().string());
258 if (path.extension() !=
".so") {
264 if (std::find(g_loaded_libraries.begin(), g_loaded_libraries.end(), path.filename()) != g_loaded_libraries.end()) {
269 void *library = dlopen(path.string().c_str(), RTLD_NOW | RTLD_GLOBAL);
270 const char *error = dlerror();
271 if (error || !library) {
277 LoadFunction load_fcn = (LoadFunction) dlsym(library,
"cpp_introspection_load_package");
279 if (error || !load_fcn) {
284 PackagePtr package __attribute__((unused)) = (*load_fcn)();
287 g_loaded_libraries.push_back(path.filename().string());
std::vector< std::string > V_string
MessagePtr messageByMD5Sum(const std::string &md5sum)
static M_TypeInfo_Message g_messages_by_typeid
#define ROS_DEBUG_STREAM_NAMED(name, args)
#define ROS_WARN_NAMED(name,...)
V_string getFields(bool expand=false, const std::string &separator=".", const std::string &prefix=std::string()) const
std::vector< boost::any > getValues(bool expand=false) const
void expand(const MessagePtr &message, const std::string &prefix)
PackagePtr load(const std::string &package_or_library_or_path)
static M_Message g_messages_by_md5sum
#define ROS_INFO_STREAM_NAMED(name, args)
MessagePtr expand(const MessagePtr &message, const std::string &separator=".", const std::string &prefix="")
const V_Package & packages()
virtual MessagePtr expand(std::size_t i=0) const
boost::shared_ptr< Package const > PackagePtr
std::map< const std::type_info *, MessageWPtr, CompareTypeInfo > M_TypeInfo_Message
MessagePtr messageByTypeId(const std::type_info &type_info)
V_Field::const_iterator const_iterator
std::vector< PackagePtr > V_Package
const_iterator begin() const
PackagePtr package(const std::string &pkg)
static V_Package g_repository
const_iterator end() const
virtual const V_Message & fields() const
static M_Message g_messages_by_name
static PackagePtr add(const PackagePtr &package)
PackagePtr loadPackage(const std::string &package_name)
virtual const char * getName() const =0
boost::shared_ptr< Message const > MessagePtr
MessagePtr message(const std::string &message) const
static M_Package g_packages
std::map< std::string, MessageWPtr > M_Message
V_string getTypes(bool expand=false) const
MessagePtr messageByDataType(const std::string &data_type, const std::string &package=std::string())
static V_string g_loaded_libraries
std::map< std::string, PackageWPtr > M_Package
std::vector< std::string > getMessages() const
#define ROS_WARN_STREAM_NAMED(name, args)