- Queued RPC calls would cause crashes due to invalid pointers to request/response and/or controller; this has been fixed - PbRpcController now takes ownership of request and response messages and will delete them when it itself is being deleted - This design mandates that request and response messages for each RPC call have to be allocated on the heap. - The convention for the Closure 'done' call now is to allocate and pass a pointer to the controller object to it which will delete it after use; this requires that controller itself be also allocated on the heap (NOTE: this is just a convention - not mandatory) - All existing RPC calls (in portgroup.cpp) have been changed to follow the above convention - Reordering of queued RPC calls has been fixed - PortManager is now destroyed at exit; because of this fix the per port temporary capture files are auto-removed at exit - WinPcapPort destructor no longer deletes the monitor threads because the parent class PcapPort already does it - Capture does not automatically (and incorrectly) stop after one packet if started immediately after a View Capture operation - User is prompted to stop transmit on a port first if he tries to apply configuration changes on a port in 'transmit' state
202 lines
4.1 KiB
C++
202 lines
4.1 KiB
C++
#include <vector>
|
|
|
|
#include <google/protobuf/descriptor.h>
|
|
|
|
#include "port.h"
|
|
#include "pbhelper.h"
|
|
|
|
uint Port::mAllocStreamId = 0;
|
|
|
|
uint Port::newStreamId()
|
|
{
|
|
return mAllocStreamId++;
|
|
}
|
|
|
|
Port::Port(quint32 id, quint32 portGroupId)
|
|
{
|
|
mPortId = id;
|
|
d.mutable_port_id()->set_id(id);
|
|
stats.mutable_port_id()->set_id(id);
|
|
mPortGroupId = portGroupId;
|
|
capFile_ = NULL;
|
|
}
|
|
|
|
Port::~Port()
|
|
{
|
|
qDebug("%s", __FUNCTION__);
|
|
while (!mStreams.isEmpty())
|
|
delete mStreams.takeFirst();
|
|
}
|
|
|
|
void Port::updatePortConfig(OstProto::Port *port)
|
|
{
|
|
d.MergeFrom(*port);
|
|
}
|
|
|
|
void Port::updateStreamOrdinalsFromIndex()
|
|
{
|
|
for (int i=0; i < mStreams.size(); i++)
|
|
mStreams[i]->setOrdinal(i);
|
|
}
|
|
|
|
void Port::reorderStreamsByOrdinals()
|
|
{
|
|
qSort(mStreams.begin(), mStreams.end(), StreamBase::StreamLessThan);
|
|
}
|
|
|
|
bool Port::newStreamAt(int index)
|
|
{
|
|
Stream *s = new Stream;
|
|
|
|
if (index > mStreams.size())
|
|
return false;
|
|
|
|
s->setId(newStreamId());
|
|
mStreams.insert(index, s);
|
|
updateStreamOrdinalsFromIndex();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool Port::deleteStreamAt(int index)
|
|
{
|
|
if (index >= mStreams.size())
|
|
return false;
|
|
|
|
delete mStreams.takeAt(index);
|
|
updateStreamOrdinalsFromIndex();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool Port::insertStream(uint streamId)
|
|
{
|
|
Stream *s = new Stream;
|
|
|
|
s->setId(streamId);
|
|
|
|
// FIXME(MED): If a stream with id already exists, what do we do?
|
|
mStreams.append(s);
|
|
|
|
// Update mAllocStreamId to take into account the stream id received
|
|
// from server
|
|
if (mAllocStreamId <= streamId)
|
|
mAllocStreamId = streamId + 1;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool Port::updateStream(uint streamId, OstProto::Stream *stream)
|
|
{
|
|
int i, streamIndex;
|
|
|
|
for (i = 0; i < mStreams.size(); i++)
|
|
{
|
|
if (streamId == mStreams[i]->id())
|
|
goto _found;
|
|
}
|
|
|
|
qDebug("%s: Invalid stream id %d", __FUNCTION__, streamId);
|
|
return false;
|
|
|
|
_found:
|
|
streamIndex = i;
|
|
|
|
mStreams[streamIndex]->protoDataCopyFrom(*stream);
|
|
reorderStreamsByOrdinals();
|
|
|
|
return true;
|
|
}
|
|
|
|
void Port::getDeletedStreamsSinceLastSync(
|
|
OstProto::StreamIdList &streamIdList)
|
|
{
|
|
streamIdList.clear_stream_id();
|
|
for (int i = 0; i < mLastSyncStreamList.size(); i++)
|
|
{
|
|
int j;
|
|
|
|
for (j = 0; j < mStreams.size(); j++)
|
|
{
|
|
if (mLastSyncStreamList[i] == mStreams[j]->id())
|
|
break;
|
|
}
|
|
|
|
if (j < mStreams.size())
|
|
{
|
|
// stream still exists!
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
// stream has been deleted since last sync
|
|
OstProto::StreamId *s;
|
|
|
|
s = streamIdList.add_stream_id();
|
|
s->set_id(mLastSyncStreamList.at(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
void Port::getNewStreamsSinceLastSync(
|
|
OstProto::StreamIdList &streamIdList)
|
|
{
|
|
streamIdList.clear_stream_id();
|
|
for (int i = 0; i < mStreams.size(); i++)
|
|
{
|
|
if (mLastSyncStreamList.contains(mStreams[i]->id()))
|
|
{
|
|
// existing stream!
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
// new stream!
|
|
OstProto::StreamId *s;
|
|
|
|
s = streamIdList.add_stream_id();
|
|
s->set_id(mStreams[i]->id());
|
|
}
|
|
}
|
|
}
|
|
|
|
void Port::getModifiedStreamsSinceLastSync(
|
|
OstProto::StreamConfigList &streamConfigList)
|
|
{
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
//streamConfigList.mutable_port_id()->set_id(mPortId);
|
|
for (int i = 0; i < mStreams.size(); i++)
|
|
{
|
|
OstProto::Stream *s;
|
|
|
|
s = streamConfigList.add_stream();
|
|
mStreams[i]->protoDataCopyInto(*s);
|
|
}
|
|
qDebug("Done %s", __FUNCTION__);
|
|
}
|
|
|
|
void Port::when_syncComplete()
|
|
{
|
|
//reorderStreamsByOrdinals();
|
|
|
|
mLastSyncStreamList.clear();
|
|
for (int i=0; i<mStreams.size(); i++)
|
|
mLastSyncStreamList.append(mStreams[i]->id());
|
|
}
|
|
|
|
void Port::updateStats(OstProto::PortStats *portStats)
|
|
{
|
|
OstProto::PortState oldState;
|
|
|
|
oldState = stats.state();
|
|
stats.MergeFrom(*portStats);
|
|
|
|
if (oldState.link_state() != stats.state().link_state())
|
|
{
|
|
qDebug("portstate changed");
|
|
emit portDataChanged(mPortGroupId, mPortId);
|
|
}
|
|
}
|
|
|