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 
120  protected:
121 
123 
124  virtual bool isLinked() const
125  { return mp_WareEnv != nullptr; };
126 
127  /**
128  Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
129  @param[in] Msg the content of the message
130  */
131  virtual void OPENFLUID_RaiseError(const std::string& Msg);
132 
133  /**
134  Gets an environment string value associated to a Key
135  @param[in] Key the requested environment key
136  @param[out] Val the value associated with the environment key
137  */
138  bool OPENFLUID_GetRunEnvironment(const std::string& Key, std::string& Val);
139 
140  /**
141  Gets an environment boolean value associated to a Key
142  @param[in] Key the requested environment key
143  @param[out] Val the value associated with the environment key
144  */
145  bool OPENFLUID_GetRunEnvironment(const std::string& Key, bool& Val);
146 
147  /**
148  Returns the ID of the ware (itself)
149  @return the ID
150  */
152  { return m_WareID; };
153 
154 
155  /**
156  Returns the type of the ware (itself)
157  @return the type
158  */
160  { return m_WareType; };
161 
162 
163  PluggableWare(WareType WType);
164 
165 
166  public:
167 
168  virtual ~PluggableWare();
169 
171  {
172  mp_WareEnv = Env;
173  };
174 
175  virtual void initializeWare(const WareID_t& ID);
176 
177  virtual void finalizeWare();
178 
179  /**
180  * Return false if ParameterKey starts nor ends with a dot, true otherwise
181  */
182  static bool isWellFormated(const openfluid::ware::WareParamKey_t& ParameterKey);
183 
184 };
185 
186 
187 } } // namespaces
188 
189 
190 #endif /* __OPENFLUID_WARE_PLUGGABLEWARE_HPP__ */
void linkToRunEnvironment(const openfluid::core::MapValue *Env)
Definition: PluggableWare.hpp:170
std::string WareID_t
Definition: TypeDefs.hpp:50
Definition: MapValue.hpp:134
Definition: PluggableWare.hpp:97
#define OPENFLUID_API
Definition: dllexport.hpp:87
Definition: ApplicationException.hpp:47
bool m_Initialized
Definition: PluggableWare.hpp:122
WareType OPENFLUID_GetWareType() const
Definition: PluggableWare.hpp:159
std::string WareParamKey_t
Definition: TypeDefs.hpp:126
virtual bool isLinked() const
Definition: PluggableWare.hpp:124
WareID_t OPENFLUID_GetWareID() const
Definition: PluggableWare.hpp:151
WareType
Definition: TypeDefs.hpp:62