Removed addtional code smells

This commit is contained in:
Andrea Bondavalli 2023-02-26 10:06:04 +01:00
parent a255f31dfd
commit 1fc529b035
9 changed files with 29 additions and 24 deletions

View File

@ -71,7 +71,7 @@ class Config {
void set_http_port(uint16_t http_port) { http_port_ = http_port; }; void set_http_port(uint16_t http_port) { http_port_ = http_port; };
void set_rtsp_port(uint16_t rtsp_port) { rtsp_port_ = rtsp_port; }; void set_rtsp_port(uint16_t rtsp_port) { rtsp_port_ = rtsp_port; };
void set_http_base_dir(const std::string& http_base_dir) { void set_http_base_dir(std::string_view http_base_dir) {
http_base_dir_ = http_base_dir; http_base_dir_ = http_base_dir;
}; };
void set_log_severity(int log_severity) { log_severity_ = log_severity; }; void set_log_severity(int log_severity) { log_severity_ = log_severity; };
@ -85,10 +85,10 @@ class Config {
max_tic_frame_size_ = max_tic_frame_size; max_tic_frame_size_ = max_tic_frame_size;
}; };
void set_sample_rate(uint32_t sample_rate) { sample_rate_ = sample_rate; }; void set_sample_rate(uint32_t sample_rate) { sample_rate_ = sample_rate; };
void set_rtp_mcast_base(const std::string& rtp_mcast_base) { void set_rtp_mcast_base(std::string_view rtp_mcast_base) {
rtp_mcast_base_ = rtp_mcast_base; rtp_mcast_base_ = rtp_mcast_base;
}; };
void set_sap_mcast_addr(const std::string& sap_mcast_addr) { void set_sap_mcast_addr(std::string_view sap_mcast_addr) {
sap_mcast_addr_ = sap_mcast_addr; sap_mcast_addr_ = sap_mcast_addr;
}; };
void set_rtp_port(uint16_t rtp_port) { rtp_port_ = rtp_port; }; void set_rtp_port(uint16_t rtp_port) { rtp_port_ = rtp_port; };
@ -97,30 +97,30 @@ class Config {
void set_sap_interval(uint16_t sap_interval) { void set_sap_interval(uint16_t sap_interval) {
sap_interval_ = sap_interval; sap_interval_ = sap_interval;
}; };
void set_syslog_proto(const std::string& syslog_proto) { void set_syslog_proto(std::string_view syslog_proto) {
syslog_proto_ = syslog_proto; syslog_proto_ = syslog_proto;
}; };
void set_syslog_server(const std::string& syslog_server) { void set_syslog_server(std::string_view syslog_server) {
syslog_server_ = syslog_server; syslog_server_ = syslog_server;
}; };
void set_status_file(const std::string& status_file) { void set_status_file(std::string_view status_file) {
status_file_ = status_file; status_file_ = status_file;
}; };
void set_interface_name(const std::string& interface_name) { void set_interface_name(std::string_view interface_name) {
interface_name_ = interface_name; interface_name_ = interface_name;
}; };
void set_ip_addr_str(const std::string& ip_str) { ip_str_ = ip_str; }; void set_ip_addr_str(std::string_view ip_str) { ip_str_ = ip_str; };
void set_ip_addr(uint32_t ip_addr) { ip_addr_ = ip_addr; }; void set_ip_addr(uint32_t ip_addr) { ip_addr_ = ip_addr; };
void set_mac_addr_str(const std::string& mac_str) { mac_str_ = mac_str; }; void set_mac_addr_str(std::string_view mac_str) { mac_str_ = mac_str; };
void set_mac_addr(const std::array<uint8_t, 6>& mac_addr) { void set_mac_addr(const std::array<uint8_t, 6>& mac_addr) {
mac_addr_ = mac_addr; mac_addr_ = mac_addr;
}; };
void set_mdns_enabled(bool enabled) { mdns_enabled_ = enabled; }; void set_mdns_enabled(bool enabled) { mdns_enabled_ = enabled; };
void set_interface_idx(int index) { interface_idx_ = index; }; void set_interface_idx(int index) { interface_idx_ = index; };
void set_ptp_status_script(const std::string& script) { void set_ptp_status_script(std::string_view script) {
ptp_status_script_ = script; ptp_status_script_ = script;
}; };
void set_custom_node_id(const std::string& node_id) { void set_custom_node_id(std::string_view node_id) {
custom_node_id_ = node_id; custom_node_id_ = node_id;
}; };
void set_auto_sinks_update(bool auto_sinks_update) { void set_auto_sinks_update(bool auto_sinks_update) {

View File

@ -39,7 +39,7 @@
class MDNSClient { class MDNSClient {
public: public:
MDNSClient(std::shared_ptr<Config> config) : config_(config){}; explicit MDNSClient(std::shared_ptr<Config> config) : config_(config){};
MDNSClient() = delete; MDNSClient() = delete;
MDNSClient(const MDNSClient&) = delete; MDNSClient(const MDNSClient&) = delete;
MDNSClient& operator=(const MDNSClient&) = delete; MDNSClient& operator=(const MDNSClient&) = delete;

View File

@ -51,7 +51,7 @@ class MDNSServer {
virtual bool init(); virtual bool init();
virtual bool terminate(); virtual bool terminate();
bool add_service(const std::string& name, const std::string& sdp); bool add_service(const std::string& name, const std::string &sdp);
bool remove_service(const std::string& name); bool remove_service(const std::string& name);
protected: protected:

View File

@ -35,7 +35,7 @@ using boost::asio::deadline_timer;
class NetlinkClient { class NetlinkClient {
public: public:
NetlinkClient() = delete; NetlinkClient() = delete;
NetlinkClient(const std::string& name) : name_(name) {} explicit NetlinkClient(const std::string& name) : name_(name) {}
void init(const nl_endpoint<nl_protocol>& listen_endpoint, void init(const nl_endpoint<nl_protocol>& listen_endpoint,
const nl_protocol& protocol) { const nl_protocol& protocol) {

View File

@ -112,6 +112,9 @@ struct RtspActiveClientRemover {
} }
} }
RtspActiveClientRemover(const RtspActiveClientRemover&) = delete;
RtspActiveClientRemover& operator=(const RtspActiveClientRemover&) = delete;
private: private:
ip::tcp::iostream* stream_{nullptr}; ip::tcp::iostream* stream_{nullptr};
const std::string& name_; const std::string& name_;

View File

@ -38,7 +38,7 @@
#include "session_manager.hpp" #include "session_manager.hpp"
#include "interface.hpp" #include "interface.hpp"
static uint8_t get_codec_word_length(const std::string& codec) { static uint8_t get_codec_word_length(std::string_view codec) {
if (codec == "L16") { if (codec == "L16") {
return 2; return 2;
} }
@ -60,7 +60,7 @@ static uint8_t get_codec_word_length(const std::string& codec) {
return 0; return 0;
} }
bool SessionManager::parse_sdp(const std::string sdp, StreamInfo& info) const { bool SessionManager::parse_sdp(const std::string& sdp, StreamInfo& info) const {
/* /*
v=0 v=0
o=- 4 0 IN IP4 10.0.0.12 o=- 4 0 IN IP4 10.0.0.12
@ -923,7 +923,7 @@ std::error_code SessionManager::get_sink_status(
return ret; return ret;
} }
std::error_code SessionManager::set_driver_config(const std::string& name, std::error_code SessionManager::set_driver_config(std::string_view name,
uint32_t value) const { uint32_t value) const {
if (name == "sample_rate") if (name == "sample_rate")
return driver_->set_sample_rate(value); return driver_->set_sample_rate(value);
@ -1103,8 +1103,9 @@ void SessionManager::on_ptp_status_changed(const std::string& status) const {
for (int i = STDERR_FILENO + 1; i < fdlimit; i++) for (int i = STDERR_FILENO + 1; i < fdlimit; i++)
close(i); close(i);
char* argv_list[] = {(char*)(config_->get_ptp_status_script().c_str()), char* argv_list[] = {
(char*)(status.c_str()), nullptr}; const_cast<char*>(config_->get_ptp_status_script().c_str()),
const_cast<char*>(status.c_str()), nullptr};
execv(config_->get_ptp_status_script().c_str(), argv_list); execv(config_->get_ptp_status_script().c_str(), argv_list);
exit(0); exit(0);
@ -1142,7 +1143,8 @@ bool SessionManager::worker() {
// return false; // return false;
} else { } else {
char ptp_clock_id[24]; char ptp_clock_id[24];
uint8_t* pui64GMID = reinterpret_cast<uint8_t*>(&ptp_status.ui64GMID); const uint8_t* pui64GMID =
reinterpret_cast<uint8_t*>(&ptp_status.ui64GMID);
snprintf(ptp_clock_id, sizeof(ptp_clock_id), snprintf(ptp_clock_id, sizeof(ptp_clock_id),
"%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X", pui64GMID[0], "%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X", pui64GMID[0],
pui64GMID[1], pui64GMID[2], pui64GMID[3], pui64GMID[4], pui64GMID[1], pui64GMID[2], pui64GMID[3], pui64GMID[4],

View File

@ -158,7 +158,7 @@ class SessionManager {
uint8_t get_sink_id(const std::string& name) const; uint8_t get_sink_id(const std::string& name) const;
std::error_code set_ptp_config(const PTPConfig& config); std::error_code set_ptp_config(const PTPConfig& config);
std::error_code set_driver_config(const std::string& name, std::error_code set_driver_config(std::string_view name,
uint32_t value) const; uint32_t value) const;
void get_ptp_config(PTPConfig& config) const; void get_ptp_config(PTPConfig& config) const;
void get_ptp_status(PTPStatus& status) const; void get_ptp_status(PTPStatus& status) const;
@ -197,7 +197,7 @@ class SessionManager {
bool sink_is_still_valid(const std::string sdp, bool sink_is_still_valid(const std::string sdp,
const std::list<RemoteSource> sources_list) const; const std::list<RemoteSource> sources_list) const;
bool parse_sdp(const std::string sdp, StreamInfo& info) const; bool parse_sdp(const std::string& sdp, StreamInfo& info) const;
bool worker(); bool worker();
// singleton, use create() to build // singleton, use create() to build
explicit SessionManager(std::shared_ptr<DriverManager> driver, explicit SessionManager(std::shared_ptr<DriverManager> driver,

View File

@ -99,7 +99,7 @@ std::string sdp_get_subject(const std::string& sdp) {
return ""; return "";
} }
SDPOrigin sdp_get_origin(const std::string sdp) { SDPOrigin sdp_get_origin(const std::string& sdp) {
SDPOrigin origin; SDPOrigin origin;
try { try {
std::stringstream sstream(sdp); std::stringstream sstream(sdp);

View File

@ -55,6 +55,6 @@ struct SDPOrigin {
} }
}; };
SDPOrigin sdp_get_origin(const std::string sdp); SDPOrigin sdp_get_origin(const std::string& sdp);
#endif #endif