2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010, 2014 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PB_RPC_CONTROLLER_H
|
|
|
|
#define _PB_RPC_CONTROLLER_H
|
|
|
|
|
|
|
|
#include <google/protobuf/message.h>
|
|
|
|
#include <google/protobuf/service.h>
|
|
|
|
|
|
|
|
class QIODevice;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
PbRpcController takes ownership of the 'request' and 'response' messages and
|
|
|
|
will delete them when it itself is destroyed
|
|
|
|
*/
|
|
|
|
class PbRpcController : public ::google::protobuf::RpcController
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PbRpcController(::google::protobuf::Message *request,
|
|
|
|
::google::protobuf::Message *response) {
|
|
|
|
request_ = request;
|
|
|
|
response_ = response;
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
~PbRpcController() { delete request_; delete response_; }
|
|
|
|
|
|
|
|
::google::protobuf::Message* request() { return request_; }
|
|
|
|
::google::protobuf::Message* response() { return response_; }
|
|
|
|
|
|
|
|
// Client Side Methods
|
|
|
|
void Reset() {
|
|
|
|
failed = false;
|
|
|
|
disconnect = false;
|
2015-05-01 11:11:04 -05:00
|
|
|
notif = true;
|
2015-04-16 11:50:07 -05:00
|
|
|
blob = NULL;
|
|
|
|
errStr = "";
|
|
|
|
}
|
|
|
|
bool Failed() const { return failed; }
|
|
|
|
void StartCancel() { /*! \todo (MED) */}
|
|
|
|
std::string ErrorText() const { return errStr.toStdString(); }
|
|
|
|
|
|
|
|
// Server Side Methods
|
|
|
|
void SetFailed(const QString &reason)
|
|
|
|
{ failed = true; errStr = reason; qWarning("%s", qPrintable(errStr)); }
|
|
|
|
void SetFailed(const std::string &reason)
|
|
|
|
{ SetFailed(QString::fromStdString(reason)); }
|
|
|
|
QString ErrorString() const { return errStr; }
|
|
|
|
bool IsCanceled() const { return false; };
|
|
|
|
void NotifyOnCancel(::google::protobuf::Closure* /* callback */) {
|
|
|
|
/*! \todo (MED) */
|
|
|
|
}
|
|
|
|
void TriggerDisconnect() {
|
|
|
|
disconnect = true;
|
|
|
|
}
|
|
|
|
bool Disconnect() const {
|
|
|
|
return disconnect;
|
|
|
|
}
|
2015-05-01 11:11:04 -05:00
|
|
|
void EnableNotif(bool enabled) {
|
|
|
|
notif = enabled;
|
|
|
|
}
|
|
|
|
bool NotifEnabled() {
|
|
|
|
return notif;
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
// srivatsp added
|
|
|
|
QIODevice* binaryBlob() { return blob; };
|
|
|
|
void setBinaryBlob(QIODevice *binaryBlob) { blob = binaryBlob; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool failed;
|
|
|
|
bool disconnect;
|
2015-05-01 11:11:04 -05:00
|
|
|
bool notif;
|
2015-04-16 11:50:07 -05:00
|
|
|
QIODevice *blob;
|
|
|
|
QString errStr;
|
|
|
|
::google::protobuf::Message *request_;
|
|
|
|
::google::protobuf::Message *response_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|