Callback Functions' Parameters Usage
woolseyj opened this issue · 2 comments
I have a few questions and comments concerning the library's callback functions' parameters.
-
What are the
flags
,rc
, andpid
parameters provided in some of the MQTT client's callback functions and what are their expected usage? I can't find much information on them in the library's documentation or in the source code itself. -
The
on_subscribe()
callback provides all of the parameters,topic
andqos
, submitted with thesubscribe()
method. However, this is not the case for theon_publish()
andpublish()
counterparts as themessage
,retain
, andqos
parameters are missing. Is it possible to include them in a future update? As an example, I am trying to print thetopic
andmessage
to the screen when a message is published. This would be nice to handle within theon_publish()
callback, but I am instead printing thetopic
andmessage
directly after publishing since theon_publish()
callback does not have access to the topic's message. Is there a way to retrieve the published topic's message within theon_publish()
callback that I am missing? -
What is the expected use case for the userdata parameter in some of the callback functions?
Your assistance would be greatly appreciated.
Let's start from the end: the user_data
parameter is handy when you want to avoid global state. For example, there can be a variable that is defined only in main() and you'd like to modify it based on MQTT events. To avoid declaring the variable as a global variable, it can be passed to the MQTT() initializer and then it will be used as 2nd argument for the callbacks. Unfortunately, the user_data
is not used for the "on_message" callbacks (#178) where it would be arguably most useful.