PdCom  5.3
Process data communication client
Process.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vim:tw=78
3  *
4  * Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net),
5  * Florian Pose (fp at igh dot de),
6  * Bjarne von Horn (vh at igh dot de).
7  *
8  * This file is part of the PdCom library.
9  *
10  * The PdCom library is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or (at your
13  * option) any later version.
14  *
15  * The PdCom library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
22  *
23  *****************************************************************************/
24 
27 #ifndef PDCOM5_PROCESS_H
28 #define PDCOM5_PROCESS_H
29 
30 #include "ClientStatistics.h"
31 #include "Variable.h"
32 
33 #include <chrono>
34 #include <memory>
35 #include <pdcom5_export.h>
36 #include <stddef.h>
37 #include <stdint.h>
38 #include <string>
39 #include <vector>
40 
41 namespace PdCom {
42 namespace impl {
43 class Process;
44 }
45 
46 class SecureProcess;
47 class Variable;
48 class Sasl;
49 class Subscription;
50 class Subscriber;
51 class MessageManagerBase;
52 
86 class PDCOM5_PUBLIC Process
87 {
88  friend class impl::Process;
89  friend class SecureProcess;
90 
91  public:
93  Process();
94  Process(Process &&) = delete;
95  Process(Process const &) = delete;
96  Process &operator=(Process &&) = delete;
97  Process &operator=(Process const &) = delete;
98 
99  protected:
104  virtual ~Process();
105 
106  public:
108  std::string name() const;
109 
111  std::string version() const;
112 
124  void asyncData();
125 
133  void callPendingCallbacks();
134 
140  void
141  broadcast(const std::string &message, const std::string &attr = "text");
142 
144  {
145  const PdCom::Subscription *subscription;
146  const PdCom::Subscriber *subscriber;
147  PdCom::Variable variable;
148 
150  const PdCom::Subscription *subscription,
151  const PdCom::Subscriber *subscriber,
152  PdCom::Variable variable) :
153  subscription(subscription),
154  subscriber(subscriber),
155  variable(variable)
156  {}
157  };
158 
159  std::vector<SubscriptionInfo> getActiveSubscriptions() const;
160 
161  protected:
163  void reset();
164 
172  virtual std::string applicationName() const { return "pdcom5"; }
173 
184  virtual std::string hostname() const { return {}; }
185 
211  virtual int read(char *buf, int count) = 0;
212 
241  virtual void write(const char *buf, size_t count) = 0;
242 
262  virtual void flush() = 0;
263 
277  virtual void connected() = 0;
278 
309  bool list(const std::string &path = "");
310 
324  virtual void
325  listReply(std::vector<Variable> variables, std::vector<std::string> dirs);
326 
343  bool find(const std::string &path);
344 
354  virtual void findReply(const Variable &variable);
355 
360  void getClientStatistics();
361 
364  virtual void
365  clientStatisticsReply(std::vector<ClientStatistics> statistics);
366 
368  void ping();
369 
375  virtual void pingReply() {}
376 
385  virtual bool alive() { return true; }
386 
393  void setAuthManager(Sasl *);
394 
399  Sasl *getAuthManager() const;
400 
407  void setMessageManager(MessageManagerBase *);
408 
420  virtual void broadcastReply(
421  const std::string &message,
422  const std::string &attr,
423  std::chrono::nanoseconds time_ns,
424  const std::string &user);
425 
426  private:
427  std::shared_ptr<impl::Process> pimpl;
428  explicit Process(std::shared_ptr<impl::Process> impl);
429 };
430 } // namespace PdCom
431 
432 #endif // PDCOM5_PROCESS_H
virtual std::string hostname() const
Host name of remote server.
Definition: Process.h:184
virtual std::string applicationName() const
Name of application user application.
Definition: Process.h:172
virtual bool alive()
Test from process whether client is alive.
Definition: Process.h:385
virtual void pingReply()
Ping reply.
Definition: Process.h:375
PdCom Variable interface.
Definition: Variable.h:67
PdCom Subscription interface.
Definition: Subscription.h:64
Definition: SecureProcess.h:45
Base class for PdCom protocol handler.
Definition: Process.h:86
Definition: Subscriber.h:106
Definition: MessageManagerBase.h:66
SASL Interface for PdCom.
Definition: Sasl.h:41
Definition: ClientStatistics.h:31
Definition: Process.h:143