PdCom  4.2
Process data communication client
Process.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vim:tw=78
3  * $Id: Process.h,v 1e99c743f804 2018/11/22 15:51:51 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 
93  class Process {
94  public:
96  Process();
97 
102  virtual ~Process();
103 
105  std::string name() const;
106 
108  std::string version() const;
109 
111  void reset();
112 
120  virtual std::string applicationName() const;
121 
132  virtual std::string hostname() const;
133 
160  virtual int read( char *buf, size_t count) = 0;
161 
190  virtual void write(const char *buf, size_t count) = 0;
191 
211  virtual void flush() = 0;
212 
227  int asyncData();
228 
242  virtual void connected() = 0;
243 
274  bool list(const std::string& path) const;
275 
289  virtual void listReply(
290  std::list<const Variable*>& variables,
291  std::list<std::string>& directories);
292 
309  bool find(const std::string& path) const;
310 
320  virtual void findReply(const Variable* variable);
321 
336  bool login(const char* mech, const char* clientData) const;
337 
340  void logout() const;
341 
357  virtual void loginReply(const char* mechlist,
358  const char* serverData, int finished);
359 
381  bool startTLS() const;
382 
390  virtual void startTLSReply();
391 
393  void ping() const;
394 
400  virtual void pingReply();
401 
410  virtual bool alive();
411 
451  void subscribe(Subscriber* subscriber,
452  const std::string& path, double interval, int id) const;
453 
456  void unsubscribe(Subscriber* subscriber) const;
457 
473  void parameterMonitor(Subscriber* subscriber, bool state) const;
474 
476  enum LogLevel_t {
486  };
487 
489  struct Message {
490  uint32_t seqNo;
493  std::string path;
494  int index;
496  uint64_t time_ns;
497  std::string text;
498  };
499 
509  virtual void processMessage(const Message& message);
510 
520  void getMessage(uint32_t seqNo) const;
521 
528  virtual void getMessageReply(const Message& message);
529 
536  void activeMessages() const;
537 
547  virtual void activeMessagesReply(
548  const std::list<Message>& messageList);
549 
561  virtual void protocolLog(
562  LogLevel_t severity,
563  const std::string& message
564  );
565 
573  virtual void broadcastReply(const std::string& message,
574  const std::string& attr);
575 
581  void broadcast(const std::string& message,
582  const std::string& attr = "text");
583 
597  virtual void transmitSemaphore(bool state);
598 
599  private:
600  ProtocolHandler *protocolHandler;
601  IOLayer* const io;
602 
603  std::string initialBuffer;
604  };
605 } // namespace
606 
607 #endif // PDCOM_PROCESS_H
Trace log level.
Definition: Process.h:485
LogLevel_t level
severity
Definition: Process.h:492
Emergency log level.
Definition: Process.h:478
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.
uint64_t time_ns
event time in nanoseconds since epoch
Definition: Process.h:496
virtual void processMessage(const Message &message)
Message event from process.
virtual void broadcastReply(const std::string &message, const std::string &attr)
Server broadcast.
std::string text
Text of message.
Definition: Process.h:497
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.
virtual void activeMessagesReply(const std::list< Message > &messageList)
Reply to activeMessages()
std::string version() const
Remote process version string.
Message structure.
Definition: Process.h:489
virtual void pingReply()
Ping reply.
Message is reset.
Definition: Process.h:477
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.
Critical log level.
Definition: Process.h:480
LogLevel_t
Log levels used in Message and protocolLog()
Definition: Process.h:476
Process variable.
Definition: Variable.h:43
uint32_t seqNo
sequence number.
Definition: Process.h:490
void logout() const
Logout from server.
std::string path
event&#39;s path
Definition: Process.h:493
virtual int read(char *buf, size_t count)=0
Read data from server.
Base class for PdCom protocol handler.
Definition: Process.h:93
virtual ~Process()
Destructor.
int index
-1 for scalar; index in case of a vector
Definition: Process.h:494
virtual void write(const char *buf, size_t count)=0
Write data to server.
Alert log level.
Definition: Process.h:479
Warn log level.
Definition: Process.h:482
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.
Error log level.
Definition: Process.h:481
void activeMessages() const
Request a list of all active messages.
void reset()
Reset communications and clean up internal buffers.
Info log level.
Definition: Process.h:483
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.
Debug log level.
Definition: Process.h:484
Definition: Process.h:37
void getMessage(uint32_t seqNo) const
Request specific message from history.
std::string name() const
Remote process name string.
virtual void getMessageReply(const Message &message)
Reply to getMessage()
void parameterMonitor(Subscriber *subscriber, bool state) const
Turn parameter monitoring on/off.