market/MarketClient.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
00035 
00036   @author JC.Fabre <fabrejc@supagro.inra.fr>
00037 */
00038 
00039 
00040 
00041 
00042 #ifndef __MARKETCLIENT_HPP__
00043 #define __MARKETCLIENT_HPP__
00044 
00045 #include <string>
00046 #include <queue>
00047 
00048 #include <openfluid/dllexport.hpp>
00049 #include <openfluid/market/MarketInfos.hpp>
00050 #include <openfluid/market/MarketSrcPackage.hpp>
00051 #include <openfluid/market/MarketBinPackage.hpp>
00052 
00053 namespace openfluid { namespace market {
00054 
00055 
00056 typedef std::map<std::string,std::string> MarketLicensesTexts_t;
00057 // List of catalog urls
00058 typedef std::map<PackageInfo::PackageType,std::string> CatalogsFileURL_t;
00059 // List of catalog data
00060 typedef std::map<PackageInfo::PackageType,std::string> CatalogsData_t;
00061 // List of MetaPackagesCatalogs
00062 typedef std::map<PackageInfo::PackageType,MetaPackagesCatalog_t> TypesMetaPackagesCatalogs_t;
00063 
00064 // =====================================================================
00065 // =====================================================================
00066 
00067 
00068 class DLLEXPORT MarketClient
00069 {
00070   public:
00071 
00072     static const std::string LOCK_FILE;
00073 
00074   private:
00075 
00076     MarketInfo m_MarketInfo;
00077     TypesMetaPackagesCatalogs_t m_TypesMetaPackagesCatalogs;
00078     std::string m_TempDir;
00079 
00080     std::string m_URL;
00081 
00082     MarketLicensesTexts_t m_LicensesTexts;
00083 
00084     bool m_IsConnected;
00085 
00086     bool m_IsLogEnabled;
00087 
00088     std::list<MarketPackage*> m_PacksToInstall;
00089 
00090     void initMarketBag();
00091 
00092     void initMarketTemp();
00093 
00094     void lockMarketTemp();
00095 
00096     void unlockMarketTemp();
00097 
00098     void parseMarketSiteData(const std::string& SiteFile);
00099 
00100     /**
00101      Store all type catalog data in MetaPackageCatalog
00102      @param CatalogType Type of catalog read
00103      @param CatalogData string with data read
00104     */
00105     void parseCatalogData(const PackageInfo::PackageType& CatalogType, const std::string& CatalogFile);
00106 
00107     void downloadAssociatedLicenses();
00108 
00109     /*
00110      @return string of SelectionType passed as parameter
00111      @param SelectionType to convert
00112     */
00113     //std::string selectionTypeToString(const MetaPackageInfo::SelectionType& Selec) const;
00114 
00115   public:
00116 
00117     MarketClient();
00118 
00119     ~MarketClient();
00120 
00121     /**
00122      @return string name of type passed as parameter
00123      @param Type Type of package
00124      @param Maj First letter in maj
00125      @param Plural Return plural name
00126     */
00127     static std::string getTypeName(const PackageInfo::PackageType& Type, const bool Maj, const bool Plural);
00128 
00129     /**
00130      @return true if MetaPackagesCatalogs contain packages
00131     */
00132     bool catalogsContainPackages() const;
00133 
00134     void connect(const std::string& URL);
00135 
00136     void disconnect();
00137 
00138     void getMarketInfo(MarketInfo& Info);
00139 
00140     const MarketLicensesTexts_t& getLicensesTexts();
00141 
00142     const TypesMetaPackagesCatalogs_t& getTypesMetaPackagesCatalogs();
00143 
00144     /**
00145      Finds the ID package in m_TypesMetaPackagesCatalogs
00146      @return iterator on ID package
00147      @param ID Id of package to find
00148     */
00149     MetaPackagesCatalog_t::iterator findInTypesMetaPackagesCatalogs(const openfluid::ware::WareID_t& ID);
00150 
00151     /**
00152      Set selected format of ID package with Flag
00153      @return true Flag has been set as selected flag
00154      @param ID Id of package to modify
00155      @param Flag Flag to be set
00156     */
00157     bool setSelectionFlag(const openfluid::ware::WareID_t& ID, const MetaPackageInfo::SelectionType& Flag);
00158 
00159     /**
00160      Set build options of ID package for source format with BuildOpts
00161      @param ID Id of package to modify
00162      @param BuildOpts Build options to be set
00163     */
00164     void setSRCBuildOptions(const openfluid::ware::WareID_t& ID, const std::string& BuildOpts);
00165 
00166     /**
00167      @return selected format of ID package
00168      @param ID Id of package to be got
00169     */
00170     MetaPackageInfo::SelectionType getSelectionFlag(const openfluid::ware::WareID_t& ID) const;
00171 
00172     void installSelection(const bool IgnoreMissing = true);
00173 
00174     void preparePackagesInstallation();
00175 
00176     unsigned int getCountOfPackagesToInstall() const { return m_PacksToInstall.size(); };
00177 
00178     const MarketPackage* getNextPackageToBeInstalled() const { return m_PacksToInstall.front(); };
00179 
00180     bool hasSelectedPackagesToInstall();
00181 
00182     void installNextSelectedPackage();
00183 
00184     const std::list<MarketPackage*>& getSelectionToInstall() const { return m_PacksToInstall; };
00185 
00186     bool isConnected() const { return m_IsConnected; };
00187 
00188     void enableLog(bool Enabled) { m_IsLogEnabled = Enabled; };
00189 
00190     /**
00191      Display packages list of market-place in console
00192     */
00193     //void displayPackages() const;
00194 
00195 };
00196 
00197 
00198 } } // namespaces
00199 
00200 
00201 #endif /* __MARKETCLIENT_HPP__ */
00202 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines