![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Stream/Network/ConnectionFactory.h>
The ConnectionFactory manages available connection protocols and creates new connections based on the provided configuration. More...
The ConnectionFactory manages available connection protocols and creates new connections based on the provided configuration.
Blueprints serve as predefined templates of type ConnectionBlueprint, describing how each connection should be established. The supported payloads are std::string and ImFusion's ByteBuffer class.
This factory enables dynamic support for different protocols (e.g., WebSocket, TCP, UDP) and modes (client or server) at runtime. If the protocol or mode is fix and known at compile time, the corresponding classes should be used directly, such as UDPSocket for UDP communication or WebsocketClient for connecting to a remote WebSocket server.
To register custom connection types in the factory, they should be added when loading a custom plugin, e.g. within the plugin constructor, or during application startup for custom applications.
Example:
Public Member Functions | |
| std::vector< ConnectionProtocol > | supportedConnections () const |
| Returns a list of the supported connection protocols. | |
| bool | registerBlueprint (ConnectionBlueprint< Payload > &&blueprint) |
| Registers a new connection protocol. | |
| std::optional< Properties > | connectionProperties (const ConnectionProtocol &connectionProtocol) const |
| Returns the properties of a connection protocol, including default values. | |
| std::unique_ptr< Network::TypedConnectionBase< Payload > > | createConnection (const ConnectionProtocol &connectionProtocol, const Properties &p) const |
| Creates and returns a connection instance (for example, server or client) using the specified protocol and properties. | |
Static Public Member Functions | |
| static ConnectionFactory & | instance () |
| Returns the singleton instance of the factory, ensuring global consistency throughout the program's execution (Singleton Pattern). | |
| bool registerBlueprint | ( | ConnectionBlueprint< Payload > && | blueprint | ) |
Registers a new connection protocol.
If the same protocol is registered multiple times, the latest registration replaces the previous one.
| blueprint | The ConnectionBlueprint to register. |
| std::optional< Properties > connectionProperties | ( | const ConnectionProtocol & | connectionProtocol | ) | const |
Returns the properties of a connection protocol, including default values.
Can also be used to verify whether a specific protocol is supported.
| std::unique_ptr< Network::TypedConnectionBase< Payload > > createConnection | ( | const ConnectionProtocol & | connectionProtocol, |
| const Properties & | p ) const |
Creates and returns a connection instance (for example, server or client) using the specified protocol and properties.
It typically establishes a connection (client) or starts to listen for incoming connections (server).
nullptr.Example usage: