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 
00061 /**
00062   Hook function name of ware plugin signature
00063 */
00064 #define WARESIGNATURE_PROC_NAME "GetWareSignature"
00065 
00066 /**
00067   Hook function name of ware ABI version
00068 */
00069 #define WAREABIVERSION_PROC_NAME "GetWareABIVersion"
00070 
00071 // =====================================================================
00072 // =====================================================================
00073 
00074 typedef std::string WareParamKey_t;
00075 typedef openfluid::core::StringValue WareParamValue_t;
00076 
00077 typedef std::map<WareParamKey_t, WareParamValue_t> WareParams_t;
00078 
00079 
00080 // =====================================================================
00081 // =====================================================================
00082 
00083 
00084 class DLLEXPORT PluggableWare
00085 {
00086   public:
00087 
00088     enum WareType { UNDEFINED, OBSERVER, SIMULATOR, OTHER };
00089 
00090 
00091   private:
00092 
00093     /**
00094       Ware execution environment
00095     */
00096     const openfluid::base::EnvironmentProperties* mp_WareEnv;
00097 
00098     /**
00099       Simulator ID
00100     */
00101     WareID_t m_WareID;
00102 
00103 
00104   protected:
00105 
00106     virtual bool isLinked() const { return mp_WareEnv != NULL; };
00107 
00108     bool m_Initialized;
00109 
00110     /**
00111       Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
00112       @param[in] Msg the content of the message
00113     */
00114     virtual void OPENFLUID_RaiseError(const std::string& Msg);
00115 
00116     /**
00117       Gets an environment string value associated to a Key
00118       @param[in] Key the sender of the message
00119       @param[out] Val the value associated with the environment key
00120     */
00121     bool OPENFLUID_GetRunEnvironment(std::string Key, std::string& Val);
00122 
00123     /**
00124       Gets an environment boolean value associated to a Key
00125       @param[in] Key the sender of the message
00126       @param[out] Val the value associated with the environment key
00127     */
00128     bool OPENFLUID_GetRunEnvironment(std::string Key, bool& Val);
00129 
00130     /**
00131       Returns the ID of the ware (itself)
00132       @return the ID
00133     */
00134     WareID_t OPENFLUID_GetWareID() const { return m_WareID; };
00135 
00136     WareType m_WareType;
00137 
00138 
00139     PluggableWare(WareType WType);
00140 
00141   public:
00142 
00143     virtual ~PluggableWare();
00144 
00145     void linkToRunEnvironment(const openfluid::base::EnvironmentProperties* Env)
00146     {
00147       mp_WareEnv = Env;
00148     };
00149 
00150     virtual void initializeWare(const WareID_t& ID);
00151 
00152     virtual void finalizeWare();
00153 
00154     /**
00155      * Return false if ParameterKey starts nor ends with a dot, true otherwise
00156      */
00157     static bool isWellFormated(const openfluid::ware::WareParamKey_t& ParameterKey);
00158 
00159     static boost::property_tree::ptree getParamsAsPropertyTree(
00160         const WareParams_t& Params);
00161 
00162 };
00163 
00164 
00165 
00166 } } // openfluid::ware
00167 
00168 
00169 
00170 #endif /* __PLUGGABLEWARE_HPP__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines