Skip to content

Commit

Permalink
Adding empty MDS+ plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jholloc committed Dec 5, 2023
1 parent 09e479e commit e44bf7f
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmake/Modules/FindMDSplus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,13 @@ include( FindPackageHandleStandardArgs )
find_package_handle_standard_args( MDSplus DEFAULT_MSG MDSPLUS_LIBRARIES MDSPLUS_INCLUDES )

mark_as_advanced( MDSPLUS_LIBRARIES MDSPLUS_INCLUDES )

# Create imported targets MDSPLUS::MDSPLUS
if( NOT TARGET MDSPLUS::MDSPLUS )
add_library( MDSPLUS::MDSPLUS SHARED IMPORTED )

set_target_properties( MDSPLUS::MDSPLUS PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MDSPLUS_INCLUDES}"
INTERFACE_LINK_LIBRARIES "${MDSPLUS_LIBRARIES}"
)
endif()
1 change: 1 addition & 0 deletions source/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ else()
add_subdirectory( hdf5 )
add_subdirectory( help )
add_subdirectory( keyvalue )
add_subdirectory( mdsplus )
add_subdirectory( template )
add_subdirectory( testplugin )
add_subdirectory( uda )
Expand Down
27 changes: 27 additions & 0 deletions source/plugins/mdsplus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
########################################################################################################################
# Dependencies

find_package( LibXml2 QUIET )
find_package( MDSplus QUIET )

if( NOT LIBXML2_FOUND )
message( WARNING "Libxml2 not found - skipping MDSplus plugin" )
return()
elseif( NOT MDSPLUS_FOUND )
message( WARNING "MDSplus not found - skipping MDSplus plugin" )
return()
endif()

include( plugins )

uda_plugin(
NAME MDSPLUS
ENTRY_FUNC mdsplusPlugin
DESCRIPTION "MDSplus reader"
EXAMPLE "MDSPLUS::read()"
LIBNAME mdsplus_plugin
SOURCES mdsplusPlugin.cpp
EXTRA_LINK_LIBS
LibXml2::LibXml2
MDSPLUS::MDSPLUS
)
167 changes: 167 additions & 0 deletions source/plugins/mdsplus/mdsplusPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include "mdsplusPlugin.h"

#include <clientserver/stringUtils.h>
#include <clientserver/initStructs.h>

class MDSplusPlugin
{
public:
void init(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
REQUEST_DATA* request = plugin_interface->request_data;
if (!init_
|| STR_IEQUALS(request->function, "init")
|| STR_IEQUALS(request->function, "initialise")) {
reset(plugin_interface);
// Initialise plugin
init_ = true;
}
}
void reset(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
if (!init_) {
// Not previously initialised: Nothing to do!
return;
}
// Free Heap & reset counters
init_ = false;
}

int help(IDAM_PLUGIN_INTERFACE* plugin_interface);
int version(IDAM_PLUGIN_INTERFACE* plugin_interface);
int build_date(IDAM_PLUGIN_INTERFACE* plugin_interface);
int default_method(IDAM_PLUGIN_INTERFACE* plugin_interface);
int max_interface_version(IDAM_PLUGIN_INTERFACE* plugin_interface);
int read(IDAM_PLUGIN_INTERFACE* plugin_interface);

private:
bool init_ = false;
};

/**
* Entry function
*/
int mdsplusPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
static MDSplusPlugin plugin = {};

if (plugin_interface->interfaceVersion > THISPLUGIN_MAX_INTERFACE_VERSION) {
RAISE_PLUGIN_ERROR("Plugin Interface Version Unknown to this plugin: Unable to execute the request!");
}

plugin_interface->pluginVersion = THISPLUGIN_VERSION;

REQUEST_DATA* request = plugin_interface->request_data;

if (plugin_interface->housekeeping || STR_IEQUALS(request->function, "reset")) {
plugin.reset(plugin_interface);
return 0;
}

//----------------------------------------------------------------------------------------
// Initialise
plugin.init(plugin_interface);
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 plugin.help(plugin_interface);
} else if (STR_IEQUALS(request->function, "version")) {
return plugin.version(plugin_interface);
} else if (STR_IEQUALS(request->function, "builddate")) {
return plugin.build_date(plugin_interface);
} else if (STR_IEQUALS(request->function, "defaultmethod")) {
return plugin.default_method(plugin_interface);
} else if (STR_IEQUALS(request->function, "maxinterfaceversion")) {
return plugin.max_interface_version(plugin_interface);
} else if (STR_IEQUALS(request->function, "read")) {
return plugin.read(plugin_interface);
} else {
RAISE_PLUGIN_ERROR("Unknown function requested!");
}
}

/**
* Help: A Description of library functionality
* @param plugin_interface
* @return
*/
int MDSplusPlugin::help(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
const char* help = "\ntemplatePlugin: Add Functions Names, Syntax, and Descriptions\n\n";
const char* desc = "templatePlugin: help = description of this plugin";

return setReturnDataString(plugin_interface->data_block, help, desc);
}

/**
* Plugin version
* @param plugin_interface
* @return
*/
int MDSplusPlugin::version(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
return setReturnDataIntScalar(plugin_interface->data_block, THISPLUGIN_VERSION, "Plugin version number");
}

/**
* Plugin Build Date
* @param plugin_interface
* @return
*/
int MDSplusPlugin::build_date(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
return setReturnDataString(plugin_interface->data_block, __DATE__, "Plugin build date");
}

/**
* Plugin Default Method
* @param plugin_interface
* @return
*/
int MDSplusPlugin::default_method(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
return setReturnDataString(plugin_interface->data_block, THISPLUGIN_DEFAULT_METHOD, "Plugin default method");
}

/**
* Plugin Maximum Interface Version
* @param plugin_interface
* @return
*/
int MDSplusPlugin::max_interface_version(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
return setReturnDataIntScalar(plugin_interface->data_block, THISPLUGIN_MAX_INTERFACE_VERSION, "Maximum Interface Version");
}

//----------------------------------------------------------------------------------------
// Add functionality here ....
int MDSplusPlugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface)
{
DATA_BLOCK* data_block = plugin_interface->data_block;

NameValueList& nvl = plugin_interface->request_data->nameValueList;

// Read arguments

const char* signal = nullptr;
FIND_REQUIRED_STRING_VALUE(nvl, signal);

// Read data from MDS+
// ...

// Return data via data_block

setReturnDataString(data_block, "result", "result of MDSplusPlugin::read");

return 0;
}
23 changes: 23 additions & 0 deletions source/plugins/mdsplus/mdsplusPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#ifndef UDA_PLUGIN_MDSPLUSPLUGIN_H
#define UDA_PLUGIN_MDSPLUSPLUGIN_H

#include <plugins/udaPlugin.h>
#include <clientserver/export.h>

#ifdef __cplusplus
extern "C" {
#endif

#define THISPLUGIN_VERSION 1
#define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood!
#define THISPLUGIN_DEFAULT_METHOD "help"

LIBRARY_API int mdsplusPlugin(IDAM_PLUGIN_INTERFACE * plugin_interface);

#ifdef __cplusplus
}
#endif

#endif // UDA_PLUGIN_MDSPLUSPLUGIN_H

0 comments on commit e44bf7f

Please sign in to comment.