From 25ef8dd1e4ebdd31d11821ec45f4aa005ae89e3a Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Fri, 1 May 2015 21:41:04 +0530 Subject: [PATCH] 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 --- binding/core.py | 1 + client/portgroup.cpp | 1 + common/protocol.proto | 1 + rpc/pbrpccontroller.h | 8 ++++++++ rpc/rpcconn.cpp | 11 ++++++++++- rpc/rpcconn.h | 1 + server/myservice.cpp | 2 ++ 7 files changed, 24 insertions(+), 1 deletion(-) diff --git a/binding/core.py b/binding/core.py index d8de580..b8d47f6 100644 --- a/binding/core.py +++ b/binding/core.py @@ -43,6 +43,7 @@ class DroneProxy(object): def connect(self): self.channel.connect(self.host, self.port) ver = ost_pb.VersionInfo() + ver.client_name = 'python-ostinato' ver.version = __version__ compat = self.checkVersion(ver) if compat.result == ost_pb.VersionCompatibility.kIncompatible: diff --git a/client/portgroup.cpp b/client/portgroup.cpp index fe4334d..6991f10 100644 --- a/client/portgroup.cpp +++ b/client/portgroup.cpp @@ -131,6 +131,7 @@ void PortGroup::on_rpcChannel_connected() reconnectAfter = kMinReconnectWaitTime; qDebug("requesting version check ..."); + verInfo->set_client_name("ostinato"); verInfo->set_version(version); PbRpcController *controller = new PbRpcController(verInfo, verCompat); diff --git a/common/protocol.proto b/common/protocol.proto index 09400b6..9d1d768 100644 --- a/common/protocol.proto +++ b/common/protocol.proto @@ -23,6 +23,7 @@ option py_generic_services = true; message VersionInfo { required string version = 1; + optional string client_name = 2; } message VersionCompatibility { diff --git a/rpc/pbrpccontroller.h b/rpc/pbrpccontroller.h index 788fc2b..69c2fe4 100644 --- a/rpc/pbrpccontroller.h +++ b/rpc/pbrpccontroller.h @@ -47,6 +47,7 @@ public: void Reset() { failed = false; disconnect = false; + notif = true; blob = NULL; errStr = ""; } @@ -70,6 +71,12 @@ public: bool Disconnect() const { return disconnect; } + void EnableNotif(bool enabled) { + notif = enabled; + } + bool NotifEnabled() { + return notif; + } // srivatsp added QIODevice* binaryBlob() { return blob; }; @@ -78,6 +85,7 @@ public: private: bool failed; bool disconnect; + bool notif; QIODevice *blob; QString errStr; ::google::protobuf::Message *request_; diff --git a/rpc/rpcconn.cpp b/rpc/rpcconn.cpp index 2931a7f..bd42c3c 100644 --- a/rpc/rpcconn.cpp +++ b/rpc/rpcconn.cpp @@ -52,6 +52,7 @@ RpcConnection::RpcConnection(int socketDescriptor, pendingMethodId = -1; // don't care as long as isPending is false isCompatCheckDone = false; + isNotifEnabled = true; } RpcConnection::~RpcConnection() @@ -183,8 +184,10 @@ void RpcConnection::sendRpcReply(PbRpcController *controller) response->SerializeToZeroCopyStream(outStream); outStream->Flush(); - if (pendingMethodId == 15) + if (pendingMethodId == 15) { isCompatCheckDone = true; + isNotifEnabled = controller->NotifEnabled(); + } _exit: if (controller->Disconnect()) @@ -201,6 +204,12 @@ void RpcConnection::sendNotification(int notifType, char* const msg = &msgBuf[0]; int len; + if (!isCompatCheckDone) + return; + + if (!isNotifEnabled) + return; + if (!notifData->IsInitialized()) { qWarning("notification missing required fields!! <----"); diff --git a/rpc/rpcconn.h b/rpc/rpcconn.h index 830826a..b73ec64 100644 --- a/rpc/rpcconn.h +++ b/rpc/rpcconn.h @@ -77,6 +77,7 @@ private: int pendingMethodId; bool isCompatCheckDone; + bool isNotifEnabled; }; #endif diff --git a/server/myservice.cpp b/server/myservice.cpp index 74468c2..0a4f7ca 100644 --- a/server/myservice.cpp +++ b/server/myservice.cpp @@ -574,6 +574,8 @@ void MyService::checkVersion(::google::protobuf::RpcController* controller, // Compare only major and minor numbers if (client[0] == my[0] && client[1] == my[1]) { response->set_result(OstProto::VersionCompatibility::kCompatible); + static_cast(controller)->EnableNotif( + request->client_name() == "python-ostinato" ? false : true); } else { response->set_result(OstProto::VersionCompatibility::kIncompatible);