sign: Do not allow port TxMode/StreamsType to be changed while tx is on

This commit is contained in:
Srivats P 2016-10-27 21:44:08 +05:30
parent a79bbb1fcd
commit 9de3f96b20
3 changed files with 32 additions and 2 deletions

View File

@ -65,6 +65,28 @@ void AbstractPort::init()
{
}
/*! Can we modify Port with these params? Should modify cause port dirty? */
bool AbstractPort::canModify(const OstProto::Port &port, bool *dirty)
{
bool allow = true;
*dirty = false;
if (port.has_transmit_mode()
&& (port.transmit_mode() != data_.transmit_mode())) {
*dirty = true;
allow = !isTransmitOn();
}
if (port.has_streams_type()
&& (port.streams_type() != data_.streams_type())) {
*dirty = true;
allow = !isTransmitOn();
}
return allow;
}
bool AbstractPort::modify(const OstProto::Port &port)
{
bool ret = true;

View File

@ -87,6 +87,7 @@ public:
const char* name() { return data_.name().c_str(); }
void protoDataCopyInto(OstProto::Port *port) { port->CopyFrom(data_); }
bool canModify(const OstProto::Port &port, bool *dirty);
bool modify(const OstProto::Port &port);
virtual OstProto::LinkState linkState() { return linkState_; }

View File

@ -133,13 +133,20 @@ void MyService::modifyPort(::google::protobuf::RpcController* /*controller*/,
id = port.port_id().id();
if (id < portInfo.size())
{
// FIXME: return error for any change in transmitMode/streamsType
// while transmit is on
bool dirty;
if (!portInfo[id]->canModify(port, &dirty)) {
qDebug("Port %d cannot be modified - stop tx and retry", id);
continue; //! \todo(LOW): Partial status of RPC
}
portLock[id]->lockForWrite();
portInfo[id]->modify(port);
if (dirty)
portInfo[id]->updatePacketList();
portLock[id]->unlock();
notif->mutable_port_id_list()->add_port_id()->set_id(id);
}
}