fledge-iot/fledge

Erroneous documentation for most plugin functions involving PLUGIN_HANDLE

Opened this issue · 1 comments

Most of the documentation involving PLUGIN_HANDLE provides erroneous usage examples for the C++ implementation of a plugin.

The plugin_init() function is correct and returns a PLUGIN_HANDLE type (void*) containing a pointer to the main plugin class (in this example a DHT11*):
image

But then most of the other functions in the documentation take a PLUGIN_HANDLE* as parameter (void**) when it should in fact use a PLUGIN_HANDLE only. It is clearly visible that the input type is actually the same type as the one returned by plugin_init() when the input type is casted into DHT11* here:
image

All of the documentation involving this type needs to be reviewed: some functions may actually need PLUGIN_HANDLE* as an input, but most of them doesn't and must be fixed.

Sadly most of the existing plugins are based on those examples and do contain this erroneous implementation which is not raising any error because it is using the "jocker" void* type.

As an example in one of the plugins I reviewed this led to really messed up codes likes this one where you end up casting a PLUGIN_HANDLE into PLUGIN_HANDLE* which makes zero sense in term of pure C++:

TEST(HNZ, PluginInit) {
  ConfigCategory *config = new ConfigCategory("Test_Config", default_config);
  config->setItemsValueFromDefault();
  PLUGIN_HANDLE handle = nullptr;

  ASSERT_NO_THROW(handle = plugin_init(config));

  if (handle != nullptr) plugin_shutdown((PLUGIN_HANDLE *)handle);

  delete config;
}

Looks like part of this issue was already reported in #843, sorry for missing it.