mirror of https://github.com/f1xpl/openauto.git
Handle invalid IP address
parent
f77cbca876
commit
991f31bc77
|
@ -28,13 +28,14 @@ public:
|
|||
signals:
|
||||
void connectToDevice(const QString& ipAddress);
|
||||
void connectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket);
|
||||
void connectionFailed();
|
||||
void connectionFailed(const QString& message);
|
||||
|
||||
private slots:
|
||||
void onConnectButtonClicked();
|
||||
void onConnectionFailed();
|
||||
void onConnectionFailed(const QString& message);
|
||||
void onConnectionSucceed();
|
||||
void setControlsEnabledStatus(bool status);
|
||||
void connectHandler(const boost::system::error_code& ec, aasdk::tcp::ITCPEndpoint::SocketPointer socket);
|
||||
|
||||
private:
|
||||
boost::asio::io_service& ioService_;
|
||||
|
|
|
@ -37,17 +37,28 @@ void ConnectDialog::onConnectButtonClicked()
|
|||
|
||||
const auto& ipAddress = ui_->lineEditIPAddress->text().toStdString();
|
||||
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
|
||||
tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, [this, socket](auto ec) mutable {
|
||||
if(!ec)
|
||||
{
|
||||
emit connectionSucceed(std::move(socket));
|
||||
this->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit connectionFailed();
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, std::bind(&ConnectDialog::connectHandler, this, std::placeholders::_1, socket));
|
||||
}
|
||||
catch(const boost::system::system_error& se)
|
||||
{
|
||||
emit connectionFailed(QString(se.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectDialog::connectHandler(const boost::system::error_code& ec, aasdk::tcp::ITCPEndpoint::SocketPointer socket)
|
||||
{
|
||||
if(!ec)
|
||||
{
|
||||
emit connectionSucceed(std::move(socket));
|
||||
this->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit connectionFailed(QString::fromStdString(ec.message()));
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectDialog::onConnectionSucceed()
|
||||
|
@ -55,11 +66,11 @@ void ConnectDialog::onConnectionSucceed()
|
|||
this->setControlsEnabledStatus(true);
|
||||
}
|
||||
|
||||
void ConnectDialog::onConnectionFailed()
|
||||
void ConnectDialog::onConnectionFailed(const QString& message)
|
||||
{
|
||||
this->setControlsEnabledStatus(true);
|
||||
|
||||
QMessageBox errorMessage(QMessageBox::Critical, "Error", "Connection failed.", QMessageBox::Ok);
|
||||
QMessageBox errorMessage(QMessageBox::Critical, "Connect error", message, QMessageBox::Ok);
|
||||
errorMessage.setWindowFlags(Qt::WindowStaysOnTopHint);
|
||||
errorMessage.exec();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue