2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portgroup.h"
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
2016-03-11 07:28:08 -06:00
|
|
|
#include "emulproto.pb.h"
|
2016-04-13 21:14:07 -05:00
|
|
|
#include "fileformat.pb.h"
|
2016-03-11 07:28:08 -06:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QCursor>
|
2016-06-23 10:06:35 -05:00
|
|
|
#include <QDesktopServices>
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QProcess>
|
2016-06-23 10:06:35 -05:00
|
|
|
#include <QRegExp>
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QtGlobal>
|
2016-06-23 10:06:35 -05:00
|
|
|
#include <QUrl>
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
using ::google::protobuf::NewCallback;
|
|
|
|
|
|
|
|
extern QMainWindow *mainWindow;
|
|
|
|
extern char *version;
|
|
|
|
|
|
|
|
quint32 PortGroup::mPortGroupAllocId = 0;
|
|
|
|
|
2015-11-06 07:27:07 -06:00
|
|
|
PortGroup::PortGroup(QString serverName, quint16 port)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
// Allocate an id for self
|
|
|
|
mPortGroupId = PortGroup::mPortGroupAllocId++;
|
|
|
|
|
|
|
|
portIdList_ = new OstProto::PortIdList;
|
|
|
|
portStatsList_ = new OstProto::PortStatsList;
|
|
|
|
|
|
|
|
statsController = new PbRpcController(portIdList_, portStatsList_);
|
|
|
|
isGetStatsPending_ = false;
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
atConnectConfig_ = NULL;
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
compat = kUnknown;
|
|
|
|
|
|
|
|
reconnect = false;
|
|
|
|
reconnectAfter = kMinReconnectWaitTime;
|
|
|
|
reconnectTimer = new QTimer(this);
|
|
|
|
reconnectTimer->setSingleShot(true);
|
|
|
|
connect(reconnectTimer, SIGNAL(timeout()),
|
|
|
|
this, SLOT(on_reconnectTimer_timeout()));
|
|
|
|
|
2015-11-06 07:27:07 -06:00
|
|
|
rpcChannel = new PbRpcChannel(serverName, port,
|
2015-04-25 09:42:37 -05:00
|
|
|
OstProto::Notification::default_instance());
|
2015-04-16 11:50:07 -05:00
|
|
|
serviceStub = new OstProto::OstService::Stub(rpcChannel);
|
|
|
|
|
|
|
|
// FIXME(LOW):Can't for my life figure out why this ain't working!
|
|
|
|
//QMetaObject::connectSlotsByName(this);
|
|
|
|
connect(rpcChannel, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
|
|
|
|
this, SLOT(on_rpcChannel_stateChanged(QAbstractSocket::SocketState)));
|
|
|
|
connect(rpcChannel, SIGNAL(connected()),
|
|
|
|
this, SLOT(on_rpcChannel_connected()));
|
|
|
|
connect(rpcChannel, SIGNAL(disconnected()),
|
|
|
|
this, SLOT(on_rpcChannel_disconnected()));
|
|
|
|
connect(rpcChannel, SIGNAL(error(QAbstractSocket::SocketError)),
|
|
|
|
this, SLOT(on_rpcChannel_error(QAbstractSocket::SocketError)));
|
|
|
|
|
2015-04-24 10:23:00 -05:00
|
|
|
connect(rpcChannel,
|
|
|
|
SIGNAL(notification(int, ::google::protobuf::Message*)),
|
|
|
|
this,
|
|
|
|
SLOT(on_rpcChannel_notification(int, ::google::protobuf::Message*)));
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
connect(this, SIGNAL(portListChanged(quint32)),
|
|
|
|
this, SLOT(when_portListChanged(quint32)), Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
PortGroup::~PortGroup()
|
|
|
|
{
|
|
|
|
qDebug("PortGroup Destructor");
|
|
|
|
// Disconnect and free rpc channel etc.
|
|
|
|
PortGroup::disconnectFromHost();
|
|
|
|
delete serviceStub;
|
|
|
|
delete rpcChannel;
|
|
|
|
delete statsController;
|
2016-04-13 21:14:07 -05:00
|
|
|
delete atConnectConfig_;
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
void PortGroup::setConfigAtConnect(const OstProto::PortGroupContent *config)
|
|
|
|
{
|
|
|
|
if (!config) {
|
|
|
|
delete atConnectConfig_;
|
|
|
|
atConnectConfig_ = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!atConnectConfig_)
|
2016-05-09 08:07:42 -05:00
|
|
|
atConnectConfig_ = new OstProto::PortGroupContent;
|
2016-04-13 21:14:07 -05:00
|
|
|
atConnectConfig_->CopyFrom(*config);
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-05-06 10:54:36 -05:00
|
|
|
int PortGroup::numReservedPorts() const
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
for (int i = 0; i < mPorts.size(); i++)
|
|
|
|
{
|
|
|
|
if (!mPorts[i]->userName().isEmpty())
|
|
|
|
count++;
|
|
|
|
}
|
2016-05-10 09:56:48 -05:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString PortGroup::serverFullName() const
|
|
|
|
{
|
|
|
|
return serverPort() == DEFAULT_SERVER_PORT ?
|
|
|
|
serverName() : QString("%1:%2").arg(serverName()).arg(serverPort());
|
2016-05-06 10:54:36 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
// ------------------------------------------------
|
|
|
|
// Slots
|
|
|
|
// ------------------------------------------------
|
|
|
|
void PortGroup::on_reconnectTimer_timeout()
|
|
|
|
{
|
|
|
|
reconnectAfter *= 2;
|
|
|
|
if (reconnectAfter > kMaxReconnectWaitTime)
|
|
|
|
reconnectAfter = kMaxReconnectWaitTime;
|
|
|
|
|
|
|
|
connectToHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::on_rpcChannel_stateChanged(QAbstractSocket::SocketState state)
|
|
|
|
{
|
|
|
|
qDebug("state changed %d", state);
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case QAbstractSocket::UnconnectedState:
|
|
|
|
case QAbstractSocket::ClosingState:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::on_rpcChannel_connected()
|
|
|
|
{
|
|
|
|
OstProto::VersionInfo *verInfo = new OstProto::VersionInfo;
|
|
|
|
OstProto::VersionCompatibility *verCompat =
|
|
|
|
new OstProto::VersionCompatibility;
|
|
|
|
|
|
|
|
qDebug("connected\n");
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
|
|
|
|
|
|
|
reconnectAfter = kMinReconnectWaitTime;
|
|
|
|
|
|
|
|
qDebug("requesting version check ...");
|
2015-05-01 11:11:04 -05:00
|
|
|
verInfo->set_client_name("ostinato");
|
2015-04-16 11:50:07 -05:00
|
|
|
verInfo->set_version(version);
|
|
|
|
|
|
|
|
PbRpcController *controller = new PbRpcController(verInfo, verCompat);
|
|
|
|
serviceStub->checkVersion(controller, verInfo, verCompat,
|
|
|
|
NewCallback(this, &PortGroup::processVersionCompatibility,
|
|
|
|
controller));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processVersionCompatibility(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
OstProto::VersionCompatibility *verCompat
|
|
|
|
= static_cast<OstProto::VersionCompatibility*>(controller->response());
|
|
|
|
|
|
|
|
Q_ASSERT(verCompat != NULL);
|
|
|
|
|
|
|
|
qDebug("got version result ...");
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verCompat->result() == OstProto::VersionCompatibility::kIncompatible) {
|
|
|
|
qWarning("incompatible version %s (%s)", version,
|
|
|
|
qPrintable(QString::fromStdString(verCompat->notes())));
|
|
|
|
compat = kIncompatible;
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
|
|
|
goto _error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
compat = kCompatible;
|
|
|
|
|
|
|
|
{
|
|
|
|
OstProto::Void *void_ = new OstProto::Void;
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
|
|
|
|
qDebug("requesting portlist ...");
|
|
|
|
PbRpcController *controller = new PbRpcController(void_, portIdList);
|
|
|
|
serviceStub->getPortIdList(controller, void_, portIdList,
|
|
|
|
NewCallback(this, &PortGroup::processPortIdList, controller));
|
|
|
|
}
|
|
|
|
|
|
|
|
_error_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::on_rpcChannel_disconnected()
|
|
|
|
{
|
|
|
|
qDebug("disconnected\n");
|
|
|
|
emit portListAboutToBeChanged(mPortGroupId);
|
|
|
|
|
|
|
|
while (!mPorts.isEmpty())
|
|
|
|
delete mPorts.takeFirst();
|
2016-05-05 08:43:00 -05:00
|
|
|
atConnectPortConfig_.clear();
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
emit portListChanged(mPortGroupId);
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
|
|
|
|
|
|
|
isGetStatsPending_ = false;
|
|
|
|
|
|
|
|
if (reconnect)
|
|
|
|
{
|
|
|
|
qDebug("starting reconnect timer for %d ms ...", reconnectAfter);
|
|
|
|
reconnectTimer->start(reconnectAfter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::on_rpcChannel_error(QAbstractSocket::SocketError socketError)
|
|
|
|
{
|
|
|
|
qDebug("%s: error %d", __FUNCTION__, socketError);
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
|
|
|
|
|
|
|
if (socketError == QAbstractSocket::RemoteHostClosedError)
|
|
|
|
reconnect = false;
|
|
|
|
|
|
|
|
qDebug("%s: state %d", __FUNCTION__, rpcChannel->state());
|
|
|
|
if ((rpcChannel->state() == QAbstractSocket::UnconnectedState) && reconnect)
|
|
|
|
{
|
|
|
|
qDebug("starting reconnect timer for %d ms...", reconnectAfter);
|
|
|
|
reconnectTimer->start(reconnectAfter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 10:23:00 -05:00
|
|
|
void PortGroup::on_rpcChannel_notification(int notifType,
|
|
|
|
::google::protobuf::Message *notification)
|
|
|
|
{
|
|
|
|
OstProto::Notification *notif =
|
|
|
|
dynamic_cast<OstProto::Notification*>(notification);
|
|
|
|
|
|
|
|
if (!notif) {
|
|
|
|
qWarning("unable to dynamic cast notif");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notifType != notif->notif_type()) {
|
|
|
|
qWarning("notif type mismatch %d/%d msg = %s",
|
|
|
|
notifType, notif->notif_type(),
|
|
|
|
notification->DebugString().c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (notifType)
|
|
|
|
{
|
|
|
|
case OstProto::portConfigChanged: {
|
|
|
|
|
|
|
|
if (!notif->port_id_list().port_id_size()) {
|
|
|
|
qWarning("notif(portConfigChanged) has an empty port_id_list");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
OstProto::PortConfigList *portConfigList =
|
|
|
|
new OstProto::PortConfigList;
|
|
|
|
PbRpcController *controller = new PbRpcController(portIdList,
|
|
|
|
portConfigList);
|
|
|
|
|
|
|
|
portIdList->CopyFrom(notif->port_id_list());
|
|
|
|
serviceStub->getPortConfig(controller, portIdList, portConfigList,
|
|
|
|
NewCallback(this, &PortGroup::processUpdatedPortConfig,
|
|
|
|
controller));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void PortGroup::when_portListChanged(quint32 /*portGroupId*/)
|
|
|
|
{
|
2016-06-23 10:06:35 -05:00
|
|
|
QString faq("http://ostinato.org/docs/faq#q-port-group-has-no-interfaces");
|
2015-04-16 11:50:07 -05:00
|
|
|
if (state() == QAbstractSocket::ConnectedState && numPorts() <= 0)
|
|
|
|
{
|
2016-06-23 10:06:35 -05:00
|
|
|
if (QMessageBox::warning(NULL, tr("No ports in portgroup"),
|
2015-04-16 11:50:07 -05:00
|
|
|
QString("The portgroup %1:%2 does not contain any ports!\n\n"
|
|
|
|
"Packet Transmit/Capture requires elevated privileges. "
|
|
|
|
"Please ensure that you are running 'drone' - the server "
|
|
|
|
"component of Ostinato with admin/root OR setuid privilege.\n\n"
|
2016-06-23 10:06:35 -05:00
|
|
|
"For help see the Ostinato FAQ (%3)")
|
2015-11-06 07:27:07 -06:00
|
|
|
.arg(serverName())
|
2016-06-23 10:06:35 -05:00
|
|
|
.arg(int(serverPort()))
|
|
|
|
.arg(faq.remove(QRegExp("#.*$"))),
|
|
|
|
QMessageBox::Ok | QMessageBox::Help,
|
|
|
|
QMessageBox::Ok) == QMessageBox::Help)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(faq));
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processPortIdList(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
OstProto::PortIdList *portIdList
|
|
|
|
= static_cast<OstProto::PortIdList*>(controller->response());
|
|
|
|
|
|
|
|
Q_ASSERT(portIdList != NULL);
|
|
|
|
|
|
|
|
qDebug("got a portlist ...");
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit portListAboutToBeChanged(mPortGroupId);
|
|
|
|
|
|
|
|
for(int i = 0; i < portIdList->port_id_size(); i++)
|
|
|
|
{
|
|
|
|
Port *p;
|
|
|
|
|
|
|
|
p = new Port(portIdList->port_id(i).id(), mPortGroupId);
|
|
|
|
connect(p, SIGNAL(portDataChanged(int, int)),
|
|
|
|
this, SIGNAL(portGroupDataChanged(int, int)));
|
|
|
|
qDebug("before port append\n");
|
|
|
|
mPorts.append(p);
|
2016-05-05 08:43:00 -05:00
|
|
|
atConnectPortConfig_.append(NULL); // will be filled later
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
emit portListChanged(mPortGroupId);
|
|
|
|
|
|
|
|
portIdList_->CopyFrom(*portIdList);
|
|
|
|
|
|
|
|
// Request PortConfigList
|
|
|
|
{
|
|
|
|
qDebug("requesting port config list ...");
|
|
|
|
OstProto::PortIdList *portIdList2 = new OstProto::PortIdList();
|
|
|
|
OstProto::PortConfigList *portConfigList = new OstProto::PortConfigList();
|
|
|
|
PbRpcController *controller2 = new PbRpcController(portIdList2,
|
|
|
|
portConfigList);
|
|
|
|
|
|
|
|
portIdList2->CopyFrom(*portIdList);
|
|
|
|
|
|
|
|
serviceStub->getPortConfig(controller, portIdList2, portConfigList,
|
|
|
|
NewCallback(this, &PortGroup::processPortConfigList, controller2));
|
|
|
|
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
_error_exit:
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processPortConfigList(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
OstProto::PortConfigList *portConfigList
|
|
|
|
= static_cast<OstProto::PortConfigList*>(controller->response());
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//emit portListAboutToBeChanged(mPortGroupId);
|
|
|
|
|
|
|
|
for(int i = 0; i < portConfigList->port_size(); i++)
|
|
|
|
{
|
|
|
|
uint id;
|
|
|
|
|
|
|
|
id = portConfigList->port(i).port_id().id();
|
|
|
|
// FIXME: don't mix port id & index into mPorts[]
|
|
|
|
mPorts[id]->updatePortConfig(portConfigList->mutable_port(i));
|
|
|
|
}
|
|
|
|
|
2015-05-08 10:54:52 -05:00
|
|
|
// FIXME: Ideally we should emit portGroupDataChanged since only
|
|
|
|
// port data is changing; but writing the corresponding slot in
|
|
|
|
// PortStatsModel for that signal turned out to be very bug prone
|
|
|
|
// causing assert failures when portgroups are added/deleted or
|
|
|
|
// connected/disconnected in different orders
|
|
|
|
// TODO: Revisit this when we refactor the domain-objects/model/view
|
|
|
|
// design
|
|
|
|
emit portListChanged(mPortGroupId);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-02-05 07:36:14 -06:00
|
|
|
if (numPorts() > 0) {
|
2016-05-12 08:17:16 -05:00
|
|
|
// XXX: The open session code (atConnectConfig_ related) assumes
|
|
|
|
// the following two RPCs are invoked in the below order
|
|
|
|
// Any change here without coressponding change in that code
|
|
|
|
// will break stuff
|
2016-02-05 07:36:14 -06:00
|
|
|
getDeviceGroupIdList();
|
2016-03-10 06:50:55 -06:00
|
|
|
getStreamIdList();
|
2016-02-05 07:36:14 -06:00
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-05-05 08:43:00 -05:00
|
|
|
// Now that we have the port details, let's identify which ports
|
|
|
|
// need to be re-configured based on atConnectConfig_
|
|
|
|
if (atConnectConfig_ && numPorts() > 0)
|
|
|
|
{
|
2016-05-10 09:56:48 -05:00
|
|
|
QString myself = appSettings->value(kUserKey, kUserDefaultValue)
|
|
|
|
.toString();
|
2016-05-05 08:43:00 -05:00
|
|
|
for (int i = 0; i < atConnectConfig_->ports_size(); i++)
|
|
|
|
{
|
|
|
|
const OstProto::PortContent *pc = &atConnectConfig_->ports(i);
|
|
|
|
for (int j = 0; j < mPorts.size(); j++)
|
|
|
|
{
|
2016-05-10 09:56:48 -05:00
|
|
|
Port *port = mPorts[j];
|
|
|
|
|
|
|
|
if (port->name() == pc->port_config().name().c_str())
|
2016-05-05 08:43:00 -05:00
|
|
|
{
|
2016-05-10 09:56:48 -05:00
|
|
|
if (!port->userName().isEmpty() // rsvd?
|
|
|
|
&& port->userName() != myself) // by someone else?
|
|
|
|
{
|
|
|
|
QString warning =
|
|
|
|
QString("%1 - %2: %3 is reserved by %4.\n\n"
|
|
|
|
"Port will not be reconfigured.")
|
|
|
|
.arg(serverFullName())
|
|
|
|
.arg(j)
|
2016-05-18 08:07:48 -05:00
|
|
|
.arg(port->userAlias())
|
2016-05-10 09:56:48 -05:00
|
|
|
.arg(port->userName());
|
|
|
|
QMessageBox::warning(NULL, tr("Open Session"), warning);
|
2016-06-01 10:21:29 -05:00
|
|
|
qWarning("%s", qPrintable(warning));
|
2016-05-10 09:56:48 -05:00
|
|
|
continue;
|
|
|
|
}
|
2016-05-05 08:43:00 -05:00
|
|
|
atConnectPortConfig_[j] = pc;
|
|
|
|
qDebug("port %d will be reconfigured", j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
_error_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::when_configApply(int portIndex)
|
|
|
|
{
|
|
|
|
OstProto::StreamIdList *streamIdList;
|
|
|
|
OstProto::StreamConfigList *streamConfigList;
|
|
|
|
OstProto::Ack *ack;
|
|
|
|
PbRpcController *controller;
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < mPorts.size());
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
mainWindow->setDisabled(true);
|
|
|
|
|
2016-03-04 16:36:36 -06:00
|
|
|
// FIXME: as currently written this code will make unnecessary RPCs
|
|
|
|
// even if the request contains no data; the fix will need to take
|
|
|
|
// care to identify when sync is complete
|
2016-03-16 10:21:36 -05:00
|
|
|
// NOTE: DeviceGroup RPCs are no longer called unnecessarily;
|
|
|
|
// Stream RPCs need to be fixed similarly
|
2016-03-10 06:50:55 -06:00
|
|
|
// Also, drone currently updates its packet list at the end of
|
|
|
|
// modifyStream() implicitly assuming that will be the last API
|
|
|
|
// called - this will also need to be fixed
|
2016-03-04 16:36:36 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// Update/Sync DeviceGroups
|
|
|
|
//
|
|
|
|
OstProto::DeviceGroupIdList *deviceGroupIdList;
|
|
|
|
OstProto::DeviceGroupConfigList *deviceGroupConfigList;
|
2016-03-16 11:04:36 -05:00
|
|
|
bool refreshReqd = false;
|
2016-03-04 16:36:36 -06:00
|
|
|
|
|
|
|
qDebug("applying 'deleted deviceGroups' ...");
|
|
|
|
deviceGroupIdList = new OstProto::DeviceGroupIdList;
|
|
|
|
deviceGroupIdList->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getDeletedDeviceGroupsSinceLastSync(*deviceGroupIdList);
|
2016-03-16 10:21:36 -05:00
|
|
|
if (deviceGroupIdList->device_group_id_size()) {
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(deviceGroupIdList, ack);
|
|
|
|
serviceStub->deleteDeviceGroup(controller, deviceGroupIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processDeleteDeviceGroupAck,
|
|
|
|
controller));
|
2016-03-16 11:04:36 -05:00
|
|
|
refreshReqd = true;
|
2016-03-16 10:21:36 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
delete deviceGroupIdList;
|
2016-03-04 16:36:36 -06:00
|
|
|
|
|
|
|
qDebug("applying 'new deviceGroups' ...");
|
|
|
|
deviceGroupIdList = new OstProto::DeviceGroupIdList;
|
|
|
|
deviceGroupIdList->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getNewDeviceGroupsSinceLastSync(*deviceGroupIdList);
|
2016-03-16 10:21:36 -05:00
|
|
|
if (deviceGroupIdList->device_group_id_size()) {
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(deviceGroupIdList, ack);
|
|
|
|
serviceStub->addDeviceGroup(controller, deviceGroupIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processAddDeviceGroupAck,
|
|
|
|
controller));
|
2016-03-16 11:04:36 -05:00
|
|
|
refreshReqd = true;
|
2016-03-16 10:21:36 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
delete deviceGroupIdList;
|
2016-03-04 16:36:36 -06:00
|
|
|
|
|
|
|
qDebug("applying 'modified deviceGroups' ...");
|
|
|
|
deviceGroupConfigList = new OstProto::DeviceGroupConfigList;
|
|
|
|
deviceGroupConfigList->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getModifiedDeviceGroupsSinceLastSync(
|
|
|
|
*deviceGroupConfigList);
|
2016-03-16 10:21:36 -05:00
|
|
|
if (deviceGroupConfigList->device_group_size()) {
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(deviceGroupConfigList, ack);
|
|
|
|
serviceStub->modifyDeviceGroup(controller, deviceGroupConfigList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processModifyDeviceGroupAck,
|
|
|
|
portIndex, controller));
|
2016-03-16 11:04:36 -05:00
|
|
|
refreshReqd = true;
|
2016-03-16 10:21:36 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
delete deviceGroupConfigList;
|
2016-03-10 06:50:55 -06:00
|
|
|
|
2016-03-16 11:04:36 -05:00
|
|
|
if (refreshReqd)
|
|
|
|
getDeviceInfo(portIndex);
|
|
|
|
|
2016-03-10 06:50:55 -06:00
|
|
|
//
|
|
|
|
// Update/Sync Streams
|
|
|
|
//
|
|
|
|
qDebug("applying 'deleted streams' ...");
|
|
|
|
streamIdList = new OstProto::StreamIdList;
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(streamIdList, ack);
|
|
|
|
|
|
|
|
streamIdList->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getDeletedStreamsSinceLastSync(*streamIdList);
|
|
|
|
|
|
|
|
serviceStub->deleteStream(controller, streamIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processDeleteStreamAck, controller));
|
|
|
|
|
|
|
|
qDebug("applying 'new streams' ...");
|
|
|
|
streamIdList = new OstProto::StreamIdList;
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(streamIdList, ack);
|
|
|
|
|
|
|
|
streamIdList->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getNewStreamsSinceLastSync(*streamIdList);
|
|
|
|
|
|
|
|
serviceStub->addStream(controller, streamIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processAddStreamAck, controller));
|
|
|
|
|
|
|
|
qDebug("applying 'modified streams' ...");
|
|
|
|
streamConfigList = new OstProto::StreamConfigList;
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(streamConfigList, ack);
|
|
|
|
|
|
|
|
streamConfigList->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getModifiedStreamsSinceLastSync(*streamConfigList);
|
|
|
|
|
|
|
|
serviceStub->modifyStream(controller, streamConfigList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processModifyStreamAck,
|
|
|
|
portIndex, controller));
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2016-03-10 06:50:55 -06:00
|
|
|
void PortGroup::processAddDeviceGroupAck(PbRpcController *controller)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-03-10 06:50:55 -06:00
|
|
|
void PortGroup::processDeleteDeviceGroupAck(PbRpcController *controller)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-06-01 10:21:29 -05:00
|
|
|
void PortGroup::processModifyDeviceGroupAck(int /*portIndex*/,
|
2015-04-16 11:50:07 -05:00
|
|
|
PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
2016-03-04 16:36:36 -06:00
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-03-10 06:50:55 -06:00
|
|
|
void PortGroup::processAddStreamAck(PbRpcController *controller)
|
2016-03-04 16:36:36 -06:00
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-03-10 06:50:55 -06:00
|
|
|
void PortGroup::processDeleteStreamAck(PbRpcController *controller)
|
2016-03-04 16:36:36 -06:00
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-03-10 06:50:55 -06:00
|
|
|
void PortGroup::processModifyStreamAck(int portIndex,
|
2016-03-04 16:36:36 -06:00
|
|
|
PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
qDebug("apply completed");
|
|
|
|
mPorts[portIndex]->when_syncComplete();
|
|
|
|
|
|
|
|
mainWindow->setEnabled(true);
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-03-12 07:26:35 -06:00
|
|
|
void PortGroup::getDeviceInfo(int portIndex)
|
2016-03-11 07:28:08 -06:00
|
|
|
{
|
|
|
|
OstProto::PortId *portId;
|
|
|
|
OstProto::PortDeviceList *deviceList;
|
2016-03-12 07:26:35 -06:00
|
|
|
OstProto::PortNeighborList *neighList;
|
2016-03-11 07:28:08 -06:00
|
|
|
PbRpcController *controller;
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < mPorts.size());
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
portId = new OstProto::PortId;
|
|
|
|
portId->set_id(mPorts[portIndex]->id());
|
|
|
|
deviceList = new OstProto::PortDeviceList;
|
|
|
|
controller = new PbRpcController(portId, deviceList);
|
|
|
|
|
|
|
|
serviceStub->getDeviceList(controller, portId, deviceList,
|
|
|
|
NewCallback(this, &PortGroup::processDeviceList,
|
|
|
|
portIndex, controller));
|
2016-03-12 07:26:35 -06:00
|
|
|
|
|
|
|
portId = new OstProto::PortId;
|
|
|
|
portId->set_id(mPorts[portIndex]->id());
|
|
|
|
neighList = new OstProto::PortNeighborList;
|
|
|
|
controller = new PbRpcController(portId, neighList);
|
|
|
|
|
|
|
|
serviceStub->getDeviceNeighbors(controller, portId, neighList,
|
|
|
|
NewCallback(this, &PortGroup::processDeviceNeighbors,
|
|
|
|
portIndex, controller));
|
2016-03-11 07:28:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processDeviceList(int portIndex, PbRpcController *controller)
|
|
|
|
{
|
|
|
|
OstProto::PortDeviceList *deviceList
|
|
|
|
= static_cast<OstProto::PortDeviceList*>(controller->response());
|
|
|
|
|
|
|
|
qDebug("In %s (portIndex = %d)", __FUNCTION__, portIndex);
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < numPorts());
|
|
|
|
|
|
|
|
if (deviceList->port_id().id() != mPorts[portIndex]->id())
|
|
|
|
{
|
|
|
|
qDebug("Invalid portId %d (expected %d) received for portIndex %d",
|
|
|
|
deviceList->port_id().id(), mPorts[portIndex]->id(), portIndex);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPorts[portIndex]->clearDeviceList();
|
2016-03-22 09:48:53 -05:00
|
|
|
for(int i = 0; i < deviceList->ExtensionSize(OstEmul::device); i++) {
|
2016-03-11 07:28:08 -06:00
|
|
|
mPorts[portIndex]->insertDevice(
|
2016-03-22 09:48:53 -05:00
|
|
|
deviceList->GetExtension(OstEmul::device, i));
|
2016-03-11 07:28:08 -06:00
|
|
|
}
|
2016-03-12 07:26:35 -06:00
|
|
|
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processDeviceNeighbors(
|
|
|
|
int portIndex, PbRpcController *controller)
|
|
|
|
{
|
|
|
|
OstProto::PortNeighborList *neighList
|
|
|
|
= static_cast<OstProto::PortNeighborList*>(controller->response());
|
|
|
|
|
|
|
|
qDebug("In %s (portIndex = %d)", __FUNCTION__, portIndex);
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < numPorts());
|
|
|
|
|
|
|
|
if (neighList->port_id().id() != mPorts[portIndex]->id())
|
|
|
|
{
|
|
|
|
qDebug("Invalid portId %d (expected %d) received for portIndex %d",
|
|
|
|
neighList->port_id().id(), mPorts[portIndex]->id(), portIndex);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPorts[portIndex]->clearDeviceNeighbors();
|
2016-03-22 09:48:53 -05:00
|
|
|
for(int i=0; i < neighList->ExtensionSize(OstEmul::device_neighbor); i++) {
|
2016-03-12 07:26:35 -06:00
|
|
|
mPorts[portIndex]->insertDeviceNeighbors(
|
2016-03-22 09:48:53 -05:00
|
|
|
neighList->GetExtension(OstEmul::device_neighbor, i));
|
2016-03-12 07:26:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
mPorts[portIndex]->deviceInfoRefreshed();
|
2016-03-11 07:28:08 -06:00
|
|
|
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void PortGroup::modifyPort(int portIndex, OstProto::Port portConfig)
|
|
|
|
{
|
|
|
|
OstProto::PortConfigList *portConfigList = new OstProto::PortConfigList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
|
|
|
|
qDebug("%s: portIndex = %d", __FUNCTION__, portIndex);
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < mPorts.size());
|
|
|
|
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
mainWindow->setDisabled(true);
|
|
|
|
|
|
|
|
OstProto::Port *port = portConfigList->add_port();
|
|
|
|
port->CopyFrom(portConfig);
|
|
|
|
port->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
|
|
|
|
PbRpcController *controller = new PbRpcController(portConfigList, ack);
|
|
|
|
serviceStub->modifyPort(controller, portConfigList, ack,
|
2016-05-14 09:43:43 -05:00
|
|
|
NewCallback(this, &PortGroup::processModifyPortAck, true, controller));
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2016-05-14 09:43:43 -05:00
|
|
|
void PortGroup::processModifyPortAck(bool restoreUi,PbRpcController *controller)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
}
|
|
|
|
|
2016-05-14 09:43:43 -05:00
|
|
|
if (restoreUi) {
|
|
|
|
mainWindow->setEnabled(true);
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processUpdatedPortConfig(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
OstProto::PortConfigList *portConfigList
|
|
|
|
= static_cast<OstProto::PortConfigList*>(controller->response());
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < portConfigList->port_size(); i++)
|
|
|
|
{
|
|
|
|
uint id;
|
|
|
|
|
|
|
|
id = portConfigList->port(i).port_id().id();
|
|
|
|
// FIXME: don't mix port id & index into mPorts[]
|
|
|
|
mPorts[id]->updatePortConfig(portConfigList->mutable_port(i));
|
|
|
|
|
|
|
|
emit portGroupDataChanged(mPortGroupId, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::getStreamIdList()
|
|
|
|
{
|
|
|
|
for (int portIndex = 0; portIndex < numPorts(); portIndex++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = new OstProto::PortId;
|
|
|
|
OstProto::StreamIdList *streamIdList = new OstProto::StreamIdList;
|
|
|
|
PbRpcController *controller = new PbRpcController(portId, streamIdList);
|
|
|
|
|
|
|
|
portId->set_id(mPorts[portIndex]->id());
|
|
|
|
|
|
|
|
serviceStub->getStreamIdList(controller, portId, streamIdList,
|
|
|
|
NewCallback(this, &PortGroup::processStreamIdList,
|
|
|
|
portIndex, controller));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processStreamIdList(int portIndex, PbRpcController *controller)
|
|
|
|
{
|
|
|
|
OstProto::StreamIdList *streamIdList
|
|
|
|
= static_cast<OstProto::StreamIdList*>(controller->response());
|
2016-05-05 08:43:00 -05:00
|
|
|
const OstProto::PortContent *newPortContent
|
|
|
|
= atConnectPortConfig_.at(portIndex);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
qDebug("In %s (portIndex = %d)", __FUNCTION__, portIndex);
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < numPorts());
|
|
|
|
|
|
|
|
if (streamIdList->port_id().id() != mPorts[portIndex]->id())
|
|
|
|
{
|
|
|
|
qDebug("Invalid portId %d (expected %d) received for portIndex %d",
|
|
|
|
streamIdList->port_id().id(), mPorts[portIndex]->id(), portIndex);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
2016-05-05 08:43:00 -05:00
|
|
|
if (newPortContent)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2016-05-05 08:43:00 -05:00
|
|
|
// This port needs to configured with new content - to do this
|
|
|
|
// we'll insert the following RPC sequence at this point and once
|
|
|
|
// this sequence is over, return to the regular RPC sequence by
|
|
|
|
// re-requesting getStreamId()
|
2016-05-12 08:17:16 -05:00
|
|
|
// * delete (existing) deviceGroups
|
|
|
|
// (already done by processDeviceIdList)
|
2016-05-05 08:43:00 -05:00
|
|
|
// * delete (existing) streams
|
|
|
|
// * modify port
|
2016-05-12 08:17:16 -05:00
|
|
|
// * add (new) deviceGroup ids
|
|
|
|
// * modify (new) deviceGroups
|
2016-05-05 08:43:00 -05:00
|
|
|
// * add (new) stream ids
|
|
|
|
// * modify (new) streams
|
2016-05-12 08:17:16 -05:00
|
|
|
// XXX: This assumes getDeviceGroupIdList() was invoked before
|
|
|
|
// getStreamIdList() - if the order changes this code will break!
|
2016-05-05 08:43:00 -05:00
|
|
|
|
|
|
|
// XXX: same name as input param, but shouldn't cause any problem
|
|
|
|
PbRpcController *controller;
|
|
|
|
quint32 portId = mPorts[portIndex]->id();
|
2016-05-10 09:56:48 -05:00
|
|
|
QString myself = appSettings->value(kUserKey, kUserDefaultValue)
|
|
|
|
.toString();
|
2016-05-05 08:43:00 -05:00
|
|
|
|
|
|
|
// delete all existing streams
|
|
|
|
if (streamIdList->stream_id_size())
|
|
|
|
{
|
|
|
|
OstProto::StreamIdList *streamIdList2 = new OstProto::StreamIdList;
|
|
|
|
streamIdList2->CopyFrom(*streamIdList);
|
|
|
|
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(streamIdList2, ack);
|
|
|
|
|
|
|
|
serviceStub->deleteStream(controller, streamIdList2, ack,
|
|
|
|
NewCallback(this, &PortGroup::processDeleteStreamAck,
|
|
|
|
controller));
|
|
|
|
}
|
|
|
|
|
2016-05-14 09:19:07 -05:00
|
|
|
OstProto::Port portCfg = newPortContent->port_config();
|
|
|
|
if (mPorts[portIndex]->modifiablePortConfig(portCfg))
|
2016-05-05 08:43:00 -05:00
|
|
|
{
|
|
|
|
OstProto::PortConfigList *portConfigList =
|
|
|
|
new OstProto::PortConfigList;
|
|
|
|
OstProto::Port *port = portConfigList->add_port();
|
2016-05-14 09:19:07 -05:00
|
|
|
port->CopyFrom(portCfg);
|
|
|
|
if (port->has_user_name())
|
2016-05-10 09:56:48 -05:00
|
|
|
port->set_user_name(qPrintable(myself)); // overwrite
|
2016-05-05 08:43:00 -05:00
|
|
|
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(portConfigList, ack);
|
|
|
|
|
|
|
|
serviceStub->modifyPort(controller, portConfigList, ack,
|
2016-05-14 09:43:43 -05:00
|
|
|
NewCallback(this, &PortGroup::processModifyPortAck,
|
|
|
|
false, controller));
|
2016-05-05 08:43:00 -05:00
|
|
|
}
|
|
|
|
|
2016-05-12 08:17:16 -05:00
|
|
|
// add/modify deviceGroups
|
|
|
|
if (newPortContent->device_groups_size())
|
|
|
|
{
|
|
|
|
OstProto::DeviceGroupIdList *deviceGroupIdList
|
|
|
|
= new OstProto::DeviceGroupIdList;
|
|
|
|
OstProto::DeviceGroupConfigList *deviceGroupConfigList
|
|
|
|
= new OstProto::DeviceGroupConfigList;
|
|
|
|
deviceGroupIdList->mutable_port_id()->set_id(portId);
|
|
|
|
deviceGroupConfigList->mutable_port_id()->set_id(portId);
|
|
|
|
for (int i = 0; i < newPortContent->device_groups_size(); i++)
|
|
|
|
{
|
|
|
|
const OstProto::DeviceGroup &dg
|
|
|
|
= newPortContent->device_groups(i);
|
|
|
|
deviceGroupIdList->add_device_group_id()->set_id(
|
|
|
|
dg.device_group_id().id());
|
|
|
|
deviceGroupConfigList->add_device_group()->CopyFrom(dg);
|
|
|
|
}
|
|
|
|
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(deviceGroupIdList, ack);
|
|
|
|
|
|
|
|
serviceStub->addDeviceGroup(controller, deviceGroupIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processAddDeviceGroupAck,
|
|
|
|
controller));
|
|
|
|
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(deviceGroupConfigList, ack);
|
|
|
|
|
|
|
|
serviceStub->modifyDeviceGroup(controller,
|
|
|
|
deviceGroupConfigList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processModifyDeviceGroupAck,
|
|
|
|
portIndex, controller));
|
|
|
|
}
|
|
|
|
|
2016-05-05 08:43:00 -05:00
|
|
|
// add/modify streams
|
|
|
|
if (newPortContent->streams_size())
|
|
|
|
{
|
|
|
|
OstProto::StreamIdList *streamIdList = new OstProto::StreamIdList;
|
|
|
|
OstProto::StreamConfigList *streamConfigList =
|
|
|
|
new OstProto::StreamConfigList;
|
|
|
|
streamIdList->mutable_port_id()->set_id(portId);
|
|
|
|
streamConfigList->mutable_port_id()->set_id(portId);
|
|
|
|
for (int i = 0; i < newPortContent->streams_size(); i++)
|
|
|
|
{
|
|
|
|
const OstProto::Stream &s = newPortContent->streams(i);
|
|
|
|
streamIdList->add_stream_id()->set_id(s.stream_id().id());
|
|
|
|
streamConfigList->add_stream()->CopyFrom(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(streamIdList, ack);
|
|
|
|
|
|
|
|
serviceStub->addStream(controller, streamIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processAddStreamAck,
|
|
|
|
controller));
|
|
|
|
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
controller = new PbRpcController(streamConfigList, ack);
|
|
|
|
|
|
|
|
serviceStub->modifyStream(controller, streamConfigList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processModifyStreamAck,
|
|
|
|
portIndex, controller));
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete newPortConfig
|
|
|
|
atConnectPortConfig_[portIndex] = NULL;
|
|
|
|
|
2016-05-12 08:17:16 -05:00
|
|
|
// return to normal sequence re-starting from
|
|
|
|
// getDeviceGroupIdList() and getStreamIdList()
|
2016-05-05 08:43:00 -05:00
|
|
|
OstProto::PortId *portId2 = new OstProto::PortId;
|
|
|
|
portId2->set_id(portId);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-05-12 08:17:16 -05:00
|
|
|
OstProto::DeviceGroupIdList *devGrpIdList
|
|
|
|
= new OstProto::DeviceGroupIdList;
|
|
|
|
controller = new PbRpcController(portId2, devGrpIdList);
|
|
|
|
|
|
|
|
serviceStub->getDeviceGroupIdList(controller, portId2, devGrpIdList,
|
|
|
|
NewCallback(this, &PortGroup::processDeviceGroupIdList,
|
|
|
|
portIndex, controller));
|
|
|
|
|
|
|
|
portId2 = new OstProto::PortId;
|
|
|
|
portId2->set_id(portId);
|
2016-05-05 08:43:00 -05:00
|
|
|
OstProto::StreamIdList *streamIdList = new OstProto::StreamIdList;
|
|
|
|
controller = new PbRpcController(portId2, streamIdList);
|
|
|
|
|
|
|
|
serviceStub->getStreamIdList(controller, portId2, streamIdList,
|
|
|
|
NewCallback(this, &PortGroup::processStreamIdList,
|
|
|
|
portIndex, controller));
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
2016-05-05 08:43:00 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int i = 0; i < streamIdList->stream_id_size(); i++)
|
|
|
|
{
|
|
|
|
uint streamId;
|
|
|
|
|
|
|
|
streamId = streamIdList->stream_id(i).id();
|
|
|
|
mPorts[portIndex]->insertStream(streamId);
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-05-13 09:40:53 -05:00
|
|
|
mPorts[portIndex]->when_syncComplete();
|
|
|
|
|
2016-05-05 08:43:00 -05:00
|
|
|
getStreamConfigList(portIndex);
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
void PortGroup::getStreamConfigList(int portIndex)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2016-04-26 09:53:50 -05:00
|
|
|
if (mPorts[portIndex]->numStreams() == 0)
|
|
|
|
return;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
qDebug("requesting stream config list (port %d)...", portIndex);
|
2016-02-05 07:36:14 -06:00
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
OstProto::StreamIdList *streamIdList = new OstProto::StreamIdList;
|
|
|
|
OstProto::StreamConfigList *streamConfigList
|
|
|
|
= new OstProto::StreamConfigList;
|
|
|
|
PbRpcController *controller = new PbRpcController(
|
|
|
|
streamIdList, streamConfigList);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
streamIdList->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
for (int j = 0; j < mPorts[portIndex]->numStreams(); j++)
|
|
|
|
{
|
|
|
|
OstProto::StreamId *s = streamIdList->add_stream_id();
|
|
|
|
s->set_id(mPorts[portIndex]->streamByIndex(j)->id());
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
2016-04-26 09:53:50 -05:00
|
|
|
|
|
|
|
serviceStub->getStreamConfig(controller, streamIdList, streamConfigList,
|
|
|
|
NewCallback(this, &PortGroup::processStreamConfigList,
|
|
|
|
portIndex, controller));
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processStreamConfigList(int portIndex,
|
|
|
|
PbRpcController *controller)
|
|
|
|
{
|
|
|
|
OstProto::StreamConfigList *streamConfigList
|
|
|
|
= static_cast<OstProto::StreamConfigList*>(controller->response());
|
|
|
|
|
|
|
|
qDebug("In %s", __PRETTY_FUNCTION__);
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < numPorts());
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < numPorts());
|
|
|
|
|
|
|
|
if (streamConfigList->port_id().id() != mPorts[portIndex]->id())
|
|
|
|
{
|
|
|
|
qDebug("Invalid portId %d (expected %d) received for portIndex %d",
|
|
|
|
streamConfigList->port_id().id(), mPorts[portIndex]->id(), portIndex);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < streamConfigList->stream_size(); i++)
|
|
|
|
{
|
|
|
|
uint streamId;
|
|
|
|
|
|
|
|
streamId = streamConfigList->stream(i).stream_id().id();
|
|
|
|
mPorts[portIndex]->updateStream(streamId,
|
|
|
|
streamConfigList->mutable_stream(i));
|
|
|
|
}
|
|
|
|
|
2016-02-05 07:36:14 -06:00
|
|
|
#if 0
|
|
|
|
// FIXME: incorrect check - will never be true if last port does not have any streams configured
|
2015-04-16 11:50:07 -05:00
|
|
|
// Are we done for all ports?
|
2016-02-05 07:36:14 -06:00
|
|
|
if (portIndex >= (numPorts()-1))
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
// FIXME(HI): some way to reset streammodel
|
|
|
|
}
|
2016-02-05 07:36:14 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::getDeviceGroupIdList()
|
|
|
|
{
|
|
|
|
using OstProto::PortId;
|
|
|
|
using OstProto::DeviceGroupIdList;
|
|
|
|
|
|
|
|
for (int portIndex = 0; portIndex < numPorts(); portIndex++)
|
|
|
|
{
|
|
|
|
PortId *portId = new PortId;
|
|
|
|
DeviceGroupIdList *devGrpIdList = new DeviceGroupIdList;
|
|
|
|
PbRpcController *controller = new PbRpcController(portId, devGrpIdList);
|
|
|
|
|
|
|
|
portId->set_id(mPorts[portIndex]->id());
|
|
|
|
|
|
|
|
serviceStub->getDeviceGroupIdList(controller, portId, devGrpIdList,
|
|
|
|
NewCallback(this, &PortGroup::processDeviceGroupIdList,
|
|
|
|
portIndex, controller));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processDeviceGroupIdList(
|
|
|
|
int portIndex,
|
|
|
|
PbRpcController *controller)
|
|
|
|
{
|
|
|
|
using OstProto::DeviceGroupIdList;
|
|
|
|
|
|
|
|
DeviceGroupIdList *devGrpIdList = static_cast<DeviceGroupIdList*>(
|
|
|
|
controller->response());
|
2016-05-12 08:17:16 -05:00
|
|
|
const OstProto::PortContent *newPortContent = atConnectPortConfig_.at(
|
|
|
|
portIndex);
|
2016-02-05 07:36:14 -06:00
|
|
|
|
|
|
|
qDebug("In %s (portIndex = %d)", __FUNCTION__, portIndex);
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < numPorts());
|
|
|
|
|
|
|
|
if (devGrpIdList->port_id().id() != mPorts[portIndex]->id())
|
|
|
|
{
|
|
|
|
qDebug("Invalid portId %d (expected %d) received for portIndex %d",
|
|
|
|
devGrpIdList->port_id().id(), mPorts[portIndex]->id(), portIndex);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
2016-05-12 08:17:16 -05:00
|
|
|
if (newPortContent)
|
2016-02-05 07:36:14 -06:00
|
|
|
{
|
2016-05-12 08:17:16 -05:00
|
|
|
// We delete all existing deviceGroups
|
|
|
|
// Remaining stuff is done in processStreamIdList() - see notes there
|
|
|
|
if (devGrpIdList->device_group_id_size())
|
|
|
|
{
|
|
|
|
OstProto::DeviceGroupIdList *devGrpIdList2
|
|
|
|
= new OstProto::DeviceGroupIdList;
|
|
|
|
devGrpIdList2->CopyFrom(*devGrpIdList);
|
2016-02-05 07:36:14 -06:00
|
|
|
|
2016-05-12 08:17:16 -05:00
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller
|
|
|
|
= new PbRpcController(devGrpIdList2, ack);
|
|
|
|
|
|
|
|
serviceStub->deleteDeviceGroup(controller, devGrpIdList2, ack,
|
|
|
|
NewCallback(this, &PortGroup::processDeleteDeviceGroupAck,
|
|
|
|
controller));
|
|
|
|
}
|
2016-02-05 07:36:14 -06:00
|
|
|
}
|
2016-05-12 08:17:16 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int i = 0; i < devGrpIdList->device_group_id_size(); i++)
|
|
|
|
{
|
|
|
|
uint devGrpId;
|
2016-02-05 07:36:14 -06:00
|
|
|
|
2016-05-12 08:17:16 -05:00
|
|
|
devGrpId = devGrpIdList->device_group_id(i).id();
|
|
|
|
mPorts[portIndex]->insertDeviceGroup(devGrpId);
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeviceGroupConfigList(portIndex);
|
|
|
|
}
|
2016-02-05 07:36:14 -06:00
|
|
|
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
void PortGroup::getDeviceGroupConfigList(int portIndex)
|
2016-02-05 07:36:14 -06:00
|
|
|
{
|
|
|
|
using OstProto::DeviceGroupId;
|
|
|
|
using OstProto::DeviceGroupIdList;
|
|
|
|
using OstProto::DeviceGroupConfigList;
|
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
if (mPorts[portIndex]->numDeviceGroups() == 0)
|
|
|
|
return;
|
2016-02-05 07:36:14 -06:00
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
qDebug("requesting device group config list (port %d) ...", portIndex);
|
2016-02-05 07:36:14 -06:00
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
DeviceGroupIdList *devGrpIdList = new DeviceGroupIdList;
|
|
|
|
DeviceGroupConfigList *devGrpCfgList = new DeviceGroupConfigList;
|
|
|
|
PbRpcController *controller = new PbRpcController(
|
|
|
|
devGrpIdList, devGrpCfgList);
|
2016-02-05 07:36:14 -06:00
|
|
|
|
2016-04-26 09:53:50 -05:00
|
|
|
devGrpIdList->mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
for (int j = 0; j < mPorts[portIndex]->numDeviceGroups(); j++)
|
|
|
|
{
|
|
|
|
DeviceGroupId *dgid = devGrpIdList->add_device_group_id();
|
|
|
|
dgid->set_id(mPorts[portIndex]->deviceGroupByIndex(j)
|
|
|
|
->device_group_id().id());
|
2016-02-05 07:36:14 -06:00
|
|
|
}
|
2016-04-26 09:53:50 -05:00
|
|
|
|
|
|
|
serviceStub->getDeviceGroupConfig(controller,
|
|
|
|
devGrpIdList, devGrpCfgList,
|
|
|
|
NewCallback(this, &PortGroup::processDeviceGroupConfigList,
|
|
|
|
portIndex, controller));
|
2016-02-05 07:36:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processDeviceGroupConfigList(int portIndex,
|
|
|
|
PbRpcController *controller)
|
|
|
|
{
|
|
|
|
using OstProto::DeviceGroupConfigList;
|
|
|
|
|
|
|
|
DeviceGroupConfigList *devGrpCfgList =
|
|
|
|
static_cast<OstProto::DeviceGroupConfigList*>(controller->response());
|
|
|
|
|
|
|
|
qDebug("In %s", __PRETTY_FUNCTION__);
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < numPorts());
|
|
|
|
|
|
|
|
if (controller->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(controller->ErrorString()));
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < numPorts());
|
|
|
|
|
|
|
|
if (devGrpCfgList->port_id().id() != mPorts[portIndex]->id())
|
|
|
|
{
|
|
|
|
qDebug("Invalid portId %d (expected %d) received for portIndex %d",
|
|
|
|
devGrpCfgList->port_id().id(), mPorts[portIndex]->id(), portIndex);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < devGrpCfgList->device_group_size(); i++)
|
|
|
|
{
|
|
|
|
uint dgid = devGrpCfgList->device_group(i).device_group_id().id();
|
|
|
|
|
|
|
|
mPorts[portIndex]->updateDeviceGroup(dgid,
|
|
|
|
devGrpCfgList->mutable_device_group(i));
|
|
|
|
}
|
|
|
|
|
2016-03-24 08:28:28 -05:00
|
|
|
if (devGrpCfgList->device_group_size())
|
|
|
|
getDeviceInfo(portIndex);
|
|
|
|
|
2016-02-05 07:36:14 -06:00
|
|
|
#if 0
|
|
|
|
// FIXME: incorrect check - will never be true if last port does not have any deviceGroups configured
|
|
|
|
// Are we done for all ports?
|
|
|
|
if (portIndex >= (numPorts()-1))
|
|
|
|
{
|
|
|
|
// FIXME: reset deviceGroupModel?
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::startTx(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
if (portList == NULL)
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
{
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller = new PbRpcController(portIdList, ack);
|
|
|
|
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = portIdList->add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceStub->startTransmit(controller, portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processStartTxAck, controller));
|
|
|
|
}
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processStartTxAck(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::stopTx(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
if ((portList == NULL) || (portList->size() == 0))
|
|
|
|
goto _exit;
|
|
|
|
{
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller = new PbRpcController(portIdList, ack);
|
|
|
|
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = portIdList->add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceStub->stopTransmit(controller, portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processStopTxAck, controller));
|
|
|
|
}
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processStopTxAck(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::startCapture(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((portList == NULL) || (portList->size() == 0))
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
{
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller = new PbRpcController(portIdList, ack);
|
|
|
|
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = portIdList->add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceStub->startCapture(controller, portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processStartCaptureAck, controller));
|
|
|
|
}
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processStartCaptureAck(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::stopCapture(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((portList == NULL) || (portList->size() == 0))
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
{
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller = new PbRpcController(portIdList, ack);
|
|
|
|
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = portIdList->add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceStub->stopCapture(controller, portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processStopCaptureAck, controller));
|
|
|
|
}
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processStopCaptureAck(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::viewCapture(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
if ((portList == NULL) || (portList->size() != 1))
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = new OstProto::PortId;
|
|
|
|
OstProto::CaptureBuffer *buf = new OstProto::CaptureBuffer;
|
|
|
|
PbRpcController *controller = new PbRpcController(portId, buf);
|
|
|
|
QFile *capFile = mPorts[portList->at(i)]->getCaptureFile();
|
|
|
|
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
|
|
|
|
capFile->open(QIODevice::ReadWrite|QIODevice::Truncate);
|
|
|
|
qDebug("Temp CapFile = %s", capFile->fileName().toAscii().constData());
|
|
|
|
controller->setBinaryBlob(capFile);
|
|
|
|
|
|
|
|
serviceStub->getCaptureBuffer(controller, portId, buf,
|
|
|
|
NewCallback(this, &PortGroup::processViewCaptureAck, controller));
|
|
|
|
}
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processViewCaptureAck(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
QFile *capFile = static_cast<QFile*>(controller->binaryBlob());
|
|
|
|
|
|
|
|
QString viewer = appSettings->value(kWiresharkPathKey,
|
|
|
|
kWiresharkPathDefaultValue).toString();
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
capFile->flush();
|
|
|
|
capFile->close();
|
|
|
|
|
|
|
|
if (!QFile::exists(viewer))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(NULL, "Can't find Wireshark",
|
|
|
|
viewer + QString(" does not exist!\n\nPlease correct the path"
|
|
|
|
" to Wireshark in the Preferences."));
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!QProcess::startDetached(viewer, QStringList() << capFile->fileName()))
|
|
|
|
qDebug("Failed starting Wireshark");
|
|
|
|
|
|
|
|
_exit:
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-03-09 09:50:11 -06:00
|
|
|
void PortGroup::resolveDeviceNeighbors(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((portList == NULL) || (portList->size() == 0))
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
{
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller = new PbRpcController(portIdList, ack);
|
|
|
|
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = portIdList->add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceStub->resolveDeviceNeighbors(controller, portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processResolveDeviceNeighborsAck,
|
|
|
|
controller));
|
|
|
|
}
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processResolveDeviceNeighborsAck(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::clearDeviceNeighbors(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((portList == NULL) || (portList->size() == 0))
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
{
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller = new PbRpcController(portIdList, ack);
|
|
|
|
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = portIdList->add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceStub->clearDeviceNeighbors(controller, portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processClearDeviceNeighborsAck,
|
|
|
|
controller));
|
|
|
|
}
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processClearDeviceNeighborsAck(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void PortGroup::getPortStats()
|
|
|
|
{
|
|
|
|
//qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
if (numPorts() <= 0)
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
if (isGetStatsPending_)
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
statsController->Reset();
|
|
|
|
isGetStatsPending_ = true;
|
|
|
|
serviceStub->getStats(statsController,
|
|
|
|
static_cast<OstProto::PortIdList*>(statsController->request()),
|
|
|
|
static_cast<OstProto::PortStatsList*>(statsController->response()),
|
|
|
|
NewCallback(this, &PortGroup::processPortStatsList));
|
|
|
|
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processPortStatsList()
|
|
|
|
{
|
|
|
|
//qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (statsController->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed(%s)", __FUNCTION__,
|
|
|
|
qPrintable(statsController->ErrorString()));
|
|
|
|
goto _error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < portStatsList_->port_stats_size(); i++)
|
|
|
|
{
|
|
|
|
uint id = portStatsList_->port_stats(i).port_id().id();
|
|
|
|
// FIXME: don't mix port id & index into mPorts[]
|
|
|
|
mPorts[id]->updateStats(portStatsList_->mutable_port_stats(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
emit statsChanged(mPortGroupId);
|
|
|
|
|
|
|
|
_error_exit:
|
|
|
|
isGetStatsPending_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::clearPortStats(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
{
|
|
|
|
OstProto::PortIdList *portIdList = new OstProto::PortIdList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller = new PbRpcController(portIdList, ack);
|
|
|
|
|
|
|
|
if (portList == NULL)
|
|
|
|
portIdList->CopyFrom(*portIdList_);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId = portIdList->add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceStub->clearStats(controller, portIdList, ack,
|
2016-11-28 08:49:17 -06:00
|
|
|
NewCallback(this, &PortGroup::processClearPortStatsAck,
|
|
|
|
controller));
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-28 08:49:17 -06:00
|
|
|
void PortGroup::processClearPortStatsAck(PbRpcController *controller)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
// Refresh stats immediately after a stats clear/reset
|
|
|
|
getPortStats();
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-11-28 08:49:17 -06:00
|
|
|
bool PortGroup::clearStreamStats(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
OstProto::StreamGuidList *guidList = new OstProto::StreamGuidList;
|
|
|
|
OstProto::Ack *ack = new OstProto::Ack;
|
|
|
|
PbRpcController *controller = new PbRpcController(guidList, ack);
|
|
|
|
|
|
|
|
if (portList == NULL)
|
|
|
|
guidList->mutable_port_id_list()->CopyFrom(*portIdList_);
|
|
|
|
else
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
guidList->mutable_port_id_list()->add_port_id()
|
|
|
|
->set_id(portList->at(i));
|
|
|
|
|
|
|
|
serviceStub->clearStreamStats(controller, guidList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processClearStreamStatsAck,
|
|
|
|
controller));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processClearStreamStatsAck(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|
2016-11-24 10:14:38 -06:00
|
|
|
bool PortGroup::getStreamStats(QList<uint> *portList)
|
|
|
|
{
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
OstProto::StreamGuidList *guidList = new OstProto::StreamGuidList;
|
|
|
|
OstProto::StreamStatsList *statsList = new OstProto::StreamStatsList;
|
|
|
|
PbRpcController *controller = new PbRpcController(guidList, statsList);
|
|
|
|
|
|
|
|
if (portList == NULL)
|
|
|
|
guidList->mutable_port_id_list()->CopyFrom(*portIdList_);
|
|
|
|
else
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
guidList->mutable_port_id_list()->add_port_id()
|
|
|
|
->set_id(portList->at(i));
|
|
|
|
|
|
|
|
serviceStub->getStreamStats(controller, guidList, statsList,
|
|
|
|
NewCallback(this, &PortGroup::processStreamStatsList, controller));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processStreamStatsList(PbRpcController *controller)
|
|
|
|
{
|
|
|
|
using OstProto::StreamStatsList;
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
StreamStatsList *streamStatsList =
|
|
|
|
static_cast<StreamStatsList*>(controller->response());
|
|
|
|
|
|
|
|
// XXX: It is required to emit the signal even if the returned
|
|
|
|
// streamStatsList contains no records since the recipient
|
|
|
|
// StreamStatsModel slot needs to disconnect this signal-slot
|
|
|
|
// connection to prevent future stream stats for this portgroup
|
|
|
|
// to be sent to it
|
|
|
|
emit streamStatsReceived(mPortGroupId, streamStatsList);
|
|
|
|
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
|