2009-11-03 08:02:09 -06:00
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QProcess>
|
|
|
|
|
2008-05-03 09:37:10 -05:00
|
|
|
#include "portgroup.h"
|
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
quint32 PortGroup::mPortGroupAllocId = 0;
|
2008-05-03 09:37:10 -05:00
|
|
|
|
|
|
|
PortGroup::PortGroup(QHostAddress ip, quint16 port)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
// Allocate an id for self
|
|
|
|
mPortGroupId = PortGroup::mPortGroupAllocId++;
|
|
|
|
|
|
|
|
rpcChannel = new PbRpcChannel(ip, port);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\todo (HIGH) RPC Controller should be allocated and deleted for each RPC invocation
|
|
|
|
as implemented currently, if a RPC is invoked before the previous completes,
|
|
|
|
rpc controller is overwritten due to the Reset() call - maybe we need to pass the
|
|
|
|
pointer to the controller to the callback function also?
|
|
|
|
*/
|
|
|
|
rpcController = new PbRpcController;
|
|
|
|
rpcControllerStats = new PbRpcController;
|
|
|
|
isGetStatsPending_ = false;
|
|
|
|
serviceStub = new OstProto::OstService::Stub(rpcChannel,
|
|
|
|
OstProto::OstService::STUB_OWNS_CHANNEL);
|
|
|
|
|
|
|
|
// 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()));
|
|
|
|
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)));
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PortGroup::~PortGroup()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("PortGroup Destructor");
|
|
|
|
// Disconnect and free rpc channel etc.
|
|
|
|
PortGroup::disconnectFromHost();
|
|
|
|
delete serviceStub;
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------
|
|
|
|
// Slots
|
|
|
|
// ------------------------------------------------
|
2008-08-08 22:22:13 -05:00
|
|
|
void PortGroup::on_rpcChannel_stateChanged()
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("state changed");
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
void PortGroup::on_rpcChannel_connected()
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::Void void_;
|
|
|
|
OstProto::PortIdList *portIdList;
|
|
|
|
|
|
|
|
qDebug("connected\n");
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
|
|
|
|
|
|
|
qDebug("requesting portlist ...");
|
|
|
|
portIdList = new OstProto::PortIdList();
|
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->getPortIdList(rpcController, &void_, portIdList,
|
|
|
|
NewCallback(this, &PortGroup::processPortIdList, portIdList));
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
void PortGroup::on_rpcChannel_disconnected()
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("disconnected\n");
|
|
|
|
emit portListAboutToBeChanged(mPortGroupId);
|
2009-11-14 09:09:19 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
while (!mPorts.isEmpty())
|
|
|
|
delete mPorts.takeFirst();
|
2009-11-14 09:09:19 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
emit portListChanged(mPortGroupId);
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
void PortGroup::on_rpcChannel_error(QAbstractSocket::SocketError socketError)
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("error\n");
|
|
|
|
emit portGroupDataChanged(mPortGroupId);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
void PortGroup::when_configApply(int portIndex, uint *cookie)
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
uint *op;
|
|
|
|
OstProto::Ack *ack;
|
|
|
|
|
|
|
|
Q_ASSERT(portIndex < mPorts.size());
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
{
|
|
|
|
if (cookie != NULL)
|
|
|
|
delete cookie;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cookie == NULL)
|
|
|
|
{
|
|
|
|
// cookie[0]: op [0 - delete, 1 - add, 2 - modify, 3 - Done!]
|
|
|
|
// cookie[1]: *ack
|
|
|
|
cookie = new uint[2];
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
|
|
|
|
cookie[0] = (uint) 0;
|
|
|
|
cookie[1] = (uint) ack;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ack = (OstProto::Ack*) cookie[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(cookie != NULL);
|
|
|
|
op = &cookie[0];
|
|
|
|
|
|
|
|
switch (*op)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
OstProto::StreamIdList streamIdList;
|
|
|
|
|
|
|
|
qDebug("applying 'deleted streams' ...");
|
|
|
|
|
|
|
|
streamIdList.mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getDeletedStreamsSinceLastSync(streamIdList);
|
|
|
|
|
|
|
|
(*op)++;
|
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->deleteStream(rpcController, &streamIdList, ack,
|
|
|
|
::google::protobuf::NewCallback(this, &PortGroup::when_configApply, portIndex, cookie));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
OstProto::StreamIdList streamIdList;
|
|
|
|
|
|
|
|
qDebug("applying 'new streams' ...");
|
|
|
|
|
|
|
|
streamIdList.mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getNewStreamsSinceLastSync(streamIdList);
|
|
|
|
|
|
|
|
(*op)++;
|
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->addStream(rpcController, &streamIdList, ack,
|
|
|
|
::google::protobuf::NewCallback(this, &PortGroup::when_configApply, portIndex, cookie));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
OstProto::StreamConfigList streamConfigList;
|
|
|
|
|
|
|
|
qDebug("applying 'modified streams' ...");
|
|
|
|
|
|
|
|
streamConfigList.mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
mPorts[portIndex]->getModifiedStreamsSinceLastSync(streamConfigList);
|
|
|
|
|
|
|
|
(*op)++;
|
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->modifyStream(rpcController, &streamConfigList, ack,
|
|
|
|
::google::protobuf::NewCallback(this, &PortGroup::when_configApply, portIndex, cookie));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
qDebug("apply completed");
|
|
|
|
mPorts[portIndex]->when_syncComplete();
|
|
|
|
delete cookie;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
qDebug("%s: Unknown Op!!!", __FUNCTION__);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
2008-08-08 22:22:13 -05:00
|
|
|
|
|
|
|
void PortGroup::processPortIdList(OstProto::PortIdList *portIdList)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("got a portlist ...");
|
|
|
|
|
|
|
|
if (rpcController->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed", __FUNCTION__);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit portListChanged(mPortGroupId);
|
|
|
|
|
|
|
|
this->portIdList.CopyFrom(*portIdList);
|
|
|
|
|
|
|
|
// Request PortConfigList
|
|
|
|
{
|
|
|
|
OstProto::PortConfigList *portConfigList;
|
|
|
|
|
|
|
|
qDebug("requesting port config list ...");
|
|
|
|
portConfigList = new OstProto::PortConfigList();
|
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->getPortConfig(rpcController,
|
|
|
|
portIdList, portConfigList, NewCallback(this,
|
|
|
|
&PortGroup::processPortConfigList, portConfigList));
|
|
|
|
}
|
|
|
|
|
|
|
|
goto _exit;
|
2008-08-08 22:22:13 -05:00
|
|
|
|
|
|
|
_error_exit:
|
|
|
|
_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
delete portIdList;
|
2008-08-08 22:22:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processPortConfigList(OstProto::PortConfigList *portConfigList)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (rpcController->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed", __FUNCTION__);
|
|
|
|
goto _error_exit;
|
|
|
|
}
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
emit portListAboutToBeChanged(mPortGroupId);
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
for(int i = 0; i < portConfigList->port_size(); i++)
|
|
|
|
{
|
|
|
|
uint id;
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
id = portConfigList->port(i).port_id().id();
|
|
|
|
// FIXME: don't mix port id & index into mPorts[]
|
|
|
|
mPorts[id]->updatePortConfig(portConfigList->mutable_port(i));
|
|
|
|
}
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
emit portListChanged(mPortGroupId);
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
// FIXME: check if we need new signals since we are not changing the
|
|
|
|
// number of ports, just the port data
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (numPorts() > 0)
|
|
|
|
getStreamIdList();
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
_error_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
delete portConfigList;
|
2008-08-08 22:22:13 -05:00
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
|
|
|
void PortGroup::getStreamIdList(int portIndex,
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::StreamIdList *streamIdList)
|
2008-08-23 23:39:08 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
::OstProto::PortId portId;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (streamIdList == NULL)
|
|
|
|
{
|
|
|
|
// First invocation (uses default params) -
|
|
|
|
// request StreamIdList for first port
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
Q_ASSERT(portIndex == 0);
|
|
|
|
Q_ASSERT(numPorts() > 0);
|
|
|
|
streamIdList = new ::OstProto::StreamIdList();
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
goto _request;
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("got a streamIdlist ...");
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (rpcController->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed", __FUNCTION__);
|
|
|
|
goto _next_port; // FIXME(MED): Partial RPC
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
Q_ASSERT(portIndex < numPorts());
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (streamIdList->port_id().id() != mPorts[portIndex]->id())
|
|
|
|
{
|
|
|
|
qDebug("%s: Invalid portId %d (expected %d) received for portIndex %d",
|
|
|
|
__FUNCTION__, streamIdList->port_id().id(), mPorts[portIndex]->id(),
|
|
|
|
portIndex);
|
|
|
|
goto _next_port; // FIXME(MED): Partial RPC
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
// FIXME(MED): need to mPorts.clear()???
|
|
|
|
for(int i = 0; i < streamIdList->stream_id_size(); i++)
|
|
|
|
{
|
|
|
|
uint streamId;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
streamId = streamIdList->stream_id(i).id();
|
|
|
|
mPorts[portIndex]->insertStream(streamId);
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
|
|
|
_next_port:
|
2009-12-28 02:31:28 -06:00
|
|
|
// FIXME(HI): ideally we shd use signals/slots but this means
|
|
|
|
// we will have to use Port* instead of Port with QList<> -
|
|
|
|
// need to find a way for this
|
|
|
|
mPorts[portIndex]->when_syncComplete();
|
|
|
|
portIndex++;
|
|
|
|
if (portIndex >= numPorts())
|
|
|
|
{
|
|
|
|
// We're done for all ports !!!
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
// FIXME(HI): some way to reset streammodel
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete streamIdList;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (numPorts() > 0)
|
|
|
|
getStreamConfigList();
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
goto _exit;
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
|
|
|
_request:
|
2009-12-28 02:31:28 -06:00
|
|
|
portId.set_id(mPorts[portIndex]->id());
|
|
|
|
streamIdList->Clear();
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->getStreamIdList(rpcController, &portId, streamIdList,
|
|
|
|
NewCallback(this, &PortGroup::getStreamIdList,
|
|
|
|
portIndex, streamIdList));
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
goto _exit;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
return;
|
2008-08-23 23:39:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::getStreamConfigList(int portIndex,
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::StreamConfigList *streamConfigList)
|
2008-08-23 23:39:08 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::StreamIdList streamIdList;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __PRETTY_FUNCTION__);
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (streamConfigList == NULL)
|
|
|
|
{
|
|
|
|
// First invocation using default params
|
|
|
|
// - request for first port
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
Q_ASSERT(portIndex == 0);
|
|
|
|
Q_ASSERT(numPorts() > 0);
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
streamConfigList = new OstProto::StreamConfigList;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
goto _request;
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("got a streamconfiglist");
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (rpcController->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed", __FUNCTION__);
|
|
|
|
goto _next_port;
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
Q_ASSERT(portIndex < numPorts());
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (streamConfigList->port_id().id() != mPorts[portIndex]->id())
|
|
|
|
{
|
|
|
|
qDebug("%s: Invalid portId %d (expected %d) received for portIndex %d",
|
|
|
|
__FUNCTION__, streamConfigList->port_id().id(),
|
|
|
|
mPorts[portIndex]->id(), portIndex);
|
|
|
|
goto _next_port; // FIXME(MED): Partial RPC
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
// FIXME(MED): need to mStreams.clear()???
|
|
|
|
for(int i = 0; i < streamConfigList->stream_size(); i++)
|
|
|
|
{
|
|
|
|
uint streamId;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
streamId = streamConfigList->stream(i).stream_id().id();
|
|
|
|
mPorts[portIndex]->updateStream(streamId,
|
|
|
|
streamConfigList->mutable_stream(i));
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
|
|
|
_next_port:
|
2009-12-28 02:31:28 -06:00
|
|
|
portIndex++;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (portIndex >= numPorts())
|
|
|
|
{
|
|
|
|
// We're done for all ports !!!
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
// FIXME(HI): some way to reset streammodel
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete streamConfigList;
|
|
|
|
goto _exit;
|
|
|
|
}
|
2008-08-23 23:39:08 -05:00
|
|
|
|
|
|
|
_request:
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("requesting stream config list ...");
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
streamIdList.Clear();
|
|
|
|
streamIdList.mutable_port_id()->set_id(mPorts[portIndex]->id());
|
|
|
|
for (int j = 0; j < mPorts[portIndex]->numStreams(); j++)
|
|
|
|
{
|
|
|
|
OstProto::StreamId *s;
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
s = streamIdList.add_stream_id();
|
|
|
|
s->set_id(mPorts[portIndex]->streamByIndex(j)->id());
|
|
|
|
}
|
|
|
|
streamConfigList->Clear();
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->getStreamConfig(rpcController,
|
|
|
|
&streamIdList, streamConfigList, NewCallback(this,
|
|
|
|
&PortGroup::getStreamConfigList, portIndex, streamConfigList));
|
2008-08-23 23:39:08 -05:00
|
|
|
|
|
|
|
_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
return;
|
2008-08-23 23:39:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processModifyStreamAck(OstProto::Ack *ack)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("Modify Successful!!");
|
2008-08-23 23:39:08 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
// TODO(HI): Apply Button should now be disabled???!!!!???
|
2008-08-23 23:39:08 -05:00
|
|
|
}
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2008-09-28 13:01:52 -05:00
|
|
|
void PortGroup::startTx(QList<uint> *portList)
|
2008-09-14 07:03:53 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::PortIdList portIdList;
|
|
|
|
OstProto::Ack *ack;
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
if (portList == NULL)
|
|
|
|
goto _exit;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId;
|
|
|
|
portId = portIdList.add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceStub->startTx(rpcController, &portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processStartTxAck, ack));
|
2008-09-28 13:01:52 -05:00
|
|
|
_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
return;
|
2008-09-28 13:01:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::stopTx(QList<uint> *portList)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::PortIdList portIdList;
|
|
|
|
OstProto::Ack *ack;
|
2008-09-28 13:01:52 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2008-09-28 13:01:52 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
goto _exit;
|
2008-09-28 13:01:52 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if ((portList == NULL) || (portList->size() == 0))
|
|
|
|
goto _exit;
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
ack = new OstProto::Ack;
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId;
|
|
|
|
portId = portIdList.add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
2008-09-28 13:01:52 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->stopTx(rpcController, &portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processStopTxAck, ack));
|
2008-09-28 13:01:52 -05:00
|
|
|
_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
return;
|
2008-09-14 07:03:53 -05:00
|
|
|
}
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
void PortGroup::startCapture(QList<uint> *portList)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::PortIdList portIdList;
|
|
|
|
OstProto::Ack *ack;
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if ((portList == NULL) || (portList->size() == 0))
|
|
|
|
goto _exit;
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
ack = new OstProto::Ack;
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId;
|
|
|
|
portId = portIdList.add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->startCapture(rpcController, &portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processStartCaptureAck, ack));
|
2009-10-14 10:16:56 -05:00
|
|
|
_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
return;
|
2009-10-14 10:16:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::stopCapture(QList<uint> *portList)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::PortIdList portIdList;
|
|
|
|
OstProto::Ack *ack;
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if ((portList == NULL) || (portList->size() == 0))
|
|
|
|
goto _exit;
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
ack = new OstProto::Ack;
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId;
|
|
|
|
portId = portIdList.add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->stopCapture(rpcController, &portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processStopCaptureAck, ack));
|
2009-10-14 10:16:56 -05:00
|
|
|
_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
return;
|
2009-10-14 10:16:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::viewCapture(QList<uint> *portList)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
static QTemporaryFile *capFile = NULL;
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
goto _exit;
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if ((portList == NULL) || (portList->size() != 1))
|
|
|
|
goto _exit;
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (capFile)
|
|
|
|
delete capFile;
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
/*! \todo (MED) unable to reuse the same file 'coz capFile->resize(0) is
|
|
|
|
not working - it fails everytime */
|
|
|
|
capFile = new QTemporaryFile();
|
|
|
|
capFile->open();
|
|
|
|
qDebug("Temp CapFile = %s", capFile->fileName().toAscii().constData());
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId portId;
|
|
|
|
OstProto::CaptureBuffer *buf;
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
portId.set_id(portList->at(i));
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
buf = new OstProto::CaptureBuffer;
|
|
|
|
rpcController->Reset();
|
|
|
|
rpcController->setBinaryBlob(capFile);
|
|
|
|
serviceStub->getCaptureBuffer(rpcController, &portId, buf,
|
|
|
|
NewCallback(this, &PortGroup::processViewCaptureAck, buf, (QFile*) capFile));
|
|
|
|
}
|
2009-10-14 10:16:56 -05:00
|
|
|
_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
return;
|
2009-10-14 10:16:56 -05:00
|
|
|
}
|
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
void PortGroup::processStartTxAck(OstProto::Ack *ack)
|
2008-09-14 07:03:53 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete ack;
|
2008-09-14 07:03:53 -05:00
|
|
|
}
|
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
void PortGroup::processStopTxAck(OstProto::Ack *ack)
|
2008-09-28 13:01:52 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2008-09-28 13:01:52 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete ack;
|
2008-09-28 13:01:52 -05:00
|
|
|
}
|
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
void PortGroup::processStartCaptureAck(OstProto::Ack *ack)
|
2009-10-14 10:16:56 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete ack;
|
2009-10-14 10:16:56 -05:00
|
|
|
}
|
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
void PortGroup::processStopCaptureAck(OstProto::Ack *ack)
|
2009-10-14 10:16:56 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete ack;
|
2009-10-14 10:16:56 -05:00
|
|
|
}
|
|
|
|
|
2009-11-03 08:02:09 -06:00
|
|
|
void PortGroup::processViewCaptureAck(OstProto::CaptureBuffer *buf, QFile *capFile)
|
2009-10-14 10:16:56 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
capFile->flush();
|
|
|
|
capFile->close();
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (!QProcess::startDetached("C:/Program Files/Wireshark/wireshark.exe",
|
|
|
|
QStringList() << capFile->fileName()))
|
|
|
|
qDebug("Failed starting Wireshark");
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete buf;
|
2009-10-14 10:16:56 -05:00
|
|
|
}
|
|
|
|
|
2008-09-14 07:03:53 -05:00
|
|
|
void PortGroup::getPortStats()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::PortStatsList *portStatsList;
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
//qDebug("In %s", __FUNCTION__);
|
2008-09-28 13:01:52 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (isGetStatsPending_)
|
|
|
|
return;
|
2009-11-29 10:32:31 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
portStatsList = new OstProto::PortStatsList;
|
|
|
|
rpcControllerStats->Reset();
|
|
|
|
isGetStatsPending_ = true;
|
|
|
|
serviceStub->getStats(rpcControllerStats, &portIdList, portStatsList,
|
|
|
|
NewCallback(this, &PortGroup::processPortStatsList, portStatsList));
|
2008-09-14 07:03:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroup::processPortStatsList(OstProto::PortStatsList *portStatsList)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
//qDebug("In %s", __FUNCTION__);
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
if (rpcControllerStats->Failed())
|
|
|
|
{
|
|
|
|
qDebug("%s: rpc failed", __FUNCTION__);
|
|
|
|
goto _error_exit;
|
|
|
|
}
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
for(int i = 0; i < portStatsList->port_stats_size(); i++)
|
|
|
|
{
|
|
|
|
uint id;
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
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));
|
|
|
|
}
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
emit statsChanged(mPortGroupId);
|
2008-09-14 07:03:53 -05:00
|
|
|
|
|
|
|
_error_exit:
|
2009-12-28 02:31:28 -06:00
|
|
|
delete portStatsList;
|
|
|
|
isGetStatsPending_ = false;
|
2008-09-14 07:03:53 -05:00
|
|
|
}
|
|
|
|
|
2008-09-28 13:01:52 -05:00
|
|
|
void PortGroup::clearPortStats(QList<uint> *portList)
|
2008-09-14 07:03:53 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
OstProto::PortIdList portIdList;
|
|
|
|
OstProto::Ack *ack;
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (state() != QAbstractSocket::ConnectedState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ack = new OstProto::Ack;
|
|
|
|
if (portList == NULL)
|
|
|
|
portIdList.CopyFrom(this->portIdList);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < portList->size(); i++)
|
|
|
|
{
|
|
|
|
OstProto::PortId *portId;
|
|
|
|
|
|
|
|
portId = portIdList.add_port_id();
|
|
|
|
portId->set_id(portList->at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcController->Reset();
|
|
|
|
serviceStub->clearStats(rpcController, &portIdList, ack,
|
|
|
|
NewCallback(this, &PortGroup::processClearStatsAck, ack));
|
2008-09-14 07:03:53 -05:00
|
|
|
}
|
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
void PortGroup::processClearStatsAck(OstProto::Ack *ack)
|
2008-09-14 07:03:53 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In %s", __FUNCTION__);
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
// Refresh stats immediately after a stats clear/reset
|
|
|
|
getPortStats();
|
2008-09-28 13:01:52 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete ack;
|
2008-09-14 07:03:53 -05:00
|
|
|
}
|
|
|
|
|