added documentation for network manager
This commit is contained in:
parent
6e93853830
commit
acdd57cfff
@ -43,8 +43,10 @@
|
||||
\value HardwareResourceTimer
|
||||
Refers to the global timer managed by the \l{DeviceManager}. Plugins should not create their own timers,
|
||||
but rather request the global timer using the hardware resources.
|
||||
\value HardwareResourceNetworkManager
|
||||
Allows to send network requests and receive replies.
|
||||
\value HardwareResourceUpnpDisovery
|
||||
Allowes plugins to search a UPnP devices in the network.
|
||||
Allowes to search a UPnP devices in the network.
|
||||
*/
|
||||
|
||||
/*! \enum DeviceManager::DeviceError
|
||||
|
||||
@ -16,16 +16,45 @@
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class NetworkManager
|
||||
\brief Allows to send network requests and receive replies.
|
||||
|
||||
\ingroup hardware
|
||||
\inmodule libguh
|
||||
|
||||
The network manager class is a reimplementation of the \l{http://doc-snapshot.qt-project.org/qt5-5.4/qnetworkaccessmanager.html}{QNetworkAccessManager}
|
||||
and allows plugins to send network requests and receive replies.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \fn NetworkManager::replyReady(const PluginId &pluginId, QNetworkReply *reply)
|
||||
* This signal will be emitted whenever a pending network \a reply for the plugin with the given \a pluginId is finished.
|
||||
*
|
||||
* \sa DevicePlugin::networkManagerReplyReady()
|
||||
*/
|
||||
|
||||
#include "networkmanager.h"
|
||||
|
||||
/*! Construct the hardware resource NetworkManager with the given \a parent. */
|
||||
NetworkManager::NetworkManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
m_manager = new QNetworkAccessManager(this);
|
||||
|
||||
connect(m_manager, &QNetworkAccessManager::finished, this, &NetworkManager::replyFinished);
|
||||
|
||||
qDebug() << "--> Network manager created successfully.";
|
||||
}
|
||||
|
||||
/*! Posts a request to obtain the contents of the target \a request from the plugin with the given \a pluginId
|
||||
* and returns a new QNetworkReply object opened for reading which emits the replyReady() signal whenever new
|
||||
* data arrives.
|
||||
* The contents as well as associated headers will be downloaded.
|
||||
*
|
||||
* \note The plugin has to delete the QNetworkReply with the function deleteLater().
|
||||
*
|
||||
* \sa DevicePlugin::networkManagerGet()
|
||||
*/
|
||||
QNetworkReply *NetworkManager::get(const PluginId &pluginId, const QNetworkRequest &request)
|
||||
{
|
||||
QNetworkReply *reply = m_manager->get(request);
|
||||
@ -33,6 +62,14 @@ QNetworkReply *NetworkManager::get(const PluginId &pluginId, const QNetworkReque
|
||||
return reply;
|
||||
}
|
||||
|
||||
/*! Sends an HTTP POST request to the destination specified by \a request from the plugin with the given
|
||||
* \a pluginId and returns a new QNetworkReply object opened for reading that will contain the reply sent
|
||||
* by the server. The contents of the \a data will be uploaded to the server.
|
||||
*
|
||||
* \note The plugin has to delete the QNetworkReply with the function deleteLater().
|
||||
*
|
||||
* \sa DevicePlugin::networkManagerPost()
|
||||
*/
|
||||
QNetworkReply *NetworkManager::post(const PluginId &pluginId, const QNetworkRequest &request, const QByteArray &data)
|
||||
{
|
||||
QNetworkReply *reply = m_manager->post(request, data);
|
||||
@ -40,6 +77,13 @@ QNetworkReply *NetworkManager::post(const PluginId &pluginId, const QNetworkRequ
|
||||
return reply;
|
||||
}
|
||||
|
||||
/*! Uploads the contents of \a data to the destination \a request from the plugin with the given
|
||||
* \a pluginId and returnes a new QNetworkReply object that will be open for reply.
|
||||
*
|
||||
* \note The plugin has to delete the QNetworkReply with the function deleteLater().
|
||||
*
|
||||
* \sa DevicePlugin::networkManagerPut()
|
||||
*/
|
||||
QNetworkReply *NetworkManager::put(const PluginId &pluginId, const QNetworkRequest &request, const QByteArray &data)
|
||||
{
|
||||
QNetworkReply *reply = m_manager->put(request, data);
|
||||
|
||||
@ -60,6 +60,12 @@
|
||||
\sa UpnpDiscovery
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn DevicePlugin::networkManagerReplyReady(QNetworkReply *reply)
|
||||
This method will be called whenever a pending network \a reply for this plugin is finished.
|
||||
\sa NetworkManager::replyReady()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void DevicePlugin::executeAction(Device *device, const Action &action)
|
||||
This will be called to actually execute actions on the hardware. The \{Device} and
|
||||
@ -518,7 +524,14 @@ bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*! Posts a request to obtain the contents of the target \a request and returns a new QNetworkReply object
|
||||
* opened for reading which emits the replyReady() signal whenever new data arrives.
|
||||
* The contents as well as associated headers will be downloaded.
|
||||
*
|
||||
* \note The plugin has to delete the QNetworkReply with the function deleteLater().
|
||||
*
|
||||
* \sa NetworkManager::get()
|
||||
*/
|
||||
QNetworkReply *DevicePlugin::networkManagerGet(const QNetworkRequest &request)
|
||||
{
|
||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
||||
@ -528,7 +541,14 @@ QNetworkReply *DevicePlugin::networkManagerGet(const QNetworkRequest &request)
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*! Sends an HTTP POST request to the destination specified by \a request and returns a new QNetworkReply object
|
||||
* opened for reading that will contain the reply sent by the server. The contents of the \a data will be
|
||||
* uploaded to the server.
|
||||
*
|
||||
* \note The plugin has to delete the QNetworkReply with the function deleteLater().
|
||||
*
|
||||
* \sa NetworkManager::post()
|
||||
*/
|
||||
QNetworkReply *DevicePlugin::networkManagerPost(const QNetworkRequest &request, const QByteArray &data)
|
||||
{
|
||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
||||
@ -539,6 +559,12 @@ QNetworkReply *DevicePlugin::networkManagerPost(const QNetworkRequest &request,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*! Uploads the contents of \a data to the destination \a request and returnes a new QNetworkReply object that will be open for reply.
|
||||
*
|
||||
* \note The plugin has to delete the QNetworkReply with the function deleteLater().
|
||||
*
|
||||
* \sa NetworkManager::put()
|
||||
*/
|
||||
QNetworkReply *DevicePlugin::networkManagerPut(const QNetworkRequest &request, const QByteArray &data)
|
||||
{
|
||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
||||
|
||||
Reference in New Issue
Block a user