2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 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_CHANNEL_H
|
|
|
|
#define _PB_RPC_CHANNEL_H
|
|
|
|
|
2015-11-06 07:27:07 -06:00
|
|
|
#include <QString>
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
|
|
|
|
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
|
|
|
#include <google/protobuf/message.h>
|
|
|
|
#include <google/protobuf/descriptor.h>
|
|
|
|
#include <google/protobuf/service.h>
|
|
|
|
|
|
|
|
#include "pbrpccommon.h"
|
|
|
|
#include "pbrpccontroller.h"
|
|
|
|
|
|
|
|
class PbRpcChannel : public QObject, public ::google::protobuf::RpcChannel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
// If isPending is TRUE, then controller, done, response
|
|
|
|
// and pendingMethodId correspond to the last method called by
|
|
|
|
// the service stub
|
|
|
|
bool isPending;
|
|
|
|
int pendingMethodId;
|
|
|
|
|
|
|
|
// controller, done, response are set to the corresponding values
|
|
|
|
// passed by the stub to CallMethod(). They are reset to NULL when
|
|
|
|
// we get a response back from the server in on_mpSocket_readyRead()
|
|
|
|
// after calling done->Run().
|
|
|
|
|
|
|
|
/*! \todo (MED) : change controller, done and response to references
|
|
|
|
instead of pointers? */
|
2016-04-26 08:03:20 -05:00
|
|
|
const ::google::protobuf::MethodDescriptor *method;
|
2015-04-16 11:50:07 -05:00
|
|
|
::google::protobuf::RpcController *controller;
|
|
|
|
::google::protobuf::Closure *done;
|
|
|
|
::google::protobuf::Message *response;
|
|
|
|
|
|
|
|
typedef struct _RpcCall {
|
|
|
|
const ::google::protobuf::MethodDescriptor *method;
|
|
|
|
::google::protobuf::RpcController *controller;
|
|
|
|
const ::google::protobuf::Message *request;
|
|
|
|
::google::protobuf::Message *response;
|
|
|
|
::google::protobuf::Closure *done;
|
|
|
|
} RpcCall;
|
|
|
|
QList<RpcCall> pendingCallList;
|
|
|
|
|
2015-04-25 09:42:37 -05:00
|
|
|
const ::google::protobuf::Message ¬ifPrototype;
|
2015-04-24 10:23:00 -05:00
|
|
|
::google::protobuf::Message *notif;
|
|
|
|
|
2015-11-06 07:27:07 -06:00
|
|
|
QString mServerHost;
|
2015-04-16 11:50:07 -05:00
|
|
|
quint16 mServerPort;
|
|
|
|
QTcpSocket *mpSocket;
|
|
|
|
|
|
|
|
::google::protobuf::io::CopyingInputStreamAdaptor *inStream;
|
|
|
|
::google::protobuf::io::CopyingOutputStreamAdaptor *outStream;
|
|
|
|
|
|
|
|
public:
|
2015-11-06 07:27:07 -06:00
|
|
|
PbRpcChannel(QString serverName, quint16 port,
|
2015-04-25 09:42:37 -05:00
|
|
|
const ::google::protobuf::Message ¬ifProto);
|
2015-04-16 11:50:07 -05:00
|
|
|
~PbRpcChannel();
|
|
|
|
|
|
|
|
void establish();
|
2015-11-06 07:27:07 -06:00
|
|
|
void establish(QString serverName, quint16 port);
|
2015-04-16 11:50:07 -05:00
|
|
|
void tearDown();
|
|
|
|
|
2015-11-06 07:27:07 -06:00
|
|
|
const QString serverName() const
|
|
|
|
{
|
|
|
|
return mpSocket->peerName();
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
quint16 serverPort() const { return mServerPort; }
|
|
|
|
|
|
|
|
QAbstractSocket::SocketState state() const
|
|
|
|
{ return mpSocket->state(); }
|
|
|
|
|
|
|
|
void CallMethod(const ::google::protobuf::MethodDescriptor *method,
|
|
|
|
::google::protobuf::RpcController *controller,
|
|
|
|
const ::google::protobuf::Message *req,
|
|
|
|
::google::protobuf::Message *response,
|
|
|
|
::google::protobuf::Closure* done);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void connected();
|
|
|
|
void disconnected();
|
|
|
|
void error(QAbstractSocket::SocketError socketError);
|
|
|
|
void stateChanged(QAbstractSocket::SocketState socketState);
|
|
|
|
|
2015-04-24 10:23:00 -05:00
|
|
|
void notification(int notifType, ::google::protobuf::Message *notifData);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
private slots:
|
|
|
|
void on_mpSocket_connected();
|
|
|
|
void on_mpSocket_disconnected();
|
|
|
|
void on_mpSocket_stateChanged(QAbstractSocket::SocketState socketState);
|
|
|
|
void on_mpSocket_error(QAbstractSocket::SocketError socketError);
|
|
|
|
|
|
|
|
void on_mpSocket_readyRead();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|