sigproxy: Modernize RPC calls (remote signals)
[quassel.git] / src / common / internalpeer.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
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) version 3.                                           *
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
21 #pragma once
22
23 #include "common-export.h"
24
25 #include <QPointer>
26 #include <QString>
27
28 #include "peer.h"
29 #include "protocol.h"
30 #include "signalproxy.h"
31
32 class COMMON_EXPORT InternalPeer : public Peer
33 {
34     Q_OBJECT
35
36 public:
37     InternalPeer(QObject* parent = nullptr);
38     ~InternalPeer() override;
39
40     Protocol::Type protocol() const override { return Protocol::InternalProtocol; }
41     QString description() const override;
42
43     QString address() const override;
44     quint16 port() const override;
45
46     SignalProxy* signalProxy() const override;
47     void setSignalProxy(SignalProxy* proxy) override;
48
49     InternalPeer* peer() const;
50     void setPeer(InternalPeer* peer);
51
52     bool isOpen() const override;
53     bool isSecure() const override;
54     bool isLocal() const override;
55
56     int lag() const override;
57
58     void dispatch(const Protocol::SyncMessage& msg) override;
59     void dispatch(const Protocol::RpcCall& msg) override;
60     void dispatch(const Protocol::InitRequest& msg) override;
61     void dispatch(const Protocol::InitData& msg) override;
62
63     /* These are not needed for InternalPeer */
64     void dispatch(const Protocol::RegisterClient&) override {}
65     void dispatch(const Protocol::ClientDenied&) override {}
66     void dispatch(const Protocol::ClientRegistered&) override {}
67     void dispatch(const Protocol::SetupData&) override {}
68     void dispatch(const Protocol::SetupFailed&) override {}
69     void dispatch(const Protocol::SetupDone&) override {}
70     void dispatch(const Protocol::Login&) override {}
71     void dispatch(const Protocol::LoginFailed&) override {}
72     void dispatch(const Protocol::LoginSuccess&) override {}
73     void dispatch(const Protocol::SessionState&) override {}
74
75 public slots:
76     void close(const QString& reason = QString()) override;
77
78 signals:
79     void dispatchMessage(const Protocol::SyncMessage& msg);
80     void dispatchMessage(const Protocol::RpcCall& msg);
81     void dispatchMessage(const Protocol::InitRequest& msg);
82     void dispatchMessage(const Protocol::InitData& msg);
83
84 private slots:
85     void peerDisconnected();
86
87     void handleMessage(const Protocol::SyncMessage& msg);
88     void handleMessage(const Protocol::RpcCall& msg);
89     void handleMessage(const Protocol::InitRequest& msg);
90     void handleMessage(const Protocol::InitData& msg);
91
92 private:
93     template<typename T>
94     void handle(const T& msg);
95
96 private:
97     SignalProxy* _proxy{nullptr};
98     bool _isOpen{true};
99 };
100
101 Q_DECLARE_METATYPE(QPointer<InternalPeer>)