Commit ac3a130a7e8f6a5d6575eb58c0c48189dd791baf

Authored by Wiebe Cazemier
1 parent ff1c33bc

Remove typedefs for shared_ptr things

My IDE didn't understand them for finding symbols, apparently.
CMakeLists.txt
... ... @@ -12,6 +12,7 @@ SET(CMAKE_CXX_FLAGS "-rdynamic")
12 12 add_compile_options(-Wall)
13 13  
14 14 add_executable(FlashMQ
  15 + forward_declarations.h
15 16 mainapp.h
16 17 utils.h
17 18 threaddata.h
... ...
client.cpp
... ... @@ -24,7 +24,7 @@ License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>.
24 24  
25 25 #include "logger.h"
26 26  
27   -Client::Client(int fd, ThreadData_p threadData, SSL *ssl, bool websocket, std::shared_ptr<Settings> settings, bool fuzzMode) :
  27 +Client::Client(int fd, std::shared_ptr<ThreadData> threadData, SSL *ssl, bool websocket, std::shared_ptr<Settings> settings, bool fuzzMode) :
28 28 fd(fd),
29 29 fuzzMode(fuzzMode),
30 30 initialBufferSize(settings->clientInitialBufferSize), // The client is constructed in the main thread, so we need to use its settings copy
... ... @@ -341,7 +341,7 @@ void Client::setReadyForReading(bool val)
341 341 check<std::runtime_error>(epoll_ctl(threadData->epollfd, EPOLL_CTL_MOD, fd, &ev));
342 342 }
343 343  
344   -bool Client::bufferToMqttPackets(std::vector<MqttPacket> &packetQueueIn, Client_p &sender)
  344 +bool Client::bufferToMqttPackets(std::vector<MqttPacket> &packetQueueIn, std::shared_ptr<Client> &sender)
345 345 {
346 346 while (readbuf.usedBytes() >= MQTT_HEADER_LENGH)
347 347 {
... ...
client.h
... ... @@ -77,7 +77,7 @@ class Client
77 77 bool will_retain = false;
78 78 char will_qos = 0;
79 79  
80   - ThreadData_p threadData;
  80 + std::shared_ptr<ThreadData> threadData;
81 81 std::mutex writeBufMutex;
82 82  
83 83 std::shared_ptr<Session> session;
... ... @@ -88,7 +88,7 @@ class Client
88 88 void setReadyForReading(bool val);
89 89  
90 90 public:
91   - Client(int fd, ThreadData_p threadData, SSL *ssl, bool websocket, std::shared_ptr<Settings> settings, bool fuzzMode=false);
  91 + Client(int fd, std::shared_ptr<ThreadData> threadData, SSL *ssl, bool websocket, std::shared_ptr<Settings> settings, bool fuzzMode=false);
92 92 Client(const Client &other) = delete;
93 93 Client(Client &&other) = delete;
94 94 ~Client();
... ... @@ -102,14 +102,14 @@ public:
102 102 void startOrContinueSslAccept();
103 103 void markAsDisconnecting();
104 104 bool readFdIntoBuffer();
105   - bool bufferToMqttPackets(std::vector<MqttPacket> &packetQueueIn, Client_p &sender);
  105 + bool bufferToMqttPackets(std::vector<MqttPacket> &packetQueueIn, std::shared_ptr<Client> &sender);
106 106 void setClientProperties(ProtocolVersion protocolVersion, const std::string &clientId, const std::string username, bool connectPacketSeen, uint16_t keepalive, bool cleanSession);
107 107 void setWill(const std::string &topic, const std::string &payload, bool retain, char qos);
108 108 void clearWill();
109 109 void setAuthenticated(bool value) { authenticated = value;}
110 110 bool getAuthenticated() { return authenticated; }
111 111 bool hasConnectPacketSeen() { return connectPacketSeen; }
112   - ThreadData_p getThreadData() { return threadData; }
  112 + std::shared_ptr<ThreadData> getThreadData() { return threadData; }
113 113 std::string &getClientId() { return this->clientid; }
114 114 const std::string &getUsername() const { return this->username; }
115 115 bool getCleanSession() { return cleanSession; }
... ...
forward_declarations.h
... ... @@ -21,9 +21,7 @@ License along with FlashMQ. If not, see &lt;https://www.gnu.org/licenses/&gt;.
21 21 #include <memory>
22 22  
23 23 class Client;
24   -typedef std::shared_ptr<Client> Client_p;
25 24 class ThreadData;
26   -typedef std::shared_ptr<ThreadData> ThreadData_p;
27 25 class MqttPacket;
28 26 class SubscriptionStore;
29 27 class Session;
... ...
mainapp.cpp
... ... @@ -91,7 +91,7 @@ void do_thread_work(ThreadData *threadData)
91 91 continue;
92 92 }
93 93  
94   - Client_p client = threadData->getClient(fd);
  94 + std::shared_ptr<Client> client = threadData->getClient(fd);
95 95  
96 96 if (client)
97 97 {
... ... @@ -437,7 +437,7 @@ void MainApp::start()
437 437  
438 438 std::shared_ptr<ThreadData> threaddata(new ThreadData(0, subscriptionStore, settings));
439 439  
440   - Client_p client(new Client(fd, threaddata, nullptr, fuzzWebsockets, settings, true));
  440 + std::shared_ptr<Client> client(new Client(fd, threaddata, nullptr, fuzzWebsockets, settings, true));
441 441  
442 442 if (fuzzWebsockets && strContains(fuzzFilePathLower, "upgrade"))
443 443 client->setFakeUpgraded();
... ... @@ -515,7 +515,7 @@ void MainApp::start()
515 515 SSL_set_fd(clientSSL, fd);
516 516 }
517 517  
518   - Client_p client(new Client(fd, thread_data, clientSSL, listener->websocket, settings));
  518 + std::shared_ptr<Client> client(new Client(fd, thread_data, clientSSL, listener->websocket, settings));
519 519 thread_data->giveClient(client);
520 520 }
521 521 else
... ...
mqttpacket.cpp
... ... @@ -29,7 +29,7 @@ RemainingLength::RemainingLength()
29 29 }
30 30  
31 31 // constructor for parsing incoming packets
32   -MqttPacket::MqttPacket(CirBuf &buf, size_t packet_len, size_t fixed_header_length, Client_p &sender) :
  32 +MqttPacket::MqttPacket(CirBuf &buf, size_t packet_len, size_t fixed_header_length, std::shared_ptr<Client> &sender) :
33 33 bites(packet_len),
34 34 fixed_header_length(fixed_header_length),
35 35 sender(sender)
... ... @@ -574,12 +574,12 @@ const std::string &amp;MqttPacket::getTopic() const
574 574 }
575 575  
576 576  
577   -Client_p MqttPacket::getSender() const
  577 +std::shared_ptr<Client> MqttPacket::getSender() const
578 578 {
579 579 return sender;
580 580 }
581 581  
582   -void MqttPacket::setSender(const Client_p &value)
  582 +void MqttPacket::setSender(const std::shared_ptr<Client> &value)
583 583 {
584 584 sender = value;
585 585 }
... ...
mqttpacket.h
... ... @@ -48,7 +48,7 @@ class MqttPacket
48 48 size_t fixed_header_length = 0; // if 0, this packet does not contain the bytes of the fixed header.
49 49 RemainingLength remainingLength;
50 50 char qos = 0;
51   - Client_p sender;
  51 + std::shared_ptr<Client> sender;
52 52 char first_byte = 0;
53 53 size_t pos = 0;
54 54 size_t packet_id_pos = 0;
... ... @@ -67,7 +67,7 @@ class MqttPacket
67 67 MqttPacket(const MqttPacket &other) = default;
68 68 public:
69 69 PacketType packetType = PacketType::Reserved;
70   - MqttPacket(CirBuf &buf, size_t packet_len, size_t fixed_header_length, Client_p &sender); // Constructor for parsing incoming packets.
  70 + MqttPacket(CirBuf &buf, size_t packet_len, size_t fixed_header_length, std::shared_ptr<Client> &sender); // Constructor for parsing incoming packets.
71 71  
72 72 MqttPacket(MqttPacket &&other) = default;
73 73  
... ... @@ -93,8 +93,8 @@ public:
93 93 const std::vector<char> &getBites() const { return bites; }
94 94 char getQos() const { return qos; }
95 95 const std::string &getTopic() const;
96   - Client_p getSender() const;
97   - void setSender(const Client_p &value);
  96 + std::shared_ptr<Client> getSender() const;
  97 + void setSender(const std::shared_ptr<Client> &value);
98 98 bool containsFixedHeader() const;
99 99 char getFirstByte() const;
100 100 RemainingLength getRemainingLength() const;
... ...
session.cpp
... ... @@ -60,7 +60,7 @@ void Session::writePacket(const MqttPacket &amp;packet, char max_qos)
60 60 {
61 61 if (!clientDisconnected())
62 62 {
63   - Client_p c = makeSharedClient();
  63 + std::shared_ptr<Client> c = makeSharedClient();
64 64 c->writeMqttPacketAndBlameThisClient(packet);
65 65 }
66 66 }
... ... @@ -84,7 +84,7 @@ void Session::writePacket(const MqttPacket &amp;packet, char max_qos)
84 84  
85 85 if (!clientDisconnected())
86 86 {
87   - Client_p c = makeSharedClient();
  87 + std::shared_ptr<Client> c = makeSharedClient();
88 88 c->writeMqttPacketAndBlameThisClient(*copyPacket.get());
89 89 copyPacket->setDuplicate(); // Any dealings with this packet from here will be a duplicate.
90 90 }
... ... @@ -130,7 +130,7 @@ void Session::sendPendingQosMessages()
130 130 {
131 131 if (!clientDisconnected())
132 132 {
133   - Client_p c = makeSharedClient();
  133 + std::shared_ptr<Client> c = makeSharedClient();
134 134 std::lock_guard<std::mutex> locker(qosQueueMutex);
135 135 for (QueuedQosPacket &qosMessage : qosPacketQueue)
136 136 {
... ...
session.h
... ... @@ -41,7 +41,7 @@ struct QueuedQosPacket
41 41 class Session
42 42 {
43 43 std::weak_ptr<Client> client;
44   - ThreadData_p thread;
  44 + std::shared_ptr<ThreadData> thread;
45 45 std::string client_id;
46 46 std::string username;
47 47 std::list<QueuedQosPacket> qosPacketQueue; // Using list because it's easiest to maintain order [MQTT-4.6.0-6]
... ...
subscriptionstore.cpp
... ... @@ -69,7 +69,7 @@ SubscriptionStore::SubscriptionStore() :
69 69  
70 70 }
71 71  
72   -void SubscriptionStore::addSubscription(Client_p &client, const std::string &topic, char qos)
  72 +void SubscriptionStore::addSubscription(std::shared_ptr<Client> &client, const std::string &topic, char qos)
73 73 {
74 74 const std::list<std::string> subtopics = split(topic, '/');
75 75  
... ... @@ -115,7 +115,7 @@ void SubscriptionStore::addSubscription(Client_p &amp;client, const std::string &amp;top
115 115  
116 116 }
117 117  
118   -void SubscriptionStore::removeSubscription(Client_p &client, const std::string &topic)
  118 +void SubscriptionStore::removeSubscription(std::shared_ptr<Client> &client, const std::string &topic)
119 119 {
120 120 const std::list<std::string> subtopics = split(topic, '/');
121 121  
... ... @@ -162,7 +162,7 @@ void SubscriptionStore::removeSubscription(Client_p &amp;client, const std::string &amp;
162 162 }
163 163  
164 164 // Removes an existing client when it already exists [MQTT-3.1.4-2].
165   -void SubscriptionStore::registerClientAndKickExistingOne(Client_p &client)
  165 +void SubscriptionStore::registerClientAndKickExistingOne(std::shared_ptr<Client> &client)
166 166 {
167 167 RWLockGuard lock_guard(&subscriptionsRwlock);
168 168 lock_guard.wrlock();
... ...
subscriptionstore.h
... ... @@ -86,9 +86,9 @@ class SubscriptionStore
86 86 public:
87 87 SubscriptionStore();
88 88  
89   - void addSubscription(Client_p &client, const std::string &topic, char qos);
90   - void removeSubscription(Client_p &client, const std::string &topic);
91   - void registerClientAndKickExistingOne(Client_p &client);
  89 + void addSubscription(std::shared_ptr<Client> &client, const std::string &topic, char qos);
  90 + void removeSubscription(std::shared_ptr<Client> &client, const std::string &topic);
  91 + void registerClientAndKickExistingOne(std::shared_ptr<Client> &client);
92 92 bool sessionPresent(const std::string &clientid);
93 93  
94 94 void queuePacketAtSubscribers(const std::string &topic, const MqttPacket &packet);
... ...
threaddata.cpp
... ... @@ -71,7 +71,7 @@ void ThreadData::quit()
71 71 running = false;
72 72 }
73 73  
74   -void ThreadData::giveClient(Client_p client)
  74 +void ThreadData::giveClient(std::shared_ptr<Client> client)
75 75 {
76 76 clients_by_fd_mutex.lock();
77 77 int fd = client->getFd();
... ... @@ -85,13 +85,13 @@ void ThreadData::giveClient(Client_p client)
85 85 check<std::runtime_error>(epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev));
86 86 }
87 87  
88   -Client_p ThreadData::getClient(int fd)
  88 +std::shared_ptr<Client> ThreadData::getClient(int fd)
89 89 {
90 90 std::lock_guard<std::mutex> lck(clients_by_fd_mutex);
91 91 return this->clients_by_fd[fd];
92 92 }
93 93  
94   -void ThreadData::removeClient(Client_p client)
  94 +void ThreadData::removeClient(std::shared_ptr<Client> client)
95 95 {
96 96 client->markAsDisconnecting();
97 97  
... ... @@ -157,7 +157,7 @@ void ThreadData::doKeepAliveCheck()
157 157 auto it = clients_by_fd.begin();
158 158 while (it != clients_by_fd.end())
159 159 {
160   - Client_p &client = it->second;
  160 + std::shared_ptr<Client> &client = it->second;
161 161 if (client && client->keepAliveExpired())
162 162 {
163 163 client->setDisconnectReason("Keep-alive expired: " + client->getKeepAliveInfoString());
... ...
threaddata.h
... ... @@ -42,7 +42,7 @@ typedef void (*thread_f)(ThreadData *);
42 42  
43 43 class ThreadData
44 44 {
45   - std::unordered_map<int, Client_p> clients_by_fd;
  45 + std::unordered_map<int, std::shared_ptr<Client>> clients_by_fd;
46 46 std::mutex clients_by_fd_mutex;
47 47 std::shared_ptr<SubscriptionStore> subscriptionStore;
48 48 Logger *logger;
... ... @@ -69,9 +69,9 @@ public:
69 69  
70 70 void start(thread_f f);
71 71  
72   - void giveClient(Client_p client);
73   - Client_p getClient(int fd);
74   - void removeClient(Client_p client);
  72 + void giveClient(std::shared_ptr<Client> client);
  73 + std::shared_ptr<Client> getClient(int fd);
  74 + void removeClient(std::shared_ptr<Client> client);
75 75 void removeClient(int fd);
76 76 std::shared_ptr<SubscriptionStore> &getSubscriptionStore();
77 77  
... ...