Device Emulation (contd.): Client calls RPCs for retreiving device group id and config list(s) at connect; optimisation - don't retreive streamConfig if port doesn't have any streams
This commit is contained in:
parent
e8030bbd01
commit
6fddf0436c
@ -605,3 +605,55 @@ _exit:
|
||||
mainWindow->setEnabled(true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ------------ Device Group ----------- //
|
||||
|
||||
int Port::numDeviceGroups()
|
||||
{
|
||||
return deviceGroups_.size();
|
||||
}
|
||||
|
||||
OstProto::DeviceGroup* Port::deviceGroupByIndex(int index)
|
||||
{
|
||||
// FIXME: do we need to index? can't we use an iterator instead?
|
||||
if ((index < 0) || (index >= numDeviceGroups())) {
|
||||
qWarning("%s: index %d out of range (0 - %d)", __FUNCTION__,
|
||||
index, numDeviceGroups() - 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Sort List by 'id', get the id at 'index' and then corresponding devGrp
|
||||
return deviceGroups_.value(deviceGroups_.uniqueKeys().value(index));
|
||||
}
|
||||
|
||||
bool Port::insertDeviceGroup(uint deviceGroupId)
|
||||
{
|
||||
OstProto::DeviceGroup *devGrp;
|
||||
|
||||
if (deviceGroups_.contains(deviceGroupId)) {
|
||||
qDebug("%s: deviceGroup id %u already exists", __FUNCTION__,
|
||||
deviceGroupId);
|
||||
return false;
|
||||
}
|
||||
|
||||
devGrp = new OstProto::DeviceGroup;
|
||||
devGrp->mutable_device_group_id()->set_id(deviceGroupId);
|
||||
deviceGroups_.insert(deviceGroupId, devGrp);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Port::updateDeviceGroup(
|
||||
uint deviceGroupId,
|
||||
OstProto::DeviceGroup *deviceGroup)
|
||||
{
|
||||
OstProto::DeviceGroup *devGrp = deviceGroups_.value(deviceGroupId);
|
||||
|
||||
if (!devGrp) {
|
||||
qDebug("%s: deviceGroup id %u does not exist", __FUNCTION__,
|
||||
deviceGroupId);
|
||||
return false;
|
||||
}
|
||||
|
||||
devGrp->CopyFrom(*deviceGroup);
|
||||
return true;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#define _PORT_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QTemporaryFile>
|
||||
@ -51,6 +52,8 @@ class Port : public QObject {
|
||||
QList<quint32> mLastSyncStreamList;
|
||||
QList<Stream*> mStreams; // sorted by stream's ordinal value
|
||||
|
||||
QHash<uint, OstProto::DeviceGroup*> deviceGroups_;
|
||||
|
||||
uint newStreamId();
|
||||
void updateStreamOrdinalsFromIndex();
|
||||
void reorderStreamsByOrdinals();
|
||||
@ -145,6 +148,18 @@ public:
|
||||
bool openStreams(QString fileName, bool append, QString &error);
|
||||
bool saveStreams(QString fileName, QString fileType, QString &error);
|
||||
|
||||
// ------------ Device Group ----------- //
|
||||
|
||||
int numDeviceGroups();
|
||||
OstProto::DeviceGroup* deviceGroupByIndex(int index);
|
||||
|
||||
//! Used by MyService::Stub to update from config received from server
|
||||
//@{
|
||||
bool insertDeviceGroup(uint deviceGroupId);
|
||||
bool updateDeviceGroup(uint deviceGroupId,
|
||||
OstProto::DeviceGroup *deviceGroup);
|
||||
//@}
|
||||
|
||||
signals:
|
||||
void portRateChanged(int portGroupId, int portId);
|
||||
void portDataChanged(int portGroupId, int portId);
|
||||
|
@ -365,8 +365,10 @@ void PortGroup::processPortConfigList(PbRpcController *controller)
|
||||
// design
|
||||
emit portListChanged(mPortGroupId);
|
||||
|
||||
if (numPorts() > 0)
|
||||
if (numPorts() > 0) {
|
||||
getStreamIdList();
|
||||
getDeviceGroupIdList();
|
||||
}
|
||||
|
||||
_error_exit:
|
||||
delete controller;
|
||||
@ -580,6 +582,9 @@ void PortGroup::getStreamConfigList()
|
||||
|
||||
for (int portIndex = 0; portIndex < numPorts(); portIndex++)
|
||||
{
|
||||
if (mPorts[portIndex]->numStreams() == 0)
|
||||
continue;
|
||||
|
||||
OstProto::StreamIdList *streamIdList = new OstProto::StreamIdList;
|
||||
OstProto::StreamConfigList *streamConfigList
|
||||
= new OstProto::StreamConfigList;
|
||||
@ -634,11 +639,160 @@ void PortGroup::processStreamConfigList(int portIndex,
|
||||
streamConfigList->mutable_stream(i));
|
||||
}
|
||||
|
||||
#if 0
|
||||
// FIXME: incorrect check - will never be true if last port does not have any streams configured
|
||||
// Are we done for all ports?
|
||||
if (portIndex >= numPorts())
|
||||
if (portIndex >= (numPorts()-1))
|
||||
{
|
||||
// FIXME(HI): some way to reset streammodel
|
||||
}
|
||||
#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());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
for(int i = 0; i < devGrpIdList->device_group_id_size(); i++)
|
||||
{
|
||||
uint devGrpId;
|
||||
|
||||
devGrpId = devGrpIdList->device_group_id(i).id();
|
||||
mPorts[portIndex]->insertDeviceGroup(devGrpId);
|
||||
}
|
||||
|
||||
//FIXME: mPorts[portIndex]->when_syncComplete();
|
||||
|
||||
// Are we done for all ports?
|
||||
if (numPorts() && portIndex >= (numPorts()-1))
|
||||
getDeviceGroupConfigList();
|
||||
|
||||
_exit:
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void PortGroup::getDeviceGroupConfigList()
|
||||
{
|
||||
using OstProto::DeviceGroupId;
|
||||
using OstProto::DeviceGroupIdList;
|
||||
using OstProto::DeviceGroupConfigList;
|
||||
|
||||
qDebug("requesting device group config list ...");
|
||||
|
||||
for (int portIndex = 0; portIndex < numPorts(); portIndex++)
|
||||
{
|
||||
if (mPorts[portIndex]->numDeviceGroups() == 0)
|
||||
continue;
|
||||
|
||||
DeviceGroupIdList *devGrpIdList = new DeviceGroupIdList;
|
||||
DeviceGroupConfigList *devGrpCfgList = new DeviceGroupConfigList;
|
||||
PbRpcController *controller = new PbRpcController(
|
||||
devGrpIdList, devGrpCfgList);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
serviceStub->getDeviceGroupConfig(controller,
|
||||
devGrpIdList, devGrpCfgList,
|
||||
NewCallback(this, &PortGroup::processDeviceGroupConfigList,
|
||||
portIndex, controller));
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
_exit:
|
||||
delete controller;
|
||||
|
@ -117,6 +117,13 @@ public:
|
||||
|
||||
void processModifyStreamAck(OstProto::Ack *ack);
|
||||
|
||||
void getDeviceGroupIdList();
|
||||
void processDeviceGroupIdList(int portIndex, PbRpcController *controller);
|
||||
void getDeviceGroupConfigList();
|
||||
void processDeviceGroupConfigList(
|
||||
int portIndex,
|
||||
PbRpcController *controller);
|
||||
|
||||
void startTx(QList<uint> *portList = NULL);
|
||||
void processStartTxAck(PbRpcController *controller);
|
||||
void stopTx(QList<uint> *portList = NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user