Skip to content

Commit

Permalink
Use DynamicCastMessage instead of dynamic_cast to downcast protos in …
Browse files Browse the repository at this point in the history
…UserCommands system

Signed-off-by: Shameek Ganguly <[email protected]>
  • Loading branch information
shameekganguly committed Jun 16, 2024
1 parent ed2b64c commit 05035c8
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/systems/user_commands/UserCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ CreateCommand::CreateCommand(msgs::EntityFactory *_msg,
//////////////////////////////////////////////////
bool CreateCommand::Execute()
{
auto createMsg = dynamic_cast<const msgs::EntityFactory *>(this->msg);
auto createMsg = proto2::DynamicCastMessage<msgs::EntityFactory>(this->msg);
if (nullptr == createMsg)
{
gzerr << "Internal error, null create message" << std::endl;
Expand Down Expand Up @@ -1324,7 +1324,7 @@ RemoveCommand::RemoveCommand(msgs::Entity *_msg,
//////////////////////////////////////////////////
bool RemoveCommand::Execute()
{
auto removeMsg = dynamic_cast<const msgs::Entity *>(this->msg);
auto removeMsg = proto2::DynamicCastMessage<msgs::Entity>(this->msg);
if (nullptr == removeMsg)
{
gzerr << "Internal error, null remove message" << std::endl;
Expand Down Expand Up @@ -1373,7 +1373,7 @@ LightCommand::LightCommand(msgs::Light *_msg,
//////////////////////////////////////////////////
bool LightCommand::Execute()
{
auto lightMsg = dynamic_cast<msgs::Light *>(this->msg);
auto lightMsg = proto2::DynamicCastMessage<msgs::Light>(this->msg);
if (nullptr == lightMsg)
{
gzerr << "Internal error, null light message" << std::endl;
Expand Down Expand Up @@ -1567,7 +1567,7 @@ PoseCommand::PoseCommand(msgs::Pose *_msg,
//////////////////////////////////////////////////
bool PoseCommand::Execute()
{
auto poseMsg = dynamic_cast<const msgs::Pose *>(this->msg);
auto poseMsg = proto2::DynamicCastMessage<msgs::Pose>(this->msg);
if (nullptr == poseMsg)
{
gzerr << "Internal error, null create message" << std::endl;
Expand All @@ -1587,7 +1587,7 @@ PoseVectorCommand::PoseVectorCommand(msgs::Pose_V *_msg,
//////////////////////////////////////////////////
bool PoseVectorCommand::Execute()
{
auto poseVectorMsg = dynamic_cast<const msgs::Pose_V *>(this->msg);
auto poseVectorMsg = proto2::DynamicCastMessage<msgs::Pose_V>(this->msg);
if (nullptr == poseVectorMsg)
{
gzerr << "Internal error, null create message" << std::endl;
Expand Down Expand Up @@ -1615,7 +1615,7 @@ PhysicsCommand::PhysicsCommand(msgs::Physics *_msg,
//////////////////////////////////////////////////
bool PhysicsCommand::Execute()
{
auto physicsMsg = dynamic_cast<const msgs::Physics *>(this->msg);
auto physicsMsg = proto2::DynamicCastMessage<msgs::Physics>(this->msg);
if (nullptr == physicsMsg)
{
gzerr << "Internal error, null physics message" << std::endl;
Expand Down Expand Up @@ -1651,7 +1651,7 @@ SphericalCoordinatesCommand::SphericalCoordinatesCommand(
bool SphericalCoordinatesCommand::Execute()
{
auto sphericalCoordinatesMsg =
dynamic_cast<const msgs::SphericalCoordinates *>(this->msg);
proto2::DynamicCastMessage<msgs::SphericalCoordinates>(this->msg);
if (nullptr == sphericalCoordinatesMsg)
{
gzerr << "Internal error, null SphericalCoordinates message" << std::endl;
Expand Down Expand Up @@ -1729,7 +1729,7 @@ EnableCollisionCommand::EnableCollisionCommand(msgs::Entity *_msg,
//////////////////////////////////////////////////
bool EnableCollisionCommand::Execute()
{
auto entityMsg = dynamic_cast<const msgs::Entity *>(this->msg);
auto entityMsg = proto2::DynamicCastMessage<msgs::Entity>(this->msg);
if (nullptr == entityMsg)
{
gzerr << "Internal error, null create message" << std::endl;
Expand Down Expand Up @@ -1779,7 +1779,7 @@ DisableCollisionCommand::DisableCollisionCommand(msgs::Entity *_msg,
//////////////////////////////////////////////////
bool DisableCollisionCommand::Execute()
{
auto entityMsg = dynamic_cast<const msgs::Entity *>(this->msg);
auto entityMsg = proto2::DynamicCastMessage<msgs::Entity>(this->msg);
if (nullptr == entityMsg)
{
gzerr << "Internal error, null create message" << std::endl;
Expand Down Expand Up @@ -1838,8 +1838,9 @@ VisualCommand::VisualCommand(msgs::MaterialColor *_msg,
//////////////////////////////////////////////////
bool VisualCommand::Execute()
{
auto visualMsg = dynamic_cast<const msgs::Visual *>(this->msg);
auto materialColorMsg = dynamic_cast<const msgs::MaterialColor *>(this->msg);
auto visualMsg = proto2::DynamicCastMessage<msgs::Visual>(this->msg);
auto materialColorMsg =
proto2::DynamicCastMessage<msgs::MaterialColor>(this->msg);
if (visualMsg != nullptr)
{
Entity visualEntity = kNullEntity;
Expand Down Expand Up @@ -1964,8 +1965,8 @@ WheelSlipCommand::WheelSlipCommand(msgs::WheelSlipParametersCmd *_msg,
//////////////////////////////////////////////////
bool WheelSlipCommand::Execute()
{
auto wheelSlipMsg = dynamic_cast<const msgs::WheelSlipParametersCmd *>(
this->msg);
auto wheelSlipMsg =
proto2::DynamicCastMessage<msgs::WheelSlipParametersCmd>(this->msg);
if (nullptr == wheelSlipMsg)
{
gzerr << "Internal error, null wheel slip message" << std::endl;
Expand Down

0 comments on commit 05035c8

Please sign in to comment.