Skip to content

Commit

Permalink
Merge pull request #10 from oblivioncth/dev
Browse files Browse the repository at this point in the history
Merge to master for v0.2
  • Loading branch information
oblivioncth committed Feb 8, 2023
2 parents afe4355 + e79fb4b commit a22c065
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-qi-qmp-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Install Doxygen
uses: oblivioncth/actions/ubuntu/install-doxygen-from-sourceforge@dev
with:
version: 1.9.5
version: 1.9.4
- name: Install Graphviz
run: sudo apt-get install graphviz
- name: Install Ninja
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option(QI_QMP_DOCS_TARGET "Build QI-QMP documentation" OFF)
# Project
# NOTE: DON'T USE TRAILING ZEROS IN VERSIONS
project(QI-QMP
VERSION 0.1.4
VERSION 0.2
LANGUAGES CXX
DESCRIPTION "Qt-based Interface for QEMU Machine Protocol"
)
Expand Down
18 changes: 10 additions & 8 deletions include/qi-qmp/qmpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ class Qmpi : public QObject
QTimer mTransactionTimer;

//-Constructor------------------------------------------------------------------------------------------------------------
private:
explicit Qmpi(quint16 port, QObject* parent);

public:
explicit Qmpi(QObject* parent = nullptr);
explicit Qmpi(const QHostAddress& address, quint16 port, QObject* parent = nullptr);
explicit Qmpi(const QString& hostname, quint16 port, QObject* parent = nullptr);

Expand Down Expand Up @@ -129,14 +127,18 @@ class Qmpi : public QObject

public:
// Info
State state() const;

// Properties
QHostAddress address() const;
QString hostname() const;
quint16 port() const;
State state() const;
int transactionTimeout() const;

// Properties
void setAddress(const QHostAddress address);
void setHostname(const QString hostname);
void setPort(quint16 port);
void setTransactionTimeout(int timeout = 30000);
int transactionTimeout() const;

// Connection
void connectToHost();
Expand All @@ -161,8 +163,8 @@ private slots:
void finished(); // Emitted when the interface is fully closed, regardless of how it got there
void responseReceived(QJsonValue value, std::any context);
void eventReceived(QString name, QJsonObject data, QDateTime timestamp);
void connectionErrorOccured(QAbstractSocket::SocketError error); // Will be disconnected after
void communicationErrorOccured(Qmpi::CommunicationError error); // Will disconnect after
void connectionErrorOccurred(QAbstractSocket::SocketError error); // Will be disconnected after
void communicationErrorOccurred(Qmpi::CommunicationError error); // Will disconnect after
void errorResponseReceived(QString errorClass, QString description, std::any context); // Will not disconnect after
void stateChanged(Qmpi::State state);
};
Expand Down
107 changes: 78 additions & 29 deletions src/qmpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,18 @@
*/

//-Constructor-------------------------------------------------------------
//Private:
Qmpi::Qmpi(quint16 port, QObject* parent) :
//Public:
/*!
* Constructs a QMP interface with parent @a parent.
*
* The connection address is set to QHostAddress::LocalHost and the port is set to 4444.
*
* @sa setAddress() and setPort().
*/
Qmpi::Qmpi(QObject* parent) :
QObject(parent),
mPort(port),
mPort(4444),
mHostId(QHostAddress::LocalHost),
mSocket(this),
mState(Disconnected)
{
Expand All @@ -129,19 +137,20 @@ Qmpi::Qmpi(quint16 port, QObject* parent) :
connect(&mTransactionTimer, &QTimer::timeout, this, &Qmpi::handleTransactionTimeout);

// Connections - Straight Forwards
connect(&mSocket, &QTcpSocket::errorOccurred, this, &Qmpi::connectionErrorOccured);
connect(&mSocket, &QTcpSocket::errorOccurred, this, &Qmpi::connectionErrorOccurred);
connect(&mSocket, &QTcpSocket::disconnected, this, &Qmpi::disconnected);
}
//Public:

/*!
* Constructs a QMP interface configured to connect to a QEMU instance at address @a address on port
* @a port. @a port is specified in native byte order.
*
* The parent of the object is set to @a parent.
*/
Qmpi::Qmpi(const QHostAddress& address, quint16 port, QObject* parent) :
Qmpi(port, parent)
Qmpi(parent)
{
mPort = port;
mHostId = address;
}

Expand All @@ -154,8 +163,9 @@ Qmpi::Qmpi(const QHostAddress& address, quint16 port, QObject* parent) :
* The parent of the object is set to @a parent.
*/
Qmpi::Qmpi(const QString& hostname, quint16 port, QObject* parent) :
Qmpi(port, parent)
Qmpi(parent)
{
mPort = port;
mHostId = hostname;
}

Expand Down Expand Up @@ -215,7 +225,7 @@ void Qmpi::reset()

void Qmpi::raiseCommunicationError(CommunicationError error)
{
emit communicationErrorOccured(error);
emit communicationErrorOccurred(error);
mSocket.abort();
}

Expand Down Expand Up @@ -474,10 +484,15 @@ bool Qmpi::processEventMessage(const QJsonObject& event)

//Public:
/*!
* Returns the IP address the interface is configured to connect to if it was constructed using a
* Returns the state of the interface.
*/
Qmpi::State Qmpi::state() const { return mState; }

/*!
* Returns the IP address the interface is configured to connect to if it was set as a
* QHostAddress; otherwise, returns QHostAddress::Null.
*
* @sa port().
* @sa setAddress() and port().
*/
QHostAddress Qmpi::address() const
{
Expand All @@ -486,10 +501,10 @@ QHostAddress Qmpi::address() const
}

/*!
* Returns the hostname the interface is configured to connect to if it was constructed using a
* Returns the hostname the interface is configured to connect to if it was set as a
* hostname; otherwise, returns a null string.
*
* @sa port().
* @sa setHostname() and port().
*/
QString Qmpi::hostname() const
{
Expand All @@ -500,14 +515,57 @@ QString Qmpi::hostname() const
/*!
* Returns the port the interface is configured to connect through.
*
* @sa address().
* @sa setPort() and address().
*/
quint16 Qmpi::port() const { return mPort; }

/*!
* Returns the state of the interface.
* Returns the transaction timeout of the interface.
*
* The default is 30,000 milliseconds.
*
* @sa setTransactionTimeout().
*/
Qmpi::State Qmpi::state() const { return mState; }
int Qmpi::transactionTimeout() const { return mTransactionTimer.interval(); }

/*!
* Sets the address of the interface to @a address.
*
* This function does nothing if the connection is currently active
*
* @sa address() and setHostname().
*/
void Qmpi::setAddress(const QHostAddress address)
{
if(!isConnectionActive())
mHostId = address;
}

/*!
* Sets the hostname of the interface to @a hostname.
*
* This function does nothing if the connection is currently active
*
* @sa hostname() and setAddress().
*/
void Qmpi::setHostname(const QString hostname)
{
if(!isConnectionActive())
mHostId = hostname;
}

/*!
* Sets the port, specified in native byte order, of the interface to @a port.
*
* This function does nothing if the connection is currently active
*
* @sa port() and setAddress().
*/
void Qmpi::setPort(quint16 port)
{
if(!isConnectionActive())
mPort = port;
}

/*!
* Sets the transaction timeout of the interface to @a timeout.
Expand All @@ -518,7 +576,7 @@ Qmpi::State Qmpi::state() const { return mState; }
* The received message does not have to be a response to that particular command; any
* received message will reset the timeout, while sending additional commands will not.
*
* If a transaction timeout occurs communicationErrorOccured() will be emitted with the
* If a transaction timeout occurs communicationErrorOccurred() will be emitted with the
* value @ref TransactionTimeout. If all sent commands have been processed and the
* interface is not currently expecting any responses the timeout will not be in effect.
*
Expand All @@ -529,17 +587,8 @@ Qmpi::State Qmpi::state() const { return mState; }
void Qmpi::setTransactionTimeout(int timeout) { mTransactionTimer.setInterval(timeout); }

/*!
* Returns the transaction timeout of the interface.
*
* The default is 30,000 milliseconds.
*
* @sa setTransactionTimeout().
*/
int Qmpi::transactionTimeout() const { return mTransactionTimer.interval(); }

/*!
* Attempts to make a connection to the QEMU instance specified by address and port
* during the interface's construction.
* Attempts to make a connection to the QEMU instance via the interfaces configured
* address and port.
*
* The interface's state immediately changes to @ref Connecting, followed by
* @ref AwaitingWelcome if the underlying socket successfully establishes a connection.
Expand Down Expand Up @@ -805,7 +854,7 @@ void Qmpi::handleTransactionTimeout() { raiseCommunicationError(CommunicationErr
*/

/*!
* @fn void Qmpi::connectionErrorOccured(QAbstractSocket::SocketError error)
* @fn void Qmpi::connectionErrorOccurred(QAbstractSocket::SocketError error)
*
* This signal is emitted when the underlying socket experiences a connection error, with @a error
* containing the type of error.
Expand All @@ -815,7 +864,7 @@ void Qmpi::handleTransactionTimeout() { raiseCommunicationError(CommunicationErr
*/

/*!
* @fn void Qmpi::communicationErrorOccured(Qmpi::CommunicationError error)
* @fn void Qmpi::communicationErrorOccurred(Qmpi::CommunicationError error)
*
* This signal is emitted when IO with the server fails, the known QMP protocol is violated during communication,
* or the server otherwise behaves unexpectedly. @a error contains the type of communication error.
Expand Down

0 comments on commit a22c065

Please sign in to comment.