cc_tools_qt
Common Environment for Protocol Analysis.
|
#include "cc_tools_qt/Socket.h"
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. | |
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().
[in] | props | Properties map. |
|
protectedvirtual |
Polymorphic inter-plugin configuration application.
Invoked by the applyInterPluginConfig().
[in] | props | Properties map. |
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.
|
protectedvirtual |
Polymorphic connection properties functionality implementation.
Invoked by connectionProperties(). In can be overriden by the derived class.
|
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().
[in] | dataPtr | New data information. |
|
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().
|
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().
[in] | msg | Error message. |
|
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.
[in] | props | Reported properties. |
void cc_tools_qt::Socket::sendData | ( | DataInfoPtr | dataPtr | ) |
Request socket to send data.
Invokes the sendDataImpl(), which must be implemented in the derived class.
[in] | dataPtr | Information about outging data |
|
protectedpure virtual |
Polymorphic data send functionality implementation.
Invoked by sendData(). It must be overridden and implemented in the derived class.
void cc_tools_qt::Socket::setConnectionStatusReportCallback | ( | TFunc && | func | ) |
Set callback to report socket connection.
The callback must have the same signature as ConnectionStatusReportCallback.
void cc_tools_qt::Socket::setDataReceivedCallback | ( | TFunc && | func | ) |
Set callback to report incoming data.
The callback must have the same signature as DataReceivedCallback.
void cc_tools_qt::Socket::setDebugOutputLevel | ( | unsigned | level = 0U | ) |
Set debug output level.
[in] | level | Debug level. If 0, debug output is disabled |
void cc_tools_qt::Socket::setErrorReportCallback | ( | TFunc && | func | ) |
Set callback to report errors.
The callback must have the same signature as ErrorReportCallback
void cc_tools_qt::Socket::setInterPluginConfigReportCallback | ( | TFunc && | func | ) |
Set callback to report inter-plugin configuration.
The callback must have the same signature as InterPluginConfigReportCallback.
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.
|
protectedvirtual |
Polymorphic socket connection functionality implementation.
Invoked by socketConnect() and default implementation does nothing. It can be overridden by the derived class.
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.
|
protectedvirtual |
Polymorphic socket disconnection functionality implementation.
Invoked by socketDisconnect() and default implementation does nothing. It can be overridden by the derived class.
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.
|
protectedvirtual |
Polymorphic start functionality implementation.
Invoked by start() and default implementation does nothing. It can be overrided by the derived class.
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
|
protectedvirtual |
Polymorphic stop functionality implementation.
Invoked by stop() and default implementation does nothing. It can be overridden by the derived class.