Skip to content

Commit

Permalink
Updating C++ plugin helper methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
jholloc committed Dec 5, 2023
1 parent 9764c4b commit bed6a41
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 286 deletions.
1 change: 1 addition & 0 deletions cmake/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ macro( uda_plugin )

include_directories(
${CMAKE_SOURCE_DIR}/source
${CMAKE_SOURCE_DIR}/source/include
)

if( NOT APPLE AND NOT WIN32 AND NOT MINGW AND CMAKE_COMPILER_IS_GNUCC )
Expand Down
6 changes: 5 additions & 1 deletion source/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ add_definitions( -DSERVERBUILD )

include_directories(
${CMAKE_SOURCE_DIR}/source
${CMAKE_SOURCE_DIR}/source/include
${LIBXML2_INCLUDE_DIR}
)

Expand Down Expand Up @@ -147,4 +148,7 @@ install( FILES ${HEADER_FILES}
DESTINATION include/uda/plugins
)


file( GLOB GSL_HEADERS "${CMAKE_SOURCE_DIR}/source/include/gsl/*" )
install( FILES ${GSL_HEADERS}
DESTINATION include/uda/gsl
)
12 changes: 6 additions & 6 deletions source/plugins/bytes/bytesPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class BytesPlugin : public UDAPluginBase {

BytesPlugin::BytesPlugin()
: UDAPluginBase(
"HDF5",
1,
"read",
boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()
)
"BYTES",
1,
"read",
boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()
)
{
register_method("read", static_cast<UDAPluginBase::plugin_member_type>(&BytesPlugin::read));
}
Expand All @@ -37,7 +37,7 @@ int bytesPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface)
// Add functionality here ....
int BytesPlugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
std::string path = required_arg<std::string>(plugin_interface, "path");
auto path = find_required_arg<std::string>(plugin_interface, "path");

char c_path[MAXPATH];
StringCopy(c_path, path.c_str(), MAXPATH);
Expand Down
4 changes: 2 additions & 2 deletions source/plugins/bytes/help.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
UDA plugin to read files as a block of bytes without interpretation
BYTES: Plugin to read files as a block of bytes without interpretation

Functions:

read
read(path=)
Arguments:
path the path of the file to read
Example:
Expand Down
12 changes: 4 additions & 8 deletions source/plugins/hdf5/hdf5plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,13 @@ int HDF5Plugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
DATA_SOURCE* data_source = plugin_interface->data_source;
SIGNAL_DESC* signal_desc = plugin_interface->signal_desc;
REQUEST_DATA* request = plugin_interface->request_data;
DATA_BLOCK* data_block = plugin_interface->data_block;

const char* file_path = nullptr;
FIND_REQUIRED_STRING_VALUE(request->nameValueList, file_path);
auto file_path = find_required_arg<std::string>(plugin_interface, "file_path");
auto cdf_path = find_required_arg<std::string>(plugin_interface, "cdf_path");

const char* cdf_path = nullptr;
FIND_REQUIRED_STRING_VALUE(request->nameValueList, cdf_path);

strcpy(data_source->path, file_path);
strcpy(signal_desc->signal_name, cdf_path);
strcpy(data_source->path, file_path.c_str());
strcpy(signal_desc->signal_name, cdf_path.c_str());

// Legacy data reader!
int err = readHDF5(*data_source, *signal_desc, data_block);
Expand Down
7 changes: 7 additions & 0 deletions source/plugins/help/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HELP: Plugin to provide server help and available services

Functions:

services() Returns a list of available services with descriptions
ping() Return the Local Server Time in seconds and microseonds
servertime() Return the Local Server Time in seconds and microseonds
116 changes: 27 additions & 89 deletions source/plugins/help/help_plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,103 +1,41 @@
#include "help_plugin.h"

#include <cstdlib>

#ifdef __GNUC__

# include <strings.h>

#else
# include <winsock2.h>
#endif
#include <plugins/uda_plugin_base.hpp>
#include <boost/filesystem.hpp>

#include <clientserver/initStructs.h>
#include <structures/struct.h>
#include <structures/accessors.h>
#include <clientserver/errorLog.h>
#include <logging/logging.h>
#include <plugins/udaPlugin.h>
#include <clientserver/stringUtils.h>
#include <fmt/format.h>

static int do_ping(IDAM_PLUGIN_INTERFACE* idam_plugin_interface);

static int do_services(IDAM_PLUGIN_INTERFACE* idam_plugin_interface);

int helpPlugin(IDAM_PLUGIN_INTERFACE* idam_plugin_interface)
class HelpPlugin : public UDAPluginBase {
public:
HelpPlugin();
int ping(IDAM_PLUGIN_INTERFACE* plugin_interface);
int services(IDAM_PLUGIN_INTERFACE* plugin_interface);
int init(IDAM_PLUGIN_INTERFACE* plugin_interface) override { return 0; }
int reset() override { return 0; }
};

HelpPlugin::HelpPlugin()
: UDAPluginBase(
"HELP",
1,
"read",
boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()
)
{
int err;
static short init = 0;

//----------------------------------------------------------------------------------------
// Standard v1 Plugin Interface

DATA_BLOCK* data_block;
REQUEST_DATA* request;

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;

data_block = idam_plugin_interface->data_block;
request = idam_plugin_interface->request_data;

unsigned short housekeeping = idam_plugin_interface->housekeeping;

//----------------------------------------------------------------------------------------
// 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

if (housekeeping || STR_IEQUALS(request->function, "reset")) {

if (!init) { return 0; } // Not previously initialised: Nothing to do!
init = 0;
return 0;
}

//----------------------------------------------------------------------------------------
// Initialise

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;
}
}

if (STR_IEQUALS(request->function, "help") || request->function[0] == '\0') {
const char* help = "\nHelp\tList of HELP plugin functions:\n\n"
"services()\tReturns a list of available services with descriptions\n"
"ping()\t\tReturn the Local Server Time in seconds and microseonds\n"
"servertime()\tReturn the Local Server Time in seconds and microseonds\n\n";
return setReturnDataString(data_block, help, "Help help = description of this plugin");
} else if (STR_IEQUALS(request->function, "version")) {
return setReturnDataIntScalar(data_block, THISPLUGIN_VERSION, "Plugin version number");
} else if (STR_IEQUALS(request->function, "builddate")) {
return setReturnDataString(data_block, __DATE__, "Plugin build date");
} else if (STR_IEQUALS(request->function, "defaultmethod")) {
return setReturnDataString(data_block, THISPLUGIN_DEFAULT_METHOD, "Plugin default method");
} else if (STR_IEQUALS(request->function, "maxinterfaceversion")) {
return setReturnDataIntScalar(data_block, THISPLUGIN_MAX_INTERFACE_VERSION, "Maximum Interface Version");
} else if (STR_IEQUALS(request->function, "ping") || STR_IEQUALS(request->function, "servertime")) {
return do_ping(idam_plugin_interface);
} else if (STR_IEQUALS(request->function, "services")) {
return do_services(idam_plugin_interface);
} else {
RAISE_PLUGIN_ERROR("Unknown function requested!");
}
register_method("ping", static_cast<UDAPluginBase::plugin_member_type>(&HelpPlugin::ping));
register_method("services", static_cast<UDAPluginBase::plugin_member_type>(&HelpPlugin::services));
}

return err;
int helpPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
static HelpPlugin plugin = {};
return plugin.call(plugin_interface);
}

static int do_ping(IDAM_PLUGIN_INTERFACE* idam_plugin_interface)
int HelpPlugin::ping(IDAM_PLUGIN_INTERFACE* idam_plugin_interface)
{
//----------------------------------------------------------------------------------------

Expand Down Expand Up @@ -166,7 +104,7 @@ static int do_ping(IDAM_PLUGIN_INTERFACE* idam_plugin_interface)
return 0;
}

static int do_services(IDAM_PLUGIN_INTERFACE* idam_plugin_interface)
int HelpPlugin::services(IDAM_PLUGIN_INTERFACE* idam_plugin_interface)
{
//======================================================================================
// Plugin functionality
Expand Down
Loading

0 comments on commit bed6a41

Please sign in to comment.