callable_overlay.hpp 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131
  1. // Copyright Takatoshi Kondo 2015
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #if !defined(MQTT_CALLABLE_OVERLAY_HPP)
  7. #define MQTT_CALLABLE_OVERLAY_HPP
  8. #include <mqtt/variant.hpp> // should be top to configure variant limit
  9. #include <mqtt/namespace.hpp>
  10. #include <mqtt/attributes.hpp>
  11. #include <mqtt/endpoint.hpp>
  12. #include <mqtt/move.hpp>
  13. namespace MQTT_NS {
  14. template<typename Impl>
  15. struct callable_overlay final : public Impl
  16. {
  17. using base = Impl;
  18. using packet_id_t = typename base::packet_id_t;
  19. template<typename ... Args>
  20. callable_overlay(Args && ... args)
  21. : base(std::forward<Args>(args)...)
  22. { }
  23. ~callable_overlay() = default;
  24. callable_overlay(callable_overlay&&) = default;
  25. callable_overlay(callable_overlay const&) = default;
  26. callable_overlay& operator=(callable_overlay&&) = default;
  27. callable_overlay& operator=(callable_overlay const&) = default;
  28. // MQTT Common handlers
  29. /**
  30. * @brief Pingreq handler
  31. * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718086<BR>
  32. * 3.13 PINGREQ – PING request
  33. * @return if the handler returns true, then continue receiving, otherwise quit.
  34. */
  35. MQTT_ALWAYS_INLINE bool on_pingreq() noexcept override final {
  36. return ! h_pingreq_ || h_pingreq_();
  37. }
  38. /**
  39. * @brief Pingresp handler
  40. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901200<BR>
  41. * 3.13 PINGRESP – PING response
  42. * @return if the handler returns true, then continue receiving, otherwise quit.
  43. */
  44. MQTT_ALWAYS_INLINE bool on_pingresp() noexcept override final {
  45. return ! h_pingresp_ || h_pingresp_();
  46. }
  47. // MQTT v3_1_1 handlers
  48. /**
  49. * @brief Connect handler
  50. * @param client_id
  51. * Client Identifier.<BR>
  52. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349245<BR>
  53. * 3.1.3.1 Client Identifier
  54. * @param user_name
  55. * User Name.<BR>
  56. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349245<BR>
  57. * 3.1.3.4 User Name
  58. * @param password
  59. * Password.<BR>
  60. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349246<BR>
  61. * 3.1.3.5 Password
  62. * @param will
  63. * Will. It contains retain, QoS, topic, and message.<BR>
  64. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349232<BR>
  65. * 3.1.2.5 Will Flag<BR>
  66. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349233<BR>
  67. * 3.1.2.6 Will QoS<BR>
  68. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349234<BR>
  69. * 3.1.2.7 Will Retain<BR>
  70. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349243<BR>
  71. * 3.1.3.2 Will Topic<BR>
  72. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349244<BR>
  73. * 3.1.3.3 Will Message<BR>
  74. * @param clean_session
  75. * Clean Session<BR>
  76. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349231<BR>
  77. * 3.1.2.4 Clean Session
  78. * @param keep_alive
  79. * Keep Alive<BR>
  80. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349237<BR>
  81. * 3.1.2.10 Keep Alive
  82. * @return if the handler returns true, then continue receiving, otherwise quit.
  83. *
  84. */
  85. MQTT_ALWAYS_INLINE bool on_connect(buffer client_id,
  86. optional<buffer> user_name,
  87. optional<buffer> password,
  88. optional<will> will,
  89. bool clean_session,
  90. std::uint16_t keep_alive) noexcept override final {
  91. return ! h_connect_
  92. || h_connect_(force_move(client_id),
  93. force_move(user_name),
  94. force_move(password),
  95. force_move(will),
  96. clean_session,
  97. keep_alive);
  98. }
  99. /**
  100. * @brief Connack handler
  101. * @param session_present
  102. * Session present flag.<BR>
  103. * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036<BR>
  104. * 3.2.2.2 Session Present
  105. * @param return_code
  106. * connect_return_code<BR>
  107. * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036<BR>
  108. * 3.2.2.3 Connect Return code
  109. * @return if the handler returns true, then continue receiving, otherwise quit.
  110. */
  111. MQTT_ALWAYS_INLINE bool on_connack(bool session_present, connect_return_code return_code) noexcept override final {
  112. return ! h_connack_
  113. || h_connack_(session_present, return_code);
  114. }
  115. /**
  116. * @brief Publish handler
  117. * @param packet_id
  118. * packet identifier<BR>
  119. * If received publish's QoS is 0, packet_id is nullopt.<BR>
  120. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718039<BR>
  121. * 3.3.2 Variable header
  122. * @param fixed_header
  123. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718038<BR>
  124. * 3.3.1 Fixed header<BR>
  125. * You can check the fixed header using publish functions.
  126. * @param topic_name
  127. * Topic name
  128. * @param contents
  129. * Published contents
  130. * @return if the handler returns true, then continue receiving, otherwise quit.
  131. */
  132. MQTT_ALWAYS_INLINE bool on_publish(optional<packet_id_t> packet_id,
  133. publish_options pubopts,
  134. buffer topic_name,
  135. buffer contents) noexcept override final {
  136. return ! h_publish_
  137. || h_publish_(packet_id,
  138. pubopts,
  139. force_move(topic_name),
  140. force_move(contents));
  141. }
  142. /**
  143. * @brief Puback handler
  144. * @param packet_id
  145. * packet identifier<BR>
  146. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045<BR>
  147. * 3.4.2 Variable header
  148. * @return if the handler returns true, then continue receiving, otherwise quit.
  149. */
  150. MQTT_ALWAYS_INLINE bool on_puback(packet_id_t packet_id) noexcept override final {
  151. return ! h_puback_
  152. || h_puback_(packet_id);
  153. }
  154. /**
  155. * @brief Pubrec handler
  156. * @param packet_id
  157. * packet identifier<BR>
  158. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718050<BR>
  159. * 3.5.2 Variable header
  160. * @return if the handler returns true, then continue receiving, otherwise quit.
  161. */
  162. MQTT_ALWAYS_INLINE bool on_pubrec(packet_id_t packet_id) noexcept override final {
  163. return ! h_pubrec_
  164. || h_pubrec_(packet_id);
  165. }
  166. /**
  167. * @brief Pubrel handler
  168. * @param packet_id
  169. * packet identifier<BR>
  170. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349791<BR>
  171. * 3.6.2 Variable header
  172. * @return if the handler returns true, then continue receiving, otherwise quit.
  173. */
  174. MQTT_ALWAYS_INLINE bool on_pubrel(packet_id_t packet_id) noexcept override final {
  175. return ! h_pubrel_
  176. || h_pubrel_(packet_id);
  177. }
  178. /**
  179. * @brief Pubcomp handler
  180. * @param packet_id
  181. * packet identifier<BR>
  182. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718060<BR>
  183. * 3.7.2 Variable header
  184. * @return if the handler returns true, then continue receiving, otherwise quit.
  185. */
  186. MQTT_ALWAYS_INLINE bool on_pubcomp(packet_id_t packet_id) noexcept override final {
  187. return ! h_pubcomp_
  188. || h_pubcomp_(packet_id);
  189. }
  190. /**
  191. * @brief Subscribe handler
  192. * @param packet_id packet identifier<BR>
  193. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349801<BR>
  194. * 3.8.2 Variable header
  195. * @param entries
  196. * Collection of Share Name, Topic Filter, and QoS.<BR>
  197. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802<BR>
  198. * @return if the handler returns true, then continue receiving, otherwise quit.
  199. */
  200. MQTT_ALWAYS_INLINE bool on_subscribe(packet_id_t packet_id,
  201. std::vector<subscribe_entry> entries) noexcept override final {
  202. return ! h_subscribe_
  203. || h_subscribe_(packet_id, force_move(entries));
  204. }
  205. /**
  206. * @brief Suback handler
  207. * @param packet_id packet identifier<BR>
  208. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718070<BR>
  209. * 3.9.2 Variable header
  210. * @param qoss
  211. * Collection of QoS that is corresponding to subscribed topic order.<BR>
  212. * If subscription is failure, the value is nullopt.<BR>
  213. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071<BR>
  214. * @return if the handler returns true, then continue receiving, otherwise quit.
  215. */
  216. MQTT_ALWAYS_INLINE bool on_suback(packet_id_t packet_id,
  217. std::vector<suback_return_code> reasons) noexcept override final {
  218. return ! h_suback_
  219. || h_suback_(packet_id, force_move(reasons));
  220. }
  221. /**
  222. * @brief Unsubscribe handler
  223. * @param packet_id packet identifier<BR>
  224. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349810<BR>
  225. * 3.10.2 Variable header
  226. * @param topics
  227. * Collection of Share Name and Topic Filter<BR>
  228. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448<BR>
  229. * @return if the handler returns true, then continue receiving, otherwise quit.
  230. */
  231. MQTT_ALWAYS_INLINE bool on_unsubscribe(packet_id_t packet_id,
  232. std::vector<unsubscribe_entry> entries) noexcept override final {
  233. return ! h_unsubscribe_
  234. || h_unsubscribe_(packet_id, force_move(entries));
  235. }
  236. /**
  237. * @brief Unsuback handler
  238. * @param packet_id packet identifier<BR>
  239. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045<BR>
  240. * 3.11.2 Variable header
  241. * @return if the handler returns true, then continue receiving, otherwise quit.
  242. */
  243. MQTT_ALWAYS_INLINE bool on_unsuback(packet_id_t packet_id) noexcept override final {
  244. return ! h_unsuback_
  245. || h_unsuback_(packet_id);
  246. }
  247. /**
  248. * @brief Disconnect handler
  249. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800463<BR>
  250. * 3.14 DISCONNECT – Disconnect notification
  251. */
  252. MQTT_ALWAYS_INLINE void on_disconnect() noexcept override final {
  253. if(h_disconnect_) h_disconnect_();
  254. }
  255. // MQTT v5 handlers
  256. /**
  257. * @brief Connect handler
  258. * @param client_id
  259. * Client Identifier.<BR>
  260. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901059<BR>
  261. * 3.1.3.1 Client Identifier
  262. * @param user_name
  263. * User Name.<BR>
  264. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901071<BR>
  265. * 3.1.3.4 User Name
  266. * @param password
  267. * Password.<BR>
  268. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901072<BR>
  269. * 3.1.3.5 Password
  270. * @param will
  271. * Will. It contains retain, QoS, propertied, topic, and message.<BR>
  272. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901040<BR>
  273. * 3.1.2.5 Will Flag<BR>
  274. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901041<BR>
  275. * 3.1.2.6 Will QoS<BR>
  276. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901042<BR>
  277. * 3.1.2.7 Will Retain<BR>
  278. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901060<BR>
  279. * 3.1.3.2 Will Properties<BR>
  280. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901069<BR>
  281. * 3.1.3.3 Will Topic<BR>
  282. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901070<BR>
  283. * 3.1.3.3 Will Payload<BR>
  284. * @param clean_start
  285. * Clean Start<BR>
  286. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901039<BR>
  287. * 3.1.2.4 Clean Session
  288. * @param keep_alive
  289. * Keep Alive<BR>
  290. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901045<BR>
  291. * 3.1.2.10 Keep Alive
  292. * @param props
  293. * Properties<BR>
  294. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046<BR>
  295. * 3.1.2.11 CONNECT Properties
  296. * @return if the handler returns true, then continue receiving, otherwise quit.
  297. *
  298. */
  299. MQTT_ALWAYS_INLINE bool on_v5_connect(buffer client_id,
  300. optional<buffer> user_name,
  301. optional<buffer> password,
  302. optional<will> will,
  303. bool clean_start,
  304. std::uint16_t keep_alive,
  305. v5::properties props) noexcept override final {
  306. return ! h_v5_connect_
  307. || h_v5_connect_(force_move(client_id),
  308. force_move(user_name),
  309. force_move(password),
  310. force_move(will),
  311. clean_start,
  312. keep_alive,
  313. force_move(props));
  314. }
  315. /**
  316. * @brief Connack handler
  317. * @param session_present
  318. * Session present flag.<BR>
  319. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901078<BR>
  320. * 3.2.2.1.1 Session Present
  321. * @param reason_code
  322. * Connect Reason Code<BR>
  323. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901079<BR>
  324. * 3.2.2.2 Connect Reason code
  325. * @param props
  326. * Properties<BR>
  327. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080<BR>
  328. * 3.2.2.3 CONNACK Properties
  329. * @return if the handler returns true, then continue receiving, otherwise quit.
  330. */
  331. MQTT_ALWAYS_INLINE bool on_v5_connack(bool session_present,
  332. v5::connect_reason_code reason_code,
  333. v5::properties props) noexcept override final {
  334. return ! h_v5_connack_
  335. || h_v5_connack_(session_present, reason_code, force_move(props));
  336. }
  337. /**
  338. * @brief Publish handler
  339. * @param packet_id
  340. * packet identifier<BR>
  341. * If received publish's QoS is 0, packet_id is nullopt.<BR>
  342. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901108<BR>
  343. * 3.3.2.2 Packet Identifier
  344. * @param fixed_header
  345. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901101<BR>
  346. * 3.3.1 Fixed header<BR>
  347. * You can check the fixed header using publish functions.
  348. * @param topic_name
  349. * Topic name<BR>
  350. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901107<BR>
  351. * 3.3.2.1 Topic Name<BR>
  352. * @param contents
  353. * Publish Payload<BR>
  354. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901119<BR>
  355. * 3.3.3 PUBLISH Payload
  356. * @param props
  357. * Properties<BR>
  358. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109<BR>
  359. * 3.3.2.3 PUBLISH Properties
  360. * @return if the handler returns true, then continue receiving, otherwise quit.
  361. */
  362. MQTT_ALWAYS_INLINE bool on_v5_publish(optional<packet_id_t> packet_id,
  363. publish_options pubopts,
  364. buffer topic_name,
  365. buffer contents,
  366. v5::properties props) noexcept override final {
  367. return ! h_v5_publish_
  368. || h_v5_publish_(packet_id,
  369. pubopts,
  370. force_move(topic_name),
  371. force_move(contents),
  372. force_move(props));
  373. }
  374. /**
  375. * @brief Puback handler
  376. * @param packet_id
  377. * packet identifier<BR>
  378. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901123<BR>
  379. * 3.4.2 Variable header
  380. * @param reason_code
  381. * PUBACK Reason Code<BR>
  382. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901124<BR>
  383. * 3.4.2.1 PUBACK Reason Code
  384. * @param props
  385. * Properties<BR>
  386. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125<BR>
  387. * 3.4.2.2 PUBACK Properties
  388. * @return if the handler returns true, then continue receiving, otherwise quit.
  389. */
  390. MQTT_ALWAYS_INLINE bool on_v5_puback(packet_id_t packet_id,
  391. v5::puback_reason_code reason_code,
  392. v5::properties props) noexcept override final {
  393. return ! h_v5_puback_
  394. || h_v5_puback_(packet_id, reason_code, force_move(props));
  395. }
  396. /**
  397. * @brief Pubrec handler
  398. * @param packet_id
  399. * packet identifier<BR>
  400. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901133<BR>
  401. * 3.5.2 Variable header
  402. * @param reason_code
  403. * PUBREC Reason Code<BR>
  404. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901134<BR>
  405. * 3.5.2.1 PUBREC Reason Code
  406. * @param props
  407. * Properties<BR>
  408. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135<BR>
  409. * 3.5.2.2 PUBREC Properties
  410. * @return if the handler returns true, then continue receiving, otherwise quit.
  411. */
  412. MQTT_ALWAYS_INLINE bool on_v5_pubrec(packet_id_t packet_id,
  413. v5::pubrec_reason_code reason_code,
  414. v5::properties props) noexcept override final {
  415. return ! h_v5_pubrec_
  416. || h_v5_pubrec_(packet_id, reason_code, force_move(props));
  417. }
  418. /**
  419. * @brief Pubrel handler
  420. * @param packet_id
  421. * packet identifier<BR>
  422. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901143<BR>
  423. * 3.6.2 Variable header
  424. * @param reason_code
  425. * PUBREL Reason Code<BR>
  426. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901144<BR>
  427. * 3.6.2.1 PUBREL Reason Code
  428. * @param props
  429. * Properties<BR>
  430. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145<BR>
  431. * 3.6.2.2 PUBREL Properties
  432. * @return if the handler returns true, then continue receiving, otherwise quit.
  433. */
  434. MQTT_ALWAYS_INLINE bool on_v5_pubrel(packet_id_t packet_id,
  435. v5::pubrel_reason_code reason_code,
  436. v5::properties props) noexcept override final {
  437. return ! h_v5_pubrel_
  438. || h_v5_pubrel_(packet_id, reason_code, force_move(props));
  439. }
  440. /**
  441. * @brief Pubcomp handler
  442. * @param packet_id
  443. * packet identifier<BR>
  444. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901153<BR>
  445. * 3.7.2 Variable header
  446. * @param reason_code
  447. * PUBCOMP Reason Code<BR>
  448. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901154<BR>
  449. * 3.7.2.1 PUBCOMP Reason Code
  450. * @param props
  451. * Properties<BR>
  452. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155<BR>
  453. * 3.7.2.2 PUBCOMP Properties
  454. * @return if the handler returns true, then continue receiving, otherwise quit.
  455. */
  456. MQTT_ALWAYS_INLINE bool on_v5_pubcomp(packet_id_t packet_id,
  457. v5::pubcomp_reason_code reason_code,
  458. v5::properties props) noexcept override final {
  459. return ! h_v5_pubcomp_
  460. || h_v5_pubcomp_(packet_id, reason_code, force_move(props));
  461. }
  462. /**
  463. * @brief Subscribe handler
  464. * @param packet_id packet identifier<BR>
  465. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901163<BR>
  466. * 3.8.2 Variable header
  467. * @param entries
  468. * Collection of Share Name, Topic Filter, and QoS.<BR>
  469. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901168<BR>
  470. * @param props
  471. * Properties<BR>
  472. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164<BR>
  473. * 3.8.2.1 SUBSCRIBE Properties
  474. * @return if the handler returns true, then continue receiving, otherwise quit.
  475. */
  476. MQTT_ALWAYS_INLINE bool on_v5_subscribe(packet_id_t packet_id,
  477. std::vector<subscribe_entry> entries,
  478. v5::properties props) noexcept override final {
  479. return ! h_v5_subscribe_
  480. || h_v5_subscribe_(packet_id, force_move(entries), force_move(props));
  481. }
  482. /**
  483. * @brief Suback handler
  484. * @param packet_id packet identifier<BR>
  485. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901173<BR>
  486. * 3.9.2 Variable header
  487. * @param reasons
  488. * Collection of reason_code.<BR>
  489. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901178<BR>
  490. * 3.9.3 SUBACK Payload
  491. * @param props
  492. * Properties<BR>
  493. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174<BR>
  494. * 3.9.2.1 SUBACK Properties
  495. * @return if the handler returns true, then continue receiving, otherwise quit.
  496. */
  497. MQTT_ALWAYS_INLINE bool on_v5_suback(packet_id_t packet_id,
  498. std::vector<v5::suback_reason_code> reasons,
  499. v5::properties props) noexcept override final {
  500. return ! h_v5_suback_
  501. || h_v5_suback_(packet_id, force_move(reasons), force_move(props));
  502. }
  503. /**
  504. * @brief Unsubscribe handler
  505. * @param packet_id packet identifier<BR>
  506. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901181<BR>
  507. * 3.10.2 Variable header
  508. * @param entries
  509. * Collection of Share Name and Topic Filter<BR>
  510. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901185<BR>
  511. * 3.10.3 UNSUBSCRIBE Payload
  512. * @param props
  513. * Properties<BR>
  514. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182<BR>
  515. * 3.10.2.1 UNSUBSCRIBE Properties
  516. * @return if the handler returns true, then continue receiving, otherwise quit.
  517. */
  518. MQTT_ALWAYS_INLINE bool on_v5_unsubscribe(packet_id_t packet_id,
  519. std::vector<unsubscribe_entry> entries,
  520. v5::properties props) noexcept override final {
  521. return ! h_v5_unsubscribe_
  522. || h_v5_unsubscribe_(packet_id, force_move(entries), force_move(props));
  523. }
  524. /**
  525. * @brief Unsuback handler
  526. * @param packet_id packet identifier<BR>
  527. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901189<BR>
  528. * 3.11.2 Variable header
  529. * @param reasons
  530. * Collection of reason_code.<BR>
  531. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901194<BR>
  532. * 3.11.3 UNSUBACK Payload
  533. * @param props
  534. * Properties<BR>
  535. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190<BR>
  536. * 3.11.2.1 UNSUBACK Properties
  537. * @return if the handler returns true, then continue receiving, otherwise quit.
  538. */
  539. MQTT_ALWAYS_INLINE bool on_v5_unsuback(packet_id_t packet_id,
  540. std::vector<v5::unsuback_reason_code> reasons,
  541. v5::properties props) noexcept override final {
  542. return ! h_v5_unsuback_
  543. || h_v5_unsuback_(packet_id, force_move(reasons), force_move(props));
  544. }
  545. /**
  546. * @brief Disconnect handler
  547. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205<BR>
  548. * 3.14 DISCONNECT – Disconnect notification
  549. * @param reason_code
  550. * DISCONNECT Reason Code<BR>
  551. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901208<BR>
  552. * 3.14.2.1 Disconnect Reason Code
  553. * @param props
  554. * Properties<BR>
  555. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209<BR>
  556. * 3.14.2.2 DISCONNECT Properties
  557. */
  558. MQTT_ALWAYS_INLINE void on_v5_disconnect(v5::disconnect_reason_code reason_code,
  559. v5::properties props) noexcept override final {
  560. if (h_v5_disconnect_) h_v5_disconnect_(reason_code, force_move(props));
  561. }
  562. /**
  563. * @brief Auth handler
  564. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901217<BR>
  565. * 3.15 AUTH – Authentication exchange
  566. * @param reason_code
  567. * AUTH Reason Code<BR>
  568. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901220<BR>
  569. * 3.15.2.1 Authenticate Reason Code
  570. * @param props
  571. * Properties<BR>
  572. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221<BR>
  573. * 3.15.2.2 AUTH Properties
  574. * @return if the handler returns true, then continue receiving, otherwise quit.
  575. */
  576. MQTT_ALWAYS_INLINE bool on_v5_auth(v5::auth_reason_code reason_code,
  577. v5::properties props) noexcept override final {
  578. return ! h_v5_auth_
  579. || h_v5_auth_(reason_code, force_move(props));
  580. }
  581. // Original handlers
  582. /**
  583. * @brief Close handler
  584. *
  585. * This handler is called if the client called `disconnect()` and the server closed the socket cleanly.
  586. * If the socket is closed by other reasons, error_handler is called.
  587. * This calls base::on_close() prior to calling the provided callback, if any.
  588. */
  589. MQTT_ALWAYS_INLINE void on_close() noexcept override final {
  590. base::on_close();
  591. if (h_close_) h_close_();
  592. }
  593. /**
  594. * @brief Error handler
  595. *
  596. * This handler is called if the socket is closed without client's `disconnect()` call.
  597. * This calls base::on_error() prior to calling the provided callback, if any.
  598. *
  599. * @param ec error code
  600. */
  601. MQTT_ALWAYS_INLINE void on_error(error_code ec) noexcept override final {
  602. base::on_error(ec);
  603. if (h_error_) h_error_(ec);
  604. }
  605. /**
  606. * @brief Publish response sent handler
  607. * This function is called just after puback sent on QoS1, or pubcomp sent on QoS2.
  608. * @param packet_id
  609. * packet identifier<BR>
  610. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901026<BR>
  611. * 2.2.1 Packet Identifier
  612. */
  613. MQTT_ALWAYS_INLINE void on_pub_res_sent(packet_id_t packet_id) noexcept override final {
  614. if (h_pub_res_sent_) h_pub_res_sent_(packet_id);
  615. }
  616. /**
  617. * @brief Serialize publish handler
  618. * You can serialize the publish message.
  619. * To restore the message, use restore_serialized_message().
  620. * @param msg publish message
  621. */
  622. MQTT_ALWAYS_INLINE void on_serialize_publish_message(basic_publish_message<sizeof(packet_id_t)> msg) noexcept override final {
  623. if (h_serialize_publish_) h_serialize_publish_(msg);
  624. }
  625. /**
  626. * @brief Serialize publish handler
  627. * You can serialize the publish message.
  628. * To restore the message, use restore_serialized_message().
  629. * @param msg v5::publish message
  630. */
  631. MQTT_ALWAYS_INLINE void on_serialize_v5_publish_message(v5::basic_publish_message<sizeof(packet_id_t)> msg) noexcept override final {
  632. if (h_serialize_v5_publish_) h_serialize_v5_publish_(msg);
  633. }
  634. /**
  635. * @brief Serialize pubrel handler
  636. * You can serialize the pubrel message.
  637. * If your storage has already had the publish message that has the same packet_id,
  638. * then you need to replace the publish message to pubrel message.
  639. * To restore the message, use restore_serialized_message().
  640. * @param msg pubrel message
  641. */
  642. MQTT_ALWAYS_INLINE void on_serialize_pubrel_message(basic_pubrel_message<sizeof(packet_id_t)> msg) noexcept override final {
  643. if (h_serialize_pubrel_) h_serialize_pubrel_(msg);
  644. }
  645. /**
  646. * @brief Serialize pubrel handler
  647. * You can serialize the pubrel message.
  648. * If your storage has already had the publish message that has the same packet_id,
  649. * then you need to replace the publish message to pubrel message.
  650. * To restore the message, use restore_serialized_message().
  651. * @param msg pubrel message
  652. */
  653. MQTT_ALWAYS_INLINE void on_serialize_v5_pubrel_message(v5::basic_pubrel_message<sizeof(packet_id_t)> msg) noexcept override final {
  654. if (h_serialize_v5_pubrel_) h_serialize_v5_pubrel_(msg);
  655. }
  656. /**
  657. * @brief Remove serialized message
  658. * @param packet_id packet identifier of the removing message
  659. */
  660. MQTT_ALWAYS_INLINE void on_serialize_remove(packet_id_t packet_id) noexcept override final {
  661. if (h_serialize_remove_) h_serialize_remove_(packet_id);
  662. }
  663. /**
  664. * @brief Pre-send handler
  665. * This handler is called when any mqtt control packet is decided to send.
  666. */
  667. MQTT_ALWAYS_INLINE void on_pre_send() noexcept override final {
  668. base::on_pre_send();
  669. if (h_pre_send_) h_pre_send_();
  670. }
  671. /**
  672. * @brief is valid length handler
  673. * This handler is called when remaining length is received.
  674. * @param control_packet_type control_packet_type that has variable length
  675. * @param remaining length
  676. * @return true if check is success, otherwise false
  677. */
  678. MQTT_ALWAYS_INLINE bool check_is_valid_length(control_packet_type packet_type, std::size_t remaining_length) noexcept override final {
  679. return ! h_is_valid_length_
  680. || h_is_valid_length_(packet_type, remaining_length);
  681. }
  682. /**
  683. * @brief next read handler
  684. * This handler is called when the current mqtt message has been processed.
  685. * This calls base::on_mqtt_message_processed() only if mqtt_message_processed handler is not set.
  686. * * `client` inherits `endpoint` and override `on_pre_send()`, `on_close()`, and `on_error()`.
  687. * And implement important process *1 in the override definition (timer reset, timer cancel).
  688. * * `client` has `set_pre_send_handler()`, `set_on_close()`, and `set_on_error()`.
  689. * If a user of `client` call them, and the event happens, set handler should be called.
  690. * Either the user set handlers or not, *1 should be executed automatically.
  691. * * `endpoint` has the default definition of `on_mqtt_message_processed()`.
  692. * `client` doesn't override `on_mqtt_message_processed()`.
  693. * If a user override this, then the default definition shouldn't be called. It makes conflict behavior.
  694. * * Other `on_*()` doesn't have the default definition. `callable_overlay` calls the corresponding
  695. * handler only if it is set.
  696. * @param func A callback function that is called when async operation will finish.
  697. */
  698. MQTT_ALWAYS_INLINE void on_mqtt_message_processed(any session_life_keeper) noexcept override final {
  699. if(h_mqtt_message_processed_) {
  700. h_mqtt_message_processed_(force_move(session_life_keeper));
  701. }
  702. else {
  703. base::on_mqtt_message_processed(force_move(session_life_keeper));
  704. }
  705. }
  706. /**
  707. * @brief Pingreq handler
  708. * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718086<BR>
  709. * 3.13 PINGREQ – PING request
  710. * @return if the handler returns true, then continue receiving, otherwise quit.
  711. */
  712. using pingreq_handler = std::function<bool()>;
  713. /**
  714. * @brief Pingresp handler
  715. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901200<BR>
  716. * 3.13 PINGRESP – PING response
  717. * @return if the handler returns true, then continue receiving, otherwise quit.
  718. */
  719. using pingresp_handler = std::function<bool()>;
  720. // MQTT v3_1_1 handlers
  721. /**
  722. * @brief Connect handler
  723. * @param client_id
  724. * Client Identifier.<BR>
  725. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349245<BR>
  726. * 3.1.3.1 Client Identifier
  727. * @param user_name
  728. * User Name.<BR>
  729. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349245<BR>
  730. * 3.1.3.4 User Name
  731. * @param password
  732. * Password.<BR>
  733. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349246<BR>
  734. * 3.1.3.5 Password
  735. * @param will
  736. * Will. It contains retain, QoS, topic, and message.<BR>
  737. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349232<BR>
  738. * 3.1.2.5 Will Flag<BR>
  739. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349233<BR>
  740. * 3.1.2.6 Will QoS<BR>
  741. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349234<BR>
  742. * 3.1.2.7 Will Retain<BR>
  743. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349243<BR>
  744. * 3.1.3.2 Will Topic<BR>
  745. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349244<BR>
  746. * 3.1.3.3 Will Message<BR>
  747. * @param clean_session
  748. * Clean Session<BR>
  749. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349231<BR>
  750. * 3.1.2.4 Clean Session
  751. * @param keep_alive
  752. * Keep Alive<BR>
  753. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349237<BR>
  754. * 3.1.2.10 Keep Alive
  755. * @return if the handler returns true, then continue receiving, otherwise quit.
  756. *
  757. */
  758. using connect_handler = std::function<
  759. bool(buffer client_id,
  760. optional<buffer> user_name,
  761. optional<buffer> password,
  762. optional<will> will,
  763. bool clean_session,
  764. std::uint16_t keep_alive)>;
  765. /**
  766. * @brief Connack handler
  767. * @param session_present
  768. * Session present flag.<BR>
  769. * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036<BR>
  770. * 3.2.2.2 Session Present
  771. * @param return_code
  772. * connect_return_code<BR>
  773. * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036<BR>
  774. * 3.2.2.3 Connect Return code
  775. * @return if the handler returns true, then continue receiving, otherwise quit.
  776. */
  777. using connack_handler = std::function<bool(bool session_present, connect_return_code return_code)>;
  778. /**
  779. * @brief Publish handler
  780. * @param fixed_header
  781. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718038<BR>
  782. * 3.3.1 Fixed header<BR>
  783. * You can check the fixed header using publish functions.
  784. * @param packet_id
  785. * packet identifier<BR>
  786. * If received publish's QoS is 0, packet_id is nullopt.<BR>
  787. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718039<BR>
  788. * 3.3.2 Variable header
  789. * @param topic_name
  790. * Topic name
  791. * @param contents
  792. * Published contents
  793. * @return if the handler returns true, then continue receiving, otherwise quit.
  794. */
  795. using publish_handler = std::function<bool(optional<packet_id_t> packet_id,
  796. publish_options pubopts,
  797. buffer topic_name,
  798. buffer contents)>;
  799. /**
  800. * @brief Puback handler
  801. * @param packet_id
  802. * packet identifier<BR>
  803. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045<BR>
  804. * 3.4.2 Variable header
  805. * @return if the handler returns true, then continue receiving, otherwise quit.
  806. */
  807. using puback_handler = std::function<bool(packet_id_t packet_id)>;
  808. /**
  809. * @brief Pubrec handler
  810. * @param packet_id
  811. * packet identifier<BR>
  812. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718050<BR>
  813. * 3.5.2 Variable header
  814. * @return if the handler returns true, then continue receiving, otherwise quit.
  815. */
  816. using pubrec_handler = std::function<bool(packet_id_t packet_id)>;
  817. /**
  818. * @brief Pubrel handler
  819. * @param packet_id
  820. * packet identifier<BR>
  821. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349791<BR>
  822. * 3.6.2 Variable header
  823. * @return if the handler returns true, then continue receiving, otherwise quit.
  824. */
  825. using pubrel_handler = std::function<bool(packet_id_t packet_id)>;
  826. /**
  827. * @brief Pubcomp handler
  828. * @param packet_id
  829. * packet identifier<BR>
  830. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718060<BR>
  831. * 3.7.2 Variable header
  832. * @return if the handler returns true, then continue receiving, otherwise quit.
  833. */
  834. using pubcomp_handler = std::function<bool(packet_id_t packet_id)>;
  835. /**
  836. * @brief Subscribe handler
  837. * @param packet_id packet identifier<BR>
  838. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349801<BR>
  839. * 3.8.2 Variable header
  840. * @param entries
  841. * Collection of Share Name, Topic Filter, and QoS.<BR>
  842. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802<BR>
  843. * @return if the handler returns true, then continue receiving, otherwise quit.
  844. */
  845. using subscribe_handler = std::function<bool(packet_id_t packet_id,
  846. std::vector<subscribe_entry> entries)>;
  847. /**
  848. * @brief Suback handler
  849. * @param packet_id packet identifier<BR>
  850. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718070<BR>
  851. * 3.9.2 Variable header
  852. * @param qoss
  853. * Collection of QoS that is corresponding to subscribed topic order.<BR>
  854. * If subscription is failure, the value is nullopt.<BR>
  855. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071<BR>
  856. * @return if the handler returns true, then continue receiving, otherwise quit.
  857. */
  858. using suback_handler = std::function<bool(packet_id_t packet_id,
  859. std::vector<suback_return_code> qoss)>;
  860. /**
  861. * @brief Unsubscribe handler
  862. * @param packet_id packet identifier<BR>
  863. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349810<BR>
  864. * 3.10.2 Variable header
  865. * @param entries
  866. * Collection of Share Name and Topic Filter<BR>
  867. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448<BR>
  868. * @return if the handler returns true, then continue receiving, otherwise quit.
  869. */
  870. using unsubscribe_handler = std::function<bool(packet_id_t packet_id,
  871. std::vector<unsubscribe_entry> entries)>;
  872. /**
  873. * @brief Unsuback handler
  874. * @param packet_id packet identifier<BR>
  875. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045<BR>
  876. * 3.11.2 Variable header
  877. * @return if the handler returns true, then continue receiving, otherwise quit.
  878. */
  879. using unsuback_handler = std::function<bool(packet_id_t)>;
  880. /**
  881. * @brief Disconnect handler
  882. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800463<BR>
  883. * 3.14 DISCONNECT – Disconnect notification
  884. */
  885. using disconnect_handler = std::function<void()>;
  886. // MQTT v5 handlers
  887. /**
  888. * @brief Connect handler
  889. * @param client_id
  890. * Client Identifier.<BR>
  891. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901059<BR>
  892. * 3.1.3.1 Client Identifier
  893. * @param user_name
  894. * User Name.<BR>
  895. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901071<BR>
  896. * 3.1.3.4 User Name
  897. * @param password
  898. * Password.<BR>
  899. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901072<BR>
  900. * 3.1.3.5 Password
  901. * @param will
  902. * Will. It contains retain, QoS, propertied, topic, and message.<BR>
  903. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901040<BR>
  904. * 3.1.2.5 Will Flag<BR>
  905. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901041<BR>
  906. * 3.1.2.6 Will QoS<BR>
  907. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901042<BR>
  908. * 3.1.2.7 Will Retain<BR>
  909. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901060<BR>
  910. * 3.1.3.2 Will Properties<BR>
  911. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901069<BR>
  912. * 3.1.3.3 Will Topic<BR>
  913. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901070<BR>
  914. * 3.1.3.3 Will Payload<BR>
  915. * @param clean_start
  916. * Clean Start<BR>
  917. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901039<BR>
  918. * 3.1.2.4 Clean Session
  919. * @param keep_alive
  920. * Keep Alive<BR>
  921. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901045<BR>
  922. * 3.1.2.10 Keep Alive
  923. * @param props
  924. * Properties<BR>
  925. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046<BR>
  926. * 3.1.2.11 CONNECT Properties
  927. * @return if the handler returns true, then continue receiving, otherwise quit.
  928. *
  929. */
  930. using v5_connect_handler = std::function<
  931. bool(buffer client_id,
  932. optional<buffer> user_name,
  933. optional<buffer> password,
  934. optional<will> will,
  935. bool clean_start,
  936. std::uint16_t keep_alive,
  937. v5::properties props)
  938. >;
  939. /**
  940. * @brief Connack handler
  941. * @param session_present
  942. * Session present flag.<BR>
  943. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901078<BR>
  944. * 3.2.2.1.1 Session Present
  945. * @param reason_code
  946. * Connect Reason Code<BR>
  947. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901079<BR>
  948. * 3.2.2.2 Connect Reason code
  949. * @param props
  950. * Properties<BR>
  951. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080<BR>
  952. * 3.2.2.3 CONNACK Properties
  953. * @return if the handler returns true, then continue receiving, otherwise quit.
  954. */
  955. using v5_connack_handler = std::function<
  956. bool(bool session_present,
  957. v5::connect_reason_code reason_code,
  958. v5::properties props)
  959. >;
  960. /**
  961. * @brief Publish handler
  962. * @param packet_id
  963. * packet identifier<BR>
  964. * If received publish's QoS is 0, packet_id is nullopt.<BR>
  965. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901108<BR>
  966. * 3.3.2.2 Packet Identifier
  967. * @param fixed_header
  968. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901101<BR>
  969. * 3.3.1 Fixed header<BR>
  970. * You can check the fixed header using publish functions.
  971. * @param topic_name
  972. * Topic name<BR>
  973. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901107<BR>
  974. * 3.3.2.1 Topic Name<BR>
  975. * @param contents
  976. * Publish Payload<BR>
  977. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901119<BR>
  978. * 3.3.3 PUBLISH Payload
  979. * @param props
  980. * Properties<BR>
  981. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109<BR>
  982. * 3.3.2.3 PUBLISH Properties
  983. * @return if the handler returns true, then continue receiving, otherwise quit.
  984. */
  985. using v5_publish_handler = std::function<
  986. bool(optional<packet_id_t> packet_id,
  987. publish_options pubopts,
  988. buffer topic_name,
  989. buffer contents,
  990. v5::properties props)
  991. >;
  992. /**
  993. * @brief Puback handler
  994. * @param packet_id
  995. * packet identifier<BR>
  996. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901123<BR>
  997. * 3.4.2 Variable header
  998. * @param reason_code
  999. * PUBACK Reason Code<BR>
  1000. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901124<BR>
  1001. * 3.4.2.1 PUBACK Reason Code
  1002. * @param props
  1003. * Properties<BR>
  1004. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125<BR>
  1005. * 3.4.2.2 PUBACK Properties
  1006. * @return if the handler returns true, then continue receiving, otherwise quit.
  1007. */
  1008. using v5_puback_handler = std::function<
  1009. bool(packet_id_t packet_id,
  1010. v5::puback_reason_code reason_code,
  1011. v5::properties props)
  1012. >;
  1013. /**
  1014. * @brief Pubrec handler
  1015. * @param packet_id
  1016. * packet identifier<BR>
  1017. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901133<BR>
  1018. * 3.5.2 Variable header
  1019. * @param reason_code
  1020. * PUBREC Reason Code<BR>
  1021. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901134<BR>
  1022. * 3.5.2.1 PUBREC Reason Code
  1023. * @param props
  1024. * Properties<BR>
  1025. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135<BR>
  1026. * 3.5.2.2 PUBREC Properties
  1027. * @return if the handler returns true, then continue receiving, otherwise quit.
  1028. */
  1029. using v5_pubrec_handler = std::function<
  1030. bool(packet_id_t packet_id,
  1031. v5::pubrec_reason_code reason_code,
  1032. v5::properties props)
  1033. >;
  1034. /**
  1035. * @brief Pubrel handler
  1036. * @param packet_id
  1037. * packet identifier<BR>
  1038. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901143<BR>
  1039. * 3.6.2 Variable header
  1040. * @param reason_code
  1041. * PUBREL Reason Code<BR>
  1042. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901144<BR>
  1043. * 3.6.2.1 PUBREL Reason Code
  1044. * @param props
  1045. * Properties<BR>
  1046. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145<BR>
  1047. * 3.6.2.2 PUBREL Properties
  1048. * @return if the handler returns true, then continue receiving, otherwise quit.
  1049. */
  1050. using v5_pubrel_handler = std::function<
  1051. bool(packet_id_t packet_id,
  1052. v5::pubrel_reason_code reason_code,
  1053. v5::properties props)
  1054. >;
  1055. /**
  1056. * @brief Pubcomp handler
  1057. * @param packet_id
  1058. * packet identifier<BR>
  1059. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901153<BR>
  1060. * 3.7.2 Variable header
  1061. * @param reason_code
  1062. * PUBCOMP Reason Code<BR>
  1063. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901154<BR>
  1064. * 3.7.2.1 PUBCOMP Reason Code
  1065. * @param props
  1066. * Properties<BR>
  1067. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155<BR>
  1068. * 3.7.2.2 PUBCOMP Properties
  1069. * @return if the handler returns true, then continue receiving, otherwise quit.
  1070. */
  1071. using v5_pubcomp_handler = std::function<
  1072. bool(packet_id_t packet_id,
  1073. v5::pubcomp_reason_code reason_code,
  1074. v5::properties props)
  1075. >;
  1076. /**
  1077. * @brief Subscribe handler
  1078. * @param packet_id packet identifier<BR>
  1079. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901163<BR>
  1080. * 3.8.2 Variable header
  1081. * @param entries
  1082. * Collection of Share Name, Topic Filter, and Subscribe Options.<BR>
  1083. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901168<BR>
  1084. * @param props
  1085. * Properties<BR>
  1086. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164<BR>
  1087. * 3.8.2.1 SUBSCRIBE Properties
  1088. * @return if the handler returns true, then continue receiving, otherwise quit.
  1089. */
  1090. using v5_subscribe_handler = std::function<
  1091. bool(packet_id_t packet_id,
  1092. std::vector<subscribe_entry> entries,
  1093. v5::properties props)
  1094. >;
  1095. /**
  1096. * @brief Suback handler
  1097. * @param packet_id packet identifier<BR>
  1098. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901173<BR>
  1099. * 3.9.2 Variable header
  1100. * @param reasons
  1101. * Collection of reason_code.<BR>
  1102. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901178<BR>
  1103. * 3.9.3 SUBACK Payload
  1104. * @param props
  1105. * Properties<BR>
  1106. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174<BR>
  1107. * 3.9.2.1 SUBACK Properties
  1108. * @return if the handler returns true, then continue receiving, otherwise quit.
  1109. */
  1110. using v5_suback_handler = std::function<
  1111. bool(packet_id_t packet_id,
  1112. std::vector<v5::suback_reason_code> reasons,
  1113. v5::properties props)
  1114. >;
  1115. /**
  1116. * @brief Unsubscribe handler
  1117. * @param packet_id packet identifier<BR>
  1118. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901181<BR>
  1119. * 3.10.2 Variable header
  1120. * @param entries
  1121. * Collection of Share Name and Topic Filter<BR>
  1122. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901185<BR>
  1123. * 3.10.3 UNSUBSCRIBE Payload
  1124. * @param props
  1125. * Properties<BR>
  1126. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182<BR>
  1127. * 3.10.2.1 UNSUBSCRIBE Properties
  1128. * @return if the handler returns true, then continue receiving, otherwise quit.
  1129. */
  1130. using v5_unsubscribe_handler = std::function<
  1131. bool(packet_id_t packet_id,
  1132. std::vector<unsubscribe_entry> entries,
  1133. v5::properties props)
  1134. >;
  1135. /**
  1136. * @brief Unsuback handler
  1137. * @param packet_id packet identifier<BR>
  1138. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901189<BR>
  1139. * 3.11.2 Variable header
  1140. * @param reasons
  1141. * Collection of reason_code.<BR>
  1142. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901194<BR>
  1143. * 3.11.3 UNSUBACK Payload
  1144. * @param props
  1145. * Properties<BR>
  1146. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190<BR>
  1147. * 3.11.2.1 UNSUBACK Properties
  1148. * @return if the handler returns true, then continue receiving, otherwise quit.
  1149. */
  1150. using v5_unsuback_handler = std::function<
  1151. bool(packet_id_t,
  1152. std::vector<v5::unsuback_reason_code> reasons,
  1153. v5::properties props)
  1154. >;
  1155. /**
  1156. * @brief Disconnect handler
  1157. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205<BR>
  1158. * 3.14 DISCONNECT – Disconnect notification
  1159. * @param reason_code
  1160. * DISCONNECT Reason Code<BR>
  1161. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901208<BR>
  1162. * 3.14.2.1 Disconnect Reason Code
  1163. * @param props
  1164. * Properties<BR>
  1165. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209<BR>
  1166. * 3.14.2.2 DISCONNECT Properties
  1167. */
  1168. using v5_disconnect_handler = std::function<
  1169. void(v5::disconnect_reason_code reason_code,
  1170. v5::properties props)
  1171. >;
  1172. /**
  1173. * @brief Auth handler
  1174. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901217<BR>
  1175. * 3.15 AUTH – Authentication exchange
  1176. * @param reason_code
  1177. * AUTH Reason Code<BR>
  1178. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901220<BR>
  1179. * 3.15.2.1 Authenticate Reason Code
  1180. * @param props
  1181. * Properties<BR>
  1182. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221<BR>
  1183. * 3.15.2.2 AUTH Properties
  1184. * @return if the handler returns true, then continue receiving, otherwise quit.
  1185. */
  1186. using v5_auth_handler = std::function<
  1187. bool(v5::auth_reason_code reason_code,
  1188. v5::properties props)
  1189. >;
  1190. // Original handlers
  1191. /**
  1192. * @brief Close handler
  1193. *
  1194. * This handler is called if the client called `disconnect()` and the server closed the socket cleanly.
  1195. * If the socket is closed by other reasons, error_handler is called.
  1196. */
  1197. using close_handler = std::function<void()>;
  1198. /**
  1199. * @brief Error handler
  1200. *
  1201. * This handler is called if the socket is closed without client's `disconnect()` call.
  1202. *
  1203. * @param ec error code
  1204. */
  1205. using error_handler = std::function<void(error_code ec)>;
  1206. /**
  1207. * @brief Publish response sent handler
  1208. * This function is called just after puback sent on QoS1, or pubcomp sent on QoS2.
  1209. * @param packet_id
  1210. * packet identifier<BR>
  1211. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901026<BR>
  1212. * 2.2.1 Packet Identifier
  1213. */
  1214. using pub_res_sent_handler = std::function<void(packet_id_t packet_id)>;
  1215. /**
  1216. * @brief Serialize publish handler
  1217. * You can serialize the publish message.
  1218. * To restore the message, use restore_serialized_message().
  1219. * @param msg publish message
  1220. */
  1221. using serialize_publish_message_handler = std::function<void(basic_publish_message<sizeof(packet_id_t)> msg)>;
  1222. /**
  1223. * @brief Serialize publish handler
  1224. * You can serialize the publish message.
  1225. * To restore the message, use restore_serialized_message().
  1226. * @param msg v5::publish message
  1227. */
  1228. using serialize_v5_publish_message_handler = std::function<void(v5::basic_publish_message<sizeof(packet_id_t)> msg)>;
  1229. /**
  1230. * @brief Serialize publish handler
  1231. * You can serialize the publish message.
  1232. * To restore the message, use restore_serialized_message().
  1233. * @param packet_id packet identifier of the serializing message
  1234. * @param data pointer to the serializing message
  1235. * @param size size of the serializing message
  1236. */
  1237. using serialize_publish_handler = std::function<void(packet_id_t packet_id, char const* data, std::size_t size)>;
  1238. /**
  1239. * @brief Serialize pubrel handler
  1240. * You can serialize the pubrel message.
  1241. * If your storage has already had the publish message that has the same packet_id,
  1242. * then you need to replace the publish message to pubrel message.
  1243. * To restore the message, use restore_serialized_message().
  1244. * @param msg pubrel message
  1245. */
  1246. using serialize_pubrel_message_handler = std::function<void(basic_pubrel_message<sizeof(packet_id_t)> msg)>;
  1247. /**
  1248. * @brief Serialize pubrel handler
  1249. * You can serialize the pubrel message.
  1250. * If your storage has already had the publish message that has the same packet_id,
  1251. * then you need to replace the publish message to pubrel message.
  1252. * To restore the message, use restore_serialized_message().
  1253. * @param msg pubrel message
  1254. */
  1255. using serialize_v5_pubrel_message_handler = std::function<void(v5::basic_pubrel_message<sizeof(packet_id_t)> msg)>;
  1256. /**
  1257. * @brief Serialize pubrel handler
  1258. * You can serialize the pubrel message.
  1259. * If your storage has already had the publish message that has the same packet_id,
  1260. * then you need to replace the publish message to pubrel message.
  1261. * To restore the message, use restore_serialized_message().
  1262. * @param packet_id packet identifier of the serializing message
  1263. * @param data pointer to the serializing message
  1264. * @param size size of the serializing message
  1265. */
  1266. using serialize_pubrel_handler = std::function<void(packet_id_t packet_id, char const* data, std::size_t size)>;
  1267. /**
  1268. * @brief Remove serialized message
  1269. * @param packet_id packet identifier of the removing message
  1270. */
  1271. using serialize_remove_handler = std::function<void(packet_id_t packet_id)>;
  1272. /**
  1273. * @brief Pre-send handler
  1274. * This handler is called when any mqtt control packet is decided to send.
  1275. */
  1276. using pre_send_handler = std::function<void()>;
  1277. /**
  1278. * @brief is valid length handler
  1279. * This handler is called when remaining length is received.
  1280. * @param control_packet_type control_packet_type that has variable length
  1281. * @param remaining length
  1282. * @return true if check is success, otherwise false
  1283. */
  1284. using is_valid_length_handler =
  1285. std::function<bool(control_packet_type packet_type, std::size_t remaining_length)>;
  1286. /**
  1287. * @brief next read handler
  1288. * This handler is called when the current mqtt message has been processed.
  1289. * @param func A callback function that is called when async operation will finish.
  1290. */
  1291. using mqtt_message_processed_handler =
  1292. std::function<void(any session_life_keeper)>;
  1293. // MQTT Common handlers
  1294. /**
  1295. * @brief Set pingreq handler
  1296. * @param h handler
  1297. */
  1298. void set_pingreq_handler(pingreq_handler h = pingreq_handler()) {
  1299. h_pingreq_ = force_move(h);
  1300. }
  1301. /**
  1302. * @brief Set pingresp handler
  1303. * @param h handler
  1304. */
  1305. void set_pingresp_handler(pingresp_handler h = pingresp_handler()) {
  1306. h_pingresp_ = force_move(h);
  1307. }
  1308. /**
  1309. * @brief Get pingreq handler
  1310. * @return handler
  1311. */
  1312. pingreq_handler const& get_pingreq_handler() const {
  1313. return h_pingreq_;
  1314. }
  1315. /**
  1316. * @brief Get pingresp handler
  1317. * @return handler
  1318. */
  1319. pingresp_handler const& get_pingresp_handler() const {
  1320. return h_pingresp_;
  1321. }
  1322. // MQTT v3_1_1 handlers
  1323. /**
  1324. * @brief Set connect handler
  1325. * @param h handler
  1326. */
  1327. void set_connect_handler(connect_handler h = connect_handler()) {
  1328. h_connect_ = force_move(h);
  1329. }
  1330. /**
  1331. * @brief Set connack handler
  1332. * @param h handler
  1333. */
  1334. void set_connack_handler(connack_handler h = connack_handler()) {
  1335. h_connack_ = force_move(h);
  1336. }
  1337. /**
  1338. * @brief Set publish handler
  1339. * @param h handler
  1340. */
  1341. void set_publish_handler(publish_handler h = publish_handler()) {
  1342. h_publish_ = force_move(h);
  1343. }
  1344. /**
  1345. * @brief Set puback handler
  1346. * @param h handler
  1347. */
  1348. void set_puback_handler(puback_handler h = puback_handler()) {
  1349. h_puback_ = force_move(h);
  1350. }
  1351. /**
  1352. * @brief Set pubrec handler
  1353. * @param h handler
  1354. */
  1355. void set_pubrec_handler(pubrec_handler h = pubrec_handler()) {
  1356. h_pubrec_ = force_move(h);
  1357. }
  1358. /**
  1359. * @brief Set pubrel handler
  1360. * @param h handler
  1361. */
  1362. void set_pubrel_handler(pubrel_handler h = pubrel_handler()) {
  1363. h_pubrel_ = force_move(h);
  1364. }
  1365. /**
  1366. * @brief Set pubcomp handler
  1367. * @param h handler
  1368. */
  1369. void set_pubcomp_handler(pubcomp_handler h = pubcomp_handler()) {
  1370. h_pubcomp_ = force_move(h);
  1371. }
  1372. /**
  1373. * @brief Set subscribe handler
  1374. * @param h handler
  1375. */
  1376. void set_subscribe_handler(subscribe_handler h = subscribe_handler()) {
  1377. h_subscribe_ = force_move(h);
  1378. }
  1379. /**
  1380. * @brief Set suback handler
  1381. * @param h handler
  1382. */
  1383. void set_suback_handler(suback_handler h = suback_handler()) {
  1384. h_suback_ = force_move(h);
  1385. }
  1386. /**
  1387. * @brief Set unsubscribe handler
  1388. * @param h handler
  1389. */
  1390. void set_unsubscribe_handler(unsubscribe_handler h = unsubscribe_handler()) {
  1391. h_unsubscribe_ = force_move(h);
  1392. }
  1393. /**
  1394. * @brief Set unsuback handler
  1395. * @param h handler
  1396. */
  1397. void set_unsuback_handler(unsuback_handler h = unsuback_handler()) {
  1398. h_unsuback_ = force_move(h);
  1399. }
  1400. /**
  1401. * @brief Set disconnect handler
  1402. * @param h handler
  1403. */
  1404. void set_disconnect_handler(disconnect_handler h = disconnect_handler()) {
  1405. h_disconnect_ = force_move(h);
  1406. }
  1407. /**
  1408. * @brief Get connect handler
  1409. * @return handler
  1410. */
  1411. connect_handler const& get_connect_handler() const {
  1412. return h_connect_;
  1413. }
  1414. /**
  1415. * @brief Get connack handler
  1416. * @return handler
  1417. */
  1418. connack_handler const& get_connack_handler() const {
  1419. return h_connack_;
  1420. }
  1421. /**
  1422. * @brief Set publish handler
  1423. * @return handler
  1424. */
  1425. publish_handler const& get_publish_handler() const {
  1426. return h_publish_;
  1427. }
  1428. /**
  1429. * @brief Get puback handler
  1430. * @return handler
  1431. */
  1432. puback_handler const& get_puback_handler() const {
  1433. return h_puback_;
  1434. }
  1435. /**
  1436. * @brief Get pubrec handler
  1437. * @return handler
  1438. */
  1439. pubrec_handler const& get_pubrec_handler() const {
  1440. return h_pubrec_;
  1441. }
  1442. /**
  1443. * @brief Get pubrel handler
  1444. * @return handler
  1445. */
  1446. pubrel_handler const& get_pubrel_handler() const {
  1447. return h_pubrel_;
  1448. }
  1449. /**
  1450. * @brief Get pubcomp handler
  1451. * @return handler
  1452. */
  1453. pubcomp_handler const& get_pubcomp_handler() const {
  1454. return h_pubcomp_;
  1455. }
  1456. /**
  1457. * @brief Get subscribe handler
  1458. * @return handler
  1459. */
  1460. subscribe_handler const& get_subscribe_handler() const {
  1461. return h_subscribe_;
  1462. }
  1463. /**
  1464. * @brief Get suback handler
  1465. * @return handler
  1466. */
  1467. suback_handler const& get_suback_handler() const {
  1468. return h_suback_;
  1469. }
  1470. /**
  1471. * @brief Get unsubscribe handler
  1472. * @return handler
  1473. */
  1474. unsubscribe_handler const& get_unsubscribe_handler() const {
  1475. return h_unsubscribe_;
  1476. }
  1477. /**
  1478. * @brief Get unsuback handler
  1479. * @return handler
  1480. */
  1481. unsuback_handler const& get_unsuback_handler() const {
  1482. return h_unsuback_;
  1483. }
  1484. /**
  1485. * @brief Get disconnect handler
  1486. * @return handler
  1487. */
  1488. disconnect_handler const& get_disconnect_handler() const {
  1489. return h_disconnect_;
  1490. }
  1491. // MQTT v5 handlers
  1492. /**
  1493. * @brief Set connect handler
  1494. * @param h handler
  1495. */
  1496. void set_v5_connect_handler(v5_connect_handler h = v5_connect_handler()) {
  1497. h_v5_connect_ = force_move(h);
  1498. }
  1499. /**
  1500. * @brief Set connack handler
  1501. * @param h handler
  1502. */
  1503. void set_v5_connack_handler(v5_connack_handler h = v5_connack_handler()) {
  1504. h_v5_connack_ = force_move(h);
  1505. }
  1506. /**
  1507. * @brief Set publish handler
  1508. * @param h handler
  1509. */
  1510. void set_v5_publish_handler(v5_publish_handler h = v5_publish_handler()) {
  1511. h_v5_publish_ = force_move(h);
  1512. }
  1513. /**
  1514. * @brief Set puback handler
  1515. * @param h handler
  1516. */
  1517. void set_v5_puback_handler(v5_puback_handler h = v5_puback_handler()) {
  1518. h_v5_puback_ = force_move(h);
  1519. }
  1520. /**
  1521. * @brief Set pubrec handler
  1522. * @param h handler
  1523. */
  1524. void set_v5_pubrec_handler(v5_pubrec_handler h = v5_pubrec_handler()) {
  1525. h_v5_pubrec_ = force_move(h);
  1526. }
  1527. /**
  1528. * @brief Set pubrel handler
  1529. * @param h handler
  1530. */
  1531. void set_v5_pubrel_handler(v5_pubrel_handler h = v5_pubrel_handler()) {
  1532. h_v5_pubrel_ = force_move(h);
  1533. }
  1534. /**
  1535. * @brief Set pubcomp handler
  1536. * @param h handler
  1537. */
  1538. void set_v5_pubcomp_handler(v5_pubcomp_handler h = v5_pubcomp_handler()) {
  1539. h_v5_pubcomp_ = force_move(h);
  1540. }
  1541. /**
  1542. * @brief Set subscribe handler
  1543. * @param h handler
  1544. */
  1545. void set_v5_subscribe_handler(v5_subscribe_handler h = v5_subscribe_handler()) {
  1546. h_v5_subscribe_ = force_move(h);
  1547. }
  1548. /**
  1549. * @brief Set suback handler
  1550. * @param h handler
  1551. */
  1552. void set_v5_suback_handler(v5_suback_handler h = v5_suback_handler()) {
  1553. h_v5_suback_ = force_move(h);
  1554. }
  1555. /**
  1556. * @brief Set unsubscribe handler
  1557. * @param h handler
  1558. */
  1559. void set_v5_unsubscribe_handler(v5_unsubscribe_handler h = v5_unsubscribe_handler()) {
  1560. h_v5_unsubscribe_ = force_move(h);
  1561. }
  1562. /**
  1563. * @brief Set unsuback handler
  1564. * @param h handler
  1565. */
  1566. void set_v5_unsuback_handler(v5_unsuback_handler h = v5_unsuback_handler()) {
  1567. h_v5_unsuback_ = force_move(h);
  1568. }
  1569. /**
  1570. * @brief Set disconnect handler
  1571. * @param h handler
  1572. */
  1573. void set_v5_disconnect_handler(v5_disconnect_handler h = v5_disconnect_handler()) {
  1574. h_v5_disconnect_ = force_move(h);
  1575. }
  1576. /**
  1577. * @brief Set auth handler
  1578. * @param h handler
  1579. */
  1580. void set_v5_auth_handler(v5_auth_handler h = v5_auth_handler()) {
  1581. h_v5_auth_ = force_move(h);
  1582. }
  1583. /**
  1584. * @brief Get connect handler
  1585. * @return handler
  1586. */
  1587. v5_connect_handler const& get_v5_connect_handler() const {
  1588. return h_v5_connect_;
  1589. }
  1590. /**
  1591. * @brief Get connack handler
  1592. * @return handler
  1593. */
  1594. v5_connack_handler const& get_v5_connack_handler() const {
  1595. return h_v5_connack_;
  1596. }
  1597. /**
  1598. * @brief Set publish handler
  1599. * @return handler
  1600. */
  1601. v5_publish_handler const& get_v5_publish_handler() const {
  1602. return h_v5_publish_;
  1603. }
  1604. /**
  1605. * @brief Get puback handler
  1606. * @return handler
  1607. */
  1608. v5_puback_handler const& get_v5_puback_handler() const {
  1609. return h_v5_puback_;
  1610. }
  1611. /**
  1612. * @brief Get pubrec handler
  1613. * @return handler
  1614. */
  1615. v5_pubrec_handler const& get_v5__handler() const {
  1616. return h_v5_pubrec_;
  1617. }
  1618. /**
  1619. * @brief Get pubrel handler
  1620. * @return handler
  1621. */
  1622. v5_pubrel_handler const& get_v5_pubrel_handler() const {
  1623. return h_v5_pubrel_;
  1624. }
  1625. /**
  1626. * @brief Get pubcomp handler
  1627. * @return handler
  1628. */
  1629. v5_pubcomp_handler const& get_v5_pubcomp_handler() const {
  1630. return h_v5_pubcomp_;
  1631. }
  1632. /**
  1633. * @brief Get subscribe handler
  1634. * @return handler
  1635. */
  1636. v5_subscribe_handler const& get_v5_subscribe_handler() const {
  1637. return h_v5_subscribe_;
  1638. }
  1639. /**
  1640. * @brief Get suback handler
  1641. * @return handler
  1642. */
  1643. v5_suback_handler const& get_v5_suback_handler() const {
  1644. return h_v5_suback_;
  1645. }
  1646. /**
  1647. * @brief Get unsubscribe handler
  1648. * @return handler
  1649. */
  1650. v5_unsubscribe_handler const& get_v5_unsubscribe_handler() const {
  1651. return h_v5_unsubscribe_;
  1652. }
  1653. /**
  1654. * @brief Get unsuback handler
  1655. * @return handler
  1656. */
  1657. v5_unsuback_handler const& get_v5_unsuback_handler() const {
  1658. return h_v5_unsuback_;
  1659. }
  1660. /**
  1661. * @brief Get disconnect handler
  1662. * @return handler
  1663. */
  1664. v5_disconnect_handler const& get_v5_disconnect_handler() const {
  1665. return h_v5_disconnect_;
  1666. }
  1667. /**
  1668. * @brief Get auth handler
  1669. * @return handler
  1670. */
  1671. v5_auth_handler const& get_v5_auth_handler() const {
  1672. return h_v5_auth_;
  1673. }
  1674. // Original handlers
  1675. /**
  1676. * @brief Set pubcomp handler
  1677. * @param h handler
  1678. */
  1679. void set_pub_res_sent_handler(pub_res_sent_handler h = pub_res_sent_handler()) {
  1680. h_pub_res_sent_ = force_move(h);
  1681. }
  1682. /**
  1683. * @brief Set serialize handlers
  1684. * @param h_publish serialize handler for publish message
  1685. * @param h_pubrel serialize handler for pubrel message
  1686. * @param h_remove remove handler for serialized message
  1687. */
  1688. void set_serialize_handlers(
  1689. serialize_publish_message_handler h_publish,
  1690. serialize_pubrel_message_handler h_pubrel,
  1691. serialize_remove_handler h_remove) {
  1692. h_serialize_publish_ = force_move(h_publish);
  1693. h_serialize_pubrel_ = force_move(h_pubrel);
  1694. h_serialize_remove_ = force_move(h_remove);
  1695. }
  1696. /**
  1697. * @brief Set serialize handlers
  1698. * @param h_publish serialize handler for publish message
  1699. * @param h_pubrel serialize handler for pubrel message
  1700. * @param h_remove remove handler for serialized message
  1701. */
  1702. void set_v5_serialize_handlers(
  1703. serialize_v5_publish_message_handler h_publish,
  1704. serialize_v5_pubrel_message_handler h_pubrel,
  1705. serialize_remove_handler h_remove) {
  1706. h_serialize_v5_publish_ = force_move(h_publish);
  1707. h_serialize_v5_pubrel_ = force_move(h_pubrel);
  1708. h_serialize_remove_ = force_move(h_remove);
  1709. }
  1710. /**
  1711. * @brief Set serialize handlers
  1712. * @param h_publish serialize handler for publish message
  1713. * @param h_pubrel serialize handler for pubrel message
  1714. * @param h_remove remove handler for serialized message
  1715. */
  1716. void set_serialize_handlers(
  1717. serialize_publish_handler h_publish,
  1718. serialize_pubrel_handler h_pubrel,
  1719. serialize_remove_handler h_remove) {
  1720. h_serialize_publish_ =
  1721. [h_publish = force_move(h_publish)]
  1722. (basic_publish_message<sizeof(packet_id_t)> msg) {
  1723. if (h_publish) {
  1724. auto buf = msg.continuous_buffer();
  1725. h_publish(msg.packet_id(), buf.data(), buf.size());
  1726. }
  1727. };
  1728. h_serialize_pubrel_ =
  1729. [h_pubrel = force_move(h_pubrel)]
  1730. (basic_pubrel_message<sizeof(packet_id_t)> msg) {
  1731. if (h_pubrel) {
  1732. auto buf = msg.continuous_buffer();
  1733. h_pubrel(msg.packet_id(), buf.data(), buf.size());
  1734. }
  1735. };
  1736. h_serialize_remove_ = force_move(h_remove);
  1737. }
  1738. /**
  1739. * @brief Set serialize handlers
  1740. * @param h_publish serialize handler for publish message
  1741. * @param h_pubrel serialize handler for pubrel message
  1742. * @param h_remove remove handler for serialized message
  1743. */
  1744. void set_v5_serialize_handlers(
  1745. serialize_publish_handler h_publish,
  1746. serialize_pubrel_handler h_pubrel,
  1747. serialize_remove_handler h_remove) {
  1748. h_serialize_v5_publish_ =
  1749. [h_publish = force_move(h_publish)]
  1750. (v5::basic_publish_message<sizeof(packet_id_t)> msg) {
  1751. if (h_publish) {
  1752. auto buf = msg.continuous_buffer();
  1753. h_publish(msg.packet_id(), buf.data(), buf.size());
  1754. }
  1755. };
  1756. h_serialize_v5_pubrel_ =
  1757. [h_pubrel = force_move(h_pubrel)]
  1758. (v5::basic_pubrel_message<sizeof(packet_id_t)> msg) {
  1759. if (h_pubrel) {
  1760. auto buf = msg.continuous_buffer();
  1761. h_pubrel(msg.packet_id(), buf.data(), buf.size());
  1762. }
  1763. };
  1764. h_serialize_remove_ = force_move(h_remove);
  1765. }
  1766. /**
  1767. * @brief Clear serialize handlers
  1768. */
  1769. void set_serialize_handlers() {
  1770. h_serialize_publish_ = serialize_publish_message_handler();
  1771. h_serialize_pubrel_ = serialize_pubrel_message_handler();
  1772. h_serialize_v5_publish_ = serialize_v5_publish_message_handler();
  1773. h_serialize_v5_pubrel_ = serialize_v5_pubrel_message_handler();
  1774. h_serialize_remove_ = serialize_remove_handler();
  1775. }
  1776. /**
  1777. * @brief Set pre-send handler
  1778. * @param h handler
  1779. */
  1780. void set_pre_send_handler(pre_send_handler h = pre_send_handler()) {
  1781. h_pre_send_ = force_move(h);
  1782. }
  1783. /**
  1784. * @brief Set check length handler
  1785. * @param h handler
  1786. */
  1787. void set_is_valid_length_handler(is_valid_length_handler h = is_valid_length_handler()) {
  1788. h_is_valid_length_ = force_move(h);
  1789. }
  1790. /**
  1791. * @brief Get publish response sent handler
  1792. * @return handler
  1793. */
  1794. pub_res_sent_handler const& get_pub_res_sent_handler() const {
  1795. return h_pub_res_sent_;
  1796. }
  1797. /**
  1798. * @brief Get serialize publish handler
  1799. * @return handler
  1800. */
  1801. serialize_publish_message_handler const& get_serialize_publish_message_handler() const {
  1802. return h_serialize_publish_;
  1803. }
  1804. /**
  1805. * @brief Get serialize pubrel handler
  1806. * @return handler
  1807. */
  1808. serialize_pubrel_message_handler const& get_serialize_pubrel_message_handler() const {
  1809. return h_serialize_pubrel_;
  1810. }
  1811. /**
  1812. * @brief Get serialize publish handler
  1813. * @return handler
  1814. */
  1815. serialize_v5_publish_message_handler const& get_serialize_v5_publish_message_handler() const {
  1816. return h_serialize_v5_publish_;
  1817. }
  1818. /**
  1819. * @brief Get serialize pubrel handler
  1820. * @return handler
  1821. */
  1822. serialize_v5_pubrel_message_handler const& get_serialize_v5_pubrel_message_handler() const {
  1823. return h_serialize_v5_pubrel_;
  1824. }
  1825. /**
  1826. * @brief Get serialize remove handler
  1827. * @return handler
  1828. */
  1829. serialize_remove_handler const& get_serialize_remove_handler() const {
  1830. return h_serialize_remove_;
  1831. }
  1832. /**
  1833. * @brief Get pre-send handler
  1834. * @return handler
  1835. */
  1836. pre_send_handler const& get_pre_send_handler() const {
  1837. return h_pre_send_;
  1838. }
  1839. /**
  1840. * @brief Get check length handler
  1841. * @return handler
  1842. */
  1843. is_valid_length_handler const& get_is_valid_length_handler() const {
  1844. return h_is_valid_length_;
  1845. }
  1846. /**
  1847. * @brief Set custom mqtt_message_processed_handler.
  1848. * The default setting is calling async_read_control_packet_type().
  1849. * (See endpoint() constructor).
  1850. * The typical usecase of this function is delaying the next
  1851. * message reading timing.
  1852. * In order to do that
  1853. * 1) store func parameter of the mqtt_message_processed_handler.
  1854. * 2) call async_read_next_message with the stored func if
  1855. * you are ready to read the next mqtt message.
  1856. * @param h mqtt_message_processed_handler.
  1857. */
  1858. void set_mqtt_message_processed_handler(
  1859. mqtt_message_processed_handler h = mqtt_message_processed_handler()) {
  1860. if (h) {
  1861. h_mqtt_message_processed_ = force_move(h);
  1862. }
  1863. else {
  1864. h_mqtt_message_processed_ = {};
  1865. }
  1866. }
  1867. /**
  1868. * @brief Get mqtt_message_processed_handler.
  1869. * @return mqtt_message_processed_handler.
  1870. */
  1871. mqtt_message_processed_handler get_mqtt_message_processed_handler() const {
  1872. return h_mqtt_message_processed_;
  1873. }
  1874. /**
  1875. * @brief Set close handler
  1876. * @param h handler
  1877. */
  1878. void set_close_handler(close_handler h = close_handler()) {
  1879. h_close_ = force_move(h);
  1880. }
  1881. /**
  1882. * @brief Set error handler
  1883. * @param h handler
  1884. */
  1885. void set_error_handler(error_handler h = error_handler()) {
  1886. h_error_ = force_move(h);
  1887. }
  1888. /**
  1889. * @brief Get close handler
  1890. * @return handler
  1891. */
  1892. close_handler get_close_handler() const {
  1893. return h_close_;
  1894. }
  1895. /**
  1896. * @brief Get error handler
  1897. * @return handler
  1898. */
  1899. error_handler get_error_handler() const {
  1900. return h_error_;
  1901. }
  1902. private:
  1903. // MQTT common handlers
  1904. pingreq_handler h_pingreq_;
  1905. pingresp_handler h_pingresp_;
  1906. // MQTT v3_1_1 handlers
  1907. connect_handler h_connect_;
  1908. connack_handler h_connack_;
  1909. publish_handler h_publish_;
  1910. puback_handler h_puback_;
  1911. pubrec_handler h_pubrec_;
  1912. pubrel_handler h_pubrel_;
  1913. pubcomp_handler h_pubcomp_;
  1914. subscribe_handler h_subscribe_;
  1915. suback_handler h_suback_;
  1916. unsubscribe_handler h_unsubscribe_;
  1917. unsuback_handler h_unsuback_;
  1918. disconnect_handler h_disconnect_;
  1919. // MQTT v5 handlers
  1920. v5_connect_handler h_v5_connect_;
  1921. v5_connack_handler h_v5_connack_;
  1922. v5_publish_handler h_v5_publish_;
  1923. v5_puback_handler h_v5_puback_;
  1924. v5_pubrec_handler h_v5_pubrec_;
  1925. v5_pubrel_handler h_v5_pubrel_;
  1926. v5_pubcomp_handler h_v5_pubcomp_;
  1927. v5_subscribe_handler h_v5_subscribe_;
  1928. v5_suback_handler h_v5_suback_;
  1929. v5_unsubscribe_handler h_v5_unsubscribe_;
  1930. v5_unsuback_handler h_v5_unsuback_;
  1931. v5_disconnect_handler h_v5_disconnect_;
  1932. v5_auth_handler h_v5_auth_;
  1933. // original handlers
  1934. close_handler h_close_;
  1935. error_handler h_error_;
  1936. pub_res_sent_handler h_pub_res_sent_;
  1937. serialize_publish_message_handler h_serialize_publish_;
  1938. serialize_v5_publish_message_handler h_serialize_v5_publish_;
  1939. serialize_pubrel_message_handler h_serialize_pubrel_;
  1940. serialize_v5_pubrel_message_handler h_serialize_v5_pubrel_;
  1941. serialize_remove_handler h_serialize_remove_;
  1942. pre_send_handler h_pre_send_;
  1943. is_valid_length_handler h_is_valid_length_;
  1944. mqtt_message_processed_handler h_mqtt_message_processed_;
  1945. }; // callable_overlay
  1946. } // namespace MQTT_NS
  1947. #endif // MQTT_CALLABLE_OVERLAY_HPP