mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Use unique_ptr for increased ownership clarity of communication components
This commit is contained in:
@@ -22,10 +22,10 @@ namespace icsneo {
|
||||
class Communication {
|
||||
public:
|
||||
Communication(
|
||||
std::shared_ptr<ICommunication> com,
|
||||
std::unique_ptr<ICommunication> com,
|
||||
std::shared_ptr<Packetizer> p,
|
||||
std::shared_ptr<Encoder> e,
|
||||
std::shared_ptr<Decoder> md) : packetizer(p), encoder(e), decoder(md), impl(com) {}
|
||||
std::unique_ptr<Encoder> e,
|
||||
std::unique_ptr<Decoder> md) : packetizer(p), encoder(std::move(e)), decoder(std::move(md)), impl(std::move(com)) {}
|
||||
virtual ~Communication() { close(); }
|
||||
|
||||
bool open();
|
||||
@@ -47,12 +47,12 @@ public:
|
||||
}
|
||||
std::shared_ptr<Message> waitForMessageSync(std::shared_ptr<MessageFilter> f, std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||
|
||||
std::shared_ptr<Packetizer> packetizer;
|
||||
std::shared_ptr<Encoder> encoder;
|
||||
std::shared_ptr<Decoder> decoder;
|
||||
std::shared_ptr<Packetizer> packetizer; // Ownership is shared with the encoder
|
||||
std::unique_ptr<Encoder> encoder;
|
||||
std::unique_ptr<Decoder> decoder;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ICommunication> impl;
|
||||
std::unique_ptr<ICommunication> impl;
|
||||
static int messageCallbackIDCounter;
|
||||
std::map<int, MessageCallback> messageCallbacks;
|
||||
std::atomic<bool> closing{false};
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace icsneo {
|
||||
class MultiChannelCommunication : public Communication {
|
||||
public:
|
||||
MultiChannelCommunication(
|
||||
std::shared_ptr<ICommunication> com,
|
||||
std::unique_ptr<ICommunication> com,
|
||||
std::shared_ptr<Packetizer> p,
|
||||
std::shared_ptr<Encoder> e,
|
||||
std::shared_ptr<Decoder> md) : Communication(com, p, e, md) {}
|
||||
std::unique_ptr<Encoder> e,
|
||||
std::unique_ptr<Decoder> md) : Communication(std::move(com), p, std::move(e), std::move(md)) {}
|
||||
void spawnThreads() override;
|
||||
void joinThreads() override;
|
||||
bool sendPacket(std::vector<uint8_t>& bytes) override;
|
||||
|
||||
Reference in New Issue
Block a user