Infra: Added code to disable notifications for python-ostinato scripts since python-ostinato does not expect and hence does not know how to deal with notifications

Updates issue 144
This commit is contained in:
Srivats P. 2015-05-01 21:41:04 +05:30
parent f1378965ca
commit 25ef8dd1e4
7 changed files with 24 additions and 1 deletions

View File

@ -43,6 +43,7 @@ class DroneProxy(object):
def connect(self): def connect(self):
self.channel.connect(self.host, self.port) self.channel.connect(self.host, self.port)
ver = ost_pb.VersionInfo() ver = ost_pb.VersionInfo()
ver.client_name = 'python-ostinato'
ver.version = __version__ ver.version = __version__
compat = self.checkVersion(ver) compat = self.checkVersion(ver)
if compat.result == ost_pb.VersionCompatibility.kIncompatible: if compat.result == ost_pb.VersionCompatibility.kIncompatible:

View File

@ -131,6 +131,7 @@ void PortGroup::on_rpcChannel_connected()
reconnectAfter = kMinReconnectWaitTime; reconnectAfter = kMinReconnectWaitTime;
qDebug("requesting version check ..."); qDebug("requesting version check ...");
verInfo->set_client_name("ostinato");
verInfo->set_version(version); verInfo->set_version(version);
PbRpcController *controller = new PbRpcController(verInfo, verCompat); PbRpcController *controller = new PbRpcController(verInfo, verCompat);

View File

@ -23,6 +23,7 @@ option py_generic_services = true;
message VersionInfo { message VersionInfo {
required string version = 1; required string version = 1;
optional string client_name = 2;
} }
message VersionCompatibility { message VersionCompatibility {

View File

@ -47,6 +47,7 @@ public:
void Reset() { void Reset() {
failed = false; failed = false;
disconnect = false; disconnect = false;
notif = true;
blob = NULL; blob = NULL;
errStr = ""; errStr = "";
} }
@ -70,6 +71,12 @@ public:
bool Disconnect() const { bool Disconnect() const {
return disconnect; return disconnect;
} }
void EnableNotif(bool enabled) {
notif = enabled;
}
bool NotifEnabled() {
return notif;
}
// srivatsp added // srivatsp added
QIODevice* binaryBlob() { return blob; }; QIODevice* binaryBlob() { return blob; };
@ -78,6 +85,7 @@ public:
private: private:
bool failed; bool failed;
bool disconnect; bool disconnect;
bool notif;
QIODevice *blob; QIODevice *blob;
QString errStr; QString errStr;
::google::protobuf::Message *request_; ::google::protobuf::Message *request_;

View File

@ -52,6 +52,7 @@ RpcConnection::RpcConnection(int socketDescriptor,
pendingMethodId = -1; // don't care as long as isPending is false pendingMethodId = -1; // don't care as long as isPending is false
isCompatCheckDone = false; isCompatCheckDone = false;
isNotifEnabled = true;
} }
RpcConnection::~RpcConnection() RpcConnection::~RpcConnection()
@ -183,8 +184,10 @@ void RpcConnection::sendRpcReply(PbRpcController *controller)
response->SerializeToZeroCopyStream(outStream); response->SerializeToZeroCopyStream(outStream);
outStream->Flush(); outStream->Flush();
if (pendingMethodId == 15) if (pendingMethodId == 15) {
isCompatCheckDone = true; isCompatCheckDone = true;
isNotifEnabled = controller->NotifEnabled();
}
_exit: _exit:
if (controller->Disconnect()) if (controller->Disconnect())
@ -201,6 +204,12 @@ void RpcConnection::sendNotification(int notifType,
char* const msg = &msgBuf[0]; char* const msg = &msgBuf[0];
int len; int len;
if (!isCompatCheckDone)
return;
if (!isNotifEnabled)
return;
if (!notifData->IsInitialized()) if (!notifData->IsInitialized())
{ {
qWarning("notification missing required fields!! <----"); qWarning("notification missing required fields!! <----");

View File

@ -77,6 +77,7 @@ private:
int pendingMethodId; int pendingMethodId;
bool isCompatCheckDone; bool isCompatCheckDone;
bool isNotifEnabled;
}; };
#endif #endif

View File

@ -574,6 +574,8 @@ void MyService::checkVersion(::google::protobuf::RpcController* controller,
// Compare only major and minor numbers // Compare only major and minor numbers
if (client[0] == my[0] && client[1] == my[1]) { if (client[0] == my[0] && client[1] == my[1]) {
response->set_result(OstProto::VersionCompatibility::kCompatible); response->set_result(OstProto::VersionCompatibility::kCompatible);
static_cast<PbRpcController*>(controller)->EnableNotif(
request->client_name() == "python-ostinato" ? false : true);
} }
else { else {
response->set_result(OstProto::VersionCompatibility::kIncompatible); response->set_result(OstProto::VersionCompatibility::kIncompatible);