Gazebo Fuel_tools

API Reference

9.1.0
FuelClient.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GZ_FUEL_TOOLS_FUELCLIENT_HH_
19 #define GZ_FUEL_TOOLS_FUELCLIENT_HH_
20 
21 #include <memory>
22 #include <string>
23 #include <tuple>
24 #include <vector>
25 #include <gz/common/URI.hh>
26 
29 #include "gz/fuel_tools/Result.hh"
31 
32 #ifdef _WIN32
33 // Disable warning C4251 which is triggered by
34 // std::unique_ptr
35 #pragma warning(push)
36 #pragma warning(disable: 4251)
37 #endif
38 
39 namespace gz::fuel_tools
40 {
42  class ClientConfig;
43  class CollectionIdentifier;
44  class FuelClientPrivate;
45  class LocalCache;
46  class ModelIdentifier;
47  class ServerConfig;
48  class WorldIdentifier;
49 
51  class GZ_FUEL_TOOLS_VISIBLE FuelClient
52  {
54  public: FuelClient();
55 
60  public: FuelClient(const ClientConfig &_config,
61  const Rest &_rest = Rest());
62 
64  public: ~FuelClient();
65 
68  public: ClientConfig &Config();
69 
75  public: Result ModelDetails(const ModelIdentifier &_id,
76  ModelIdentifier &_model) const;
77 
84  public: Result ModelDetails(const ModelIdentifier &_id,
85  ModelIdentifier &_model,
86  const std::vector<std::string> &_headers) const;
87 
88 
98  public: ModelIter Models(const ServerConfig &_server);
99 
109  public: ModelIter Models(const ServerConfig &_server) const;
110 
115  public: Result WorldDetails(const WorldIdentifier &_id,
116  WorldIdentifier &_world) const;
117 
123  public: Result WorldDetails(const WorldIdentifier &_id,
124  WorldIdentifier &_world,
125  const std::vector<std::string> &_headers) const;
126 
133  public: WorldIter Worlds(const ServerConfig &_server) const;
134 
142  public: ModelIter Models(const ModelIdentifier &_id);
143 
151  public: ModelIter Models(const ModelIdentifier &_id) const;
152 
161  public: ModelIter Models(const ModelIdentifier &_id, bool _checkCache);
162 
171  public: ModelIter Models(const ModelIdentifier &_id,
172  bool _checkCache) const;
173 
178  public: ModelIter Models(const CollectionIdentifier &_id) const;
179 
183  public: WorldIter Worlds(const WorldIdentifier &_id) const;
184 
189  public: WorldIter Worlds(const CollectionIdentifier &_id) const;
190 
197  public: Result UploadModel(const std::string &_pathToModelDir,
198  const ModelIdentifier &_id,
199  const std::vector<std::string> &_headers,
200  bool _private = false);
201 
210  public: Result UploadModel(const std::string &_pathToModelDir,
211  const ModelIdentifier &_id,
212  const std::vector<std::string> &_headers,
213  bool _private,
214  const std::string &_owner);
215 
221  public: Result DeleteUrl(const gz::common::URI &_uri,
222  const std::vector<std::string> &_headers);
223 
228  public: Result DownloadModel(const ModelIdentifier &_id);
229 
236  const std::vector<std::string> &_headers);
237 
245  const std::vector<std::string> &_headers,
246  std::vector<ModelIdentifier> &_dependencies);
247 
253  std::vector<ModelIdentifier> &_dependencies);
254 
260  const std::vector<ModelIdentifier> &_id,
261  std::vector<ModelIdentifier> &_dependencies);
262 
268 
275  const std::vector<std::string> &_headers);
276 
283  public: Result DownloadModel(const common::URI &_modelUrl,
284  std::string &_path);
285 
292  public: Result DownloadWorld(const common::URI &_worldUrl,
293  std::string &_path);
294 
296 
302  // The resulting vector will be at least the size of the _ids input
303  // vector, but may be larger depending on the number of depedencies
304  // downloaded
306  const std::vector<ModelIdentifier> &_ids,
307  size_t _jobs = 2);
308 
314  const std::vector<WorldIdentifier> &_ids,
315  size_t _jobs = 2);
316 
321  public: Result CachedModel(const ModelIdentifier &_id,
322  std::string &_path);
323 
329  public: Result CachedModel(const common::URI &_modelUrl,
330  std::string &_path);
331 
336  public: bool CachedModel(const common::URI &_modelUrl);
337 
343  public: Result CachedWorld(const common::URI &_worldUrl,
344  std::string &_path);
345 
350  public: bool CachedWorld(const common::URI &_worldUrl);
351 
358  public: Result CachedModelFile(const common::URI &_fileUrl,
359  std::string &_path);
360 
367  public: Result CachedWorldFile(const common::URI &_fileUrl,
368  std::string &_path);
369 
379  public: bool ParseModelUrl(const common::URI &_modelUrl,
380  ModelIdentifier &_id);
381 
391  public: bool ParseWorldUrl(const common::URI &_worldUrl,
392  WorldIdentifier &_id);
393 
403  public: bool ParseModelFileUrl(const common::URI &_modelFileUrl,
404  ModelIdentifier &_id,
405  std::string &_filePath);
406 
416  public: bool ParseWorldFileUrl(const common::URI &_worldFileUrl,
417  WorldIdentifier &_id,
418  std::string &_filePath);
419 
430  public: void PopulateLicenses(const ServerConfig &_server);
431 
442  const gz::fuel_tools::ModelIdentifier &_model,
443  const std::vector<std::string> &_headers);
444 
459  const gz::fuel_tools::ModelIdentifier &_model,
460  const std::vector<std::string> &_headers,
461  const std::string &_pathToModelDir);
462 
471  public: bool ParseCollectionUrl(const common::URI &_url,
472  CollectionIdentifier &_id);
473 
477  public: bool UpdateModels(const std::vector<std::string> &_headers);
478 
482  public: bool UpdateWorlds(const std::vector<std::string> &_headers);
483 
487  private: void AddServerConfigParametersToHeaders(
488  const gz::fuel_tools::ServerConfig &_serverConfig,
489  std::vector<std::string> &_headers) const;
490 
492  private: std::unique_ptr<FuelClientPrivate> dataPtr;
493  };
494 } // namespace gz::fuel_tools
495 
496 #ifdef _MSC_VER
497 #pragma warning(pop)
498 #endif
499 
500 #endif // GZ_FUEL_TOOLS_FUELCLIENT_HH_