PdCom  4.1
Process data communication client
Process.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vim:tw=78
3  * $Id: Process.h,v 57767466729c 2018/06/07 13:49:31 lerichi $
4  *
5  * Copyright (C) 2016 Richard Hacker (lerichi at gmx dot net)
6  *
7  * This file is part of the PdCom library.
8  *
9  * The PdCom library is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or (at your
12  * option) any later version.
13  *
14  * The PdCom library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
21  *
22  *****************************************************************************/
23 
26 #ifndef PDCOM_PROCESS_H
27 #define PDCOM_PROCESS_H
28 
29 #include <stddef.h>
30 #include <string>
31 #include <list>
32 #include <stdint.h>
33 
34 class IOLayer;
35 class ProtocolHandler;
36 
37 namespace PdCom {
38 
39  struct Subscriber;
40  class Variable;
41 
87  class Process {
88  public:
90  Process();
91 
96  virtual ~Process();
97 
99  std::string name() const;
100 
102  std::string version() const;
103 
105  void reset();
106 
114  virtual std::string applicationName() const;
115 
126  virtual std::string hostname() const;
127 
154  virtual int read( char *buf, size_t count) = 0;
155 
184  virtual void write(const char *buf, size_t count) = 0;
185 
205  virtual void flush() = 0;
206 
221  int asyncData();
222 
236  virtual void connected() = 0;
237 
268  bool list(const std::string& path) const;
269 
283  virtual void listReply(
284  std::list<const Variable*>& variables,
285  std::list<std::string>& directories);
286 
303  bool find(const std::string& path) const;
304 
314  virtual void findReply(const Variable* variable);
315 
330  bool login(const char* mech, const char* clientData) const;
331 
334  void logout() const;
335 
351  virtual void loginReply(const char* mechlist,
352  const char* serverData, int finished);
353 
375  bool startTLS() const;
376 
384  virtual void startTLSReply();
385 
387  void ping() const;
388 
394  virtual void pingReply();
395 
404  virtual bool alive();
405 
445  void subscribe(Subscriber* subscriber,
446  const std::string& path, double interval, int id) const;
447 
450  void unsubscribe(Subscriber* subscriber) const;
451 
467  void parameterMonitor(Subscriber* subscriber, bool state) const;
468 
474  enum LogLevel_t {
475  Emergency,
476  Alert,
477  Critical,
478  Error,
479  Warn,
480  Info,
481  Debug,
482  Trace
483  };
484 
505  virtual void processMessage(
506  LogLevel_t level,
507  const std::string& path,
508  int index,
509  bool state,
510  uint64_t time_ns,
511  const std::string& text
512  );
513 
532  void messageHistory(unsigned int limit) const;
533 
541  virtual void messageHistoryEnd(unsigned int count);
542 
554  virtual void protocolLog(
555  LogLevel_t severity,
556  const std::string& message
557  );
558 
566  virtual void broadcastReply(const std::string& message,
567  const std::string& attr);
568 
574  void broadcast(const std::string& message,
575  const std::string& attr = "text");
576 
590  virtual void transmitSemaphore(bool state);
591 
592  private:
593  ProtocolHandler *protocolHandler;
594  IOLayer* const io;
595 
596  std::string initialBuffer;
597  };
598 } // namespace
599 
600 #endif // PDCOM_PROCESS_H
virtual std::string hostname() const
Host name of remote server.
int asyncData()
Library entry point for new data.
virtual std::string applicationName() const
Name of application user application.
virtual void listReply(std::list< const Variable *> &variables, std::list< std::string > &directories)
Reply to list() call.
void ping() const
Ping server.
bool list(const std::string &path) const
List a directory path.
virtual void startTLSReply()
TLS reply.
bool find(const std::string &path) const
Find a variable with a corresponding path.
virtual bool alive()
Test from process whether client is alive.
virtual void broadcastReply(const std::string &message, const std::string &attr)
Server broadcast.
void unsubscribe(Subscriber *subscriber) const
Unsubscribe all subscriptions from subscriber.
void subscribe(Subscriber *subscriber, const std::string &path, double interval, int id) const
Subscribe to a variable.
std::string version() const
Remote process version string.
virtual void pingReply()
Ping reply.
Process()
Constructor.
virtual void flush()=0
Flush unsent data in output buffer.
bool login(const char *mech, const char *clientData) const
Perform SASL login step.
Class required to receive subscribed variables.
Definition: Subscriber.h:91
void broadcast(const std::string &message, const std::string &attr="text")
Send broadcast to all clients.
virtual void connected()=0
Protocol initialization completed.
LogLevel_t
Log levels.
Definition: Process.h:474
virtual void messageHistoryEnd(unsigned int count)
End of message history block.
Process variable.
Definition: Variable.h:43
void logout() const
Logout from server.
virtual int read(char *buf, size_t count)=0
Read data from server.
Base class for PdCom protocol handler.
Definition: Process.h:87
virtual ~Process()
Destructor.
virtual void write(const char *buf, size_t count)=0
Write data to server.
virtual void processMessage(LogLevel_t level, const std::string &path, int index, bool state, uint64_t time_ns, const std::string &text)
Message event from process.
virtual void findReply(const Variable *variable)
Reply to find()
virtual void protocolLog(LogLevel_t severity, const std::string &message)
Message event from protocol handler.
bool startTLS() const
Start TLS.
void reset()
Reset communications and clean up internal buffers.
void messageHistory(unsigned int limit) const
Request history of messages from the process.
virtual void loginReply(const char *mechlist, const char *serverData, int finished)
SASL server reply to login()
virtual void transmitSemaphore(bool state)
Client to server communication semaphore.
Definition: Process.h:37
std::string name() const
Remote process name string.
void parameterMonitor(Subscriber *subscriber, bool state) const
Turn parameter monitoring on/off.