Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split ServerConfig and ClientConfig across multiple files #380

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 1 addition & 64 deletions include/gz/fuel_tools/ClientConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <gz/common/URI.hh>

#include "gz/fuel_tools/Export.hh"
#include "gz/fuel_tools/ServerConfig.hh"

#ifdef _WIN32
// Disable warning C4251 which is triggered by
Expand All @@ -37,73 +38,9 @@ namespace gz
{
namespace fuel_tools
{
/// \brief forward declaration
class ServerConfigPrivate;

/// \brief Forward Declaration
class ClientConfigPrivate;

/// \brief Describes options needed for a server.
class GZ_FUEL_TOOLS_VISIBLE ServerConfig
{
/// \brief Constructor.
public: ServerConfig();

/// \brief Copy constructor.
/// \param[in] _orig The server config to copy.
public: ServerConfig(const ServerConfig &_orig);

/// \brief Assignment operator overload.
/// \param[in] _orig The server config to copy.
public: ServerConfig &operator=(const ServerConfig &_orig);

/// \brief Destructor.
public: ~ServerConfig();

/// \brief Clear the server config. This will set all values to empty
/// strings, except the version string which will be set to its default
/// value.
public: void Clear();

/// \brief Get the URL to access the server.
/// \return The URL of this server.
public: common::URI Url() const;

/// \brief Set the URL of this server.
/// \param[in] _url URL of this server.
public: void SetUrl(const common::URI &_url);

/// \brief Get the API key to auth with the server.
/// \return The API key.
public: std::string ApiKey() const;

/// \brief Set the API key to auth with the server.
/// \param[in] _key The API key.
public: void SetApiKey(const std::string &_key);

/// \brief Get the protocol version used with this server.
/// \return The version. E.g.: "1.0".
public: std::string Version() const;

/// \brief Set the protocol version used with this server.
/// \param[in] _version The version. E.g.: "1.0".
public: void SetVersion(const std::string &_version);

/// \brief Returns all the server information as a string.
/// \param[in] _prefix Optional prefix for every line of the string.
/// \return Server information string
public: std::string AsString(const std::string &_prefix = "") const;

/// \brief Returns all the available model information as a string using
/// colors for better human parsing.
/// \param[in] _prefix Optional prefix for every line of the string.
/// \return Model information string
public: std::string AsPrettyString(const std::string &_prefix = "") const;

/// \brief PIMPL
private: std::unique_ptr<ServerConfigPrivate> dataPtr;
};

/// \brief High level interface to Gazebo Fuel.
///
class GZ_FUEL_TOOLS_VISIBLE ClientConfig
Expand Down
109 changes: 109 additions & 0 deletions include/gz/fuel_tools/ServerConfig.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef GZ_FUEL_TOOLS_SERVERCONFIG_HH_
#define GZ_FUEL_TOOLS_SERVERCONFIG_HH_

#include <memory>
#include <string>

#include <gz/common/URI.hh>

#include "gz/fuel_tools/Export.hh"

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif

namespace gz
{
namespace fuel_tools
{
/// \brief forward declaration
class ServerConfigPrivate;

/// \brief Describes options needed for a server.
class GZ_FUEL_TOOLS_VISIBLE ServerConfig
{
/// \brief Constructor.
public: ServerConfig();

/// \brief Copy constructor.
/// \param[in] _orig The server config to copy.
public: ServerConfig(const ServerConfig &_orig);

/// \brief Assignment operator overload.
/// \param[in] _orig The server config to copy.
public: ServerConfig &operator=(const ServerConfig &_orig);

/// \brief Destructor.
public: ~ServerConfig();

/// \brief Clear the server config. This will set all values to empty
/// strings, except the version string which will be set to its default
/// value.
public: void Clear();

/// \brief Get the URL to access the server.
/// \return The URL of this server.
public: common::URI Url() const;

/// \brief Set the URL of this server.
/// \param[in] _url URL of this server.
public: void SetUrl(const common::URI &_url);

/// \brief Get the API key to auth with the server.
/// \return The API key.
public: std::string ApiKey() const;

/// \brief Set the API key to auth with the server.
/// \param[in] _key The API key.
public: void SetApiKey(const std::string &_key);

/// \brief Get the protocol version used with this server.
/// \return The version. E.g.: "1.0".
public: std::string Version() const;

/// \brief Set the protocol version used with this server.
/// \param[in] _version The version. E.g.: "1.0".
public: void SetVersion(const std::string &_version);

/// \brief Returns all the server information as a string.
/// \param[in] _prefix Optional prefix for every line of the string.
/// \return Server information string
public: std::string AsString(const std::string &_prefix = "") const;

/// \brief Returns all the available model information as a string using
/// colors for better human parsing.
/// \param[in] _prefix Optional prefix for every line of the string.
/// \return Model information string
public: std::string AsPrettyString(const std::string &_prefix = "") const;

/// \brief PIMPL
private: std::unique_ptr<ServerConfigPrivate> dataPtr;
};
}
}

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif // GZ_FUEL_TOOLS_SERVERCONFIG_HH_
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set (sources
ModelIter.cc
RestClient.cc
Result.cc
ServerConfig.cc
Zip.cc
WorldIdentifier.cc
WorldIter.cc
Expand All @@ -31,6 +32,7 @@ set (gtest_sources
Model_TEST.cc
RestClient_TEST.cc
Result_TEST.cc
ServerConfig_TEST.cc
WorldIdentifier_TEST.cc
WorldIter_TEST.cc
Zip_TEST.cc
Expand Down
128 changes: 0 additions & 128 deletions src/ClientConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,134 +70,6 @@ class gz::fuel_tools::ClientConfigPrivate
"GazeboFuelTools-" GZ_FUEL_TOOLS_VERSION_FULL;
};

//////////////////////////////////////////////////
/// \brief Private data class
class gz::fuel_tools::ServerConfigPrivate
{
/// \brief Clear values.
public: void Clear()
{
this->url.Clear();
this->key = "";
this->version = "1.0";
}

/// \brief URL to reach server
public: common::URI url{"https://fuel.gazebosim.org"};

/// \brief A key to auth with the server
public: std::string key = "";

/// \brief The protocol version used when talking with this server.
public: std::string version = "1.0";
};

//////////////////////////////////////////////////
ServerConfig::ServerConfig()
: dataPtr (new ServerConfigPrivate)
{
}

//////////////////////////////////////////////////
ServerConfig::ServerConfig(const ServerConfig &_orig)
: dataPtr(new ServerConfigPrivate)
{
*(this->dataPtr) = *(_orig.dataPtr);
}

//////////////////////////////////////////////////
void ServerConfig::Clear()
{
this->dataPtr->Clear();
}

//////////////////////////////////////////////////
ServerConfig &ServerConfig::operator=(const ServerConfig &_orig)
{
*(this->dataPtr) = *(_orig.dataPtr);
return *this;
}

//////////////////////////////////////////////////
ServerConfig::~ServerConfig()
{
}

//////////////////////////////////////////////////
common::URI ServerConfig::Url() const
{
return this->dataPtr->url;
}

//////////////////////////////////////////////////
void ServerConfig::SetUrl(const common::URI &_url)
{
this->dataPtr->url = _url;
}

//////////////////////////////////////////////////
std::string ServerConfig::ApiKey() const
{
return this->dataPtr->key;
}

//////////////////////////////////////////////////
void ServerConfig::SetApiKey(const std::string &_key)
{
this->dataPtr->key = _key;
}

//////////////////////////////////////////////////
std::string ServerConfig::Version() const
{
return this->dataPtr->version;
}

//////////////////////////////////////////////////
void ServerConfig::SetVersion(const std::string &_version)
{
this->dataPtr->version = _version;
}

//////////////////////////////////////////////////
std::string ServerConfig::AsString(const std::string &_prefix) const
{
std::stringstream out;
out << _prefix << "URL: " << this->Url().Str() << std::endl
<< _prefix << "Version: " << this->Version() << std::endl
<< _prefix << "API key: " << this->ApiKey() << std::endl;
return out.str();
}

//////////////////////////////////////////////////
std::string ServerConfig::AsPrettyString(const std::string &_prefix) const
{
std::string prop = "\033[96m\033[1m";
std::string value = "\033[37m";
std::string reset = "\033[0m";

std::stringstream out;

if (this->Url().Valid())
{
out << _prefix << prop << "URL: " << reset
<< value << this->Url().Str() << reset << std::endl;
}

if (!this->Version().empty())
{
out << _prefix << prop << "Version: " << reset
<< value << this->Version() << reset << std::endl;
}

if (!this->ApiKey().empty())
{
out << _prefix << prop << "API key: " << reset
<< value << this->ApiKey() << reset << std::endl;
}
return out.str();
}

//////////////////////////////////////////////////
ClientConfig::ClientConfig() : dataPtr(new ClientConfigPrivate)
{
Expand Down
Loading