MarketClient.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 MarketClient.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
37 */
38 
39 
40 
41 
42 #ifndef __OPENFLUID_MARKET_MARKETCLIENT_HPP__
43 #define __OPENFLUID_MARKET_MARKETCLIENT_HPP__
44 
45 #include <string>
46 #include <queue>
47 
48 #include <openfluid/dllexport.hpp>
52 
53 namespace openfluid { namespace market {
54 
55 
56 typedef std::map<std::string,std::string> MarketLicensesTexts_t;
57 // List of catalog urls
58 typedef std::map<PackageInfo::PackageType,std::string> CatalogsFileURL_t;
59 // List of catalog data
60 typedef std::map<PackageInfo::PackageType,std::string> CatalogsData_t;
61 // List of MetaPackagesCatalogs
62 typedef std::map<PackageInfo::PackageType,MetaPackagesCatalog_t> TypesMetaPackagesCatalogs_t;
63 
64 // =====================================================================
65 // =====================================================================
66 
67 
69 {
70  public:
71 
72  static const std::string LOCK_FILE;
73 
74  private:
75 
76  MarketInfo m_MarketInfo;
77  TypesMetaPackagesCatalogs_t m_TypesMetaPackagesCatalogs;
78  std::string m_TempDir;
79 
80  std::string m_URL;
81 
82  MarketLicensesTexts_t m_LicensesTexts;
83 
84  bool m_IsConnected;
85 
86  bool m_IsLogEnabled;
87 
88  std::list<MarketPackage*> m_PacksToInstall;
89 
90  void initMarketBag();
91 
92  void initMarketTemp();
93 
94  void lockMarketTemp();
95 
96  void unlockMarketTemp();
97 
98  void parseMarketSiteData(const std::string& SiteFile);
99 
100  /**
101  Store all type catalog data in MetaPackageCatalog
102  @param CatalogType Type of catalog read
103  @param CatalogData string with data read
104  */
105  void parseCatalogData(const PackageInfo::PackageType& CatalogType, const std::string& CatalogFile);
106 
107  void downloadAssociatedLicenses();
108 
109  /*
110  @return string of SelectionType passed as parameter
111  @param SelectionType to convert
112  */
113  //std::string selectionTypeToString(const MetaPackageInfo::SelectionType& Selec) const;
114 
115  public:
116 
117  MarketClient();
118 
119  ~MarketClient();
120 
121  /**
122  @return string name of type passed as parameter
123  @param Type Type of package
124  @param Maj First letter in maj
125  @param Plural Return plural name
126  */
127  static std::string getTypeName(const PackageInfo::PackageType& Type, const bool Maj, const bool Plural);
128 
129  /**
130  @return true if MetaPackagesCatalogs contain packages
131  */
132  bool catalogsContainPackages() const;
133 
134  void connect(const std::string& URL);
135 
136  void disconnect();
137 
138  void getMarketInfo(MarketInfo& Info);
139 
140  const MarketLicensesTexts_t& licensesTexts();
141 
142  const TypesMetaPackagesCatalogs_t& typesMetaPackagesCatalogs();
143 
144  /**
145  Finds the ID package in m_TypesMetaPackagesCatalogs
146  @return iterator on ID package
147  @param ID Id of package to find
148  */
149  MetaPackagesCatalog_t::iterator findInTypesMetaPackagesCatalogs(const openfluid::ware::WareID_t& ID);
150 
151  /**
152  Set selected format of ID package with Flag
153  @return true Flag has been set as selected flag
154  @param ID Id of package to modify
155  @param Flag Flag to be set
156  */
157  bool setSelectionFlag(const openfluid::ware::WareID_t& ID, const MetaPackageInfo::SelectionType& Flag);
158 
159  /**
160  Set build options of ID package for source format with BuildOpts
161  @param ID Id of package to modify
162  @param BuildOpts Build options to be set
163  */
164  void setSRCBuildOptions(const openfluid::ware::WareID_t& ID, const std::string& BuildOpts);
165 
166  /**
167  @return selected format of ID package
168  @param ID Id of package to be got
169  */
170  MetaPackageInfo::SelectionType getSelectionFlag(const openfluid::ware::WareID_t& ID) const;
171 
172  void installSelection(const bool IgnoreMissing = true);
173 
174  void preparePackagesInstallation();
175 
176  unsigned int getCountOfPackagesToInstall() const { return m_PacksToInstall.size(); };
177 
178  const MarketPackage* nextPackageToBeInstalled() const { return m_PacksToInstall.front(); };
179 
180  bool hasSelectedPackagesToInstall();
181 
182  void installNextSelectedPackage();
183 
184  const std::list<MarketPackage*>& selectionToInstall() const { return m_PacksToInstall; };
185 
186  bool isConnected() const { return m_IsConnected; };
187 
188  void enableLog(bool Enabled) { m_IsLogEnabled = Enabled; };
189 
190  /**
191  Display packages list of market-place in console
192  */
193  //void displayPackages() const;
194 
195 };
196 
197 
198 } } // namespaces
199 
200 
201 #endif /* __OPENFLUID_MARKET_MARKETCLIENT_HPP__ */
202 
const MarketPackage * nextPackageToBeInstalled() const
Definition: MarketClient.hpp:178
unsigned int getCountOfPackagesToInstall() const
Definition: MarketClient.hpp:176
Definition: MarketClient.hpp:68
SelectionType
Definition: MarketInfos.hpp:128
std::map< PackageInfo::PackageType, MetaPackagesCatalog_t > TypesMetaPackagesCatalogs_t
Definition: MarketClient.hpp:62
PackageType
Definition: MarketInfos.hpp:93
std::string WareID_t
Definition: TypeDefs.hpp:50
void enableLog(bool Enabled)
Definition: MarketClient.hpp:188
std::map< PackageInfo::PackageType, std::string > CatalogsData_t
Definition: MarketClient.hpp:60
Definition: MarketInfos.hpp:53
bool isConnected() const
Definition: MarketClient.hpp:186
std::map< PackageInfo::PackageType, std::string > CatalogsFileURL_t
Definition: MarketClient.hpp:58
const std::list< MarketPackage * > & selectionToInstall() const
Definition: MarketClient.hpp:184
std::map< std::string, std::string > MarketLicensesTexts_t
Definition: MarketClient.hpp:56
Definition: ApplicationException.hpp:47
#define OPENFLUID_API
Definition: dllexport.hpp:87
static const std::string LOCK_FILE
Definition: MarketClient.hpp:72
Definition: MarketPackage.hpp:52