apigear-io / template-cpp14

C++14 technology template
https://apigear.io/template-cpp14/docs/intro
MIT License
0 stars 2 forks source link

Clean up and refactor mqtt wrapper implementation #108

Open w4bremer opened 1 year ago

w4bremer commented 1 year ago

CWrapper should not contain the client/service interface, but only expose sending messages and helpers for creating ones. Like: For simple messages (only like property or signal) sendMessage(topic, payload) and sendRetainedMessage(topic, payload) or sendMessage(topic, payload, bool) { MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;

opts.onFailure5 = onSendFailure; // Not sure about this line and one below it is in Property Change, but not in  notifySignal, setRemoteProperty. Is it necessary for Property Change
opts.context = new genericContext{getPtr()}; 
pubmsg.payload = const_cast<void*>(static_cast<const void*>(value.c_str()));
pubmsg.payloadlen = static_cast<int>(value.size());
pubmsg.qos = QOS;
// property changes shall be retained and automatically send to new clients
pubmsg.retained = 1;

sendMessage(topic.getEncodedTopic(), &pubmsg, &opts);

} and sendMessage(..., context) which requires also createContextFunction sth like createOptions and then add(opts, identifier, data) { MQTTProperty dataProperty; correlationDataProperty.identifier = identifier; correlationDataProperty.value.data = { static_cast(value)), const_cast<char*>(value.c_str()) }; MQTTProperties_add(&(opts.properties), &correlationDataProperty); } this way the wrapper doesn't know about objects that use it and client and servers side add their specific logic, also some repetitive code is removed

_Originally posted by @dorotaphanSiili in https://github.com/apigear-io/template-cpp14/pull/73#discussion_r1299908939_