Populate Ack for every RPC

Also make error strings in Ack and RPC failure consistent
This commit is contained in:
Srivats P 2019-02-16 20:38:25 +05:30
parent 95578e5094
commit 7ea8c96543

View File

@ -110,6 +110,7 @@ void MyService::getPortConfig(::google::protobuf::RpcController* /*controller*/,
portInfo[id]->protoDataCopyInto(p); portInfo[id]->protoDataCopyInto(p);
portLock[id]->unlock(); portLock[id]->unlock();
} }
// XXX: no way to inform RPC caller of an invalid port!
} }
done->Run(); done->Run();
@ -122,6 +123,7 @@ void MyService::modifyPort(::google::protobuf::RpcController* /*controller*/,
{ {
bool fail = false; bool fail = false;
QString notes; QString notes;
// notification needs to be on heap because signal/slot is across threads! // notification needs to be on heap because signal/slot is across threads!
OstProto::Notification *notif = new OstProto::Notification; OstProto::Notification *notif = new OstProto::Notification;
@ -140,7 +142,10 @@ void MyService::modifyPort(::google::protobuf::RpcController* /*controller*/,
if (!portInfo[id]->canModify(port, &dirty)) { if (!portInfo[id]->canModify(port, &dirty)) {
qDebug("Port %d cannot be modified - stop tx and retry", id); qDebug("Port %d cannot be modified - stop tx and retry", id);
continue; //! \todo(LOW): Partial status of RPC fail = true;
notes += QString("Port %1 modify: operation disallowed on "
"transmitting port\n").arg(id);
continue;
} }
portLock[id]->lockForWrite(); portLock[id]->lockForWrite();
@ -149,11 +154,15 @@ void MyService::modifyPort(::google::protobuf::RpcController* /*controller*/,
err = portInfo[id]->updatePacketList(); err = portInfo[id]->updatePacketList();
portLock[id]->unlock(); portLock[id]->unlock();
if (err) { if (err) {
notes += frameValueErrorNotes(id, err);
fail = true; fail = true;
notes += frameValueErrorNotes(id, err);
} }
notif->mutable_port_id_list()->add_port_id()->set_id(id); notif->mutable_port_id_list()->add_port_id()->set_id(id);
} }
else {
fail = true;
notes += QString("Port %1 modify: invalid port\n").arg(id);
}
} }
if (fail) { if (fail) {
@ -200,7 +209,8 @@ void MyService::getStreamIdList(::google::protobuf::RpcController* controller,
return; return;
_invalid_port: _invalid_port:
controller->SetFailed("Invalid Port Id"); controller->SetFailed(QString("Port %1 get stream id list: invalid port")
.arg(portId).toStdString());
done->Run(); done->Run();
} }
@ -226,7 +236,7 @@ void MyService::getStreamConfig(::google::protobuf::RpcController* controller,
stream = portInfo[portId]->stream(request->stream_id(i).id()); stream = portInfo[portId]->stream(request->stream_id(i).id());
if (!stream) if (!stream)
continue; //! \todo(LOW): Partial status of RPC continue; //! XXX: no way to inform RPC caller of invalid stream id
s = response->add_stream(); s = response->add_stream();
stream->protoDataCopyInto(*s); stream->protoDataCopyInto(*s);
@ -237,15 +247,18 @@ void MyService::getStreamConfig(::google::protobuf::RpcController* controller,
return; return;
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed(QString("Port %1 get stream config: invalid port")
.arg(portId).toStdString());
done->Run(); done->Run();
} }
void MyService::addStream(::google::protobuf::RpcController* controller, void MyService::addStream(::google::protobuf::RpcController* controller,
const ::OstProto::StreamIdList* request, const ::OstProto::StreamIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
int portId; int portId;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
@ -264,8 +277,13 @@ void MyService::addStream(::google::protobuf::RpcController* controller,
// If stream with same id as in request exists already ==> error!! // If stream with same id as in request exists already ==> error!!
stream = portInfo[portId]->stream(request->stream_id(i).id()); stream = portInfo[portId]->stream(request->stream_id(i).id());
if (stream) if (stream) {
continue; //! \todo (LOW): Partial status of RPC fail = true;
notes += QString("Port %1 Stream %2 add stream: "
"stream already exists\n")
.arg(portId).arg(request->stream_id(i).id());
continue;
}
// Append a new "default" stream - actual contents of the new stream is // Append a new "default" stream - actual contents of the new stream is
// expected in a subsequent "modifyStream" request - set the stream id // expected in a subsequent "modifyStream" request - set the stream id
@ -276,26 +294,35 @@ void MyService::addStream(::google::protobuf::RpcController* controller,
} }
portLock[portId]->unlock(); portLock[portId]->unlock();
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
return; return;
_port_busy: _port_busy:
controller->SetFailed("Port Busy"); controller->SetFailed(QString("Port %1 add stream: operation disallowed on "
"transmitting port")
.arg(portId).toStdString());
goto _exit; goto _exit;
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed(QString("Port %1 add stream: invalid port")
.arg(portId).toStdString());
_exit: _exit:
done->Run(); done->Run();
} }
void MyService::deleteStream(::google::protobuf::RpcController* controller, void MyService::deleteStream(::google::protobuf::RpcController* controller,
const ::OstProto::StreamIdList* request, const ::OstProto::StreamIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
int portId; int portId;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
@ -308,20 +335,32 @@ void MyService::deleteStream(::google::protobuf::RpcController* controller,
goto _port_busy; goto _port_busy;
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
for (int i = 0; i < request->stream_id_size(); i++) for (int i = 0; i < request->stream_id_size(); i++) {
portInfo[portId]->deleteStream(request->stream_id(i).id()); if (!portInfo[portId]->deleteStream(request->stream_id(i).id())) {
fail = true;
notes += QString("Port %1 Stream %2 stream delete: "
"stream not found\n")
.arg(portId).arg(request->stream_id(i).id());
}
}
portLock[portId]->unlock(); portLock[portId]->unlock();
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
return; return;
_port_busy: _port_busy:
controller->SetFailed("Port Busy"); controller->SetFailed(QString("Port %1 delete stream: operation disallowed " "on transmitting port")
.arg(portId).toStdString());
goto _exit; goto _exit;
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed(QString("Port %1 delete stream: invalid port")
.arg(portId).toStdString());
_exit: _exit:
done->Run(); done->Run();
} }
@ -331,6 +370,8 @@ void MyService::modifyStream(::google::protobuf::RpcController* controller,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
int portId; int portId;
int err = 0; int err = 0;
@ -346,22 +387,26 @@ void MyService::modifyStream(::google::protobuf::RpcController* controller,
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
for (int i = 0; i < request->stream_size(); i++) for (int i = 0; i < request->stream_size(); i++)
{ {
StreamBase *stream; quint32 sid = request->stream(i).stream_id().id();
StreamBase *stream = portInfo[portId]->stream(sid);
stream = portInfo[portId]->stream(request->stream(i).stream_id().id());
if (stream) if (stream)
{ {
stream->protoDataCopyFrom(request->stream(i)); stream->protoDataCopyFrom(request->stream(i));
portInfo[portId]->setDirty(); portInfo[portId]->setDirty();
} }
else {
fail = true;
notes += QString("Port %1 Stream %2 modify stream: "
"stream not found\n").arg(portId).arg(sid);
}
} }
if (portInfo[portId]->isDirty()) if (portInfo[portId]->isDirty())
err = portInfo[portId]->updatePacketList(); err = portInfo[portId]->updatePacketList();
portLock[portId]->unlock(); portLock[portId]->unlock();
if (err) { if (fail || err) {
QString notes = frameValueErrorNotes(portId, err); notes += frameValueErrorNotes(portId, err);
response->set_status(OstProto::Ack::kRpcFail); response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString()); response->set_notes(notes.toStdString());
} }
@ -371,10 +416,12 @@ void MyService::modifyStream(::google::protobuf::RpcController* controller,
return; return;
_port_busy: _port_busy:
controller->SetFailed("Port Busy"); controller->SetFailed(QString("Port %1 modify stream: operation disallowed " "on transmitting port")
.arg(portId).toStdString());
goto _exit; goto _exit;
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed(QString("Port %1 modify stream: invalid port")
.arg(portId).toStdString());
_exit: _exit:
done->Run(); done->Run();
} }
@ -395,8 +442,12 @@ void MyService::startTransmit(::google::protobuf::RpcController* /*controller*/,
int err = 0; int err = 0;
portId = request->port_id(i).id(); portId = request->port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size())) {
continue; //! \todo (LOW): partial RPC? fail = true;
notes += QString("Port %1 start transmit: invalid port\n")
.arg(portId);
continue;
}
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
if (portInfo[portId]->isDirty()) if (portInfo[portId]->isDirty())
@ -404,8 +455,8 @@ void MyService::startTransmit(::google::protobuf::RpcController* /*controller*/,
portInfo[portId]->startTransmit(); portInfo[portId]->startTransmit();
portLock[portId]->unlock(); portLock[portId]->unlock();
if (err) { if (err) {
notes += frameValueErrorNotes(portId, err);
fail = true; fail = true;
notes += frameValueErrorNotes(portId, err);
} }
} }
@ -421,9 +472,12 @@ void MyService::startTransmit(::google::protobuf::RpcController* /*controller*/,
void MyService::stopTransmit(::google::protobuf::RpcController* /*controller*/, void MyService::stopTransmit(::google::protobuf::RpcController* /*controller*/,
const ::OstProto::PortIdList* request, const ::OstProto::PortIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (int i = 0; i < request->port_id_size(); i++) for (int i = 0; i < request->port_id_size(); i++)
@ -431,24 +485,35 @@ void MyService::stopTransmit(::google::protobuf::RpcController* /*controller*/,
int portId; int portId;
portId = request->port_id(i).id(); portId = request->port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size())) {
continue; //! \todo (LOW): partial RPC? fail = true;
notes += QString("Port %1 stop transmit: invalid port\n")
.arg(portId);
continue;
}
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
portInfo[portId]->stopTransmit(); portInfo[portId]->stopTransmit();
portLock[portId]->unlock(); portLock[portId]->unlock();
} }
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
} }
void MyService::startCapture(::google::protobuf::RpcController* /*controller*/, void MyService::startCapture(::google::protobuf::RpcController* /*controller*/,
const ::OstProto::PortIdList* request, const ::OstProto::PortIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (int i = 0; i < request->port_id_size(); i++) for (int i = 0; i < request->port_id_size(); i++)
@ -456,40 +521,59 @@ void MyService::startCapture(::google::protobuf::RpcController* /*controller*/,
int portId; int portId;
portId = request->port_id(i).id(); portId = request->port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size())) {
continue; //! \todo (LOW): partial RPC? fail = true;
notes += QString("Port %1 start capture: invalid port\n")
.arg(portId);
continue;
}
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
portInfo[portId]->startCapture(); portInfo[portId]->startCapture();
portLock[portId]->unlock(); portLock[portId]->unlock();
} }
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
} }
void MyService::stopCapture(::google::protobuf::RpcController* /*controller*/, void MyService::stopCapture(::google::protobuf::RpcController* /*controller*/,
const ::OstProto::PortIdList* request, const ::OstProto::PortIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (int i=0; i < request->port_id_size(); i++) for (int i=0; i < request->port_id_size(); i++)
{ {
int portId; int portId;
portId = request->port_id(i).id(); portId = request->port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size())) {
continue; //! \todo (LOW): partial RPC? fail = true;
notes += QString("Port %1 stop capture: invalid port\n")
.arg(portId);
continue;
}
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
portInfo[portId]->stopCapture(); portInfo[portId]->stopCapture();
portLock[portId]->unlock(); portLock[portId]->unlock();
} }
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
} }
@ -517,6 +601,8 @@ void MyService::getCaptureBuffer(::google::protobuf::RpcController* controller,
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed("invalid portid");
controller->SetFailed(QString("Port %1 get capture buffer: invalid port")
.arg(portId).toStdString());
done->Run(); done->Run();
} }
@ -536,7 +622,7 @@ void MyService::getStats(::google::protobuf::RpcController* /*controller*/,
portId = request->port_id(i).id(); portId = request->port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size()))
continue; //! \todo(LOW): partial rpc? continue; // XXX: no way to inform RPC caller of invalid port
s = response->add_port_stats(); s = response->add_port_stats();
s->mutable_port_id()->set_id(request->port_id(i).id()); s->mutable_port_id()->set_id(request->port_id(i).id());
@ -576,9 +662,12 @@ void MyService::getStats(::google::protobuf::RpcController* /*controller*/,
void MyService::clearStats(::google::protobuf::RpcController* /*controller*/, void MyService::clearStats(::google::protobuf::RpcController* /*controller*/,
const ::OstProto::PortIdList* request, const ::OstProto::PortIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (int i = 0; i < request->port_id_size(); i++) for (int i = 0; i < request->port_id_size(); i++)
@ -586,16 +675,24 @@ void MyService::clearStats(::google::protobuf::RpcController* /*controller*/,
int portId; int portId;
portId = request->port_id(i).id(); portId = request->port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size())) {
continue; //! \todo (LOW): partial RPC? fail = true;
notes += QString("Port %1 clear statistics: invalid port\n")
.arg(portId);
continue;
}
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
portInfo[portId]->resetStats(); portInfo[portId]->resetStats();
portLock[portId]->unlock(); portLock[portId]->unlock();
} }
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
} }
@ -613,7 +710,7 @@ void MyService::getStreamStats(
portId = request->port_id_list().port_id(i).id(); portId = request->port_id_list().port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size()))
continue; //! \todo(LOW): partial rpc? continue; // XXX: no way to inform RPC caller of invalid port
portLock[portId]->lockForRead(); portLock[portId]->lockForRead();
if (request->stream_guid_size()) if (request->stream_guid_size())
@ -631,9 +728,12 @@ void MyService::getStreamStats(
void MyService::clearStreamStats( void MyService::clearStreamStats(
::google::protobuf::RpcController* /*controller*/, ::google::protobuf::RpcController* /*controller*/,
const ::OstProto::StreamGuidList* request, const ::OstProto::StreamGuidList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (int i = 0; i < request->port_id_list().port_id_size(); i++) for (int i = 0; i < request->port_id_list().port_id_size(); i++)
@ -641,8 +741,12 @@ void MyService::clearStreamStats(
int portId; int portId;
portId = request->port_id_list().port_id(i).id(); portId = request->port_id_list().port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size())) {
continue; //! \todo (LOW): partial RPC? fail = true;
notes += QString("Port %1 clear stream statistics: invalid port\n")
.arg(portId);
continue;
}
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
if (request->stream_guid_size()) if (request->stream_guid_size())
@ -654,8 +758,12 @@ void MyService::clearStreamStats(
portLock[portId]->unlock(); portLock[portId]->unlock();
} }
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
} }
@ -747,7 +855,8 @@ void MyService::getDeviceGroupIdList(
return; return;
_invalid_port: _invalid_port:
controller->SetFailed("Invalid Port Id"); controller->SetFailed(QString("Port %1 get device group id list: "
"invalid port").arg(portId).toStdString());
done->Run(); done->Run();
} }
@ -776,7 +885,7 @@ void MyService::getDeviceGroupConfig(
dg = devMgr->deviceGroup(request->device_group_id(i).id()); dg = devMgr->deviceGroup(request->device_group_id(i).id());
if (!dg) if (!dg)
continue; //! \todo(LOW): Partial status of RPC continue; // XXX: no way to inform RPC caller of invalid dgid
response->add_device_group()->CopyFrom(*dg); response->add_device_group()->CopyFrom(*dg);
} }
@ -786,16 +895,19 @@ void MyService::getDeviceGroupConfig(
return; return;
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed(QString("Port %1 get device group config: "
"invalid port").arg(portId).toStdString());
done->Run(); done->Run();
} }
void MyService::addDeviceGroup( void MyService::addDeviceGroup(
::google::protobuf::RpcController* controller, ::google::protobuf::RpcController* controller,
const ::OstProto::DeviceGroupIdList* request, const ::OstProto::DeviceGroupIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
DeviceManager *devMgr; DeviceManager *devMgr;
int portId; int portId;
@ -817,24 +929,37 @@ void MyService::addDeviceGroup(
const OstProto::DeviceGroup *dg = devMgr->deviceGroup(id); const OstProto::DeviceGroup *dg = devMgr->deviceGroup(id);
// If device group with same id as in request exists already ==> error! // If device group with same id as in request exists already ==> error!
if (dg) if (dg) {
continue; //! \todo (LOW): Partial status of RPC fail = true;
notes += QString("Port %1 DeviceGroup %2 add device group: "
" device group already exists\n")
.arg(portId).arg(id);
continue;
}
devMgr->addDeviceGroup(id); devMgr->addDeviceGroup(id);
} }
portLock[portId]->unlock(); portLock[portId]->unlock();
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
return; return;
_port_busy: _port_busy:
controller->SetFailed("Port Busy"); controller->SetFailed(QString("Port %1 add device group: "
"operation disallowed on transmitting port")
.arg(portId).toStdString());
goto _exit; goto _exit;
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed(QString("Port %1 add device group: "
"invalid port")
.arg(portId).toStdString());
_exit: _exit:
done->Run(); done->Run();
} }
@ -842,9 +967,11 @@ _exit:
void MyService::deleteDeviceGroup( void MyService::deleteDeviceGroup(
::google::protobuf::RpcController* controller, ::google::protobuf::RpcController* controller,
const ::OstProto::DeviceGroupIdList* request, const ::OstProto::DeviceGroupIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
DeviceManager *devMgr; DeviceManager *devMgr;
int portId; int portId;
@ -860,20 +987,33 @@ void MyService::deleteDeviceGroup(
goto _port_busy; goto _port_busy;
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
for (int i = 0; i < request->device_group_id_size(); i++) for (int i = 0; i < request->device_group_id_size(); i++) {
devMgr->deleteDeviceGroup(request->device_group_id(i).id()); quint32 id = request->device_group_id(i).id();
if (!devMgr->deleteDeviceGroup(id)) {
fail = true;
notes += QString("Port %1 DeviceGroup %2 delete device group: "
"device group not found\n").arg(portId).arg(id);
}
}
portLock[portId]->unlock(); portLock[portId]->unlock();
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
return; return;
_port_busy: _port_busy:
controller->SetFailed("Port Busy"); controller->SetFailed(QString("Port %1 delete device group: "
"operation disallowed on transmitting port")
.arg(portId).toStdString());
goto _exit; goto _exit;
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed(QString("Port %1 delete device group: "
"invalid port").arg(portId).toStdString());
_exit: _exit:
done->Run(); done->Run();
} }
@ -881,9 +1021,11 @@ _exit:
void MyService::modifyDeviceGroup( void MyService::modifyDeviceGroup(
::google::protobuf::RpcController* controller, ::google::protobuf::RpcController* controller,
const ::OstProto::DeviceGroupConfigList* request, const ::OstProto::DeviceGroupConfigList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
DeviceManager *devMgr; DeviceManager *devMgr;
int portId; int portId;
@ -899,20 +1041,33 @@ void MyService::modifyDeviceGroup(
goto _port_busy; goto _port_busy;
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
for (int i = 0; i < request->device_group_size(); i++) for (int i = 0; i < request->device_group_size(); i++) {
devMgr->modifyDeviceGroup(&request->device_group(i)); quint32 id = request->device_group(i).device_group_id().id();
if (!devMgr->modifyDeviceGroup(&request->device_group(i))) {
fail = true;
notes += QString("Port %1 DeviceGroup %2 modify device group: "
"device group not found\n").arg(portId).arg(id);
}
}
portLock[portId]->unlock(); portLock[portId]->unlock();
//! \todo(LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
return; return;
_port_busy: _port_busy:
controller->SetFailed("Port Busy"); controller->SetFailed(QString("Port %1 modify device group: "
"operation disallowed on transmitting port")
.arg(portId).toStdString());
goto _exit; goto _exit;
_invalid_port: _invalid_port:
controller->SetFailed("invalid portid"); controller->SetFailed(QString("Port %1 modify device group: "
"invalid port").arg(portId).toStdString());
_exit: _exit:
done->Run(); done->Run();
} }
@ -943,16 +1098,20 @@ void MyService::getDeviceList(
return; return;
_invalid_port: _invalid_port:
controller->SetFailed("Invalid Port Id"); controller->SetFailed(QString("Port %1 get device list: "
"invalid port").arg(portId).toStdString());
done->Run(); done->Run();
} }
void MyService::resolveDeviceNeighbors( void MyService::resolveDeviceNeighbors(
::google::protobuf::RpcController* /*controller*/, ::google::protobuf::RpcController* /*controller*/,
const ::OstProto::PortIdList* request, const ::OstProto::PortIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (int i = 0; i < request->port_id_size(); i++) for (int i = 0; i < request->port_id_size(); i++)
@ -960,25 +1119,36 @@ void MyService::resolveDeviceNeighbors(
int portId; int portId;
portId = request->port_id(i).id(); portId = request->port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size())) {
continue; //! \todo (LOW): partial RPC? fail = true;
notes += QString("Port %1 resolve device neighbors: "
"invalid port\n").arg(portId);
continue;
}
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
portInfo[portId]->resolveDeviceNeighbors(); portInfo[portId]->resolveDeviceNeighbors();
portLock[portId]->unlock(); portLock[portId]->unlock();
} }
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
} }
void MyService::clearDeviceNeighbors( void MyService::clearDeviceNeighbors(
::google::protobuf::RpcController* /*controller*/, ::google::protobuf::RpcController* /*controller*/,
const ::OstProto::PortIdList* request, const ::OstProto::PortIdList* request,
::OstProto::Ack* /*response*/, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
bool fail = false;
QString notes;
qDebug("In %s", __PRETTY_FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (int i = 0; i < request->port_id_size(); i++) for (int i = 0; i < request->port_id_size(); i++)
@ -986,16 +1156,24 @@ void MyService::clearDeviceNeighbors(
int portId; int portId;
portId = request->port_id(i).id(); portId = request->port_id(i).id();
if ((portId < 0) || (portId >= portInfo.size())) if ((portId < 0) || (portId >= portInfo.size())) {
continue; //! \todo (LOW): partial RPC? fail = true;
notes += QString("Port %1 clear device neighbors: "
"invalid port\n").arg(portId);
continue;
}
portLock[portId]->lockForWrite(); portLock[portId]->lockForWrite();
portInfo[portId]->clearDeviceNeighbors(); portInfo[portId]->clearDeviceNeighbors();
portLock[portId]->unlock(); portLock[portId]->unlock();
} }
//! \todo (LOW): fill-in response "Ack"???? if (fail) {
response->set_status(OstProto::Ack::kRpcFail);
response->set_notes(notes.toStdString());
}
else
response->set_status(OstProto::Ack::kRpcSuccess);
done->Run(); done->Run();
} }
@ -1025,7 +1203,8 @@ void MyService::getDeviceNeighbors(
return; return;
_invalid_port: _invalid_port:
controller->SetFailed("Invalid Port Id"); controller->SetFailed(QString("Port %1 get device neighbors: "
"invalid port").arg(portId).toStdString());
done->Run(); done->Run();
} }
@ -1043,7 +1222,7 @@ QString MyService::frameValueErrorNotes(int portId, int error)
if (errorFlags & FrameValueAttrib::UnresolvedSrcMacError) if (errorFlags & FrameValueAttrib::UnresolvedSrcMacError)
return pfx + "Source mac resolve failed for one or more " return pfx + "Source mac resolve failed for one or more "
"streams - Device matching stream's source ip not found\n"; "streams - Device matching stream's source IP not found\n";
if (errorFlags & FrameValueAttrib::UnresolvedDstMacError) if (errorFlags & FrameValueAttrib::UnresolvedDstMacError)
return pfx + "Destination mac resolve failed for one or more " return pfx + "Destination mac resolve failed for one or more "