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