Ignition Fuel_tools

API Reference

4.4.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 IGNITION_FUEL_TOOLS_FUELCLIENT_HH_
19 #define IGNITION_FUEL_TOOLS_FUELCLIENT_HH_
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 #include <ignition/common/URI.hh>
25 
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 ignition
40 {
41  namespace fuel_tools
42  {
44  class ClientConfig;
45  class CollectionIdentifier;
46  class FuelClientPrivate;
47  class LocalCache;
48  class ModelIdentifier;
49  class ServerConfig;
50 
52  class IGNITION_FUEL_TOOLS_VISIBLE FuelClient
53  {
55  public: FuelClient();
56 
65  public: FuelClient(const ClientConfig &_config,
66  const Rest &_rest = Rest(),
67  LocalCache *_cache = nullptr);
68 
70  public: ~FuelClient();
71 
74  public: ClientConfig &Config();
75 
81  public: Result ModelDetails(const ModelIdentifier &_id,
82  ModelIdentifier &_model) const;
83 
89  public: Result ModelDetails(const ModelIdentifier &_id,
90  ModelIdentifier &_model,
91  const std::vector<std::string> &_headers) const;
92 
93 
103  public: ModelIter Models(const ServerConfig &_server);
104 
114  public: ModelIter Models(const ServerConfig &_server) const;
115 
120  public: Result WorldDetails(const WorldIdentifier &_id,
121  WorldIdentifier &_world) const;
122 
129  public: WorldIter Worlds(const ServerConfig &_server) const;
130 
138  public: ModelIter Models(const ModelIdentifier &_id);
139 
147  public: ModelIter Models(const ModelIdentifier &_id) const;
148 
153  public: ModelIter Models(const CollectionIdentifier &_id) const;
154 
158  public: WorldIter Worlds(const WorldIdentifier &_id) const;
159 
164  public: WorldIter Worlds(const CollectionIdentifier &_id) const;
165 
172  public: Result UploadModel(const std::string &_pathToModelDir,
173  const ModelIdentifier &_id,
174  const std::vector<std::string> &_headers,
175  bool _private = false);
176 
182  public: Result DeleteModel(const ModelIdentifier &_id);
183 
190  const std::vector<std::string> &_headers);
191 
196  public: Result DownloadModel(const ModelIdentifier &_id);
197 
204  const std::vector<std::string> &_headers);
205 
211 
218  public: Result DownloadModel(const common::URI &_modelUrl,
219  std::string &_path);
220 
227  public: Result DownloadWorld(const common::URI &_worldUrl,
228  std::string &_path);
229 
235  public: Result CachedModel(const common::URI &_modelUrl,
236  std::string &_path);
237 
242  public: bool CachedModel(const common::URI &_modelUrl);
243 
249  public: Result CachedWorld(const common::URI &_worldUrl,
250  std::string &_path);
251 
256  public: bool CachedWorld(const common::URI &_worldUrl);
257 
264  public: Result CachedModelFile(const common::URI &_fileUrl,
265  std::string &_path);
266 
273  public: Result CachedWorldFile(const common::URI &_fileUrl,
274  std::string &_path);
275 
285  public: bool ParseModelUrl(const common::URI &_modelUrl,
286  ModelIdentifier &_id);
287 
297  public: bool ParseWorldUrl(const common::URI &_worldUrl,
298  WorldIdentifier &_id);
299 
309  public: bool ParseModelFileUrl(const common::URI &_modelFileUrl,
310  ModelIdentifier &_id,
311  std::string &_filePath);
312 
322  public: bool ParseWorldFileUrl(const common::URI &_worldFileUrl,
323  WorldIdentifier &_id,
324  std::string &_filePath);
325 
336  public: void PopulateLicenses(const ServerConfig &_server);
337 
349  const std::vector<std::string> &_headers);
350 
366  const std::vector<std::string> &_headers,
367  const std::string &_pathToModelDir);
368 
377  public: bool ParseCollectionUrl(const common::URI &_url,
378  CollectionIdentifier &_id);
379 
383  private: void AddServerConfigParametersToHeaders(
384  const ignition::fuel_tools::ServerConfig &_serverConfig,
385  std::vector<std::string> &_headers) const;
386 
388  private: std::unique_ptr<FuelClientPrivate> dataPtr;
389  };
390  }
391 }
392 
393 #ifdef _MSC_VER
394 #pragma warning(pop)
395 #endif
396 
397 #endif
High level interface to ignition fuel.
Definition: ClientConfig.hh:110
Defines how to identify a collection.
Definition: CollectionIdentifier.hh:43
High level interface to ignition fuel.
Definition: FuelClient.hh:53
Result CachedWorld(const common::URI &_worldUrl, std::string &_path)
Check if a world is already present in the local cache.
ModelIter Models(const ServerConfig &_server)
Returns an iterator that can return names of models.
void PopulateLicenses(const ServerConfig &_server)
This function requests the available licenses from the Fuel server and stores this information locall...
WorldIter Worlds(const WorldIdentifier &_id) const
Returns worlds matching a given identifying criteria.
Result DownloadModel(const ModelIdentifier &_id, const std::vector< std::string > &_headers)
Download a model from ignition fuel. This will override an existing local copy of the model.
Result DownloadWorld(const common::URI &_worldUrl, std::string &_path)
Download a world from ignition fuel. This will override an existing local copy of the world.
ModelIter Models(const ServerConfig &_server) const
Returns an iterator that can return names of models.
Result PatchModel(const ModelIdentifier &_model, const std::vector< std::string > &_headers)
Update a model using a PATCH request.
bool CachedModel(const common::URI &_modelUrl)
Check if a model exists in the cache.
bool ParseWorldFileUrl(const common::URI &_worldFileUrl, WorldIdentifier &_id, std::string &_filePath)
Parse world file identifier from world file URL.
bool ParseModelFileUrl(const common::URI &_modelFileUrl, ModelIdentifier &_id, std::string &_filePath)
Parse model file identifier from model file URL.
Result PatchModel(const ModelIdentifier &_model, const std::vector< std::string > &_headers, const std::string &_pathToModelDir)
Update a model using a PATCH request.
Result ModelDetails(const ModelIdentifier &_id, ModelIdentifier &_model, const std::vector< std::string > &_headers) const
Fetch the details of a model.
FuelClient(const ClientConfig &_config, const Rest &_rest=Rest(), LocalCache *_cache=nullptr)
Constructor accepts server and auth configuration.
ModelIter Models(const ModelIdentifier &_id) const
Returns models matching a given identifying criteria.
Result WorldDetails(const WorldIdentifier &_id, WorldIdentifier &_world) const
Fetch the details of a world.
Result DeleteModel(const ModelIdentifier &_id)
Remove a model from ignition fuel.
Result DeleteUrl(const ignition::common::URI &_uri, const std::vector< std::string > &_headers)
Remove a resource, such as a model or world, from Ignition Fuel.
ModelIter Models(const CollectionIdentifier &_id) const
Returns an iterator for the models found in a collection.
Result DownloadModel(const ModelIdentifier &_id)
Download a model from ignition fuel. This will override an existing local copy of the model.
WorldIter Worlds(const CollectionIdentifier &_id) const
Returns an iterator for the worlds found in a collection.
FuelClient()
Default constructor.
Result ModelDetails(const ModelIdentifier &_id, ModelIdentifier &_model) const
Fetch the details of a model.
Result DownloadModel(const common::URI &_modelUrl, std::string &_path)
Download a model from ignition fuel. This will override an existing local copy of the model.
bool ParseWorldUrl(const common::URI &_worldUrl, WorldIdentifier &_id)
Parse world identifier from world URL or unique name.
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 DownloadWorld(WorldIdentifier &_id)
Download a world from Ignition Fuel. This will override an existing local copy of the world.
Result CachedModel(const common::URI &_modelUrl, std::string &_path)
Check if a model is already present in the local cache.
bool ParseCollectionUrl(const common::URI &_url, CollectionIdentifier &_id)
Parse Collection identifer from URL.
WorldIter Worlds(const ServerConfig &_server) const
Returns an iterator that can return information of worlds.
Result CachedModelFile(const common::URI &_fileUrl, std::string &_path)
Check if a file belonging to a model is already present in the local cache.
bool ParseModelUrl(const common::URI &_modelUrl, ModelIdentifier &_id)
Parse model identifier from model URL or unique name.
bool CachedWorld(const common::URI &_worldUrl)
Check if a world exists in the cache.
ModelIter Models(const ModelIdentifier &_id)
Returns models matching a given identifying criteria.
ClientConfig & Config()
Get a mutable reference to the client configuration.
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.
Class for managing stuff in the local cache.
Definition: LocalCache.hh:47
Defines how to identify a model.
Definition: ModelIdentifier.hh:46
class for iterating through models
Definition: ModelIter.hh:44
A helper class for making REST requests.
Definition: RestClient.hh:81
Class describing a result of an operation.
Definition: Result.hh:89
Describes options needed for a server.
Definition: ClientConfig.hh:48
Defines how to identify a world.
Definition: WorldIdentifier.hh:43
class for iterating through worlds
Definition: WorldIter.hh:43