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