Commit bf9612351bfab03cec6a51ecb2655fc776876adc

Authored by Wiebe Cazemier
1 parent 33d19cec

Corrected subscribing a bit

mqttpacket.cpp
@@ -196,19 +196,20 @@ void MqttPacket::handleSubscribe(std::shared_ptr<SubscriptionStore> &subscriptio @@ -196,19 +196,20 @@ void MqttPacket::handleSubscribe(std::shared_ptr<SubscriptionStore> &subscriptio
196 { 196 {
197 uint16_t packet_id = readTwoBytesToUInt16(); 197 uint16_t packet_id = readTwoBytesToUInt16();
198 198
199 - std::list<std::string> subs; // TODO: list of tuples, probably  
200 - while (remainingAfterPos() > 1) 199 + std::list<char> subs_reponse_codes;
  200 + while (remainingAfterPos() > 0)
201 { 201 {
202 uint16_t topicLength = readTwoBytesToUInt16(); 202 uint16_t topicLength = readTwoBytesToUInt16();
203 std::string topic(readBytes(topicLength), topicLength); 203 std::string topic(readBytes(topicLength), topicLength);
  204 + char qos = readByte();
  205 + if (qos > 0)
  206 + throw NotImplementedException("QoS not implemented");
204 std::cout << sender->repr() << " Subscribed to " << topic << std::endl; 207 std::cout << sender->repr() << " Subscribed to " << topic << std::endl;
205 subscriptionStore->addSubscription(sender, topic); 208 subscriptionStore->addSubscription(sender, topic);
206 - subs.push_back(std::move(topic)); 209 + subs_reponse_codes.push_back(qos);
207 } 210 }
208 211
209 - char flags = readByte();  
210 -  
211 - SubAck subAck(packet_id, subs); 212 + SubAck subAck(packet_id, subs_reponse_codes);
212 MqttPacket response(subAck); 213 MqttPacket response(subAck);
213 sender->writeMqttPacket(response); 214 sender->writeMqttPacket(response);
214 } 215 }
types.cpp
@@ -6,13 +6,12 @@ ConnAck::ConnAck(ConnAckReturnCodes return_code) : @@ -6,13 +6,12 @@ ConnAck::ConnAck(ConnAckReturnCodes return_code) :
6 6
7 } 7 }
8 8
9 -SubAck::SubAck(uint16_t packet_id, const std::list<std::string> &subs) : 9 +SubAck::SubAck(uint16_t packet_id, const std::list<char> &subs_qos_reponses) :
10 packet_id(packet_id) 10 packet_id(packet_id)
11 { 11 {
12 - // dummy  
13 - for(size_t i = 0; i < subs.size(); i++) 12 + for (char ack_code : subs_qos_reponses)
14 { 13 {
15 - responses.push_back(SubAckReturnCodes::MaxQoS0); 14 + responses.push_back(static_cast<SubAckReturnCodes>(ack_code));
16 } 15 }
17 } 16 }
18 17
@@ -64,7 +64,7 @@ class SubAck @@ -64,7 +64,7 @@ class SubAck
64 public: 64 public:
65 uint16_t packet_id; 65 uint16_t packet_id;
66 std::list<SubAckReturnCodes> responses; 66 std::list<SubAckReturnCodes> responses;
67 - SubAck(uint16_t packet_id, const std::list<std::string> &subs); 67 + SubAck(uint16_t packet_id, const std::list<char> &subs_qos_reponses);
68 }; 68 };
69 69
70 class Publish 70 class Publish