Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+129
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* VapixConfig configurates Axis Cameras through Axis HTTP API Vapix
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Terrell Scharfenberg, SLSE, 2016-05-27
|
||||
*/
|
||||
|
||||
#include "vapixconfig.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "httprequesthandler.h"
|
||||
#include "request.h"
|
||||
#include <QDebug>
|
||||
#include <QUrl>
|
||||
|
||||
namespace VapixConfig
|
||||
{
|
||||
VapixConfig::VapixConfig(QNetworkAccessManager *networkAccessManager, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_networkAccessManager(networkAccessManager)
|
||||
, m_requestHandler(new HTTPRequestHandler)
|
||||
, m_config(new Config)
|
||||
{
|
||||
// connect(m_networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
|
||||
}
|
||||
|
||||
VapixConfig::~VapixConfig()
|
||||
{
|
||||
delete m_requestHandler;
|
||||
delete m_config;
|
||||
}
|
||||
|
||||
// Init is needed to set the required parameter like ip,password and username.
|
||||
void VapixConfig::init(const QString &ip, const QString &password, const QString &username)
|
||||
{
|
||||
m_ip = ip;
|
||||
m_password = password;
|
||||
m_username = username;
|
||||
|
||||
m_requestHandler->init(ip, password, username);
|
||||
|
||||
connect(this, &VapixConfig::setConfigFinished, this, &VapixConfig::startNextRequest);
|
||||
connect(this, &VapixConfig::setConfigError, this, &VapixConfig::configError);
|
||||
}
|
||||
// Gets the current configuration for initialized camera
|
||||
void VapixConfig::getConfig()
|
||||
{
|
||||
const QVector<QString> tempList({QLatin1String("Image"),
|
||||
QLatin1String("Motion"),
|
||||
QLatin1String("EventServers"),
|
||||
QLatin1String("Event"),
|
||||
QLatin1String("Event.*.Actions")});
|
||||
m_config->init();
|
||||
for (const QString ¶mName : tempList)
|
||||
{
|
||||
const QVector<QMap<QString,QString>> paramList = m_requestHandler->getParams(paramName, m_networkAccessManager);
|
||||
typedef QMap<QString,QString> strMap;
|
||||
for (const strMap &map : paramList)
|
||||
m_config->addElementToXml(map, paramName);
|
||||
}
|
||||
}
|
||||
// to save the configuration to a XML
|
||||
void VapixConfig::saveConfig(const QString &savePath)
|
||||
{
|
||||
m_config->saveConfig(savePath);
|
||||
}
|
||||
|
||||
void VapixConfig::resetConfig()
|
||||
{
|
||||
const QVector<QString> paramList({QLatin1String("Motion"),
|
||||
QLatin1String("EventServers.TCP"),
|
||||
QLatin1String("Event")});
|
||||
for (const QString ¶mName : paramList)
|
||||
m_requestHandler->removeParams(paramName, m_networkAccessManager);
|
||||
qDebug() << "Parameter resetted!";
|
||||
}
|
||||
|
||||
//Configurates initialized camera
|
||||
//TO-DO: Need to check for the right Event-ID for "Action"
|
||||
bool VapixConfig::setConfig(const QString &xmlString)
|
||||
{
|
||||
int ID = 0;
|
||||
if (!m_config->processConfig(xmlString))
|
||||
{
|
||||
emit setConfigError(QLatin1String("+++Error while setting config+++"));
|
||||
return false;
|
||||
}
|
||||
// fill queue with urls
|
||||
for (const auto &map : m_config->getImageList())
|
||||
m_requestQueue.enqueue(Request::updateImageParams(map, m_ip));
|
||||
for (const auto &map : m_config->getServerList())
|
||||
m_requestQueue.enqueue(Request::addEventServer(map, m_ip));
|
||||
for (const auto &map : m_config->getWindowList())
|
||||
m_requestQueue.enqueue(Request::addMotionWindow(map, m_ip));
|
||||
for (const auto &map : m_config->getEventList())
|
||||
m_requestQueue.enqueue(Request::addEvent(map, m_ip));
|
||||
for (const auto &map : m_config->getActionList())
|
||||
m_requestQueue.enqueue(Request::addActionToEvent(map, ID, m_ip));
|
||||
return true;
|
||||
}
|
||||
// dequeues the QQueue and send requests to camera in this recursive method
|
||||
void VapixConfig::startNextRequest()
|
||||
{
|
||||
if (m_requestQueue.isEmpty())
|
||||
{
|
||||
qDebug() << "All requests done!";
|
||||
emit requestsFinished();
|
||||
return;
|
||||
}
|
||||
QUrl requestUrl;
|
||||
requestUrl.setUrl(m_requestQueue.dequeue());
|
||||
requestUrl.setUserName(m_username);
|
||||
requestUrl.setPassword(m_password);
|
||||
m_requestHandler->sendRequest(requestUrl, m_networkAccessManager);
|
||||
startNextRequest();
|
||||
|
||||
}
|
||||
void VapixConfig::startRequests()
|
||||
{
|
||||
emit setConfigFinished();
|
||||
}
|
||||
|
||||
void VapixConfig::configError(const QString &error)
|
||||
{
|
||||
qDebug() << error;
|
||||
}
|
||||
} // namespace VapixConfig
|
||||
Reference in new issue
Block a user