Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
PluggableWare.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
5
6
7 == GNU General Public License Usage ==
8
9 OpenFLUID is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OpenFLUID is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21
22
23 == Other Usage ==
24
25 Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26 license, and requires a written agreement between You and INRA.
27 Licensees for Other Usage of OpenFLUID may use this file in accordance
28 with the terms contained in the written agreement between You and INRA.
29
30*/
31
32
33/**
34 @file PluggableWare.hpp
35
36 @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 */
38
39
40#ifndef __OPENFLUID_WARE_PLUGGABLEWARE_HPP__
41#define __OPENFLUID_WARE_PLUGGABLEWARE_HPP__
42
43
44#include <string>
45
48
49
50namespace openfluid { namespace ware {
51
52
53/**
54 Hook function name of ware plugin body
55*/
56#define WAREBODY_PROC_NAME "GetWareBody"
57#define WAREBODY_PROC_DECL GetWareBody
58
59/**
60 Hook function name of ware plugin signature
61*/
62#define WARESIGNATURE_PROC_NAME "GetWareSignature"
63#define WARESIGNATURE_PROC_DECL GetWareSignature
64
65/**
66 Hook function name of ware ABI version
67*/
68#define WAREABIVERSION_PROC_NAME "GetWareABIVersion"
69#define WAREABIVERSION_PROC_DECL GetWareABIVersion
70
71
72/**
73 Hook function name of ware ABI version
74*/
75#define WARELINKUID_PROC_NAME "GetWareLinkUID"
76#define WARELINKUID_PROC_DECL GetWareLinkUID
77
78
79// =====================================================================
80// =====================================================================
81
82
83#define DEFINE_WARE_LINKUID(linkuid) \
84 extern "C" \
85 { \
86 OPENFLUID_PLUGIN const std::string* WARELINKUID_PROC_DECL() \
87 { \
88 return new std::string(linkuid); \
89 } \
90 }
91
92
93// =====================================================================
94// =====================================================================
95
96
98{
99 private:
100
101 /**
102 Ware execution environment
103 */
104 const openfluid::core::MapValue* mp_WareEnv = nullptr;
105
106
107 /**
108 Ware Type
109 */
110 WareType m_WareType = WareType::UNDEFINED;
111
112
113 /**
114 Ware ID
115 */
116 WareID_t m_WareID;
117
118
119 protected:
120
121 bool m_Initialized = false;
122
123 virtual bool isLinked() const
124 {
125 return mp_WareEnv != nullptr;
126 }
127
128 /**
129 Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
130 @param[in] Msg the content of the message
131
132 @cond OpenFLUID:completion
133 {
134 "contexts" : ["SIMULATOR","OBSERVER"],
135 "menupath" : ["Compute code","Messages"],
136 "title" : "Raise fatal error",
137 "text" : "OPENFLUID_RaiseError(%%SEL_START%%\"message\"%%SEL_END%%)"
138 }
139 @endcond
140 */
141 virtual void OPENFLUID_RaiseError(const std::string& Msg);
142
143 /**
144 Gets an environment string value associated to a Key
145 @param[in] Key the requested environment key
146 @param[out] Val the value associated with the environment key
147 */
148 bool OPENFLUID_GetRunEnvironment(const std::string& Key, std::string& Val);
149
150 /**
151 Gets an environment boolean value associated to a Key
152 @param[in] Key the requested environment key
153 @param[out] Val the value associated with the environment key
154
155 @cond OpenFLUID:completion
156 {
157 "contexts" : ["ANYWARE"],
158 "menupath" : ["Run environment"],
159 "title" : "Get information about run environment",
160 "text" : "OPENFLUID_GetRunEnvironment(%%SEL_START%%\"key\"%%SEL_END%%,Value)"
161 }
162 @endcond
163
164 @cond OpenFLUID:completion
165 {
166 "contexts" : ["ANYWARE"],
167 "menupath" : ["Run environment"],
168 "title" : "Get current input dataset directory",
169 "text" : "OPENFLUID_GetRunEnvironment(\"dir.input\",%%SEL_START%%Value%%SEL_END%%)"
170 }
171 @endcond
172
173 @cond OpenFLUID:completion
174 {
175 "contexts" : ["ANYWARE"],
176 "menupath" : ["Run environment"],
177 "title" : "Get current output results directory",
178 "text" : "OPENFLUID_GetRunEnvironment(\"dir.output\",%%SEL_START%%Value%%SEL_END%%)"
179 }
180 @endcond
181
182 @cond OpenFLUID:completion
183 {
184 "contexts" : ["ANYWARE"],
185 "menupath" : ["Run environment"],
186 "title" : "Get current directory for temporary data",
187 "text" : "OPENFLUID_GetRunEnvironment(\"dir.temp\",%%SEL_START%%Value%%SEL_END%%)"
188 }
189 @endcond
190 */
191 bool OPENFLUID_GetRunEnvironment(const std::string& Key, bool& Val);
192
193 /**
194 Returns the ID of the ware (itself)
195 @return the ID
196
197 @cond OpenFLUID:completion
198 {
199 "contexts" : ["ANYWARE"],
200 "menupath" : ["Run environment"],
201 "title" : "Get current ware ID",
202 "text" : "OPENFLUID_GetWareID()"
203 }
204 @endcond
205 */
207 {
208 return m_WareID;
209 }
210
211
212 /**
213 Returns the type of the ware (itself)
214 @return the type
215 */
217 {
218 return m_WareType;
219 }
220
221
223
224
225 public:
226
227 PluggableWare() = default;
228
229 PluggableWare(const PluggableWare&) = delete;
230
232
234
236
237 virtual ~PluggableWare() = default;
238
240 {
241 mp_WareEnv = Env;
242 }
243
244 virtual void initializeWare(const WareID_t& ID);
245
246 virtual void finalizeWare();
247
248 /**
249 * Return false if ParameterKey starts nor ends with a dot, true otherwise
250 */
251 static bool isWellFormatted(const openfluid::ware::WareParamKey_t& ParameterKey);
252
253};
254
255
256} } // namespaces
257
258
259#endif /* __OPENFLUID_WARE_PLUGGABLEWARE_HPP__ */
Definition MapValue.hpp:93
Definition PluggableWare.hpp:98
virtual void OPENFLUID_RaiseError(const std::string &Msg)
PluggableWare & operator=(PluggableWare &&)=default
virtual ~PluggableWare()=default
WareID_t OPENFLUID_GetWareID() const
Definition PluggableWare.hpp:206
static bool isWellFormatted(const openfluid::ware::WareParamKey_t &ParameterKey)
bool OPENFLUID_GetRunEnvironment(const std::string &Key, bool &Val)
virtual void initializeWare(const WareID_t &ID)
virtual bool isLinked() const
Definition PluggableWare.hpp:123
PluggableWare(PluggableWare &&)=default
WareType OPENFLUID_GetWareType() const
Definition PluggableWare.hpp:216
PluggableWare & operator=(const PluggableWare &)=delete
bool OPENFLUID_GetRunEnvironment(const std::string &Key, std::string &Val)
void linkToRunEnvironment(const openfluid::core::MapValue *Env)
Definition PluggableWare.hpp:239
PluggableWare(const PluggableWare &)=delete
#define OPENFLUID_API
Definition dllexport.hpp:86
WareType
Definition TypeDefs.hpp:61
std::string WareID_t
Definition TypeDefs.hpp:49
std::string WareParamKey_t
Definition TypeDefs.hpp:142
Definition ApplicationException.hpp:47