Skip to content

Commit

Permalink
Use helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Feb 4, 2025
1 parent 22dc664 commit 8ceac76
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include <string_view>

#define DISABLE_DEFAULT(TypeName) TypeName() = delete
#define DISABLE_COPY(TypeName) \
TypeName(const TypeName&) = delete; \
TypeName& operator=(const TypeName&) = delete
Expand Down
6 changes: 3 additions & 3 deletions include/http/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace OpenShock::HTTP {
class HTTPClient {
DISABLE_DEFAULT(HTTPClient);
DISABLE_COPY(HTTPClient);

public:
HTTPClient(const char* url, int timeout_ms = 10'000)
{
Expand All @@ -30,7 +33,6 @@ namespace OpenShock::HTTP {
esp_http_client_cleanup(handle);
}
}
HTTPClient(const HTTPClient&) = delete;
HTTPClient(HTTPClient&& other)
{
handle = other.handle;
Expand Down Expand Up @@ -81,8 +83,6 @@ namespace OpenShock::HTTP {

HTTPResponse Get(const char* url) { return Send(url, HTTP_METHOD_GET); }

HTTPClient& operator=(const HTTPClient&) = delete;

private:
esp_http_client_handle_t handle;
};
Expand Down
6 changes: 3 additions & 3 deletions include/http/HTTPResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
namespace OpenShock::HTTP {
class HTTPClient;
class HTTPResponse {
DISABLE_DEFAULT(HTTPResponse);
DISABLE_COPY(HTTPResponse);

friend class HTTPClient;

HTTPResponse(esp_err_t error)
Expand All @@ -28,7 +31,6 @@ namespace OpenShock::HTTP {
}

public:
HTTPResponse(const HTTPResponse&) = delete;
HTTPResponse(HTTPResponse&& other)
{
m_handle = other.m_handle;
Expand All @@ -38,8 +40,6 @@ namespace OpenShock::HTTP {
constexpr bool IsValid() const { return m_handle != nullptr; }
constexpr esp_err_t GetError() const { return m_handle == nullptr ? m_error : ESP_OK; }

HTTPResponse& operator=(const HTTPResponse&) = delete;

private:
esp_http_client_handle_t m_handle;
union {
Expand Down

0 comments on commit 8ceac76

Please sign in to comment.