-
Notifications
You must be signed in to change notification settings - Fork 0
/
twowaystream.h
69 lines (61 loc) · 2.71 KB
/
twowaystream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Copyright (C) 2009 Frederik M.J.V
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* LGPL is available on the internet at
* http://www.gnu.org/licenses/lgpl-2.1.html and from Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef TWOWAYSTREAM_H
#define TWOWAYSTREAM_H
#include <Qt/QtCore>
#include <Qt/QtNetwork>
#include <callentry.h>
#include <streamcallbackinfo.h>
#include <google/protobuf/message.h>
#include <google/protobuf/service.h>
namespace protorpc{
class TwoWayStream : public QThread, public google::protobuf::RpcChannel
{
Q_OBJECT
protected:
QIODevice *idev;
QIODevice *odev;
QMutex *streamlock;
QMutex devlock;
bool connected,stopped;
QWaitCondition initcond;
google::protobuf::Closure* shutdownCallback;
private:
int timeout;
google::protobuf::Service *service;
uint32_t callnum;
bool spawnCallers;
QHash<uint32_t,CallEntry> currentCalls;
public:
TwoWayStream(QIODevice *dev,google::protobuf::Service* srv,bool autostart=false,google::protobuf::Closure *shutdownClosure=NULL);
~TwoWayStream();
//void callMethod(const google::protobuf::MethodDescriptor * method, google::protobuf::RpcController * controller, const google::protobuf::Message * request, google::protobuf::Message * response, google::protobuf::Closure * done);
void CallMethod(const google::protobuf::MethodDescriptor* method, google::protobuf::RpcController* controller, const google::protobuf::Message* request, google::protobuf::Message* response, google::protobuf::Closure* done);
void response(StreamCallbackInfo *entry);
void start();
void setInputDevice(QIODevice *idev);
/*Not owned by stream, must be deleted if set !=idev*/
void setOutputDevice(QIODevice *odev);
void shutdown(bool closeStreams);
bool cancelMethodCall(google::protobuf::Message* response);
protected:
void writeMessage(google::protobuf::Message* m);
void callMethodThreaded(const google::protobuf::MethodDescriptor * method, google::protobuf::RpcController * controller, const google::protobuf::Message * request, google::protobuf::Message * response, google::protobuf::Closure * done);
google::protobuf::Message *fillMessage(google::protobuf::Message *type);
void requestServiceDescriptor(google::protobuf::Closure *cb,google::protobuf::RpcController *ctrl);
void run();
void cleanup();
signals:
void channelBroken(google::protobuf::RpcChannel *chan);
};
};
//#include "twowaystream.moc"
#endif // TWOWAYSTREAM_H