Base module

PacketFactory

Priority-ordered factory that creates typed packets from raw buffers using registered strategies.

PacketFactory

#include <icy/packetfactory.h>

Priority-ordered factory that creates typed packets from raw buffers using registered strategies.

Public Methods

ReturnNameDescription
PacketFactoryDefaulted constructor.
voidregisterPacketType inlineRegisters a [PacketCreationStrategy](icy-PacketCreationStrategy.html#packetcreationstrategy)<PacketT> at the given priority. Any previously registered strategy for PacketT is replaced.
voidunregisterPacketType inlineRemoves the [PacketCreationStrategy](icy-PacketCreationStrategy.html#packetcreationstrategy)<PacketT> from the factory, if present.
voidregisterStrategy inlineRegisters an arbitrary [IPacketCreationStrategy](icy-IPacketCreationStrategy.html#ipacketcreationstrategy) subclass at the given priority. Any previously registered instance of the same type is replaced.
voidunregisterStrategy inlineRemoves the StrategyT instance from the factory, if present.
PacketCreationStrategyList &types inline#### Returns
const PacketCreationStrategyList &types const inline#### Returns
boolonPacketCreated virtual inlineCalled after a packet is successfully created by a strategy. Override to apply filtering; return false to reject the packet (it will be deleted).
IPacket *createPacket virtual inlineIterates registered strategies in priority order and returns the first successfully created packet.

PacketFactory

PacketFactory() = default

Defaulted constructor.


registerPacketType

inline

template<class PacketT> inline void registerPacketType(int priority)

Registers a [PacketCreationStrategy](icy-PacketCreationStrategy.html#packetcreationstrategy)<PacketT> at the given priority. Any previously registered strategy for PacketT is replaced.

Parameters

  • PacketT Packet type to register; must default-constructible with a read() method.

Parameters

  • priority Dispatch priority (0–100; higher runs first).

unregisterPacketType

inline

template<class PacketT> inline void unregisterPacketType()

Removes the [PacketCreationStrategy](icy-PacketCreationStrategy.html#packetcreationstrategy)<PacketT> from the factory, if present.

Parameters

  • PacketT Packet type whose strategy should be removed.

registerStrategy

inline

template<class StrategyT> inline void registerStrategy(int priority)

Registers an arbitrary [IPacketCreationStrategy](icy-IPacketCreationStrategy.html#ipacketcreationstrategy) subclass at the given priority. Any previously registered instance of the same type is replaced.

Parameters

  • StrategyT Strategy type to instantiate; must accept a priority int in its constructor.

Parameters

  • priority Dispatch priority (0–100; higher runs first).

unregisterStrategy

inline

template<class StrategyT> inline void unregisterStrategy()

Removes the StrategyT instance from the factory, if present.

Parameters

  • StrategyT Strategy type to remove.

types

inline

inline PacketCreationStrategyList & types()

Returns

Mutable reference to the ordered list of registered strategies.


types

const inline

inline const PacketCreationStrategyList & types() const

Returns

Const reference to the ordered list of registered strategies.


onPacketCreated

virtual inline

virtual inline bool onPacketCreated(IPacket * packet)

Called after a packet is successfully created by a strategy. Override to apply filtering; return false to reject the packet (it will be deleted).

Parameters

  • packet Newly created packet.

Returns

True to accept the packet, false to discard it and try the next strategy.


createPacket

virtual inline

virtual inline IPacket * createPacket(const ConstBuffer & buffer, size_t & nread)

Iterates registered strategies in priority order and returns the first successfully created packet.

Parameters

  • buffer Raw input data.

  • nread Set to the number of bytes consumed on success.

Returns

Newly allocated packet, or nullptr if no strategy matched.

Exceptions

  • std::logic_error if no packet types have been registered.

Protected Attributes

ReturnNameDescription
PacketCreationStrategyList_types

_types

PacketCreationStrategyList _types

Private Methods

ReturnNameDescription
voidsortTypes inline

sortTypes

inline

inline void sortTypes()