cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
cc_tools_qt::Socket Class Referenceabstract

#include "cc_tools_qt/Socket.h"

Detailed Description

Main polymorphic interface class for sockets.

It is used by CommsChampion Tools to drive low level I/O operations.

Public Types

enum  ConnectionProperty { ConnectionProperty_Autoconnect = 0x1 , ConnectionProperty_NonDisconnectable = 0x2 }
 Available socket connection properties values. More...
 
using ConnectionStatusReportCallback = std::function< void(bool)>
 Callback to report socket connection status.
 
using DataReceivedCallback = std::function< void(DataInfoPtr)>
 Callback to report incoming data.
 
using ErrorReportCallback = std::function< void(const QString &msg)>
 Callback to report errors.
 
using InterPluginConfigReportCallback = std::function< void(const QVariantMap &)>
 Callback to report inter-plugin configuration updates.
 

Public Member Functions

 Socket ()
 Constructor.
 
virtual ~Socket () noexcept
 Destructor.
 
void applyInterPluginConfig (const QVariantMap &props)
 Apply inter-plugin configuration.
 
unsigned connectionProperties () const
 Get properties describing socket connection right after plugins have been loaded and applied.
 
bool isRunning () const
 Report whether the socket has been properly started.
 
bool isSocketConnected () const
 Check socket connected.
 
void sendData (DataInfoPtr dataPtr)
 Request socket to send data.
 
template<typename TFunc >
void setConnectionStatusReportCallback (TFunc &&func)
 Set callback to report socket connection.
 
template<typename TFunc >
void setDataReceivedCallback (TFunc &&func)
 Set callback to report incoming data.
 
void setDebugOutputLevel (unsigned level=0U)
 Set debug output level.
 
template<typename TFunc >
void setErrorReportCallback (TFunc &&func)
 Set callback to report errors.
 
template<typename TFunc >
void setInterPluginConfigReportCallback (TFunc &&func)
 Set callback to report inter-plugin configuration.
 
bool socketConnect ()
 Connect socket.
 
void socketDisconnect ()
 Disconnect socket.
 
bool start ()
 Start socket's operation.
 
void stop ()
 Stop socket's operation.
 

Protected Member Functions

virtual void applyInterPluginConfigImpl (const QVariantMap &props)
 Polymorphic inter-plugin configuration application.
 
virtual unsigned connectionPropertiesImpl () const
 Polymorphic connection properties functionality implementation.
 
unsigned getDebugOutputLevel () const
 Get current debug output level.
 
void reportDataReceived (DataInfoPtr dataPtr)
 Report new data has been received.
 
void reportDisconnected ()
 Report socket disconnection.
 
void reportError (const QString &msg)
 Report I/O operation error.
 
void reportInterPluginConfig (const QVariantMap &props)
 Report inter-plugin configuration.
 
virtual void sendDataImpl (DataInfoPtr dataPtr)=0
 Polymorphic data send functionality implementation.
 
virtual bool socketConnectImpl ()
 Polymorphic socket connection functionality implementation.
 
virtual void socketDisconnectImpl ()
 Polymorphic socket disconnection functionality implementation.
 
virtual bool startImpl ()
 Polymorphic start functionality implementation.
 
virtual void stopImpl ()
 Polymorphic stop functionality implementation.
 

Static Protected Member Functions

static unsigned long long currTimestamp ()
 Get current timestamp.
 

Member Enumeration Documentation

◆ ConnectionProperty

Available socket connection properties values.

Enumerator
ConnectionProperty_Autoconnect 

Perfrom "connect" upon startup.

ConnectionProperty_NonDisconnectable 

Do not allow socket disconnection.

Member Function Documentation

◆ applyInterPluginConfig()

void cc_tools_qt::Socket::applyInterPluginConfig ( const QVariantMap &  props)

Apply inter-plugin configuration.

Allows one plugin to influence the configuration of another. This function will be called for all currently chosen plugins to override current configuration. Invokes polymorphic applyInterPluginConfigImpl().

Parameters
[in]propsProperties map.

◆ applyInterPluginConfigImpl()

virtual void cc_tools_qt::Socket::applyInterPluginConfigImpl ( const QVariantMap &  props)
protectedvirtual

Polymorphic inter-plugin configuration application.

Invoked by the applyInterPluginConfig().

Parameters
[in]propsProperties map.

◆ connectionProperties()

unsigned cc_tools_qt::Socket::connectionProperties ( ) const

Get properties describing socket connection right after plugins have been loaded and applied.

The returned value is used by the driving application to properly present user interface. For example, whether the socket needs to be auto-connected or the application should wait for explicty user request.

Returns
OR-ed values of ConnectionProperty values.

◆ connectionPropertiesImpl()

virtual unsigned cc_tools_qt::Socket::connectionPropertiesImpl ( ) const
protectedvirtual

Polymorphic connection properties functionality implementation.

Invoked by connectionProperties(). In can be overriden by the derived class.

Returns
0.

◆ reportDataReceived()

void cc_tools_qt::Socket::reportDataReceived ( DataInfoPtr  dataPtr)
protected

Report new data has been received.

This function needs to be invoked by the derived class when new data has been received from the I/O link. This function will invoke callback set by setDataReceivedCallback().

Parameters
[in]dataPtrNew data information.

◆ reportDisconnected()

void cc_tools_qt::Socket::reportDisconnected ( )
protected

Report socket disconnection.

Sometimes socket may get unexpectedly disconnected. When such situation is discovered, it should be reported to the running application. This function is expected to be invoked by the derived class and it will invoke callback set by setDisconnectedReportCallback().

◆ reportError()

void cc_tools_qt::Socket::reportError ( const QString &  msg)
protected

Report I/O operation error.

This function is expected to be invoked by the derived class, when I/O error is detected. This function will invoke callback set by setErrorReportCallback().

Parameters
[in]msgError message.

◆ reportInterPluginConfig()

void cc_tools_qt::Socket::reportInterPluginConfig ( const QVariantMap &  props)
protected

Report inter-plugin configuration.

Sometimes configuration of one plugin may influence configuration of another. Use this function to report inter-plugin configuration properties. When invoked all other plugins are expected to get their respecitve applyInterPluginConfig() functions invoked.

Parameters
[in]propsReported properties.

◆ sendData()

void cc_tools_qt::Socket::sendData ( DataInfoPtr  dataPtr)

Request socket to send data.

Invokes the sendDataImpl(), which must be implemented in the derived class.

Parameters
[in]dataPtrInformation about outging data

◆ sendDataImpl()

virtual void cc_tools_qt::Socket::sendDataImpl ( DataInfoPtr  dataPtr)
protectedpure virtual

Polymorphic data send functionality implementation.

Invoked by sendData(). It must be overridden and implemented in the derived class.

◆ setConnectionStatusReportCallback()

template<typename TFunc >
void cc_tools_qt::Socket::setConnectionStatusReportCallback ( TFunc &&  func)

Set callback to report socket connection.

The callback must have the same signature as ConnectionStatusReportCallback.

◆ setDataReceivedCallback()

template<typename TFunc >
void cc_tools_qt::Socket::setDataReceivedCallback ( TFunc &&  func)

Set callback to report incoming data.

The callback must have the same signature as DataReceivedCallback.

◆ setDebugOutputLevel()

void cc_tools_qt::Socket::setDebugOutputLevel ( unsigned  level = 0U)

Set debug output level.

Parameters
[in]levelDebug level. If 0, debug output is disabled

◆ setErrorReportCallback()

template<typename TFunc >
void cc_tools_qt::Socket::setErrorReportCallback ( TFunc &&  func)

Set callback to report errors.

The callback must have the same signature as ErrorReportCallback

◆ setInterPluginConfigReportCallback()

template<typename TFunc >
void cc_tools_qt::Socket::setInterPluginConfigReportCallback ( TFunc &&  func)

Set callback to report inter-plugin configuration.

The callback must have the same signature as InterPluginConfigReportCallback.

◆ socketConnect()

bool cc_tools_qt::Socket::socketConnect ( )

Connect socket.

After the socket has been successfully started (see start()), the driving application invokes this function as well. It can be used to open the I/O device and/or connect to remote host (in case of network socket). The function invokes virtual socketConnectImpl(), which can be overridden by the derived class.

Returns
true in case the operation is successful, false otherwise.

◆ socketConnectImpl()

virtual bool cc_tools_qt::Socket::socketConnectImpl ( )
protectedvirtual

Polymorphic socket connection functionality implementation.

Invoked by socketConnect() and default implementation does nothing. It can be overridden by the derived class.

Returns
true

◆ socketDisconnect()

void cc_tools_qt::Socket::socketDisconnect ( )

Disconnect socket.

This function is used to close the opened I/O device and/or to disconnect from the remote host (in case of network socket). The function invokes virtual socketDisconnectImpl(), which can be overridden by the derived class.

◆ socketDisconnectImpl()

virtual void cc_tools_qt::Socket::socketDisconnectImpl ( )
protectedvirtual

Polymorphic socket disconnection functionality implementation.

Invoked by socketDisconnect() and default implementation does nothing. It can be overridden by the derived class.

◆ start()

bool cc_tools_qt::Socket::start ( )

Start socket's operation.

Prior to being started, the socket is not allowed to generate any events. The function invokes virtual startImpl() which can be overriden by the derived class.

Returns
true in case the socket's operation has been successfully started, false otherwise.

◆ startImpl()

virtual bool cc_tools_qt::Socket::startImpl ( )
protectedvirtual

Polymorphic start functionality implementation.

Invoked by start() and default implementation does nothing. It can be overrided by the derived class.

Returns
true

◆ stop()

void cc_tools_qt::Socket::stop ( )

Stop socket's operation.

After being stopped, the socket is not allowed to generate any events. The function invokes virtual stopImpl(), which can be overriden by the derived class

◆ stopImpl()

virtual void cc_tools_qt::Socket::stopImpl ( )
protectedvirtual

Polymorphic stop functionality implementation.

Invoked by stop() and default implementation does nothing. It can be overridden by the derived class.


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