Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* PluginEngine.h Support for an engine implemented outside libadios2
*
* Created on: July 17, 2017
* Author: Chuck Atkins <chuck.atkins@kitware.com>
*/
#ifndef ADIOS2_ENGINE_PLUGIN_PLUGINENGINE_H_
#define ADIOS2_ENGINE_PLUGIN_PLUGINENGINE_H_
#include "PluginEngineInterface.h"
#include <functional> // for function
#include <memory> // for unique_ptr
#include <string> // for string
#include <type_traits> // for add_pointer
#include <vector> // for vector
#include "adios2/ADIOSMPICommOnly.h"
#include "adios2/ADIOSMacros.h"
#include "adios2/ADIOSTypes.h"
#include "adios2/core/Engine.h"
#include "adios2/core/IO.h"
#include "adios2/core/Variable.h"
#include "adios2/core/VariableCompound.h"
namespace adios2
{
/** A front-end wrapper for an engine implemented outside of libadios2 */
class PluginEngine : public Engine
{
public:
// Function pointers used for the plugin factory methods
using EngineCreatePtr = std::add_pointer<PluginEngineInterface *(
IO &, const std::string &, const OpenMode, MPI_Comm)>::type;
using EngineDestroyPtr =
std::add_pointer<void(PluginEngineInterface *)>::type;
using EngineCreateFun =
std::function<std::remove_pointer<EngineCreatePtr>::type>;
using EngineDestroyFun =
std::function<std::remove_pointer<EngineDestroyPtr>::type>;
static void RegisterPlugin(const std::string pluginName,
EngineCreateFun create,
EngineDestroyFun destroy);
static void RegisterPlugin(const std::string pluginName,
EngineCreatePtr create, EngineDestroyPtr destroy)
{
RegisterPlugin(pluginName, EngineCreateFun(create),
EngineDestroyFun(destroy));
}
// This is just a shortcut method to handle the case where the class type is
// directly available to the caller so a sim[ple new and delete call is
// sufficient to create and destroy the engine object
template <typename T>
static void RegisterPlugin(const std::string name);
public:
PluginEngine(IO &io, const std::string &name, const OpenMode openMode,
MPI_Comm mpiComm);
virtual ~PluginEngine();
void PerformReads(ReadMode mode) override;
void Release() override;
void Advance(const float timeoutSeconds = 0.0) override;
void Advance(const AdvanceMode mode,
const float timeoutSeconds = 0.0) override;
void AdvanceAsync(const AdvanceMode mode,
AdvanceAsyncCallback callback) override;
void SetCallBack(std::function<void(const void *, std::string, std::string,
std::string, std::vector<size_t>)>
callback) override;
void Close(const int transportIndex = -1) override;
protected:
void Init() override;
#define declare(T) \
void DoWrite(Variable<T> &variable, const T *values) override; \
void DoScheduleRead(Variable<T> &variable, const T *values) override; \
void DoScheduleRead(const std::string &variableName, const T *values) \
override;
ADIOS2_FOREACH_TYPE_1ARG(declare)
#undef declare
void DoWrite(VariableCompound &variable, const void *values) override;
#define declare(T, L) \
Variable<T> *InquireVariable##L(const std::string &name, \
const bool readIn) override;
ADIOS2_FOREACH_TYPE_2ARGS(declare)
#undef declare
VariableBase *InquireVariableUnknown(const std::string &name,
const bool readIn) override;
private:
struct Impl;
std::unique_ptr<Impl> m_Impl;
};
} // end namespace adios
#include "PluginEngine.inl"
#endif /* ADIOS2_ENGINE_PLUGIN_PLUGINENGINE_H_ */