review comments

This commit is contained in:
2019-02-09 17:29:01 +01:00
parent 4d92edaca2
commit 981f3af686
13 changed files with 67 additions and 74 deletions

View File

@@ -12,7 +12,7 @@
#endif
#include "Common/Flag.h"
#include "EXI_DeviceEthernetBase.h"
#include "Core/HW/EXI/EXI_DeviceEthernetBase.h"
namespace ExpansionInterface
{

View File

@@ -2,13 +2,12 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Core/HW/EXI/EXI_DeviceEthernetTAP.h"
#include "Core/HW/EXI/EXI_DeviceEthernetTAP_Win32.h"
#include "Common/Assert.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "Core/HW/EXI/EXI_DeviceEthernetTAP.h"
#include "Core/HW/EXI/EXI_DeviceEthernetTAP_Win32.h"
namespace Win32TAPHelper
{

View File

@@ -58,9 +58,9 @@ bool CEXIEthernetTCP::IsActivated() const
bool CEXIEthernetTCP::SendFrame(const u8* frame, u32 size)
{
INFO_LOG(SP1, "SendFrame %i", size);
INFO_LOG(SP1, "SendFrame %u", size);
std::unique_ptr<u8[]> packet = std::make_unique<u8[]>(sizeof(int) + size);
const auto packet = std::make_unique<u8[]>(sizeof(int) + size);
// prepend size
for (std::size_t i = 0; i < sizeof(int); i++)
@@ -102,10 +102,12 @@ void CEXIEthernetTCP::ReadThreadHandler(CEXIEthernetTCP* self)
selector.add(*self->m_socket);
// are we currently waiting for size (4 bytes) or payload?
enum { StateSize, StatePayload } state = StateSize;
enum class SocketState { Size, Payload };
SocketState state { SocketState::Size };
// buffer to store size temporarily
u8 sizeBuffer[sizeof(int)];
u8 size_buffer[sizeof(int)];
// how much of size or payload have we already received?
std::size_t offset = 0;
@@ -123,9 +125,9 @@ void CEXIEthernetTCP::ReadThreadHandler(CEXIEthernetTCP* self)
switch (state)
{
case StateSize:
case SocketState::Size:
// try to read remaining bytes for size
status = self->m_socket->receive(&sizeBuffer + offset, sizeof(int) - offset, received);
status = self->m_socket->receive(&size_buffer + offset, sizeof(int) - offset, received);
if (status != sf::Socket::Done)
{
ERROR_LOG(SP1, "Receiving failed %i", status);
@@ -143,7 +145,7 @@ void CEXIEthernetTCP::ReadThreadHandler(CEXIEthernetTCP* self)
// convert char array to size int
size = 0;
for(int i = 0; i < sizeof(int); i++)
size |= sizeBuffer[i] << (i * 8);
size |= size_buffer[i] << (i * 8);
DEBUG_LOG(SP1, "Finished size %i", size);
@@ -153,8 +155,9 @@ void CEXIEthernetTCP::ReadThreadHandler(CEXIEthernetTCP* self)
return;
}
state = StatePayload;
case StatePayload:
state = SocketState::Payload;
// [[fallthough]]
case SocketState::Payload:
// try to read remaining bytes for payload
status = self->m_socket->receive(self->m_recv_buffer.get() + offset, size - offset, received);
if (status != sf::Socket::Done)
@@ -179,7 +182,7 @@ void CEXIEthernetTCP::ReadThreadHandler(CEXIEthernetTCP* self)
self->RecvHandlePacket();
}
state = StateSize;
state = SocketState::Size;
}
}

View File

@@ -7,7 +7,7 @@
#include <thread>
#include "Common/Flag.h"
#include "EXI_DeviceEthernetBase.h"
#include "Core/HW/EXI/EXI_DeviceEthernetBase.h"
namespace sf { class TcpSocket; }

View File

@@ -14,8 +14,7 @@
BBAClient::BBAClient(QTcpSocket &socket, BBAServer &server) :
QObject(&server),
m_socket(socket),
m_server(server),
m_state(SocketState::Size)
m_server(server)
{
m_socket.setParent(this);
connect(&m_socket, &QIODevice::readyRead, this, &BBAClient::ReadyRead);
@@ -35,9 +34,9 @@ BBADebug BBAClient::LogInfo()
void BBAClient::SendMessage(const QByteArray &buffer)
{
{
QDataStream dataStream(&m_socket);
dataStream.setByteOrder(QDataStream::LittleEndian);
dataStream << buffer.size();
QDataStream data_stream(&m_socket);
data_stream.setByteOrder(QDataStream::LittleEndian);
data_stream << buffer.size();
}
m_socket.write(buffer);
}

View File

@@ -39,6 +39,6 @@ private:
BBAServer &m_server;
QByteArray m_buffer;
SocketState m_state;
SocketState m_state { SocketState::Size };
int m_size;
};

View File

@@ -65,11 +65,6 @@ QHostAddress BBAServer::ServerAddress() const
return m_server.serverAddress();
}
//QAbstractSocket::SocketError BbaServer::ServerError() const
//{
// return m_server.serverError();
//}
QString BBAServer::ErrorString() const
{
return m_server.errorString();
@@ -86,9 +81,9 @@ void BBAServer::ResumeAccepting()
}
#ifndef QT_NO_NETWORKPROXY
void BBAServer::SetProxy(const QNetworkProxy &networkProxy)
void BBAServer::SetProxy(const QNetworkProxy &network_proxy)
{
m_server.setProxy(networkProxy);
m_server.setProxy(network_proxy);
}
QNetworkProxy BBAServer::Proxy() const
@@ -124,11 +119,11 @@ void BBAServer::NewConnection()
if (!socket)
return;
auto client = new BBAClient(*socket, *this);
for(auto otherClient : m_clients)
auto* client = new BBAClient(*socket, *this);
for(auto* other_client : m_clients)
{
connect(client, &BBAClient::ReceivedMessage, otherClient, &BBAClient::SendMessage);
connect(otherClient, &BBAClient::ReceivedMessage, client, &BBAClient::SendMessage);
connect(client, &BBAClient::ReceivedMessage, other_client, &BBAClient::SendMessage);
connect(other_client, &BBAClient::ReceivedMessage, client, &BBAClient::SendMessage);
}
if (m_timer_id == -1)
m_timer_id = startTimer(1000);

View File

@@ -33,14 +33,13 @@ public:
quint16 ServerPort() const;
QHostAddress ServerAddress() const;
//QAbstractSocket::SocketError ServerError() const; // can't be forward declared
QString ErrorString() const;
void PauseAccepting();
void ResumeAccepting();
#ifndef QT_NO_NETWORKPROXY
void SetProxy(const QNetworkProxy &networkProxy);
void SetProxy(const QNetworkProxy &network_proxy);
QNetworkProxy Proxy() const;
#endif

View File

@@ -22,12 +22,12 @@ BBAServerWindow::BBAServerWindow(QWidget *parent) :
QDialog(parent),
m_server(this)
{
auto vbox_layout = new QVBoxLayout(this);
auto* vbox_layout = new QVBoxLayout(this);
{
auto hbox_layout = new QHBoxLayout;
auto* hbox_layout = new QHBoxLayout;
auto host_addr_label = new QLabel(tr("Host address:"), this);
auto* host_addr_label = new QLabel(tr("Host address:"), this);
hbox_layout->addWidget(host_addr_label);
m_host_addr = new QLineEdit(this);
@@ -35,7 +35,7 @@ BBAServerWindow::BBAServerWindow(QWidget *parent) :
m_host_addr->setPlaceholderText(tr("Leave empty for Any"));
hbox_layout->addWidget(m_host_addr);
auto port_label = new QLabel(tr("Port:"), this);
auto* port_label = new QLabel(tr("Port:"), this);
hbox_layout->addWidget(port_label);
m_port = new QSpinBox(this);
@@ -57,7 +57,7 @@ BBAServerWindow::BBAServerWindow(QWidget *parent) :
vbox_layout->addWidget(m_log_output, 1);
{
auto button_box = new QDialogButtonBox(QDialogButtonBox::Close, this);
auto* button_box = new QDialogButtonBox(QDialogButtonBox::Close, this);
connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
vbox_layout->addWidget(button_box, 1);
}
@@ -87,8 +87,8 @@ void BBAServerWindow::Toggle()
void BBAServerWindow::LogOutput(const QDateTime &timestamp, const QString &log_line)
{
m_log_output->appendPlainText(QStringLiteral("%0: %1").arg(timestamp.toString(QStringLiteral("HH:mm:ss.zzz")), log_line));
auto scrollBar = m_log_output->verticalScrollBar();
scrollBar->setValue(scrollBar->maximum());
auto* scroll_bar = m_log_output->verticalScrollBar();
scroll_bar->setValue(scroll_bar->maximum());
}
void BBAServerWindow::Update()

View File

@@ -5,6 +5,10 @@ message(STATUS "Found Qt version ${Qt5Core_VERSION}")
set(CMAKE_AUTOMOC ON)
add_library(bbaserverlib BBAClient.cpp BBADebug.cpp BBAServer.cpp)
target_link_libraries(bbaserverlib PUBLIC Qt5::Core PRIVATE Qt5::Network)
add_executable(dolphin-emu
AboutDialog.cpp
BBAServerWindow.cpp
@@ -244,8 +248,4 @@ endif()
add_executable(bbaserver BBAServer_main.cpp)
target_link_libraries(bbaserver Qt5::Core Qt5::Network bbaserverlib)
add_library(bbaserverlib BBAClient.cpp BBADebug.cpp BBAServer.cpp)
target_link_libraries(bbaserverlib PUBLIC Qt5::Core PRIVATE Qt5::Network)
target_link_libraries(bbaserver PRIVATE Qt5::Core Qt5::Network bbaserverlib)

View File

@@ -16,21 +16,19 @@
#include "Common/Network.h"
BBAConfigWidget::BBAConfigWidget(bool showServer, QWidget* parent) :
QDialog(parent),
m_server(nullptr),
m_port(nullptr)
BBAConfigWidget::BBAConfigWidget(bool show_server, QWidget* parent) :
QDialog(parent)
{
setWindowTitle(tr("Broadband Adapter Configuration"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
auto vbox_layout = new QVBoxLayout(this);
auto* vbox_layout = new QVBoxLayout(this);
{
auto form_layout = new QFormLayout;
auto* form_layout = new QFormLayout;
{
auto hbox_layout = new QHBoxLayout;
auto* hbox_layout = new QHBoxLayout;
m_mac_addr = new QLineEdit(this);
m_mac_addr->setPlaceholderText(tr("Leave empty for random"));
@@ -38,7 +36,7 @@ BBAConfigWidget::BBAConfigWidget(bool showServer, QWidget* parent) :
hbox_layout->addWidget(m_mac_addr);
{
auto button = new QToolButton(this);
auto* button = new QToolButton(this);
button->setText(tr("Randomize"));
connect(button, &QAbstractButton::pressed, this, &BBAConfigWidget::GenerateMac);
hbox_layout->addWidget(button);
@@ -47,32 +45,32 @@ BBAConfigWidget::BBAConfigWidget(bool showServer, QWidget* parent) :
form_layout->addRow(tr("MAC address:"), hbox_layout);
}
if (showServer)
if (show_server)
{
auto hboxLayout = new QHBoxLayout;
auto* hbox_layout = new QHBoxLayout;
m_server = new QLineEdit(this);
hboxLayout->addWidget(m_server);
hbox_layout->addWidget(m_server);
auto portLabel = new QLabel(tr("Port:"), this);
hboxLayout->addWidget(portLabel);
auto* portLabel = new QLabel(tr("Port:"), this);
hbox_layout->addWidget(portLabel);
m_port = new QSpinBox(this);
portLabel->setBuddy(m_port);
m_port->setRange(std::numeric_limits<quint16>::min(), std::numeric_limits<quint16>::max());
hboxLayout->addWidget(m_port);
hbox_layout->addWidget(m_port);
form_layout->addRow(tr("Server:"), hboxLayout);
form_layout->addRow(tr("Server:"), hbox_layout);
}
vbox_layout->addLayout(form_layout, 1);
}
{
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &BBAConfigWidget::Submit);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
vbox_layout->addWidget(buttonBox, 1);
auto* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, this);
connect(button_box, &QDialogButtonBox::accepted, this, &BBAConfigWidget::Submit);
connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
vbox_layout->addWidget(button_box, 1);
}
setLayout(vbox_layout);

View File

@@ -13,7 +13,7 @@ class BBAConfigWidget : public QDialog {
Q_OBJECT
public:
explicit BBAConfigWidget(bool showServer, QWidget* parent = nullptr);
explicit BBAConfigWidget(bool show_server, QWidget* parent = nullptr);
QString MacAddr() const;
void SetMacAddr(const QString& mac_addr);
@@ -31,6 +31,6 @@ private slots:
private:
QLineEdit *m_mac_addr;
QLineEdit *m_server;
QSpinBox *m_port;
QLineEdit *m_server { nullptr };
QSpinBox *m_port { nullptr };
};

View File

@@ -175,9 +175,9 @@ void GameCubePane::OnConfigPressed(int slot)
QString filter;
bool memcard = false;
const auto currentData = m_slot_combos[slot]->currentData().toInt();
const auto current_data = m_slot_combos[slot]->currentData().toInt();
switch (currentData)
switch (current_data)
{
case ExpansionInterface::EXIDEVICE_MEMORYCARD:
filter = tr("GameCube Memory Cards (*.raw *.gcp)");
@@ -192,10 +192,10 @@ void GameCubePane::OnConfigPressed(int slot)
case ExpansionInterface::EXIDEVICE_ETH_TAP:
case ExpansionInterface::EXIDEVICE_ETH_TCP:
{
const auto isTcp = currentData == ExpansionInterface::EXIDEVICE_ETH_TCP;
BBAConfigWidget dialog(isTcp, this);
const auto is_tcp = current_data == ExpansionInterface::EXIDEVICE_ETH_TCP;
BBAConfigWidget dialog(is_tcp, this);
dialog.SetMacAddr(QString::fromStdString(SConfig::GetInstance().m_bba_mac));
if (isTcp)
if (is_tcp)
{
dialog.SetServer(QString::fromStdString(SConfig::GetInstance().m_bba_server));
dialog.SetPort(SConfig::GetInstance().m_bba_port);
@@ -203,7 +203,7 @@ void GameCubePane::OnConfigPressed(int slot)
if(dialog.exec() == QDialog::Accepted)
{
SConfig::GetInstance().m_bba_mac = dialog.MacAddr().toStdString();
if (isTcp)
if (is_tcp)
{
SConfig::GetInstance().m_bba_server = dialog.Server().toStdString();
SConfig::GetInstance().m_bba_port = dialog.Port();