Skip to content

Commit

Permalink
ign -> gz Macro Migration : gz-plugin (#87)
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <[email protected]>
  • Loading branch information
methylDragon authored Jun 17, 2022
1 parent 7d43bae commit dbd0f97
Show file tree
Hide file tree
Showing 44 changed files with 203 additions and 168 deletions.
15 changes: 15 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ release will remove the deprecated code.

* Header files under `ignition/...` are deprecated and will be removed in future versions.
Use `gz/...` instead.

* The following `IGN_` / `IGNITION_` prefixed macros are deprecated and will be removed in future versions.
Additionally, they will only be available when including the corresponding `ignition/...` header.
Use the `GZ_` prefix instead.
* `IGN_PLUGIN_REGISTER_MORE_TRANS_UNITS`

* `IGNITION_ADD_PLUGIN`
* `IGNITION_ADD_PLUGIN_ALIAS`
* `IGNITION_ADD_FACTORY`
* `IGNITION_ADD_FACTORY_ALIAS`
* `IGN_CREATE_INTERFACE`
* `IGNITION_UNITTEST_SPECIALIZED_PLUGIN_ACCESS`

* `ignitionVersion()` is deprecated and will be removed in future versions.
Use `gzVersion()` instead.
14 changes: 7 additions & 7 deletions MigrationFromCommon.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ The name of the header for registering plugins has changed:
* `<ignition/common/PluginMacros.hh>` should be replaced by `<ignition/plugin/Register.hh>`

The old `ign-common` plugin registration method had numerous macros for registering
plugins. Those have all been replaced with `IGNITION_ADD_PLUGIN`. Specifically:
plugins. Those have all been replaced with `GZ_ADD_PLUGIN`. Specifically:

* `IGN_COMMON_REGISTER_SINGLE_MACRO` can be directly replaced with `IGNITION_ADD_PLUGIN`.
* `IGN_COMMON_ADD_PLUGIN` can be directly replaced with `IGNITION_ADD_PLUGIN`.
* `IGN_COMMON_REGISTER_SINGLE_MACRO` can be directly replaced with `GZ_ADD_PLUGIN`.
* `IGN_COMMON_ADD_PLUGIN` can be directly replaced with `GZ_ADD_PLUGIN`.
* All uses of `IGN_COMMON_BEGIN_ADDING_PLUGINS` can simply be removed.
* All uses of `IGN_COMMON_FINISH_ADDING_PLUGINS` can simply be removed.
* All uses of `IGN_COMMON_SPECIALIZE_INTERFACE` can simply be removed. Interfaces no longer need to be "specialized" in order to have specialized plugins.

You can also register multiple interfaces with a single call to `IGNITION_ADD_PLUGIN`, e.g.:
You can also register multiple interfaces with a single call to `GZ_ADD_PLUGIN`, e.g.:

```
IGNITION_ADD_PLUGIN(MyPluginClass, MyInterface1, MyInterface2, MyInterface3)
GZ_ADD_PLUGIN(MyPluginClass, MyInterface1, MyInterface2, MyInterface3)
```

You may also place the `IGNITION_ADD_PLUGIN` macro into **any namespace**. You
You may also place the `GZ_ADD_PLUGIN` macro into **any namespace**. You
simply need to make sure that the compiler can resolve the names of the classes
that you pass to it (and there will be a compilation error if it cannot).

Expand Down Expand Up @@ -127,7 +127,7 @@ public:
}
};
IGNITION_ADD_PLUGIN(MyGetT_Plugin<double>, GetT_Interface<double>)
GZ_ADD_PLUGIN(MyGetT_Plugin<double>, GetT_Interface<double>)
```

When using the loader, you would call
Expand Down
4 changes: 2 additions & 2 deletions core/include/gz/plugin/EnablePluginFromThis.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ namespace gz
private: void PrivateSetPluginFromThis(const PluginPtr &_ptr);

private: class Implementation;
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
private: std::unique_ptr<Implementation> pimpl;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/include/gz/plugin/Factory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ namespace gz
/// defines a factory that can produce a `std::unique_ptr<InterfaceClass>`
/// given arguments of `InputType1` and `InputType2`.
///
/// To register a factory, use the `IGNITION_ADD_FACTORY` macro, e.g.:
/// To register a factory, use the `GZ_ADD_FACTORY` macro, e.g.:
///
/// \code
/// IGNITION_ADD_FACTORY(ImplementedClass, MyFactory)
/// GZ_ADD_FACTORY(ImplementedClass, MyFactory)
/// \endcode
///
/// where `ImplementedClass` is the name of the class that your plugin
Expand Down
24 changes: 12 additions & 12 deletions core/include/gz/plugin/Info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,44 +54,44 @@ namespace gz
void Clear();

/// \brief The name of the plugin
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
std::string name;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief Alternative names that may be used to instantiate the plugin
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
std::set<std::string> aliases;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief The keys are the names of the types of interfaces that this
/// plugin provides. The values are functions that convert a void
/// pointer (which actually points to the plugin instance) to another
/// void pointer (which actually points to the location of the interface
/// within the plugin instance).
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
using InterfaceCastingMap =
std::unordered_map< std::string, std::function<void*(void*)> >;
InterfaceCastingMap interfaces;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief This is a set containing the demangled versions of the names
/// of the interfaces provided by this plugin. This gets filled in by
/// the Loader after receiving the Info. It is only used by
/// the user-facing API. Internally, when looking up Interfaces, the
/// mangled `interfaces` map will still be used.
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
std::set<std::string> demangledInterfaces;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief A method that instantiates a new instance of a plugin
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
std::function<void*()> factory;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief A method that safely deletes an instance of the plugin
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
std::function<void(void*)> deleter;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
};
}

Expand Down
4 changes: 2 additions & 2 deletions core/include/gz/plugin/Plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ namespace gz
const std::string &_interfaceName);

class Implementation;
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
/// \brief PIMPL pointer to the implementation of this class.
private: const std::unique_ptr<Implementation> dataPtr;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief Virtual destructor
public: virtual ~Plugin();
Expand Down
4 changes: 2 additions & 2 deletions core/include/gz/plugin/WeakPluginPtr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ namespace gz
public: ~WeakPluginPtr();

private: class Implementation;
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
/// \brief PIMPL pointer to the implementation of this class
private: std::unique_ptr<Implementation> pimpl;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/include/gz/plugin/detail/Factory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ namespace gz
/// to do anything with the Product (including deleting it).
class GZ_PLUGIN_VISIBLE FactoryCounter
{
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
/// \brief A reference to the factory that created this product
private: std::shared_ptr<void> factoryPluginInstancePtr;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief A special destructor that ensures the shared library remains
/// loaded throughout the destruction process of this product.
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/BoxEnvironment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ class Plugin : public virtual gz::plugin::examples::Environment

}

IGNITION_ADD_PLUGIN(
GZ_ADD_PLUGIN(
BoxEnvironment::Plugin,
gz::plugin::examples::Environment)
2 changes: 1 addition & 1 deletion examples/plugins/CautiousBot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CautiousBot
public: double distance = std::numeric_limits<double>::infinity();
};

IGNITION_ADD_PLUGIN(CautiousBot,
GZ_ADD_PLUGIN(CautiousBot,
CautiousBot::Drive,
CautiousBot::ProximitySensor)

Expand Down
4 changes: 2 additions & 2 deletions examples/plugins/CrashBot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CrashBot
return gz::math::Vector3d(1.0, 0.0, 0.0);

// If we have not detected a wall, drive in a spiral, searching for a wall
return gz::math::Vector3d(0.5, 0.0, 20.0*IGN_PI/180.0);
return gz::math::Vector3d(0.5, 0.0, 20.0*GZ_PI/180.0);
}

// Documentation inherited
Expand All @@ -60,6 +60,6 @@ class CrashBot
public: bool detectedWall;
};

IGNITION_ADD_PLUGIN(CrashBot, Drive, ProximitySensor)
GZ_ADD_PLUGIN(CrashBot, Drive, ProximitySensor)

}
2 changes: 1 addition & 1 deletion examples/plugins/ExponentialODE.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Factory : public ODESystemFactory
}
};

IGNITION_ADD_PLUGIN(Factory, ODESystemFactory)
GZ_ADD_PLUGIN(Factory, ODESystemFactory)

}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/ForwardEuler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Integrator : public gz::plugin::examples::NumericalIntegrator

};

IGNITION_ADD_PLUGIN(Integrator, NumericalIntegrator)
GZ_ADD_PLUGIN(Integrator, NumericalIntegrator)

}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/plugins/PolynomialODE.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ class CubicFactory : public ODESystemFactory
}

// Register multiple plugins for this library
IGNITION_ADD_PLUGIN(
GZ_ADD_PLUGIN(
gz::plugin::examples::PolynomialODE::ParabolicFactory,
gz::plugin::examples::ODESystemFactory)

IGNITION_ADD_PLUGIN(
GZ_ADD_PLUGIN(
gz::plugin::examples::PolynomialODE::CubicFactory,
gz::plugin::examples::ODESystemFactory)

2 changes: 1 addition & 1 deletion examples/plugins/RungeKutta4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Integrator : public gz::plugin::examples::NumericalIntegrator

};

IGNITION_ADD_PLUGIN(Integrator, NumericalIntegrator)
GZ_ADD_PLUGIN(Integrator, NumericalIntegrator)

}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/robot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ void Simulate(const EnvironmentPluginPtr &_environment,
if (_printState)
{
std::cout << "Location: (" << x[0] << "m, " << x[1] << "m) | Yaw: "
<< 180.0*theta/IGN_PI << "-degrees | Time: " << time
<< 180.0*theta/GZ_PI << "-degrees | Time: " << time
<< "s |==| Velocity output: " << vel << std::endl;
}
}

std::cout << "The simulation has finished (time: " << time << "s).\n"
<< " -- Final robot location: (" << x[0] << "m, " << x[1] << "m)\n"
<< " -- Yaw: " << 180.0*theta/IGN_PI << "-degrees\n" << std::endl;
<< " -- Yaw: " << 180.0*theta/GZ_PI << "-degrees\n" << std::endl;
}

/////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions loader/include/gz/plugin/Loader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ namespace gz
const std::string &_resolvedName) const;

class Implementation;
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
/// \brief PIMPL pointer to class implementation
private: std::unique_ptr<Implementation> dataPtr;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions loader/src/Loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ namespace gz
"Bug in code: Loader::Implementation::LoadPlugins was called with "
"a nullptr value for _dlHandle.");

const std::string infoSymbol = "IgnitionPluginHook";
const std::string infoSymbol = "GzPluginHook";
void *infoFuncPtr = dlsym(_dlHandle.get(), infoSymbol.c_str());

// Does the library have the right symbol?
Expand Down Expand Up @@ -584,7 +584,7 @@ namespace gz
// pointer gets used, so we do not need to worry about its memory address
// being filled with a non-compatible type. The only risk would be if a
// user decides to implement their own version of
// IgnitionPluginHook, but they surely would have no
// GzPluginHook, but they surely would have no
// incentive in doing that.
//
// Also note that the main reason we jump through these hoops is in order
Expand All @@ -599,7 +599,7 @@ namespace gz
{
// TODO(anyone): When we need to support multiple API versions,
// put the logic for it into here.
// We can call IgnitionPluginHook(~) again with the
// We can call GzPluginHook(~) again with the
// API version that it expects.

std::cerr << "The library [" << _pathToLibrary << "] is using an "
Expand Down
7 changes: 6 additions & 1 deletion loader/src/cmd/ign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ extern "C" void cmdPluginInfo(
}

//////////////////////////////////////////////////
extern "C" const char *ignitionVersion()
extern "C" const char *gzVersion()
{
return strdup(GZ_PLUGIN_VERSION_FULL);
}

extern "C" const char *ignitionVersion()
{
return gzVersion();
}
3 changes: 2 additions & 1 deletion loader/src/cmd/ign.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

/// \brief External hook to read the library version.
/// \return C-string representing the version. Ex.: 0.1.2
extern "C" const char *ignitionVersion();
extern "C" const char *gzVersion();
extern "C" const char GZ_DEPRECATED(2) *ignitionVersion();

/// \brief Plugin info
/// \param[in] _plugin Name of the plugin
Expand Down
2 changes: 1 addition & 1 deletion loader/src/cmd/plugin_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int main(int argc, char** argv)
app.set_help_all_flag("--help-all", "Show all help");

app.add_flag_callback("--version", [](){
std::cout << ignitionVersion() << std::endl;
std::cout << gzVersion() << std::endl;
throw CLI::Success();
});

Expand Down
2 changes: 1 addition & 1 deletion loader/src/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ TEST(ignTest, PluginInfoNonPluginLibrary)
GZ_PLUGIN_LIB);

EXPECT_NE(std::string::npos, output.find("does not export any plugins. The "
"symbol [IgnitionPluginHook] is missing, or it is not externally visible."))
"symbol [GzPluginHook] is missing, or it is not externally visible."))
<< output;
EXPECT_NE(std::string::npos, output.find("Found 0 plugins in library file"))
<< output;
Expand Down
Loading

0 comments on commit dbd0f97

Please sign in to comment.