libktorrent  2.2.0
rpccall.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef DHTRPCCALL_H
21 #define DHTRPCCALL_H
22 
23 #include <qtimer.h>
24 #include "key.h"
25 #include "rpcmsg.h"
26 
27 namespace dht
28 {
29  class RPCCall;
30 
34  class RPCCallListener : public QObject
35  {
36  Q_OBJECT
37  public:
38  RPCCallListener(QObject* parent);
39  ~RPCCallListener() override;
40 
41  public Q_SLOTS:
47  virtual void onResponse(RPCCall* c, RPCMsg::Ptr rsp) = 0;
48 
53  virtual void onTimeout(RPCCall* c) = 0;
54  };
55 
59  class RPCCall : public QObject
60  {
61  Q_OBJECT
62  public:
63  RPCCall(RPCMsg::Ptr msg, bool queued);
64  ~RPCCall() override;
65 
69  void start();
70 
75  void response(RPCMsg::Ptr rsp);
76 
82 
84  Method getMsgMethod() const;
85 
87  const RPCMsg::Ptr getRequest() const {return msg;}
88 
90  RPCMsg::Ptr getRequest() {return msg;}
91 
92  private Q_SLOTS:
93  void onTimeout();
94 
95  Q_SIGNALS:
96  void response(RPCCall* c, RPCMsg::Ptr rsp);
97  void timeout(RPCCall* c);
98 
99  private:
100  RPCMsg::Ptr msg;
101  QTimer timer;
102  bool queued;
103  };
104 
105 }
106 
107 #endif
dht::RPCCall::addListener
void addListener(RPCCallListener *cl)
dht::RPCCall::getMsgMethod
Method getMsgMethod() const
Get the message type.
dht::RPCCallListener::onResponse
virtual void onResponse(RPCCall *c, RPCMsg::Ptr rsp)=0
dht::RPCCallListener
Definition: rpccall.h:35
dht::RPCCall::getRequest
RPCMsg::Ptr getRequest()
Get the request sent.
Definition: rpccall.h:90
dht::RPCCallListener::onTimeout
virtual void onTimeout(RPCCall *c)=0
dht::RPCCall::getRequest
const RPCMsg::Ptr getRequest() const
Get the request sent.
Definition: rpccall.h:87
dht::RPCCall::response
void response(RPCMsg::Ptr rsp)
dht::RPCCall::start
void start()
dht::RPCCall
Definition: rpccall.h:60