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:
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 
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 
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 
394 
400 
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
Definition: MessageManagerBase.h:67
Base class for PdCom protocol handler.
Definition: Process.h:87
void asyncData()
Library entry point for new data.
virtual void write(const char *buf, size_t count)=0
Write data to server.
virtual int read(char *buf, int count)=0
Read data from server.
Sasl * getAuthManager() const
Get the current SASL handler.
void broadcast(const std::string &message, const std::string &attr="text")
Send a broadcast message to the server and other clients.
std::string version() const
Remote process version string.
void reset()
Reset communications and clean up internal buffers.
virtual std::string hostname() const
Host name of remote server.
Definition: Process.h:184
Process()
Constructor.
virtual bool alive()
Test from process whether client is alive.
Definition: Process.h:385
virtual void broadcastReply(const std::string &message, const std::string &attr, std::chrono::nanoseconds time_ns, const std::string &user)
Recieve a broadcast message from other clients.
virtual void clientStatisticsReply(std::vector< ClientStatistics > statistics)
Reply for getClientStatistics().
virtual void connected()=0
Protocol initialization completed.
virtual void findReply(const Variable &variable)
Reply to find()
virtual std::string applicationName() const
Name of application user application.
Definition: Process.h:172
void callPendingCallbacks()
Call delayed callbacks.
void getClientStatistics()
Request client statistics from the server.
virtual void pingReply()
Ping reply.
Definition: Process.h:375
virtual ~Process()
Destructor.
void setAuthManager(Sasl *)
Register a SASL handler.
bool find(const std::string &path)
Find a variable with a corresponding path.
virtual void flush()=0
Flush unsent data in output buffer.
virtual void listReply(std::vector< Variable > variables, std::vector< std::string > dirs)
Reply to list() call.
void setMessageManager(MessageManagerBase *)
Register a Message handler.
std::string name() const
Remote process name string.
void ping()
Ping server.
bool list(const std::string &path="")
List a directory path.
SASL Interface for PdCom.
Definition: Sasl.h:42
Definition: SecureProcess.h:46
Definition: Subscriber.h:107
PdCom Subscription interface.
Definition: Subscription.h:65
PdCom Variable interface.
Definition: Variable.h:68
Definition: Process.h:144