ware/PluggableWare.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 
00033 /**
00034   \file PluggableWare.hpp
00035   \brief Header of ...
00036 
00037   \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00038  */
00039 
00040 
00041 #ifndef __PLUGGABLEWARE_HPP__
00042 #define __PLUGGABLEWARE_HPP__
00043 
00044 #include <boost/filesystem/path.hpp>
00045 #include <boost/property_tree/ptree.hpp>
00046 #include <string>
00047 
00048 #include <openfluid/dllexport.hpp>
00049 #include <openfluid/base/EnvProperties.hpp>
00050 #include <openfluid/ware/WareSignature.hpp>
00051 
00052 
00053 namespace openfluid { namespace ware {
00054 
00055 
00056 /**
00057   Hook function name of ware plugin body
00058 */
00059 #define WAREBODY_PROC_NAME "GetWareBody"
00060 #define WAREBODY_PROC_DECL GetWareBody
00061 
00062 /**
00063   Hook function name of ware plugin signature
00064 */
00065 #define WARESIGNATURE_PROC_NAME "GetWareSignature"
00066 #define WARESIGNATURE_PROC_DECL GetWareSignature
00067 
00068 /**
00069   Hook function name of ware ABI version
00070 */
00071 #define WAREABIVERSION_PROC_NAME "GetWareABIVersion"
00072 #define WAREABIVERSION_PROC_DECL GetWareABIVersion
00073 
00074 
00075 // =====================================================================
00076 // =====================================================================
00077 
00078 
00079 typedef std::string WareParamKey_t;
00080 typedef openfluid::core::StringValue WareParamValue_t;
00081 
00082 typedef std::map<WareParamKey_t, WareParamValue_t> WareParams_t;
00083 
00084 
00085 // =====================================================================
00086 // =====================================================================
00087 
00088 
00089 class DLLEXPORT PluggableWare
00090 {
00091   public:
00092 
00093     enum WareType { UNDEFINED, OBSERVER, SIMULATOR, OTHER };
00094 
00095 
00096   private:
00097 
00098     /**
00099       Ware execution environment
00100     */
00101     const openfluid::base::EnvironmentProperties* mp_WareEnv;
00102 
00103     /**
00104       Simulator ID
00105     */
00106     WareID_t m_WareID;
00107 
00108 
00109   protected:
00110 
00111     virtual bool isLinked() const { return mp_WareEnv != NULL; };
00112 
00113     bool m_Initialized;
00114 
00115     /**
00116       Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
00117       @param[in] Msg the content of the message
00118     */
00119     virtual void OPENFLUID_RaiseError(const std::string& Msg);
00120 
00121     /**
00122       Gets an environment string value associated to a Key
00123       @param[in] Key the sender of the message
00124       @param[out] Val the value associated with the environment key
00125     */
00126     bool OPENFLUID_GetRunEnvironment(std::string Key, std::string& Val);
00127 
00128     /**
00129       Gets an environment boolean value associated to a Key
00130       @param[in] Key the sender of the message
00131       @param[out] Val the value associated with the environment key
00132     */
00133     bool OPENFLUID_GetRunEnvironment(std::string Key, bool& Val);
00134 
00135     /**
00136       Returns the ID of the ware (itself)
00137       @return the ID
00138     */
00139     WareID_t OPENFLUID_GetWareID() const { return m_WareID; };
00140 
00141     WareType m_WareType;
00142 
00143 
00144     PluggableWare(WareType WType);
00145 
00146   public:
00147 
00148     virtual ~PluggableWare();
00149 
00150     void linkToRunEnvironment(const openfluid::base::EnvironmentProperties* Env)
00151     {
00152       mp_WareEnv = Env;
00153     };
00154 
00155     virtual void initializeWare(const WareID_t& ID);
00156 
00157     virtual void finalizeWare();
00158 
00159     /**
00160      * Return false if ParameterKey starts nor ends with a dot, true otherwise
00161      */
00162     static bool isWellFormated(const openfluid::ware::WareParamKey_t& ParameterKey);
00163 
00164     static boost::property_tree::ptree getParamsAsPropertyTree(
00165         const WareParams_t& Params);
00166 
00167 };
00168 
00169 
00170 
00171 } } // openfluid::ware
00172 
00173 
00174 
00175 #endif /* __PLUGGABLEWARE_HPP__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines