Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
Fix clang-tidy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekjaszczak committed Nov 11, 2023
1 parent 83bd057 commit ec419e8
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Checks: '-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,portability-*,readability-*'
Checks: '-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,portability-*,readability-*,-bugprone-easily-swappable-parameters,-readability-redundant-access-specifier,-readability-implicit-bool-conversion'
7 changes: 6 additions & 1 deletion include/rito/lcu_process_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class RITO_EXPORT Lcu_process_handler
Lcu_process_handler(std::filesystem::path proc_dir = "/proc");
~Lcu_process_handler();

Lcu_process_handler(const Lcu_process_handler&) = delete;
Lcu_process_handler(Lcu_process_handler&&) = delete;
auto operator=(const Lcu_process_handler&) -> Lcu_process_handler& = delete;
auto operator=(Lcu_process_handler&&) -> Lcu_process_handler& = delete;

/**
* @brief Obtains connection parameters of running LCU process.
*
Expand All @@ -64,7 +69,7 @@ class RITO_EXPORT Lcu_process_handler
* If process directory could not be found (e.g., Lcu_process_handler was created with
* incorrect parameter), Path_not_found_exception is thrown.
*/
Lcu_parameters get_lcu_process_parameters();
auto get_lcu_process_parameters() -> Lcu_parameters;

private:
std::unique_ptr<Lcu_process_handler_impl> m_pimpl;
Expand Down
7 changes: 6 additions & 1 deletion include/rito/lcu_rest_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class RITO_EXPORT Lcu_rest_handler
Lcu_rest_handler();
~Lcu_rest_handler();

Lcu_rest_handler(const Lcu_rest_handler&) = delete;
Lcu_rest_handler(Lcu_rest_handler&&) = delete;
auto operator=(const Lcu_rest_handler&) -> Lcu_rest_handler& = delete;
auto operator=(Lcu_rest_handler&&) -> Lcu_rest_handler& = delete;

/**
* @brief Executes REST request synchronously.
*
Expand Down Expand Up @@ -58,7 +63,7 @@ class RITO_EXPORT Lcu_rest_handler
* If there is some error while sending request to the server or receiving response, either
* Message_exception or Unknown_exception is thrown (depending on source of error).
*/
Http_response request(Request_type type, const std::string& message);
auto request(Request_type type, const std::string& message) -> Http_response;

private:
void attempt_reconnect();
Expand Down
19 changes: 9 additions & 10 deletions include/rito/lcu_wamp_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class RITO_EXPORT Lcu_wamp_handler
* This method should be called from separate thread.
*/
template <Convertible_to_string... Args>
bool call(const std::string& id, const std::string& function, Args&&... args) noexcept;
auto call(const std::string& identifier, const std::string& function, Args&&... args) noexcept -> bool;

/**
* @brief Sends message of WAMP type CALL (without arguments) to the LCU (if it's connected).
Expand All @@ -198,7 +198,7 @@ class RITO_EXPORT Lcu_wamp_handler
*
* This method should be called from separate thread.
*/
bool call(const std::string& id, const std::string& function) noexcept;
auto call(const std::string& identifier, const std::string& function) noexcept -> bool;

/**
* @brief Sends message of WAMP type SUBSCRIBE to the LCU (if it's connected).
Expand All @@ -218,7 +218,7 @@ class RITO_EXPORT Lcu_wamp_handler
* @note Subscription information is lost between sessions. If LCU is disconnected from and
* then connected to again, you'll need to subscribe to your events again.
*/
bool subscribe(const std::string& event) noexcept;
auto subscribe(const std::string& event) noexcept -> bool;

/**
* @brief Sends message of WAMP type UNSUBSCRIBE to the LCU (if it's connected).
Expand All @@ -235,7 +235,7 @@ class RITO_EXPORT Lcu_wamp_handler
*
* This method should be called from separate thread.
*/
bool unsubscribe(const std::string& event) noexcept;
auto unsubscribe(const std::string& event) noexcept -> bool;

private:
void on_connected();
Expand All @@ -245,12 +245,11 @@ class RITO_EXPORT Lcu_wamp_handler
void dispatch_message(const std::string& message);

void on_event(const std::string& event, const std::string& json_data);
void on_call_result(const std::string& id, const std::string& json_data);
void on_call_error(const std::string& id,
void on_call_result(const std::string& identifier, const std::string& json_data);
void on_call_error(const std::string& identifier,
const std::string& error,
const std::string& error_description);

private:
bool m_is_connected;

Lcu_websocket_handler m_lcu_websocket_handler;
Expand All @@ -263,14 +262,14 @@ class RITO_EXPORT Lcu_wamp_handler
};

template <Convertible_to_string... Args>
bool Lcu_wamp_handler::call(const std::string& id, const std::string& function, Args&&... args) noexcept
auto Lcu_wamp_handler::call(const std::string& identifier, const std::string& function, Args&&... args) noexcept -> bool
{
std::string argument_list{((", \""s + args + "\""s) + ...)}; // Produces: , "a", "b", "c"

return m_lcu_websocket_handler.send_message(
std::format("[{}, \"{}\", \"{}\"{}]",
std::format(R"([{}, "{}", "{}"{}])",
static_cast<int>(Wamp_message_type::call),
id,
identifier,
function,
argument_list));
}
Expand Down
10 changes: 7 additions & 3 deletions include/rito/lcu_websocket_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class RITO_EXPORT Lcu_websocket_handler
Lcu_websocket_handler();
~Lcu_websocket_handler();

Lcu_websocket_handler(const Lcu_websocket_handler&) = delete;
Lcu_websocket_handler(Lcu_websocket_handler&&) = delete;
auto operator=(const Lcu_websocket_handler&) -> Lcu_websocket_handler& = delete;
auto operator=(Lcu_websocket_handler&&) -> Lcu_websocket_handler& = delete;

/**
* @brief Starts internal polling loop. Will not return unless stop() is called from another
* thread.
Expand Down Expand Up @@ -116,19 +121,18 @@ class RITO_EXPORT Lcu_websocket_handler
*
* This method should be called from separate thread.
*/
bool send_message(std::string_view message) noexcept;
auto send_message(std::string_view message) noexcept -> bool;

private:
void reconnect();
bool is_connected();
auto is_connected() -> bool;

void notify_connection_state_changed(bool connected);
void receive_message();
void reconnect_and_notify();

void main_loop();

private:
std::unique_ptr<Https_websocket_client> m_websocket;
std::mutex m_socket_mutex;

Expand Down
12 changes: 8 additions & 4 deletions include/rito/riot_rest_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ class RITO_EXPORT Riot_rest_handler
* @param api_key - Riot API key. Can be either development API key or application-specific
* API key.
*/
Riot_rest_handler(const std::string& api_key);
Riot_rest_handler(std::string api_key);
~Riot_rest_handler();

Riot_rest_handler(const Riot_rest_handler&) = delete;
Riot_rest_handler(Riot_rest_handler&&) = delete;
auto operator=(const Riot_rest_handler&) -> Riot_rest_handler& = delete;
auto operator=(Riot_rest_handler&&) -> Riot_rest_handler& = delete;

/**
* @brief Sets region. Required to use REST communication.
*
Expand Down Expand Up @@ -80,13 +85,12 @@ class RITO_EXPORT Riot_rest_handler
* If there is some error while sending request to the server or receiving response, either
* Message_exception or Unknown_exception is thrown (depending on source of error).
*/
Http_response request(Request_type type, const std::string& message);
auto request(Request_type type, const std::string& message) -> Http_response;

private:
Http_response send_request(Request_type type, const std::string& message);
auto send_request(Request_type type, const std::string& message) -> Http_response;
void attempt_reconnect();

private:
Region m_region;
std::string m_api_key;
std::unique_ptr<Https_rest_client> m_client;
Expand Down
18 changes: 9 additions & 9 deletions src/https_rest_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ using Poco::Net::HTTPMessage;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;

Https_rest_client::Https_rest_client(const std::string& host, std::uint16_t port)
: m_host{host},
Https_rest_client::Https_rest_client(std::string host, std::uint16_t port)
: m_host{std::move(host)},
m_port{port},
m_context{new Context(Context::TLS_CLIENT_USE, "", "", "", Context::VERIFY_NONE)},
m_session{m_host, m_port, m_context}
{
}

Http_response Https_rest_client::request(Request_type type,
const std::string& path_and_query,
const Key_value_map& headers)
auto Https_rest_client::request(Request_type type,
const std::string& path_and_query,
const Key_value_map& headers) -> Http_response
{
send_request(to_poco_request_type(type), path_and_query, headers);

return receive_response();
}

void Https_rest_client::send_request(const std::string& type,
const std::string& pathAndQuery,
const std::string& path_and_query,
const Key_value_map& headers)
{
HTTPRequest request(type, pathAndQuery, HTTPMessage::HTTP_1_1);
HTTPRequest request(type, path_and_query, HTTPMessage::HTTP_1_1);
request.setHost(m_host, m_port);
request.setKeepAlive(true);

Expand All @@ -56,7 +56,7 @@ void Https_rest_client::send_request(const std::string& type,
m_session.sendRequest(request);
}

Http_response Https_rest_client::receive_response()
auto Https_rest_client::receive_response() -> Http_response
{
try
{
Expand All @@ -77,7 +77,7 @@ Http_response Https_rest_client::receive_response()
throw Unknown_exception{"HttpsRestClient: Unexpected error while receiving message"};
}

std::string to_poco_request_type(Request_type type)
auto to_poco_request_type(Request_type type) -> std::string
{
switch (type)
{
Expand Down
16 changes: 8 additions & 8 deletions src/https_websocket_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
namespace rito {

namespace {
std::uint32_t max_frame_size{65536};
std::uint8_t max_frames_per_message{255};
constexpr std::uint32_t max_frame_size{65536};
constexpr std::uint8_t max_frames_per_message{255};
}

using namespace std::literals::string_literals;
Expand All @@ -26,9 +26,9 @@ using Poco::Net::HTTPMessage;
using Poco::Net::HTTPRequest;
using Poco::Net::WebSocket;

Https_websocket_client::Https_websocket_client(const std::string& host, std::uint16_t port)
Https_websocket_client::Https_websocket_client(std::string host, std::uint16_t port)
: m_connected{false},
m_host{host},
m_host{std::move(host)},
m_port{port},
m_context{new Context(Context::TLS_CLIENT_USE, "", "", "", Context::VERIFY_NONE)},
m_session{m_host, m_port, m_context},
Expand All @@ -49,7 +49,7 @@ void Https_websocket_client::set_credentials(const std::string& username,
m_credentials.authenticate(m_request);
}

bool Https_websocket_client::is_connected()
auto Https_websocket_client::is_connected() const -> bool
{
return m_connected;
}
Expand Down Expand Up @@ -85,18 +85,18 @@ void Https_websocket_client::stop()
m_websocket.reset();
}

bool Https_websocket_client::send_message(std::string_view message)
auto Https_websocket_client::send_message(std::string_view message) -> bool
{
if (m_websocket)
{
m_websocket->sendFrame(message.data(), message.size(), WebSocket::FRAME_TEXT);
m_websocket->sendFrame(message.data(), static_cast<int>(message.size()), WebSocket::FRAME_TEXT);
return true;
}

return false;
}

Poco::Buffer<char> Https_websocket_client::receive_message()
auto Https_websocket_client::receive_message() -> Poco::Buffer<char>
{
if (m_websocket)
{
Expand Down
16 changes: 8 additions & 8 deletions src/include/https_rest_client.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "common_types.h"
#include "internal_constants.h"

#include <Poco/Net/Context.h>
#include <Poco/Net/HTTPBasicCredentials.h>
Expand All @@ -17,33 +18,32 @@ using Key_value_map = std::unordered_map<std::string, std::string>;
class Https_rest_client
{
public:
Https_rest_client(const std::string& host, std::uint16_t port = 443);
Https_rest_client(std::string host, std::uint16_t port = https_port);

void set_credentials(const std::string& username, const std::string& password)
{
m_credentials.setUsername(username);
m_credentials.setPassword(password);
}

Http_response request(Request_type type,
const std::string& path_and_query,
const Key_value_map& headers = {});
auto request(Request_type type,
const std::string& path_and_query,
const Key_value_map& headers = {}) -> Http_response;

private:
void send_request(const std::string& type,
const std::string& path_and_query,
const Key_value_map& headers);
Http_response receive_response();
auto receive_response() -> Http_response;

private:
std::string m_host;
std::uint16_t m_port;

const Poco::Net::Context::Ptr m_context;
Poco::Net::Context::Ptr m_context;
Poco::Net::HTTPSClientSession m_session;
Poco::Net::HTTPBasicCredentials m_credentials;
};

std::string to_poco_request_type(Request_type type);
auto to_poco_request_type(Request_type type) -> std::string;

} // namespace rito
17 changes: 12 additions & 5 deletions src/include/https_websocket_client.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "internal_constants.h"

#include <Poco/Buffer.h>
#include <Poco/Net/Context.h>
#include <Poco/Net/HTTPBasicCredentials.h>
Expand All @@ -18,18 +20,23 @@ namespace rito {
class Https_websocket_client
{
public:
Https_websocket_client(const std::string& host, std::uint16_t port = 443);
Https_websocket_client(const Https_websocket_client&) = delete;
~Https_websocket_client();

Https_websocket_client(Https_websocket_client&&) = delete;
auto operator=(const Https_websocket_client&) -> Https_websocket_client& = delete;
auto operator=(Https_websocket_client&&) -> Https_websocket_client& = delete;
Https_websocket_client(std::string host, std::uint16_t port = https_port);

void set_credentials(const std::string& username, const std::string& password);

bool is_connected();
auto is_connected() const -> bool;

void start();
void stop();

bool send_message(std::string_view message);
Poco::Buffer<char> receive_message();
auto send_message(std::string_view message) -> bool;
auto receive_message() -> Poco::Buffer<char>;

private:
void run();
Expand All @@ -40,7 +47,7 @@ class Https_websocket_client
std::string m_host;
std::uint16_t m_port;

const Poco::Net::Context::Ptr m_context;
Poco::Net::Context::Ptr m_context;
Poco::Net::HTTPSClientSession m_session;
Poco::Net::HTTPBasicCredentials m_credentials;

Expand Down
5 changes: 5 additions & 0 deletions src/include/internal_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

namespace rito {
constexpr auto https_port{443};
}
6 changes: 3 additions & 3 deletions src/include/lcu_process_handler_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace rito {

std::string extract_remoting_auth_token(const std::string& lcu_command);
std::string extract_app_port(const std::string& lcu_command);
bool is_integer(std::string_view str);
auto extract_remoting_auth_token(const std::string& lcu_command) -> std::string;
auto extract_app_port(const std::string& lcu_command) -> std::string;
auto is_positive_integer(std::string_view str) -> bool;

}
Loading

0 comments on commit ec419e8

Please sign in to comment.