PluggableWare.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
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 
46 #include <openfluid/dllexport.hpp>
48 
49 
50 namespace 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 std::string WARELINKUID_PROC_DECL() \
87  { \
88  return 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;
105 
106 
107  /**
108  Ware Type
109  */
110  WareType m_WareType;
111 
112 
113  /**
114  Ware ID
115  */
116  WareID_t m_WareID;
117 
118 
119  protected:
120 
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" : ["Compute code", "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" : ["Compute code", "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" : ["Compute code", "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" : ["Compute code", "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" : ["Compute code", "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 
222  PluggableWare(WareType WType);
223 
224 
225  public:
226 
227  virtual ~PluggableWare();
228 
230  {
231  mp_WareEnv = Env;
232  }
233 
234  virtual void initializeWare(const WareID_t& ID);
235 
236  virtual void finalizeWare();
237 
238  /**
239  * Return false if ParameterKey starts nor ends with a dot, true otherwise
240  */
241  static bool isWellFormatted(const openfluid::ware::WareParamKey_t& ParameterKey);
242 
243 };
244 
245 
246 } } // namespaces
247 
248 
249 #endif /* __OPENFLUID_WARE_PLUGGABLEWARE_HPP__ */
std::string WareID_t
Definition: TypeDefs.hpp:49
std::string WareParamKey_t
Definition: TypeDefs.hpp:124
virtual bool isLinked() const
Definition: PluggableWare.hpp:123
void linkToRunEnvironment(const openfluid::core::MapValue *Env)
Definition: PluggableWare.hpp:229
WareType
Definition: TypeDefs.hpp:60
Definition: MapValue.hpp:92
Definition: ApplicationException.hpp:47
WareID_t OPENFLUID_GetWareID() const
Definition: PluggableWare.hpp:206
Definition: PluggableWare.hpp:97
WareType OPENFLUID_GetWareType() const
Definition: PluggableWare.hpp:216
bool m_Initialized
Definition: PluggableWare.hpp:121
#define OPENFLUID_API
Definition: dllexport.hpp:86