QtPdCom  1.5.2
Process Class Reference

PdCom::Process implementation for Qt. More...

#include <Process.h>

Inheritance diagram for Process:
Collaboration diagram for Process:

Public Types

enum class  SslCaMode { NoTLS , DefaultCAs , CustomCAs , IgnoreCertificate }
 
enum  ConnectionState {
  Disconnected , Connecting , Connected , ConnectError ,
  ConnectedError
}
 State of the process connection. More...
 

Signals

void processConnected ()
 Connection established.
 
void disconnected ()
 Disconnected gracefully.
 
void error ()
 Connection error.
 
void broadcastReceived (const QString &message, const QString &attr, std::uint64_t time_ns, const QString &user)
 
void connectionStatusChanged ()
 
void sslCaModeChanged ()
 

Public Member Functions

 Process (QObject *parent=nullptr)
 Constructor.
 
virtual ~Process ()
 Destructor.
 
void setApplicationName (const QString &)
 Sets the application name.
 
QString getApplicationName () const
 
Q_INVOKABLE void connectToHost (const QString &, quint16=2345)
 Starts to connect to a process.
 
Q_INVOKABLE void disconnectFromHost ()
 Disconnects from a process.
 
 Q_ENUM (ConnectionState)
 
ConnectionState getConnectionState () const
 
bool isConnected () const
 
const QString & getErrorString () const
 
QString getPeerName () const
 
QUrl getUrl () const
 
int getPort () const
 
QString getHost () const
 
Q_INVOKABLE void sendBroadcast (const QString &, const QString &attr="text")
 Send a broadcast message.
 
Q_INVOKABLE quint64 getRxBytes () const
 
Q_INVOKABLE quint64 getTxBytes () const
 
QVariant nameQt () const
 Remote process name string.
 
QVariant versionQt () const
 Remote process version string.
 
QFuture< PdCom::Variable > find (const QString &)
 Find a Variable.
 
template<class Class, class Function>
QFutureWatcher< PdCom::Variable > & find (const QString &path, Class *obj, Function &&callback)
 Also find a Variable.
 
QFuture< VariableList > list (const QString &="")
 Wrapper function for Process::list.
 
template<class Class, class Function>
QFutureWatcher< VariableList > & list (const QString &path, Class *obj, Function &&callback)
 
QFuture< void > pingQt ()
 
QFuture< std::vector< PdCom::ClientStatistics > > getClientStatisticsQt ()
 
template<class Class, class Function>
QFutureWatcher< void > & ping (Class *obj, Function &&callback)
 
template<class Class, class Function>
QFutureWatcher< std::vector< PdCom::ClientStatistics > > & getClientStatistics (Class *obj, Function &&callback)
 
void setCaMode (SslCaMode mode)
 Set Traffic Encryption mode.
 
SslCaMode getCaMode () const
 Get Traffic Encryption mode.
 
void setClientCertificate (const QSslCertificate &cert, const QSslKey &key)
 Provide a client certificate.
 
void setCustomCAs (QList< QSslCertificate > cas)
 Set list of trusted Certificate Authorities.
 
PdCom::MessageManagerBase * getMessageManager () const
 
void setLoginManager (LoginManager *lm)
 Set the Login Manager.
 
LoginManagergetLoginManager () const
 

Static Public Member Functions

static QtPdCom::ProcessgetDefaultProcess ()
 
static void setDefaultProcess (QtPdCom::Process *)
 Set default process "manually".
 

Properties

bool connected
 The process is connected and ready.
 
ConnectionState connectionState
 
SslCaMode sslCaMode
 
int port
 
QString host
 
QUrl url
 
QString applicationName
 
QtPdCom::LoginManagerloginManager
 
QVariant name
 
QVariant version
 

Private Slots

void socketConnected ()
 Socket connection established.
 
void socketDisconnected ()
 Socket disconnected.
 
void socketError ()
 There was a socket error.
 
void socketRead ()
 The socket has new data to read.
 

Private Member Functions

void connected () override
 
std::string applicationName () const override
 Virtual from PdCom::Process.
 
std::string hostname () const override
 
int read (char *, int) override
 Read data from the socket.
 
void write (const char *, size_t) override
 Sends data via the socket.
 
void flush () override
 Flushed the socket.
 
void broadcastReply (const std::string &message, const std::string &attr, std::chrono::nanoseconds time_ns, const std::string &user) override
 Broadcast Reply.
 
void pingReply () override
 Ping Reply.
 
void findReply (PdCom::Variable const &var) override
 
void listReply (std::vector< PdCom::Variable > vars, std::vector< std::string > dirs) override
 
void clientStatisticsReply (std::vector< PdCom::ClientStatistics > statistics) override
 
void reset ()
 Resets the PdCom process.
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *method=0)
 Disconnect method inherited from QObject.
 

Private Attributes

struct Q_DECL_HIDDEN Impl
 
std::unique_ptr< Implimpl
 

Detailed Description

PdCom::Process implementation for Qt.

Member Enumeration Documentation

◆ ConnectionState

State of the process connection.

Enumerator
Disconnected 

Process disconnected.

Connecting 

Currently connecting.

Connected 

Process connection established.

ConnectError 

An error happened while connecting.

ConnectedError 

An error happened, after the connection was established.

◆ SslCaMode

enum class QtPdCom::Process::SslCaMode
strong
Enumerator
NoTLS 

Disable TLS, unencrypted traffic only.

DefaultCAs 

Use system-default Certificate Authories.

CustomCAs 

Use provided CAs only.

IgnoreCertificate 

Accept any server certificate.

Constructor & Destructor Documentation

◆ Process()

Process::Process ( QObject * parent = nullptr)

Constructor.

◆ ~Process()

Process::~Process ( )
virtual

Destructor.

Member Function Documentation

◆ applicationName()

std::string Process::applicationName ( ) const
overrideprivate

Virtual from PdCom::Process.

◆ broadcastReceived

void QtPdCom::Process::broadcastReceived ( const QString & message,
const QString & attr,
std::uint64_t time_ns,
const QString & user )
signal

◆ broadcastReply()

void Process::broadcastReply ( const std::string & message,
const std::string & attr,
std::chrono::nanoseconds time_ns,
const std::string & user )
overrideprivate

Broadcast Reply.

◆ clientStatisticsReply()

void QtPdCom::Process::clientStatisticsReply ( std::vector< PdCom::ClientStatistics > statistics)
overrideprivate

◆ connected()

void QtPdCom::Process::connected ( )
overrideprivate

◆ connectionStatusChanged

void QtPdCom::Process::connectionStatusChanged ( )
signal

◆ connectToHost()

void Process::connectToHost ( const QString & address,
quint16 port = 2345 )

Starts to connect to a process.

◆ disconnect()

bool QtPdCom::Process::disconnect ( const char * signal = 0,
const QObject * receiver = 0,
const char * method = 0 )
private

Disconnect method inherited from QObject.

This is made private, to avoid confusion.

Parameters
signalSignal.
receiverReceiver.
methodMethod.

◆ disconnected

void QtPdCom::Process::disconnected ( )
signal

Disconnected gracefully.

This is only emitted, after the user called disconnectFromHost().

◆ disconnectFromHost()

void Process::disconnectFromHost ( )

Disconnects from a process.

◆ error

void QtPdCom::Process::error ( )
signal

Connection error.

This is emitted after a connection error or when the connection was closed due to a parser error.

◆ find() [1/2]

QFuture< PdCom::Variable > Process::find ( const QString & path)

Find a Variable.

Wrapper function for Process::findVariable.

Finding a variable is asynchronous in general. If you need to write to a variable, a variable object is needed. To write a variable with a single call you can use futures and a lambda function. See the example in the overloaded method find(const QString&, Class *, Function&&).

Returns
A Future. You can use VariableWatcher to monitor it.

◆ find() [2/2]

template<class Class, class Function>
QFutureWatcher< PdCom::Variable > & QtPdCom::Process::find ( const QString & path,
Class * obj,
Function && callback )
inline

Also find a Variable.

Here, a FutureWatcher is created on your behalf. Callback can be one of

  • a member Function of obj which takes a PdCom::Variable
  • a lambda which takes a reference to obj and a PdCom::Variable
  • a lambda which takes only a PdCom::Variable

The obj reference is needed to use it as a parent for the watcher and to make the connections disconnect automatically when the Process or the object itself goes away.

Below is an example of how to make use of a lambda function to find a variable and write to it once it is found:

const double val = 30.0;
const QString path = "/osc/amplitude/Setpoint";
process->find(path, this, [val](const PdCom::Variable& var) {
if (var.empty()) {
std::cerr << "Variable not found." << std::endl;
}
else {
var.setValue(val);
std::cerr << "Set " << var.getPath()
<< " to " << val << std::endl;
}
});
Parameters
pathVariable to find.
objQObject-derived class.
callbackCallback which receives the result.
Returns
A freshly created FutureWatcher instance with all signals connected.

◆ findReply()

void Process::findReply ( PdCom::Variable const & var)
overrideprivate

◆ flush()

void Process::flush ( )
overrideprivate

Flushed the socket.

◆ getApplicationName()

QString Process::getApplicationName ( ) const

◆ getCaMode()

Process::SslCaMode Process::getCaMode ( ) const

Get Traffic Encryption mode.

Returns
Traffic Encryption mode.

◆ getClientStatistics()

template<class Class, class Function>
QFutureWatcher< std::vector< PdCom::ClientStatistics > > & QtPdCom::Process::getClientStatistics ( Class * obj,
Function && callback )
inline

◆ getClientStatisticsQt()

QFuture< std::vector< PdCom::ClientStatistics > > QtPdCom::Process::getClientStatisticsQt ( )

◆ getConnectionState()

Process::ConnectionState Process::getConnectionState ( ) const
Returns
The connection state.

◆ getDefaultProcess()

QtPdCom::Process * Process::getDefaultProcess ( )
static

◆ getErrorString()

const QString & Process::getErrorString ( ) const
Returns
Error reason after the error() signal was emitted.

◆ getHost()

QString Process::getHost ( ) const

◆ getLoginManager()

QtPdCom::LoginManager * Process::getLoginManager ( ) const

◆ getMessageManager()

PdCom::MessageManagerBase * Process::getMessageManager ( ) const

◆ getPeerName()

QString Process::getPeerName ( ) const
Returns
Host name of the process.

◆ getPort()

int Process::getPort ( ) const

◆ getRxBytes()

quint64 Process::getRxBytes ( ) const

◆ getTxBytes()

quint64 Process::getTxBytes ( ) const

◆ getUrl()

QUrl Process::getUrl ( ) const

◆ hostname()

std::string Process::hostname ( ) const
overrideprivate

◆ isConnected()

bool Process::isConnected ( ) const
Returns
true, if the process is connected.

◆ list() [1/2]

QFuture< QtPdCom::VariableList > Process::list ( const QString & path = "")

Wrapper function for Process::list.

◆ list() [2/2]

template<class Class, class Function>
QFutureWatcher< VariableList > & QtPdCom::Process::list ( const QString & path,
Class * obj,
Function && callback )
inline

◆ listReply()

void Process::listReply ( std::vector< PdCom::Variable > vars,
std::vector< std::string > dirs )
overrideprivate

◆ nameQt()

QVariant Process::nameQt ( ) const

Remote process name string.

◆ ping()

template<class Class, class Function>
QFutureWatcher< void > & QtPdCom::Process::ping ( Class * obj,
Function && callback )
inline

◆ pingQt()

QFuture< void > Process::pingQt ( )

◆ pingReply()

void Process::pingReply ( )
overrideprivate

Ping Reply.

◆ processConnected

void QtPdCom::Process::processConnected ( )
signal

Connection established.

This is emitted after the connection is established.

◆ Q_ENUM()

QtPdCom::Process::Q_ENUM ( ConnectionState )

◆ read()

int Process::read ( char * buf,
int count )
overrideprivate

Read data from the socket.

◆ reset()

void Process::reset ( )
private

Resets the PdCom process.

◆ sendBroadcast()

void Process::sendBroadcast ( const QString & msg,
const QString & attr = "text" )

Send a broadcast message.

◆ setApplicationName()

void Process::setApplicationName ( const QString & name)

Sets the application name.

◆ setCaMode()

void QtPdCom::Process::setCaMode ( SslCaMode mode)

Set Traffic Encryption mode.

See the SslCaMode enum for details.

Parameters
modeMode.

◆ setClientCertificate()

void QtPdCom::Process::setClientCertificate ( const QSslCertificate & cert,
const QSslKey & key )

Provide a client certificate.

Parameters
certPublic certificate.
keyPrivate key.

◆ setCustomCAs()

void QtPdCom::Process::setCustomCAs ( QList< QSslCertificate > cas)

Set list of trusted Certificate Authorities.

For SslCaMode::CustomCAs mode.

Parameters
casList of trusted CAs.

◆ setDefaultProcess()

void Process::setDefaultProcess ( QtPdCom::Process * process)
static

Set default process "manually".

◆ setLoginManager()

void QtPdCom::Process::setLoginManager ( LoginManager * lm)

Set the Login Manager.

Parameters
lmThe Login manager. May be NULL.

◆ socketConnected

void Process::socketConnected ( )
privateslot

Socket connection established.

This is called, when the pure socket connection was established and the Process object can start using it.

◆ socketDisconnected

void Process::socketDisconnected ( )
privateslot

Socket disconnected.

The socket was closed and the process has to be told, that it is disconnected.

◆ socketError

void Process::socketError ( )
privateslot

There was a socket error.

The error could come up either while connecting the socket, or when the socket was already connected.

◆ socketRead

void Process::socketRead ( )
privateslot

The socket has new data to read.

◆ sslCaModeChanged

void QtPdCom::Process::sslCaModeChanged ( )
signal

◆ versionQt()

QVariant Process::versionQt ( ) const

Remote process version string.

◆ write()

void Process::write ( const char * buf,
size_t count )
overrideprivate

Sends data via the socket.

This is the implementation of the virtual PdCom::Process method to enable the Process object to send data to the process.

Member Data Documentation

◆ Impl

struct Q_DECL_HIDDEN QtPdCom::Process::Impl
private

◆ impl

std::unique_ptr<Impl> QtPdCom::Process::impl
private

Property Documentation

◆ applicationName

QString QtPdCom::Process::applicationName
readwrite

◆ connected

void Process::connected
read

The process is connected and ready.

This virtual function from PdCom::Process has to be overloaded to let subclasses know about this event.

◆ connectionState

ConnectionState QtPdCom::Process::connectionState
read

◆ host

QString QtPdCom::Process::host
read

◆ loginManager

QtPdCom::LoginManager * QtPdCom::Process::loginManager
readwrite

◆ name

QVariant QtPdCom::Process::name
read

◆ port

int QtPdCom::Process::port
read

◆ sslCaMode

SslCaMode QtPdCom::Process::sslCaMode
readwrite

◆ url

QUrl QtPdCom::Process::url
read

◆ version

QVariant QtPdCom::Process::version
read

The documentation for this class was generated from the following files: