-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding C++ plugin base class to reduce boilerplate in C++ plugins
- Loading branch information
Showing
11 changed files
with
318 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,160 +1,48 @@ | ||
#include "bytesPlugin.h" | ||
|
||
#include <plugins/uda_plugin_base.hpp> | ||
#include <clientserver/stringUtils.h> | ||
#include <clientserver/makeRequestBlock.h> | ||
|
||
#include "readBytesNonOptimally.h" | ||
|
||
static int do_help(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); | ||
|
||
static int do_version(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); | ||
|
||
static int do_builddate(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); | ||
|
||
static int do_defaultmethod(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); | ||
|
||
static int do_maxinterfaceversion(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); | ||
|
||
static int do_read(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); | ||
|
||
int bytesPlugin(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) | ||
{ | ||
static int init = 0; | ||
|
||
//---------------------------------------------------------------------------------------- | ||
// Standard v1 Plugin Interface | ||
|
||
if (idam_plugin_interface->interfaceVersion > THISPLUGIN_MAX_INTERFACE_VERSION) { | ||
RAISE_PLUGIN_ERROR("Plugin Interface Version Unknown to this plugin: Unable to execute the request!"); | ||
} | ||
|
||
idam_plugin_interface->pluginVersion = THISPLUGIN_VERSION; | ||
|
||
//---------------------------------------------------------------------------------------- | ||
// Heap Housekeeping | ||
|
||
// Plugin must maintain a list of open file handles and sockets: loop over and close all files and sockets | ||
// Plugin must maintain a list of plugin functions called: loop over and reset state and free heap. | ||
// Plugin must maintain a list of calls to other plugins: loop over and call each plugin with the housekeeping request | ||
// Plugin must destroy lists at end of housekeeping | ||
|
||
// A plugin only has a single instance on a server. For multiple instances, multiple servers are needed. | ||
// Plugins can maintain state so recursive calls (on the same server) must respect this. | ||
// If the housekeeping action is requested, this must be also applied to all plugins called. | ||
// A list must be maintained to register these plugin calls to manage housekeeping. | ||
// Calls to plugins must also respect access policy and user authentication policy | ||
|
||
REQUEST_DATA* request = idam_plugin_interface->request_data; | ||
|
||
if (idam_plugin_interface->housekeeping || STR_IEQUALS(request->function, "reset")) { | ||
if (!init) return 0; // Not previously initialised: Nothing to do! | ||
// Free Heap & reset counters | ||
init = 0; | ||
return 0; | ||
} | ||
|
||
//---------------------------------------------------------------------------------------- | ||
// Initialise | ||
#include <boost/filesystem.hpp> | ||
|
||
if (!init || STR_IEQUALS(request->function, "init") | ||
|| STR_IEQUALS(request->function, "initialise")) { | ||
|
||
init = 1; | ||
if (STR_IEQUALS(request->function, "init") || STR_IEQUALS(request->function, "initialise")) | ||
return 0; | ||
} | ||
|
||
//---------------------------------------------------------------------------------------- | ||
// Plugin Functions | ||
//---------------------------------------------------------------------------------------- | ||
|
||
//---------------------------------------------------------------------------------------- | ||
// Standard methods: version, builddate, defaultmethod, maxinterfaceversion | ||
|
||
if (STR_IEQUALS(request->function, "help")) { | ||
return do_help(idam_plugin_interface); | ||
} else if (STR_IEQUALS(request->function, "version")) { | ||
return do_version(idam_plugin_interface); | ||
} else if (STR_IEQUALS(request->function, "builddate")) { | ||
return do_builddate(idam_plugin_interface); | ||
} else if (STR_IEQUALS(request->function, "defaultmethod")) { | ||
return do_defaultmethod(idam_plugin_interface); | ||
} else if (STR_IEQUALS(request->function, "maxinterfaceversion")) { | ||
return do_maxinterfaceversion(idam_plugin_interface); | ||
} else if (STR_IEQUALS(request->function, "read")) { | ||
return do_read(idam_plugin_interface); | ||
} else { | ||
RAISE_PLUGIN_ERROR("Unknown function requested!"); | ||
} | ||
} | ||
|
||
/** | ||
* Help: A Description of library functionality | ||
* @param idam_plugin_interface | ||
* @return | ||
*/ | ||
int do_help(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) | ||
{ | ||
const char* help = "\nbytes: data reader to access files as a block of bytes without interpretation\n\n"; | ||
const char* desc = "bytes: help = description of this plugin"; | ||
|
||
return setReturnDataString(idam_plugin_interface->data_block, help, desc); | ||
} | ||
|
||
/** | ||
* Plugin version | ||
* @param idam_plugin_interface | ||
* @return | ||
*/ | ||
int do_version(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) | ||
{ | ||
return setReturnDataIntScalar(idam_plugin_interface->data_block, THISPLUGIN_VERSION, "Plugin version number"); | ||
} | ||
|
||
/** | ||
* Plugin Build Date | ||
* @param idam_plugin_interface | ||
* @return | ||
*/ | ||
int do_builddate(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) | ||
{ | ||
return setReturnDataString(idam_plugin_interface->data_block, __DATE__, "Plugin build date"); | ||
} | ||
#include "readBytesNonOptimally.h" | ||
|
||
/** | ||
* Plugin Default Method | ||
* @param idam_plugin_interface | ||
* @return | ||
*/ | ||
int do_defaultmethod(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) | ||
class BytesPlugin : public UDAPluginBase { | ||
public: | ||
BytesPlugin(); | ||
int read(IDAM_PLUGIN_INTERFACE* plugin_interface); | ||
int init(IDAM_PLUGIN_INTERFACE* plugin_interface) override { return 0; } | ||
int reset() override { return 0; } | ||
}; | ||
|
||
BytesPlugin::BytesPlugin() | ||
: UDAPluginBase( | ||
"HDF5", | ||
1, | ||
"read", | ||
boost::filesystem::path(__FILE__).parent_path().append("help.txt").string() | ||
) | ||
{ | ||
return setReturnDataString(idam_plugin_interface->data_block, THISPLUGIN_DEFAULT_METHOD, "Plugin default method"); | ||
register_method("read", static_cast<UDAPluginBase::plugin_member_type>(&BytesPlugin::read)); | ||
} | ||
|
||
/** | ||
* Plugin Maximum Interface Version | ||
* @param idam_plugin_interface | ||
* @return | ||
*/ | ||
int do_maxinterfaceversion(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) | ||
int bytesPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface) | ||
{ | ||
return setReturnDataIntScalar(idam_plugin_interface->data_block, THISPLUGIN_MAX_INTERFACE_VERSION, "Maximum Interface Version"); | ||
static BytesPlugin plugin = {}; | ||
return plugin.call(plugin_interface); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------- | ||
// Add functionality here .... | ||
int do_read(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) | ||
int BytesPlugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface) | ||
{ | ||
DATA_SOURCE* data_source = idam_plugin_interface->data_source; | ||
SIGNAL_DESC* signal_desc = idam_plugin_interface->signal_desc; | ||
DATA_BLOCK* data_block = idam_plugin_interface->data_block; | ||
|
||
const char* path; | ||
FIND_REQUIRED_STRING_VALUE(idam_plugin_interface->request_data->nameValueList, path); | ||
std::string path = required_arg<std::string>(plugin_interface, "path"); | ||
|
||
StringCopy(data_source->path, path, MAXPATH); | ||
UDA_LOG(UDA_LOG_DEBUG, "expandEnvironmentvariables! \n"); | ||
expand_environment_variables(data_source->path); | ||
char c_path[MAXPATH]; | ||
StringCopy(c_path, path.c_str(), MAXPATH); | ||
debug("expand_environment_variables!"); | ||
expand_environment_variables(c_path); | ||
|
||
return readBytes(*data_source, *signal_desc, data_block, idam_plugin_interface->environment); | ||
return readBytes(c_path, plugin_interface); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
UDA plugin to read files as a block of bytes without interpretation | ||
|
||
Functions: | ||
|
||
read | ||
Arguments: | ||
path the path of the file to read | ||
Example: | ||
path(read=/path/to/file.txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.