All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>
49 
50 
51 namespace openfluid { namespace ware {
52 
53 
54 /**
55  Hook function name of ware plugin body
56 */
57 #define WAREBODY_PROC_NAME "GetWareBody"
58 #define WAREBODY_PROC_DECL GetWareBody
59 
60 /**
61  Hook function name of ware plugin signature
62 */
63 #define WARESIGNATURE_PROC_NAME "GetWareSignature"
64 #define WARESIGNATURE_PROC_DECL GetWareSignature
65 
66 /**
67  Hook function name of ware ABI version
68 */
69 #define WAREABIVERSION_PROC_NAME "GetWareABIVersion"
70 #define WAREABIVERSION_PROC_DECL GetWareABIVersion
71 
72 
73 /**
74  Hook function name of ware ABI version
75 */
76 #define WARELINKUID_PROC_NAME "GetWareLinkUID"
77 #define WARELINKUID_PROC_DECL GetWareLinkUID
78 
79 
80 // =====================================================================
81 // =====================================================================
82 
83 
84 #define DEFINE_WARE_LINKUID(linkuid) \
85  extern "C" \
86  { \
87  OPENFLUID_PLUGIN std::string WARELINKUID_PROC_DECL() \
88  { \
89  return std::string(linkuid); \
90  } \
91  }
92 
93 // =====================================================================
94 // =====================================================================
95 
96 
98 {
99  public:
100 
101  enum WareType { UNDEFINED, OBSERVER, SIMULATOR, OTHER };
102 
103 
104  private:
105 
106  /**
107  Ware execution environment
108  */
109  const openfluid::base::EnvironmentProperties* mp_WareEnv;
110 
111 
112  /**
113  Ware Type
114  */
115  WareType m_WareType;
116 
117 
118  /**
119  Ware ID
120  */
121  WareID_t m_WareID;
122 
123 
124 
125  protected:
126 
127  virtual bool isLinked() const { return mp_WareEnv != NULL; };
128 
129  bool m_Initialized;
130 
131  /**
132  Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
133  @param[in] Msg the content of the message
134  */
135  virtual void OPENFLUID_RaiseError(const std::string& Msg);
136 
137  /**
138  Gets an environment string value associated to a Key
139  @param[in] Key the sender of the message
140  @param[out] Val the value associated with the environment key
141  */
142  bool OPENFLUID_GetRunEnvironment(const std::string& Key, std::string& Val);
143 
144  /**
145  Gets an environment boolean value associated to a Key
146  @param[in] Key the sender of the message
147  @param[out] Val the value associated with the environment key
148  */
149  bool OPENFLUID_GetRunEnvironment(const std::string& Key, bool& Val);
150 
151  /**
152  Returns the ID of the ware (itself)
153  @return the ID
154  */
156  { return m_WareID; };
157 
158 
159  /**
160  Returns the type of the ware (itself)
161  @return the type
162  */
164  { return m_WareType; };
165 
166 
167  PluggableWare(WareType WType);
168 
169 
170  public:
171 
172  virtual ~PluggableWare();
173 
175  {
176  mp_WareEnv = Env;
177  };
178 
179  virtual void initializeWare(const WareID_t& ID);
180 
181  virtual void finalizeWare();
182 
183  /**
184  * Return false if ParameterKey starts nor ends with a dot, true otherwise
185  */
186  static bool isWellFormated(const openfluid::ware::WareParamKey_t& ParameterKey);
187 
188 };
189 
190 
191 
192 } } // openfluid::ware
193 
194 
195 
196 #endif /* __OPENFLUID_WARE_PLUGGABLEWARE_HPP__ */
WareID_t OPENFLUID_GetWareID() const
Definition: PluggableWare.hpp:155
std::string WareParamKey_t
Definition: TypeDefs.hpp:89
Definition: PluggableWare.hpp:97
WareType OPENFLUID_GetWareType() const
Definition: PluggableWare.hpp:163
Definition: EnvProperties.hpp:53
WareType
Definition: PluggableWare.hpp:101
void linkToRunEnvironment(const openfluid::base::EnvironmentProperties *Env)
Definition: PluggableWare.hpp:174
#define OPENFLUID_API
Definition: dllexport.hpp:87
std::string WareID_t
Definition: TypeDefs.hpp:50