Skip to content

Commit

Permalink
Tidying up and renaming plugin data return functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jholloc committed Feb 2, 2024
1 parent 205a0b4 commit c29e3c6
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 348 deletions.
27 changes: 27 additions & 0 deletions source/clientserver/type_convertor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

template <typename T>
struct TypeConvertor
{
static UdaType type;
};

template <typename T>
UdaType TypeConvertor<T>::type = UdaType::UDA_TYPE_UNKNOWN;

template <> UdaType TypeConvertor<char>::type = UDA_TYPE_CHAR;
template <> UdaType TypeConvertor<short>::type = UDA_TYPE_SHORT;
template <> UdaType TypeConvertor<int>::type = UDA_TYPE_INT;
template <> UdaType TypeConvertor<unsigned int>::type = UDA_TYPE_UNSIGNED_INT;
template <> UdaType TypeConvertor<long>::type = UDA_TYPE_LONG;
template <> UdaType TypeConvertor<float>::type = UDA_TYPE_FLOAT;
template <> UdaType TypeConvertor<double>::type = UDA_TYPE_DOUBLE;
template <> UdaType TypeConvertor<unsigned char>::type = UDA_TYPE_UNSIGNED_CHAR;
template <> UdaType TypeConvertor<unsigned short>::type = UDA_TYPE_UNSIGNED_SHORT;
template <> UdaType TypeConvertor<unsigned long>::type = UDA_TYPE_UNSIGNED_LONG;
template <> UdaType TypeConvertor<long long>::type = UDA_TYPE_LONG64;
template <> UdaType TypeConvertor<unsigned long long>::type = UDA_TYPE_UNSIGNED_LONG64;
template <> UdaType TypeConvertor<float _Complex>::type = UDA_TYPE_COMPLEX;
template <> UdaType TypeConvertor<double _Complex>::type = UDA_TYPE_DCOMPLEX;
template <> UdaType TypeConvertor<void>::type = UDA_TYPE_UNDEFINED;
template <> UdaType TypeConvertor<const char*>::type = UDA_TYPE_STRING;
55 changes: 29 additions & 26 deletions source/include/uda/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,39 @@ LIBRARY_API const char* udaPluginPluginExtension(UDA_PLUGIN_INTERFACE* plugin_in
LIBRARY_API const char* udaPluginPluginDescription(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num);
LIBRARY_API const char* udaPluginPluginExample(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num);

LIBRARY_API int setReturnDataLabel(UDA_PLUGIN_INTERFACE* plugin_interface, const char* label);
LIBRARY_API int setReturnDataUnits(UDA_PLUGIN_INTERFACE* plugin_interface, const char* units);

LIBRARY_API int setReturnDataFloatArray(UDA_PLUGIN_INTERFACE* plugin_interface, float* values, size_t rank, const size_t* shape,
const char* description);
LIBRARY_API int setReturnDataDoubleArray(UDA_PLUGIN_INTERFACE* plugin_interface, double* values, size_t rank, const size_t* shape,
const char* description);
LIBRARY_API int setReturnDataCharArray(UDA_PLUGIN_INTERFACE* plugin_interface, const char* values, size_t rank, int *shape,
const char* description);
LIBRARY_API int setReturnDataIntArray(UDA_PLUGIN_INTERFACE* plugin_interface, int* values, size_t rank, const size_t* shape,
const char* description);
LIBRARY_API int setReturnDataDoubleScalar(UDA_PLUGIN_INTERFACE* plugin_interface, double value, const char* description);
LIBRARY_API int setReturnDataFloatScalar(UDA_PLUGIN_INTERFACE* plugin_interface, float value, const char* description);
LIBRARY_API int setReturnDataIntScalar(UDA_PLUGIN_INTERFACE* plugin_interface, int value, const char* description);
LIBRARY_API int setReturnDataLongScalar(UDA_PLUGIN_INTERFACE* plugin_interface, long value, const char* description);
LIBRARY_API int setReturnDataShortScalar(UDA_PLUGIN_INTERFACE* plugin_interface, short value, const char* description);
LIBRARY_API int setReturnDataString(UDA_PLUGIN_INTERFACE* plugin_interface, const char* value, const char* description);

LIBRARY_API int setReturnData(UDA_PLUGIN_INTERFACE* plugin_interface, void* value, size_t size, UDA_TYPE type, int rank,
LIBRARY_API int udaPluginReturnDataLabel(UDA_PLUGIN_INTERFACE* plugin_interface, const char* label);
LIBRARY_API int udaPluginReturnDataUnits(UDA_PLUGIN_INTERFACE* plugin_interface, const char* units);

#define UDA_DEF_SET_RETURN_FUNCS(NAME, TYPE) \
LIBRARY_API int udaPluginReturnData##NAME##Scalar(UDA_PLUGIN_INTERFACE* plugin_interface, const TYPE value, const char* description); \
LIBRARY_API int udaPluginReturnData##NAME##Array(UDA_PLUGIN_INTERFACE* plugin_interface, const TYPE* values, size_t rank, const size_t* shape, const char* description);

UDA_DEF_SET_RETURN_FUNCS(Float, float)
UDA_DEF_SET_RETURN_FUNCS(Double, double)
UDA_DEF_SET_RETURN_FUNCS(Char, char)
UDA_DEF_SET_RETURN_FUNCS(UChar, unsigned char)
UDA_DEF_SET_RETURN_FUNCS(Short, short)
UDA_DEF_SET_RETURN_FUNCS(UShort, unsigned short)
UDA_DEF_SET_RETURN_FUNCS(Int, int)
UDA_DEF_SET_RETURN_FUNCS(UInt, unsigned int)
UDA_DEF_SET_RETURN_FUNCS(Long, long)
UDA_DEF_SET_RETURN_FUNCS(ULong, unsigned long)
UDA_DEF_SET_RETURN_FUNCS(String, char*)

#undef UDA_DEF_SET_RETURN_FUNCS

LIBRARY_API int udaPluginReturnData(UDA_PLUGIN_INTERFACE* plugin_interface, void* value, size_t size, UDA_TYPE type, int rank,
const int* shape, const char* description);

LIBRARY_API int setReturnDimensionFloatArray(UDA_PLUGIN_INTERFACE* plugin_interface, int dim_n, float* data, size_t size, const char* label, const char* units);
LIBRARY_API int udaPluginReturnDimensionFloatArray(UDA_PLUGIN_INTERFACE* plugin_interface, int dim_n, float* data, size_t size, const char* label, const char* units);

LIBRARY_API int setReturnErrorAsymmetry(UDA_PLUGIN_INTERFACE* plugin_interface, bool flag);
LIBRARY_API int setReturnErrorLow(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size);
LIBRARY_API int setReturnErrorHigh(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size);
LIBRARY_API int setReturnDataOrder(UDA_PLUGIN_INTERFACE* plugin_interface, int order);
LIBRARY_API int udaPluginReturnErrorAsymmetry(UDA_PLUGIN_INTERFACE* plugin_interface, bool flag);
LIBRARY_API int udaPluginReturnErrorLow(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size);
LIBRARY_API int udaPluginReturnErrorHigh(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size);
LIBRARY_API int udaPluginReturnDataOrder(UDA_PLUGIN_INTERFACE* plugin_interface, int order);

LIBRARY_API int setReturnCompoundData(UDA_PLUGIN_INTERFACE* plugin_interface, char* data, const char* user_type, const char* description);
LIBRARY_API int setReturnCompoundArrayData(UDA_PLUGIN_INTERFACE *plugin_interface, char* data, const char *user_type, const char* description, int rank, int* shape);
LIBRARY_API int udaPluginReturnCompoundData(UDA_PLUGIN_INTERFACE* plugin_interface, char* data, const char* user_type, const char* description);
LIBRARY_API int udaPluginReturnCompoundArrayData(UDA_PLUGIN_INTERFACE *plugin_interface, char* data, const char *user_type, const char* description, int rank, int* shape);

LIBRARY_API int udaPluginArgumentCount(const UDA_PLUGIN_INTERFACE* plugin_interface);
LIBRARY_API const char* udaPluginArgument(const UDA_PLUGIN_INTERFACE* plugin_interface, int num);
Expand Down
2 changes: 1 addition & 1 deletion source/plugins/bytes/readBytesNonOptimally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int readBytes(const std::string& path, UDA_PLUGIN_INTERFACE* plugin_interface)
auto read_hash = get_hash_sum(ctx);

int shape[] = { (int)nchar };
setReturnData(plugin_interface, bp, nchar, UDA_TYPE_CHAR, 1, shape, read_hash.c_str());
udaPluginReturnData(plugin_interface, bp, nchar, UDA_TYPE_CHAR, 1, shape, read_hash.c_str());

// TODO: read sha256 sum command from config and try and run
// std::string cmd = "sha3sum -a 256 -b " + path;
Expand Down
4 changes: 2 additions & 2 deletions source/plugins/help/help_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int HelpPlugin::ping(UDA_PLUGIN_INTERFACE* plugin_interface)
data->microseconds = (unsigned int)serverTime.tv_usec;

// return to the client
setReturnCompoundData(plugin_interface, (char*)data, "HELP_PING", nullptr);
udaPluginReturnCompoundData(plugin_interface, (char*)data, "HELP_PING", nullptr);

return 0;
}
Expand Down Expand Up @@ -152,5 +152,5 @@ int HelpPlugin::services(UDA_PLUGIN_INTERFACE* plugin_interface)

doc += "\n\n";

return setReturnDataString(plugin_interface, doc.c_str(), "Description of UDA data access services");
return udaPluginReturnDataStringScalar(plugin_interface, doc.c_str(), "Description of UDA data access services");
}
2 changes: 1 addition & 1 deletion source/plugins/keyvalue/keyvaluePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int uda::keyvalue::Plugin::read(UDA_PLUGIN_INTERFACE* plugin_interface)
}

int shape[] = { (int)value_len };
setReturnData(plugin_interface, value, value_len, UDA_TYPE_CHAR, 1, shape, nullptr);
udaPluginReturnData(plugin_interface, value, value_len, UDA_TYPE_CHAR, 1, shape, nullptr);

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions source/plugins/template/templatePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ int TemplatePlugin::function(UDA_PLUGIN_INTERFACE* plugin_interface)
std::string result =
fmt::format("Passed args: required={}, array=[{}], optional={}", required, to_string(array), optional_str);

setReturnDataString(plugin_interface, result.c_str(), "result of TemplatePlugin::function");
setReturnDataLabel(plugin_interface, "");
setReturnDataUnits(plugin_interface, "");
udaPluginReturnDataStringScalar(plugin_interface, result.c_str(), "result of TemplatePlugin::function");
udaPluginReturnDataLabel(plugin_interface, "");
udaPluginReturnDataUnits(plugin_interface, "");

return 0;
}
Loading

0 comments on commit c29e3c6

Please sign in to comment.