QtPdCom  1.0.0
Process.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2009-2022 Florian Pose <fp@igh.de>
4  *
5  * This file is part of the QtPdCom library.
6  *
7  * The QtPdCom library is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * The QtPdCom library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15  * License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>.
19  *
20  ****************************************************************************/
21 
22 #ifndef QTPDCOM_PROCESS_H
23 #define QTPDCOM_PROCESS_H
24 
25 #include <QObject>
26 #include <QString>
27 
28 #include <pdcom5.h>
29 #include <pdcom5/Process.h>
30 
31 #ifndef PDCOM_VERSION_CODE
32 # error "No PDCOM_VERSION_CODE found."
33 #elif \
34  !PDCOM_DEVEL \
35  && (PDCOM_VERSION_CODE < PDCOM_VERSION(5, 0, 0) \
36  || PDCOM_VERSION_CODE >= PDCOM_VERSION(6, 0, 0))
37 # error "Invalid PdCom version."
38 #endif
39 
40 #include "Export.h"
41 
42 class QTranslator;
43 
44 namespace QtPdCom {
45 
46 /****************************************************************************/
47 
51  public QObject, public PdCom::Process
52 {
53  Q_OBJECT
54 
55  public:
56  Process(QObject *parent = nullptr);
57  virtual ~Process();
58 
59  void setApplicationName(const QString &);
60  void connectToHost(const QString &, quint16 = 2345);
61  void disconnectFromHost();
62 
70  ConnectedError
72  };
73  ConnectionState getConnectionState() const;
74  bool isConnected() const;
75  const QString &getErrorString() const;
76  QString getPeerName() const;
77 
78  void find(const QString &);
79  void sendBroadcast(const QString &, const QString &attr = "text");
80  quint64 getRxBytes() const;
81  quint64 getTxBytes() const;
82 
83  static QtPdCom::Process *getDefaultProcess();
84  static void setDefaultProcess(QtPdCom::Process *);
85  static bool loadTranslations(QTranslator& translator, const QString &locale);
86 
87  PdCom::MessageManagerBase *getMessageManager() const;
88 
89  // make some protected interfaces public
90  using PdCom::Process::ping;
91 
92  private:
93  struct Q_DECL_HIDDEN Impl;
94  std::unique_ptr<Impl> impl;
95 
97  std::string applicationName() const override;
98  std::string hostname() const override;
99  int read(char *, int) override;
100  void write(const char *, size_t) override;
101  void flush() override;
102  void connected() override;
103  void broadcastReply(
104  const std::string &message,
105  const std::string &attr,
106  std::chrono::nanoseconds time_ns,
107  const std::string &user) override;
108  void pingReply() override;
109  void reset();
110 
115  bool disconnect(
116  const char *signal = 0,
117  const QObject *receiver = 0,
118  const char *method = 0
119  );
120 
121  // make setMessageManager() private
122  using PdCom::Process::setMessageManager;
123 
124  signals:
129  void processConnected();
130 
135  void disconnected();
136 
142  void error();
143 
144  void broadcastReceived(
145  const QString &message,
146  const QString &attr,
147  std::uint64_t time_ns,
148  const QString &user);
149 
155  void pingReceived();
156 
157  private slots:
158  void socketConnected();
159  void socketDisconnected();
160  void socketError();
161  void socketRead();
162 };
163 
164 /****************************************************************************/
165 
166 } // namespace
167 
168 #endif
Definition: Process.cpp:46
Process connection established.
Definition: Process.h:68
Currently connecting.
Definition: Process.h:67
PdCom::Process implementation for Qt.
Definition: Process.h:50
An error happened while connecting.
Definition: Process.h:69
Definition: Message.h:31
ConnectionState
State of the process connection.
Definition: Process.h:65
#define QTPDCOM_PUBLIC
Definition: Export.h:30
Process disconnected.
Definition: Process.h:66
std::unique_ptr< Impl > impl
Definition: Process.h:94