Sync::Sync(ConnectionInfo info) //info contains ip address and user auth
{
p = new SyncPrivate;
p->mManager = new QNetworkAccessManager(this);
connect(p->mManager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
SLOT(authenticate(QNetworkReply*, QAuthenticator*)));
p->mIpAddress = info.remoteIP();
switch(info.userLevel()) {
//UserAuth info here
}
p->mPassword = info.password();
}
void ControllerListEntry::on_actionStop_Monitoring_All_Nodes_triggered()
{
if (mSync != 0)
return;
mSync = new Sync(mController->connectionInfo());
connect(mSync, SIGNAL(finished()), this, SLOT(stopMonitoringAllNodesFinished()));
foreach(Node *mNode, mController->getNodes()){ //Looping through all nodes
if(!mSync->setMonitoring(mNode, false))
break;
}
}
void ControllerListEntry::on_actionStart_Monitoring_All_Nodes_triggered()
{
if (mSync != 0)
return;
mSync = new Sync(mController->connectionInfo());
connect(mSync, SIGNAL(finished()), this, SLOT(startMonitoringAllNodesFinished()));
foreach(Node *mNode, mController->getNodes()){ //Looping through all nodes
if(!mSync->setMonitoring(mNode, true))
break;
}
}
//For each iteration of the previous loop, the following method is called:
bool Sync::setMonitoring(Node n, bool enabled)
{
QNetworkRequest req
(QUrl("http://" + p
->mIpAddress
+ "/rpc/set-monitoring"));
req.
setAttribute(QNetworkRequest
::HttpPipeliningAllowedAttribute,
QVariant(true));
QByteArray postReq
= "nodename=" + encode
(n
->getName
());
postReq
+= "&monitoring=" + QByteArray(enabled ?
"true" : "false");
p->mBusy = true;
p->mReply = p->mManager->post(req, postReq);
connect(p->mReply, SIGNAL(finished()), SLOT(replyFinished()));
return true;
}
//For completeness sake
void Sync::replyFinished()
{
p->mReply->deleteLater();
p->mBusy = false;
// Check for errors.
if (p->mReply->error() != QNetworkReply::NoError) {
emit error(p->mReply->errorString()); //will call slot showing error message
return;
}
emit finished(); //ControllerListEntry will do some ui stuff
}
Sync::Sync(ConnectionInfo info) //info contains ip address and user auth
{
p = new SyncPrivate;
p->mManager = new QNetworkAccessManager(this);
connect(p->mManager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
SLOT(authenticate(QNetworkReply*, QAuthenticator*)));
p->mIpAddress = info.remoteIP();
switch(info.userLevel()) {
//UserAuth info here
}
p->mPassword = info.password();
}
void ControllerListEntry::on_actionStop_Monitoring_All_Nodes_triggered()
{
if (mSync != 0)
return;
mSync = new Sync(mController->connectionInfo());
connect(mSync, SIGNAL(finished()), this, SLOT(stopMonitoringAllNodesFinished()));
foreach(Node *mNode, mController->getNodes()){ //Looping through all nodes
if(!mSync->setMonitoring(mNode, false))
break;
}
}
void ControllerListEntry::on_actionStart_Monitoring_All_Nodes_triggered()
{
if (mSync != 0)
return;
mSync = new Sync(mController->connectionInfo());
connect(mSync, SIGNAL(finished()), this, SLOT(startMonitoringAllNodesFinished()));
foreach(Node *mNode, mController->getNodes()){ //Looping through all nodes
if(!mSync->setMonitoring(mNode, true))
break;
}
}
//For each iteration of the previous loop, the following method is called:
bool Sync::setMonitoring(Node n, bool enabled)
{
QNetworkRequest req(QUrl("http://" + p->mIpAddress + "/rpc/set-monitoring"));
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, QVariant(true));
QByteArray postReq = "nodename=" + encode(n->getName());
postReq += "&monitoring=" + QByteArray(enabled ? "true" : "false");
p->mBusy = true;
p->mReply = p->mManager->post(req, postReq);
connect(p->mReply, SIGNAL(finished()), SLOT(replyFinished()));
return true;
}
//For completeness sake
void Sync::replyFinished()
{
p->mReply->deleteLater();
p->mBusy = false;
// Check for errors.
if (p->mReply->error() != QNetworkReply::NoError) {
emit error(p->mReply->errorString()); //will call slot showing error message
return;
}
emit finished(); //ControllerListEntry will do some ui stuff
}
To copy to clipboard, switch view to plain text mode
Bookmarks