publishcopyfactory.h
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef PUBLISHCOPYFACTORY_H
#define PUBLISHCOPYFACTORY_H
#include <vector>
#include "forward_declarations.h"
#include "types.h"
#include "unordered_map"
/**
* @brief The PublishCopyFactory class is for managing copies of an incoming publish, including sometimes not making copies at all.
*
* The idea is that certain incoming packets can just be written to the receiving client as-is, without constructing a new one. We do have to change the bytes
* where the QoS is stored, so we keep track of the original QoS.
*
* Ownership info: object of this type are never copied or transferred, so the internal pointers come from (near) the same scope these objects
* are created from.
*/
class PublishCopyFactory
{
MqttPacket *packet = nullptr;
Publish *publish = nullptr;
std::unique_ptr<MqttPacket> oneShotPacket;
const char orgQos;
std::unordered_map<uint8_t, std::unique_ptr<MqttPacket>> constructedPacketCache;
public:
PublishCopyFactory(MqttPacket *packet);
PublishCopyFactory(Publish *publish);
PublishCopyFactory(const PublishCopyFactory &other) = delete;
PublishCopyFactory(PublishCopyFactory &&other) = delete;
MqttPacket *getOptimumPacket(const char max_qos, const ProtocolVersion protocolVersion, uint16_t topic_alias, bool skip_topic);
char getEffectiveQos(char max_qos) const;
const std::string &getTopic() const;
const std::vector<std::string> &getSubtopics();
bool getRetain() const;
Publish getNewPublish(char new_max_qos) const;
std::shared_ptr<Client> getSender();
const std::vector<std::pair<std::string, std::string>> *getUserProperties() const;
};
#endif // PUBLISHCOPYFACTORY_H