Gazebo Fuel_tools

API Reference

4.9.1
gz/fuel_tools/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 
27 #include "gz/fuel_tools/Helpers.hh"
30 #include "gz/fuel_tools/Result.hh"
32 
33 #ifdef _WIN32
34 // Disable warning C4251 which is triggered by
35 // std::unique_ptr
36 #pragma warning(push)
37 #pragma warning(disable: 4251)
38 #endif
39 
40 namespace ignition
41 {
42  namespace fuel_tools
43  {
45  class ClientConfig;
46  class CollectionIdentifier;
47  class FuelClientPrivate;
48  class LocalCache;
49  class ModelIdentifier;
50  class ServerConfig;
51 
53  class IGNITION_FUEL_TOOLS_VISIBLE FuelClient
54  {
56  public: FuelClient();
57 
66  public: FuelClient(const ClientConfig &_config,
67  const Rest &_rest = Rest(),
68  LocalCache *_cache = nullptr);
69 
71  public: ~FuelClient();
72 
75  public: ClientConfig &Config();
76 
82  public: Result ModelDetails(const ModelIdentifier &_id,
83  ModelIdentifier &_model) const;
84 
90  public: Result ModelDetails(const ModelIdentifier &_id,
91  ModelIdentifier &_model,
92  const std::vector<std::string> &_headers) const;
93 
94 
104  public: ModelIter Models(const ServerConfig &_server);
105 
115  public: ModelIter Models(const ServerConfig &_server) const;
116 
121  public: Result WorldDetails(const WorldIdentifier &_id,
122  WorldIdentifier &_world) const;
123 
130  public: WorldIter Worlds(const ServerConfig &_server) const;
131 
139  public: ModelIter Models(const ModelIdentifier &_id);
140 
148  public: ModelIter Models(const ModelIdentifier &_id) const;
149 
158  public: ModelIter Models(const ModelIdentifier &_id, bool _checkCache);
159 
168  public: ModelIter Models(const ModelIdentifier &_id,
169  bool _checkCache) const;
170 
175  public: ModelIter Models(const CollectionIdentifier &_id) const;
176 
180  public: WorldIter Worlds(const WorldIdentifier &_id) const;
181 
186  public: WorldIter Worlds(const CollectionIdentifier &_id) const;
187 
194  public: Result UploadModel(const std::string &_pathToModelDir,
195  const ModelIdentifier &_id,
196  const std::vector<std::string> &_headers,
197  bool _private = false);
198 
204  public: Result DeleteModel(const ModelIdentifier &_id);
205 
211  public: Result DeleteUrl(const gz::common::URI &_uri,
212  const std::vector<std::string> &_headers);
213 
218  public: Result DownloadModel(const ModelIdentifier &_id);
219 
225  public: Result DownloadModel(const ModelIdentifier &_id,
226  const std::vector<std::string> &_headers);
227 
234  public: Result DownloadModel(const ModelIdentifier &_id,
235  const std::vector<std::string> &_headers,
236  std::vector<ModelIdentifier> &_dependencies);
237 
242  public: Result ModelDependencies(const ModelIdentifier &_id,
243  std::vector<ModelIdentifier> &_dependencies);
244 
249  public: Result ModelDependencies(
250  const std::vector<ModelIdentifier> &_id,
251  std::vector<ModelIdentifier> &_dependencies);
252 
257  public: Result DownloadWorld(WorldIdentifier &_id);
258 
265  public: Result DownloadModel(const common::URI &_modelUrl,
266  std::string &_path);
267 
274  public: Result DownloadWorld(const common::URI &_worldUrl,
275  std::string &_path);
276 
278 
284  // The resulting vector will be at least the size of the _ids input
285  // vector, but may be larger depending on the number of depedencies
286  // downloaded
287  public: std::vector<ModelResult> DownloadModels(
288  const std::vector<ModelIdentifier> &_ids,
289  size_t _jobs = 2);
290 
295  public: Result DownloadWorlds(
296  const std::vector<WorldIdentifier> &_ids,
297  size_t _jobs = 2);
298 
304  public: Result CachedModel(const common::URI &_modelUrl,
305  std::string &_path);
306 
311  public: bool CachedModel(const common::URI &_modelUrl);
312 
318  public: Result CachedWorld(const common::URI &_worldUrl,
319  std::string &_path);
320 
325  public: bool CachedWorld(const common::URI &_worldUrl);
326 
333  public: Result CachedModelFile(const common::URI &_fileUrl,
334  std::string &_path);
335 
342  public: Result CachedWorldFile(const common::URI &_fileUrl,
343  std::string &_path);
344 
354  public: bool ParseModelUrl(const common::URI &_modelUrl,
355  ModelIdentifier &_id);
356 
366  public: bool ParseWorldUrl(const common::URI &_worldUrl,
367  WorldIdentifier &_id);
368 
378  public: bool ParseModelFileUrl(const common::URI &_modelFileUrl,
379  ModelIdentifier &_id,
380  std::string &_filePath);
381 
391  public: bool ParseWorldFileUrl(const common::URI &_worldFileUrl,
392  WorldIdentifier &_id,
393  std::string &_filePath);
394 
405  public: void PopulateLicenses(const ServerConfig &_server);
406 
416  public: Result PatchModel(
417  const gz::fuel_tools::ModelIdentifier &_model,
418  const std::vector<std::string> &_headers);
419 
433  public: Result PatchModel(
434  const gz::fuel_tools::ModelIdentifier &_model,
435  const std::vector<std::string> &_headers,
436  const std::string &_pathToModelDir);
437 
446  public: bool ParseCollectionUrl(const common::URI &_url,
447  CollectionIdentifier &_id);
448 
452  private: void AddServerConfigParametersToHeaders(
453  const gz::fuel_tools::ServerConfig &_serverConfig,
454  std::vector<std::string> &_headers) const;
455 
457  private: std::unique_ptr<FuelClientPrivate> dataPtr;
458  };
459  }
460 }
461 
462 #ifdef _MSC_VER
463 #pragma warning(pop)
464 #endif
465 
466 #endif
High level interface to ignition fuel.
Definition: gz/fuel_tools/ClientConfig.hh:109
class for iterating through models
Definition: gz/fuel_tools/ModelIter.hh:43
Result UploadModel(const std::string &_pathToModelDir, const ModelIdentifier &_id, const std::vector< std::string > &_headers, bool _private=false)
Upload a directory as a new model.
STL class.
High level interface to ignition fuel.
Definition: gz/fuel_tools/FuelClient.hh:53
STL class.
ClientConfig & Config()
Get a mutable reference to the client configuration.
Result PatchModel(const ModelIdentifier &_model, const std::vector< std::string > &_headers)
Update a model using a PATCH request.
Defines how to identify a model.
Definition: gz/fuel_tools/ModelIdentifier.hh:45
std::vector< ModelResult > DownloadModels(const std::vector< ModelIdentifier > &_ids, size_t _jobs=2)
Download a list of models from ignition fuel.
ModelIter Models(const ServerConfig &_server)
Returns an iterator that can return names of models.
Class describing a result of an operation.
Definition: gz/fuel_tools/Result.hh:89
Result DeleteModel(const ModelIdentifier &_id)
Remove a model from ignition fuel.
class for iterating through worlds
Definition: gz/fuel_tools/WorldIter.hh:42
Result CachedWorld(const common::URI &_worldUrl, std::string &_path)
Check if a world is already present in the local cache.
bool ParseCollectionUrl(const common::URI &_url, CollectionIdentifier &_id)
Parse Collection identifer from URL.
bool ParseModelUrl(const common::URI &_modelUrl, ModelIdentifier &_id)
Parse model identifier from model URL or unique name.
Result DownloadWorld(WorldIdentifier &_id)
Download a world from Ignition Fuel. This will override an existing local copy of the world.
Result DownloadModel(const ModelIdentifier &_id)
Download a model from ignition fuel. This will override an existing local copy of the model.
Describes options needed for a server.
Definition: gz/fuel_tools/ClientConfig.hh:47
bool ParseModelFileUrl(const common::URI &_modelFileUrl, ModelIdentifier &_id, std::string &_filePath)
Parse model file identifier from model file URL.
Result ModelDependencies(const ModelIdentifier &_id, std::vector< ModelIdentifier > &_dependencies)
Retrieve the list of dependencies for a model.
bool ParseWorldUrl(const common::URI &_worldUrl, WorldIdentifier &_id)
Parse world identifier from world URL or unique name.
Result DeleteUrl(const gz::common::URI &_uri, const std::vector< std::string > &_headers)
Remove a resource, such as a model or world, from Ignition Fuel.
Result ModelDetails(const ModelIdentifier &_id, ModelIdentifier &_model) const
Fetch the details of a model.
A helper class for making REST requests.
Definition: gz/fuel_tools/RestClient.hh:80
Result CachedModel(const common::URI &_modelUrl, std::string &_path)
Check if a model is already present in the local cache.
Defines how to identify a world.
Definition: gz/fuel_tools/WorldIdentifier.hh:42
void PopulateLicenses(const ServerConfig &_server)
This function requests the available licenses from the Fuel server and stores this information locall...
bool ParseWorldFileUrl(const common::URI &_worldFileUrl, WorldIdentifier &_id, std::string &_filePath)
Parse world file identifier from world file URL.
Result CachedModelFile(const common::URI &_fileUrl, std::string &_path)
Check if a file belonging to a model is already present in the local cache.
Defines how to identify a collection.
Definition: gz/fuel_tools/CollectionIdentifier.hh:42
Result CachedWorldFile(const common::URI &_fileUrl, std::string &_path)
Check if a file belonging to a world is already present in the local cache.
Result DownloadWorlds(const std::vector< WorldIdentifier > &_ids, size_t _jobs=2)
Download a list of mworlds from ignition fuel.
FuelClient()
Default constructor.
WorldIter Worlds(const ServerConfig &_server) const
Returns an iterator that can return information of worlds.
Result WorldDetails(const WorldIdentifier &_id, WorldIdentifier &_world) const
Fetch the details of a world.
Class for managing stuff in the local cache.
Definition: gz/fuel_tools/LocalCache.hh:46