Skip to content

Commit

Permalink
Remove ignition (#367)
Browse files Browse the repository at this point in the history
Signed-off-by: Nate Koenig <[email protected]>
  • Loading branch information
nkoenig authored Aug 11, 2023
1 parent 241b06e commit 47df55c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 74 deletions.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
http://ignition_robotics.org
http://gazebosim.org
22 changes: 3 additions & 19 deletions include/gz/msgs/Factory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,8 @@ namespace gz
public: template<typename T>
static std::unique_ptr<T> New(const std::string &_msgType)
{
auto msgType = _msgType;
if (msgType.find("ignition") == 0)
{
msgType.replace(0, 8, "gz");
std::cerr << "Trying to create deprecated message type ["
<< _msgType << "]. Using [" << msgType
<< "] instead." << std::endl;
}
return std::unique_ptr<T>(
static_cast<T*>(New(msgType).release()));
return std::unique_ptr<T>(
static_cast<T*>(New(_msgType).release()));
}

/// \brief Create a new instance of a message.
Expand All @@ -85,16 +77,8 @@ namespace gz
static std::unique_ptr<T> New(const std::string &_msgType,
const std::string &_args)
{
auto msgType = _msgType;
if (msgType.find("ignition") == 0)
{
msgType.replace(0, 8, "gz");
std::cerr << "Trying to create deprecated message type ["
<< _msgType << "]. Using [" << msgType
<< "] instead." << std::endl;
}
return std::unique_ptr<T>(
static_cast<T*>(New(msgType, _args).release()));
static_cast<T*>(New(_msgType, _args).release()));
}

/// \brief Create a new instance of a message.
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ gz_install_includes(

# Install gz/msgs/details
gz_install_includes(
"${GZ_INCLUDE_INSTALL_DIR_POSTFIX}/gz/${IGN_DESIGNATION}/details"
"${GZ_INCLUDE_INSTALL_DIR_POSTFIX}/gz/${GZ_DESIGNATION}/details"
${gen_detail_headers})

##################################################
Expand Down
63 changes: 11 additions & 52 deletions src/Factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,7 @@ class DynamicFactory
// Try to get the list of paths from an environment variable.
const char *descPaths = std::getenv("GZ_DESCRIPTOR_PATH");
if (!descPaths)
{
// TODO(CH3): Deprecated. Remove on tock.
// Remember to still return !!
descPaths = std::getenv("IGN_DESCRIPTOR_PATH");

if (!descPaths)
{
return;
}
else
{
std::cerr << "IGN_DESCRIPTOR_PATH is deprecated and will be removed! "
<< "Use GZ_DESCRIPTOR_PATH instead!" << std::endl;
}
}
return;

// Load all the descriptors found in the paths set with GZ_DESCRIPTOR_PATH.
this->LoadDescriptors(descPaths);
Expand Down Expand Up @@ -161,25 +147,16 @@ class DynamicFactory
/// type could not be handled.
public: static ProtoUniquePtr New(const std::string &_msgType)
{
auto msgType = _msgType;
if (msgType.find("ignition") == 0)
{
msgType.replace(0, 8, "gz");
std::cerr << "Trying to create deprecated message type ["
<< _msgType << "]. Using [" << msgType << "] instead."
<< std::endl;
}

// Shortcut if the type has been already registered.
std::map<std::string, std::function<ProtoUniquePtr()>>::iterator msgF =
dynamicMsgMap.find(msgType);
dynamicMsgMap.find(_msgType);

if (msgF != dynamicMsgMap.end())
return msgF->second();

// Nothing to do if we don't know about this type in the descriptor map.
const google::protobuf::Descriptor *descriptor =
pool.FindMessageTypeByName(msgType);
pool.FindMessageTypeByName(_msgType);
if (!descriptor)
return nullptr;

Expand Down Expand Up @@ -236,42 +213,33 @@ void Factory::Register(const std::string &_msgType,
std::unique_ptr<google::protobuf::Message> Factory::New(
const std::string &_msgType)
{
auto msgType = _msgType;
if (msgType.find("ignition") == 0)
{
msgType.replace(0, 8, "gz");
std::cerr << "Trying to create deprecated message type ["
<< _msgType << "]. Using [" << msgType << "] instead."
<< std::endl;
}

std::unique_ptr<google::protobuf::Message> msg;

std::string type;
// Convert "gz.msgs." to "gz_msgs.".
if (msgType.find("gz.msgs.") == 0)
if (_msgType.find("gz.msgs.") == 0)
{
type = "gz_msgs." + msgType.substr(8);
type = "gz_msgs." + _msgType.substr(8);
}
// Convert ".gz.msgs." to "gz_msgs.".
else if (msgType.find(".gz.msgs.") == 0)
else if (_msgType.find(".gz.msgs.") == 0)
{
type = "gz_msgs." + msgType.substr(9);
type = "gz_msgs." + _msgType.substr(9);
}
else
{
// Fix typenames that are missing "gz_msgs." at the beginning.
if (msgType.find("gz_msgs.") != 0)
if (_msgType.find("gz_msgs.") != 0)
type = "gz_msgs.";
type += msgType;
type += _msgType;
}

// Create a new message if a FactoryFn has been assigned to the message type
if (msgMap->find(type) != msgMap->end())
return ((*msgMap)[type]) ();

// Check if we have the message descriptor.
msg = dynamicFactory.New(msgType);
msg = dynamicFactory.New(_msgType);

return msg;
}
Expand All @@ -280,16 +248,7 @@ std::unique_ptr<google::protobuf::Message> Factory::New(
std::unique_ptr<google::protobuf::Message> Factory::New(
const std::string &_msgType, const std::string &_args)
{
auto msgType = _msgType;
if (msgType.find("ignition") == 0)
{
msgType.replace(0, 8, "gz");
std::cerr << "Trying to create deprecated message type ["
<< _msgType << "]. Using [" << msgType << "] instead."
<< std::endl;
}

std::unique_ptr<google::protobuf::Message> msg = New(msgType);
std::unique_ptr<google::protobuf::Message> msg = New(_msgType);
if (msg)
{
google::protobuf::TextFormat::ParseFromString(_args, msg.get());
Expand Down
2 changes: 1 addition & 1 deletion src/Generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool Generator::Generate(const FileDescriptor *_file,
auto parent_path = filePath.parent_path();
auto fileStem = filePath.stem().string();

// protoc generates ignition/msgs/msg.pb.cc and ignition/msgs/msg.pb.hh
// protoc generates gz/msgs/msg.pb.cc and gz/msgs/msg.pb.hh
// This generator injects code into the msg.pb.cc file, but generates
// a completely new header that wraps the original protobuf header
//
Expand Down

0 comments on commit 47df55c

Please sign in to comment.