1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131 |
- // Copyright Takatoshi Kondo 2015
- //
- // Distributed under the Boost Software License, Version 1.0.
- // (See accompanying file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt)
- #if !defined(MQTT_CALLABLE_OVERLAY_HPP)
- #define MQTT_CALLABLE_OVERLAY_HPP
- #include <mqtt/variant.hpp> // should be top to configure variant limit
- #include <mqtt/namespace.hpp>
- #include <mqtt/attributes.hpp>
- #include <mqtt/endpoint.hpp>
- #include <mqtt/move.hpp>
- namespace MQTT_NS {
- template<typename Impl>
- struct callable_overlay final : public Impl
- {
- using base = Impl;
- using packet_id_t = typename base::packet_id_t;
- template<typename ... Args>
- callable_overlay(Args && ... args)
- : base(std::forward<Args>(args)...)
- { }
- ~callable_overlay() = default;
- callable_overlay(callable_overlay&&) = default;
- callable_overlay(callable_overlay const&) = default;
- callable_overlay& operator=(callable_overlay&&) = default;
- callable_overlay& operator=(callable_overlay const&) = default;
- // MQTT Common handlers
- /**
- * @brief Pingreq handler
- * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718086<BR>
- * 3.13 PINGREQ – PING request
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_pingreq() noexcept override final {
- return ! h_pingreq_ || h_pingreq_();
- }
- /**
- * @brief Pingresp handler
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901200<BR>
- * 3.13 PINGRESP – PING response
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_pingresp() noexcept override final {
- return ! h_pingresp_ || h_pingresp_();
- }
- // MQTT v3_1_1 handlers
- /**
- * @brief Connect handler
- * @param client_id
- * Client Identifier.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349245<BR>
- * 3.1.3.1 Client Identifier
- * @param user_name
- * User Name.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349245<BR>
- * 3.1.3.4 User Name
- * @param password
- * Password.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349246<BR>
- * 3.1.3.5 Password
- * @param will
- * Will. It contains retain, QoS, topic, and message.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349232<BR>
- * 3.1.2.5 Will Flag<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349233<BR>
- * 3.1.2.6 Will QoS<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349234<BR>
- * 3.1.2.7 Will Retain<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349243<BR>
- * 3.1.3.2 Will Topic<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349244<BR>
- * 3.1.3.3 Will Message<BR>
- * @param clean_session
- * Clean Session<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349231<BR>
- * 3.1.2.4 Clean Session
- * @param keep_alive
- * Keep Alive<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349237<BR>
- * 3.1.2.10 Keep Alive
- * @return if the handler returns true, then continue receiving, otherwise quit.
- *
- */
- MQTT_ALWAYS_INLINE bool on_connect(buffer client_id,
- optional<buffer> user_name,
- optional<buffer> password,
- optional<will> will,
- bool clean_session,
- std::uint16_t keep_alive) noexcept override final {
- return ! h_connect_
- || h_connect_(force_move(client_id),
- force_move(user_name),
- force_move(password),
- force_move(will),
- clean_session,
- keep_alive);
- }
- /**
- * @brief Connack handler
- * @param session_present
- * Session present flag.<BR>
- * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036<BR>
- * 3.2.2.2 Session Present
- * @param return_code
- * connect_return_code<BR>
- * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036<BR>
- * 3.2.2.3 Connect Return code
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_connack(bool session_present, connect_return_code return_code) noexcept override final {
- return ! h_connack_
- || h_connack_(session_present, return_code);
- }
- /**
- * @brief Publish handler
- * @param packet_id
- * packet identifier<BR>
- * If received publish's QoS is 0, packet_id is nullopt.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718039<BR>
- * 3.3.2 Variable header
- * @param fixed_header
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718038<BR>
- * 3.3.1 Fixed header<BR>
- * You can check the fixed header using publish functions.
- * @param topic_name
- * Topic name
- * @param contents
- * Published contents
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_publish(optional<packet_id_t> packet_id,
- publish_options pubopts,
- buffer topic_name,
- buffer contents) noexcept override final {
- return ! h_publish_
- || h_publish_(packet_id,
- pubopts,
- force_move(topic_name),
- force_move(contents));
- }
- /**
- * @brief Puback handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045<BR>
- * 3.4.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_puback(packet_id_t packet_id) noexcept override final {
- return ! h_puback_
- || h_puback_(packet_id);
- }
- /**
- * @brief Pubrec handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718050<BR>
- * 3.5.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_pubrec(packet_id_t packet_id) noexcept override final {
- return ! h_pubrec_
- || h_pubrec_(packet_id);
- }
- /**
- * @brief Pubrel handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349791<BR>
- * 3.6.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_pubrel(packet_id_t packet_id) noexcept override final {
- return ! h_pubrel_
- || h_pubrel_(packet_id);
- }
- /**
- * @brief Pubcomp handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718060<BR>
- * 3.7.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_pubcomp(packet_id_t packet_id) noexcept override final {
- return ! h_pubcomp_
- || h_pubcomp_(packet_id);
- }
- /**
- * @brief Subscribe handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349801<BR>
- * 3.8.2 Variable header
- * @param entries
- * Collection of Share Name, Topic Filter, and QoS.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802<BR>
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_subscribe(packet_id_t packet_id,
- std::vector<subscribe_entry> entries) noexcept override final {
- return ! h_subscribe_
- || h_subscribe_(packet_id, force_move(entries));
- }
- /**
- * @brief Suback handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718070<BR>
- * 3.9.2 Variable header
- * @param qoss
- * Collection of QoS that is corresponding to subscribed topic order.<BR>
- * If subscription is failure, the value is nullopt.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071<BR>
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_suback(packet_id_t packet_id,
- std::vector<suback_return_code> reasons) noexcept override final {
- return ! h_suback_
- || h_suback_(packet_id, force_move(reasons));
- }
- /**
- * @brief Unsubscribe handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349810<BR>
- * 3.10.2 Variable header
- * @param topics
- * Collection of Share Name and Topic Filter<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448<BR>
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_unsubscribe(packet_id_t packet_id,
- std::vector<unsubscribe_entry> entries) noexcept override final {
- return ! h_unsubscribe_
- || h_unsubscribe_(packet_id, force_move(entries));
- }
- /**
- * @brief Unsuback handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045<BR>
- * 3.11.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_unsuback(packet_id_t packet_id) noexcept override final {
- return ! h_unsuback_
- || h_unsuback_(packet_id);
- }
- /**
- * @brief Disconnect handler
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800463<BR>
- * 3.14 DISCONNECT – Disconnect notification
- */
- MQTT_ALWAYS_INLINE void on_disconnect() noexcept override final {
- if(h_disconnect_) h_disconnect_();
- }
- // MQTT v5 handlers
- /**
- * @brief Connect handler
- * @param client_id
- * Client Identifier.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901059<BR>
- * 3.1.3.1 Client Identifier
- * @param user_name
- * User Name.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901071<BR>
- * 3.1.3.4 User Name
- * @param password
- * Password.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901072<BR>
- * 3.1.3.5 Password
- * @param will
- * Will. It contains retain, QoS, propertied, topic, and message.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901040<BR>
- * 3.1.2.5 Will Flag<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901041<BR>
- * 3.1.2.6 Will QoS<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901042<BR>
- * 3.1.2.7 Will Retain<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901060<BR>
- * 3.1.3.2 Will Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901069<BR>
- * 3.1.3.3 Will Topic<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901070<BR>
- * 3.1.3.3 Will Payload<BR>
- * @param clean_start
- * Clean Start<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901039<BR>
- * 3.1.2.4 Clean Session
- * @param keep_alive
- * Keep Alive<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901045<BR>
- * 3.1.2.10 Keep Alive
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046<BR>
- * 3.1.2.11 CONNECT Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- *
- */
- MQTT_ALWAYS_INLINE bool on_v5_connect(buffer client_id,
- optional<buffer> user_name,
- optional<buffer> password,
- optional<will> will,
- bool clean_start,
- std::uint16_t keep_alive,
- v5::properties props) noexcept override final {
- return ! h_v5_connect_
- || h_v5_connect_(force_move(client_id),
- force_move(user_name),
- force_move(password),
- force_move(will),
- clean_start,
- keep_alive,
- force_move(props));
- }
- /**
- * @brief Connack handler
- * @param session_present
- * Session present flag.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901078<BR>
- * 3.2.2.1.1 Session Present
- * @param reason_code
- * Connect Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901079<BR>
- * 3.2.2.2 Connect Reason code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080<BR>
- * 3.2.2.3 CONNACK Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_connack(bool session_present,
- v5::connect_reason_code reason_code,
- v5::properties props) noexcept override final {
- return ! h_v5_connack_
- || h_v5_connack_(session_present, reason_code, force_move(props));
- }
- /**
- * @brief Publish handler
- * @param packet_id
- * packet identifier<BR>
- * If received publish's QoS is 0, packet_id is nullopt.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901108<BR>
- * 3.3.2.2 Packet Identifier
- * @param fixed_header
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901101<BR>
- * 3.3.1 Fixed header<BR>
- * You can check the fixed header using publish functions.
- * @param topic_name
- * Topic name<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901107<BR>
- * 3.3.2.1 Topic Name<BR>
- * @param contents
- * Publish Payload<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901119<BR>
- * 3.3.3 PUBLISH Payload
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109<BR>
- * 3.3.2.3 PUBLISH Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_publish(optional<packet_id_t> packet_id,
- publish_options pubopts,
- buffer topic_name,
- buffer contents,
- v5::properties props) noexcept override final {
- return ! h_v5_publish_
- || h_v5_publish_(packet_id,
- pubopts,
- force_move(topic_name),
- force_move(contents),
- force_move(props));
- }
- /**
- * @brief Puback handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901123<BR>
- * 3.4.2 Variable header
- * @param reason_code
- * PUBACK Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901124<BR>
- * 3.4.2.1 PUBACK Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125<BR>
- * 3.4.2.2 PUBACK Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_puback(packet_id_t packet_id,
- v5::puback_reason_code reason_code,
- v5::properties props) noexcept override final {
- return ! h_v5_puback_
- || h_v5_puback_(packet_id, reason_code, force_move(props));
- }
- /**
- * @brief Pubrec handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901133<BR>
- * 3.5.2 Variable header
- * @param reason_code
- * PUBREC Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901134<BR>
- * 3.5.2.1 PUBREC Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135<BR>
- * 3.5.2.2 PUBREC Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_pubrec(packet_id_t packet_id,
- v5::pubrec_reason_code reason_code,
- v5::properties props) noexcept override final {
- return ! h_v5_pubrec_
- || h_v5_pubrec_(packet_id, reason_code, force_move(props));
- }
- /**
- * @brief Pubrel handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901143<BR>
- * 3.6.2 Variable header
- * @param reason_code
- * PUBREL Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901144<BR>
- * 3.6.2.1 PUBREL Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145<BR>
- * 3.6.2.2 PUBREL Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_pubrel(packet_id_t packet_id,
- v5::pubrel_reason_code reason_code,
- v5::properties props) noexcept override final {
- return ! h_v5_pubrel_
- || h_v5_pubrel_(packet_id, reason_code, force_move(props));
- }
- /**
- * @brief Pubcomp handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901153<BR>
- * 3.7.2 Variable header
- * @param reason_code
- * PUBCOMP Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901154<BR>
- * 3.7.2.1 PUBCOMP Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155<BR>
- * 3.7.2.2 PUBCOMP Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_pubcomp(packet_id_t packet_id,
- v5::pubcomp_reason_code reason_code,
- v5::properties props) noexcept override final {
- return ! h_v5_pubcomp_
- || h_v5_pubcomp_(packet_id, reason_code, force_move(props));
- }
- /**
- * @brief Subscribe handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901163<BR>
- * 3.8.2 Variable header
- * @param entries
- * Collection of Share Name, Topic Filter, and QoS.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901168<BR>
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164<BR>
- * 3.8.2.1 SUBSCRIBE Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_subscribe(packet_id_t packet_id,
- std::vector<subscribe_entry> entries,
- v5::properties props) noexcept override final {
- return ! h_v5_subscribe_
- || h_v5_subscribe_(packet_id, force_move(entries), force_move(props));
- }
- /**
- * @brief Suback handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901173<BR>
- * 3.9.2 Variable header
- * @param reasons
- * Collection of reason_code.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901178<BR>
- * 3.9.3 SUBACK Payload
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174<BR>
- * 3.9.2.1 SUBACK Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_suback(packet_id_t packet_id,
- std::vector<v5::suback_reason_code> reasons,
- v5::properties props) noexcept override final {
- return ! h_v5_suback_
- || h_v5_suback_(packet_id, force_move(reasons), force_move(props));
- }
- /**
- * @brief Unsubscribe handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901181<BR>
- * 3.10.2 Variable header
- * @param entries
- * Collection of Share Name and Topic Filter<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901185<BR>
- * 3.10.3 UNSUBSCRIBE Payload
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182<BR>
- * 3.10.2.1 UNSUBSCRIBE Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_unsubscribe(packet_id_t packet_id,
- std::vector<unsubscribe_entry> entries,
- v5::properties props) noexcept override final {
- return ! h_v5_unsubscribe_
- || h_v5_unsubscribe_(packet_id, force_move(entries), force_move(props));
- }
- /**
- * @brief Unsuback handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901189<BR>
- * 3.11.2 Variable header
- * @param reasons
- * Collection of reason_code.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901194<BR>
- * 3.11.3 UNSUBACK Payload
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190<BR>
- * 3.11.2.1 UNSUBACK Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_unsuback(packet_id_t packet_id,
- std::vector<v5::unsuback_reason_code> reasons,
- v5::properties props) noexcept override final {
- return ! h_v5_unsuback_
- || h_v5_unsuback_(packet_id, force_move(reasons), force_move(props));
- }
- /**
- * @brief Disconnect handler
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205<BR>
- * 3.14 DISCONNECT – Disconnect notification
- * @param reason_code
- * DISCONNECT Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901208<BR>
- * 3.14.2.1 Disconnect Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209<BR>
- * 3.14.2.2 DISCONNECT Properties
- */
- MQTT_ALWAYS_INLINE void on_v5_disconnect(v5::disconnect_reason_code reason_code,
- v5::properties props) noexcept override final {
- if (h_v5_disconnect_) h_v5_disconnect_(reason_code, force_move(props));
- }
- /**
- * @brief Auth handler
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901217<BR>
- * 3.15 AUTH – Authentication exchange
- * @param reason_code
- * AUTH Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901220<BR>
- * 3.15.2.1 Authenticate Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221<BR>
- * 3.15.2.2 AUTH Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- MQTT_ALWAYS_INLINE bool on_v5_auth(v5::auth_reason_code reason_code,
- v5::properties props) noexcept override final {
- return ! h_v5_auth_
- || h_v5_auth_(reason_code, force_move(props));
- }
- // Original handlers
- /**
- * @brief Close handler
- *
- * This handler is called if the client called `disconnect()` and the server closed the socket cleanly.
- * If the socket is closed by other reasons, error_handler is called.
- * This calls base::on_close() prior to calling the provided callback, if any.
- */
- MQTT_ALWAYS_INLINE void on_close() noexcept override final {
- base::on_close();
- if (h_close_) h_close_();
- }
- /**
- * @brief Error handler
- *
- * This handler is called if the socket is closed without client's `disconnect()` call.
- * This calls base::on_error() prior to calling the provided callback, if any.
- *
- * @param ec error code
- */
- MQTT_ALWAYS_INLINE void on_error(error_code ec) noexcept override final {
- base::on_error(ec);
- if (h_error_) h_error_(ec);
- }
- /**
- * @brief Publish response sent handler
- * This function is called just after puback sent on QoS1, or pubcomp sent on QoS2.
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901026<BR>
- * 2.2.1 Packet Identifier
- */
- MQTT_ALWAYS_INLINE void on_pub_res_sent(packet_id_t packet_id) noexcept override final {
- if (h_pub_res_sent_) h_pub_res_sent_(packet_id);
- }
- /**
- * @brief Serialize publish handler
- * You can serialize the publish message.
- * To restore the message, use restore_serialized_message().
- * @param msg publish message
- */
- MQTT_ALWAYS_INLINE void on_serialize_publish_message(basic_publish_message<sizeof(packet_id_t)> msg) noexcept override final {
- if (h_serialize_publish_) h_serialize_publish_(msg);
- }
- /**
- * @brief Serialize publish handler
- * You can serialize the publish message.
- * To restore the message, use restore_serialized_message().
- * @param msg v5::publish message
- */
- MQTT_ALWAYS_INLINE void on_serialize_v5_publish_message(v5::basic_publish_message<sizeof(packet_id_t)> msg) noexcept override final {
- if (h_serialize_v5_publish_) h_serialize_v5_publish_(msg);
- }
- /**
- * @brief Serialize pubrel handler
- * You can serialize the pubrel message.
- * If your storage has already had the publish message that has the same packet_id,
- * then you need to replace the publish message to pubrel message.
- * To restore the message, use restore_serialized_message().
- * @param msg pubrel message
- */
- MQTT_ALWAYS_INLINE void on_serialize_pubrel_message(basic_pubrel_message<sizeof(packet_id_t)> msg) noexcept override final {
- if (h_serialize_pubrel_) h_serialize_pubrel_(msg);
- }
- /**
- * @brief Serialize pubrel handler
- * You can serialize the pubrel message.
- * If your storage has already had the publish message that has the same packet_id,
- * then you need to replace the publish message to pubrel message.
- * To restore the message, use restore_serialized_message().
- * @param msg pubrel message
- */
- MQTT_ALWAYS_INLINE void on_serialize_v5_pubrel_message(v5::basic_pubrel_message<sizeof(packet_id_t)> msg) noexcept override final {
- if (h_serialize_v5_pubrel_) h_serialize_v5_pubrel_(msg);
- }
- /**
- * @brief Remove serialized message
- * @param packet_id packet identifier of the removing message
- */
- MQTT_ALWAYS_INLINE void on_serialize_remove(packet_id_t packet_id) noexcept override final {
- if (h_serialize_remove_) h_serialize_remove_(packet_id);
- }
- /**
- * @brief Pre-send handler
- * This handler is called when any mqtt control packet is decided to send.
- */
- MQTT_ALWAYS_INLINE void on_pre_send() noexcept override final {
- base::on_pre_send();
- if (h_pre_send_) h_pre_send_();
- }
- /**
- * @brief is valid length handler
- * This handler is called when remaining length is received.
- * @param control_packet_type control_packet_type that has variable length
- * @param remaining length
- * @return true if check is success, otherwise false
- */
- MQTT_ALWAYS_INLINE bool check_is_valid_length(control_packet_type packet_type, std::size_t remaining_length) noexcept override final {
- return ! h_is_valid_length_
- || h_is_valid_length_(packet_type, remaining_length);
- }
- /**
- * @brief next read handler
- * This handler is called when the current mqtt message has been processed.
- * This calls base::on_mqtt_message_processed() only if mqtt_message_processed handler is not set.
- * * `client` inherits `endpoint` and override `on_pre_send()`, `on_close()`, and `on_error()`.
- * And implement important process *1 in the override definition (timer reset, timer cancel).
- * * `client` has `set_pre_send_handler()`, `set_on_close()`, and `set_on_error()`.
- * If a user of `client` call them, and the event happens, set handler should be called.
- * Either the user set handlers or not, *1 should be executed automatically.
- * * `endpoint` has the default definition of `on_mqtt_message_processed()`.
- * `client` doesn't override `on_mqtt_message_processed()`.
- * If a user override this, then the default definition shouldn't be called. It makes conflict behavior.
- * * Other `on_*()` doesn't have the default definition. `callable_overlay` calls the corresponding
- * handler only if it is set.
- * @param func A callback function that is called when async operation will finish.
- */
- MQTT_ALWAYS_INLINE void on_mqtt_message_processed(any session_life_keeper) noexcept override final {
- if(h_mqtt_message_processed_) {
- h_mqtt_message_processed_(force_move(session_life_keeper));
- }
- else {
- base::on_mqtt_message_processed(force_move(session_life_keeper));
- }
- }
- /**
- * @brief Pingreq handler
- * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718086<BR>
- * 3.13 PINGREQ – PING request
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using pingreq_handler = std::function<bool()>;
- /**
- * @brief Pingresp handler
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901200<BR>
- * 3.13 PINGRESP – PING response
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using pingresp_handler = std::function<bool()>;
- // MQTT v3_1_1 handlers
- /**
- * @brief Connect handler
- * @param client_id
- * Client Identifier.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349245<BR>
- * 3.1.3.1 Client Identifier
- * @param user_name
- * User Name.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349245<BR>
- * 3.1.3.4 User Name
- * @param password
- * Password.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349246<BR>
- * 3.1.3.5 Password
- * @param will
- * Will. It contains retain, QoS, topic, and message.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349232<BR>
- * 3.1.2.5 Will Flag<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349233<BR>
- * 3.1.2.6 Will QoS<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349234<BR>
- * 3.1.2.7 Will Retain<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349243<BR>
- * 3.1.3.2 Will Topic<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349244<BR>
- * 3.1.3.3 Will Message<BR>
- * @param clean_session
- * Clean Session<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349231<BR>
- * 3.1.2.4 Clean Session
- * @param keep_alive
- * Keep Alive<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349237<BR>
- * 3.1.2.10 Keep Alive
- * @return if the handler returns true, then continue receiving, otherwise quit.
- *
- */
- using connect_handler = std::function<
- bool(buffer client_id,
- optional<buffer> user_name,
- optional<buffer> password,
- optional<will> will,
- bool clean_session,
- std::uint16_t keep_alive)>;
- /**
- * @brief Connack handler
- * @param session_present
- * Session present flag.<BR>
- * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036<BR>
- * 3.2.2.2 Session Present
- * @param return_code
- * connect_return_code<BR>
- * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036<BR>
- * 3.2.2.3 Connect Return code
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using connack_handler = std::function<bool(bool session_present, connect_return_code return_code)>;
- /**
- * @brief Publish handler
- * @param fixed_header
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718038<BR>
- * 3.3.1 Fixed header<BR>
- * You can check the fixed header using publish functions.
- * @param packet_id
- * packet identifier<BR>
- * If received publish's QoS is 0, packet_id is nullopt.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718039<BR>
- * 3.3.2 Variable header
- * @param topic_name
- * Topic name
- * @param contents
- * Published contents
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using publish_handler = std::function<bool(optional<packet_id_t> packet_id,
- publish_options pubopts,
- buffer topic_name,
- buffer contents)>;
- /**
- * @brief Puback handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045<BR>
- * 3.4.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using puback_handler = std::function<bool(packet_id_t packet_id)>;
- /**
- * @brief Pubrec handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718050<BR>
- * 3.5.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using pubrec_handler = std::function<bool(packet_id_t packet_id)>;
- /**
- * @brief Pubrel handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349791<BR>
- * 3.6.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using pubrel_handler = std::function<bool(packet_id_t packet_id)>;
- /**
- * @brief Pubcomp handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718060<BR>
- * 3.7.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using pubcomp_handler = std::function<bool(packet_id_t packet_id)>;
- /**
- * @brief Subscribe handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349801<BR>
- * 3.8.2 Variable header
- * @param entries
- * Collection of Share Name, Topic Filter, and QoS.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802<BR>
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using subscribe_handler = std::function<bool(packet_id_t packet_id,
- std::vector<subscribe_entry> entries)>;
- /**
- * @brief Suback handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718070<BR>
- * 3.9.2 Variable header
- * @param qoss
- * Collection of QoS that is corresponding to subscribed topic order.<BR>
- * If subscription is failure, the value is nullopt.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071<BR>
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using suback_handler = std::function<bool(packet_id_t packet_id,
- std::vector<suback_return_code> qoss)>;
- /**
- * @brief Unsubscribe handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349810<BR>
- * 3.10.2 Variable header
- * @param entries
- * Collection of Share Name and Topic Filter<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448<BR>
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using unsubscribe_handler = std::function<bool(packet_id_t packet_id,
- std::vector<unsubscribe_entry> entries)>;
- /**
- * @brief Unsuback handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045<BR>
- * 3.11.2 Variable header
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using unsuback_handler = std::function<bool(packet_id_t)>;
- /**
- * @brief Disconnect handler
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800463<BR>
- * 3.14 DISCONNECT – Disconnect notification
- */
- using disconnect_handler = std::function<void()>;
- // MQTT v5 handlers
- /**
- * @brief Connect handler
- * @param client_id
- * Client Identifier.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901059<BR>
- * 3.1.3.1 Client Identifier
- * @param user_name
- * User Name.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901071<BR>
- * 3.1.3.4 User Name
- * @param password
- * Password.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901072<BR>
- * 3.1.3.5 Password
- * @param will
- * Will. It contains retain, QoS, propertied, topic, and message.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901040<BR>
- * 3.1.2.5 Will Flag<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901041<BR>
- * 3.1.2.6 Will QoS<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901042<BR>
- * 3.1.2.7 Will Retain<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901060<BR>
- * 3.1.3.2 Will Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901069<BR>
- * 3.1.3.3 Will Topic<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901070<BR>
- * 3.1.3.3 Will Payload<BR>
- * @param clean_start
- * Clean Start<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901039<BR>
- * 3.1.2.4 Clean Session
- * @param keep_alive
- * Keep Alive<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901045<BR>
- * 3.1.2.10 Keep Alive
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046<BR>
- * 3.1.2.11 CONNECT Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- *
- */
- using v5_connect_handler = std::function<
- bool(buffer client_id,
- optional<buffer> user_name,
- optional<buffer> password,
- optional<will> will,
- bool clean_start,
- std::uint16_t keep_alive,
- v5::properties props)
- >;
- /**
- * @brief Connack handler
- * @param session_present
- * Session present flag.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901078<BR>
- * 3.2.2.1.1 Session Present
- * @param reason_code
- * Connect Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901079<BR>
- * 3.2.2.2 Connect Reason code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080<BR>
- * 3.2.2.3 CONNACK Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_connack_handler = std::function<
- bool(bool session_present,
- v5::connect_reason_code reason_code,
- v5::properties props)
- >;
- /**
- * @brief Publish handler
- * @param packet_id
- * packet identifier<BR>
- * If received publish's QoS is 0, packet_id is nullopt.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901108<BR>
- * 3.3.2.2 Packet Identifier
- * @param fixed_header
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901101<BR>
- * 3.3.1 Fixed header<BR>
- * You can check the fixed header using publish functions.
- * @param topic_name
- * Topic name<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901107<BR>
- * 3.3.2.1 Topic Name<BR>
- * @param contents
- * Publish Payload<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901119<BR>
- * 3.3.3 PUBLISH Payload
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109<BR>
- * 3.3.2.3 PUBLISH Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_publish_handler = std::function<
- bool(optional<packet_id_t> packet_id,
- publish_options pubopts,
- buffer topic_name,
- buffer contents,
- v5::properties props)
- >;
- /**
- * @brief Puback handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901123<BR>
- * 3.4.2 Variable header
- * @param reason_code
- * PUBACK Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901124<BR>
- * 3.4.2.1 PUBACK Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125<BR>
- * 3.4.2.2 PUBACK Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_puback_handler = std::function<
- bool(packet_id_t packet_id,
- v5::puback_reason_code reason_code,
- v5::properties props)
- >;
- /**
- * @brief Pubrec handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901133<BR>
- * 3.5.2 Variable header
- * @param reason_code
- * PUBREC Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901134<BR>
- * 3.5.2.1 PUBREC Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135<BR>
- * 3.5.2.2 PUBREC Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_pubrec_handler = std::function<
- bool(packet_id_t packet_id,
- v5::pubrec_reason_code reason_code,
- v5::properties props)
- >;
- /**
- * @brief Pubrel handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901143<BR>
- * 3.6.2 Variable header
- * @param reason_code
- * PUBREL Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901144<BR>
- * 3.6.2.1 PUBREL Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145<BR>
- * 3.6.2.2 PUBREL Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_pubrel_handler = std::function<
- bool(packet_id_t packet_id,
- v5::pubrel_reason_code reason_code,
- v5::properties props)
- >;
- /**
- * @brief Pubcomp handler
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901153<BR>
- * 3.7.2 Variable header
- * @param reason_code
- * PUBCOMP Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901154<BR>
- * 3.7.2.1 PUBCOMP Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155<BR>
- * 3.7.2.2 PUBCOMP Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_pubcomp_handler = std::function<
- bool(packet_id_t packet_id,
- v5::pubcomp_reason_code reason_code,
- v5::properties props)
- >;
- /**
- * @brief Subscribe handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901163<BR>
- * 3.8.2 Variable header
- * @param entries
- * Collection of Share Name, Topic Filter, and Subscribe Options.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901168<BR>
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164<BR>
- * 3.8.2.1 SUBSCRIBE Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_subscribe_handler = std::function<
- bool(packet_id_t packet_id,
- std::vector<subscribe_entry> entries,
- v5::properties props)
- >;
- /**
- * @brief Suback handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901173<BR>
- * 3.9.2 Variable header
- * @param reasons
- * Collection of reason_code.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901178<BR>
- * 3.9.3 SUBACK Payload
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174<BR>
- * 3.9.2.1 SUBACK Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_suback_handler = std::function<
- bool(packet_id_t packet_id,
- std::vector<v5::suback_reason_code> reasons,
- v5::properties props)
- >;
- /**
- * @brief Unsubscribe handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901181<BR>
- * 3.10.2 Variable header
- * @param entries
- * Collection of Share Name and Topic Filter<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901185<BR>
- * 3.10.3 UNSUBSCRIBE Payload
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182<BR>
- * 3.10.2.1 UNSUBSCRIBE Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_unsubscribe_handler = std::function<
- bool(packet_id_t packet_id,
- std::vector<unsubscribe_entry> entries,
- v5::properties props)
- >;
- /**
- * @brief Unsuback handler
- * @param packet_id packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901189<BR>
- * 3.11.2 Variable header
- * @param reasons
- * Collection of reason_code.<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901194<BR>
- * 3.11.3 UNSUBACK Payload
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190<BR>
- * 3.11.2.1 UNSUBACK Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_unsuback_handler = std::function<
- bool(packet_id_t,
- std::vector<v5::unsuback_reason_code> reasons,
- v5::properties props)
- >;
- /**
- * @brief Disconnect handler
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205<BR>
- * 3.14 DISCONNECT – Disconnect notification
- * @param reason_code
- * DISCONNECT Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901208<BR>
- * 3.14.2.1 Disconnect Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209<BR>
- * 3.14.2.2 DISCONNECT Properties
- */
- using v5_disconnect_handler = std::function<
- void(v5::disconnect_reason_code reason_code,
- v5::properties props)
- >;
- /**
- * @brief Auth handler
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901217<BR>
- * 3.15 AUTH – Authentication exchange
- * @param reason_code
- * AUTH Reason Code<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901220<BR>
- * 3.15.2.1 Authenticate Reason Code
- * @param props
- * Properties<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221<BR>
- * 3.15.2.2 AUTH Properties
- * @return if the handler returns true, then continue receiving, otherwise quit.
- */
- using v5_auth_handler = std::function<
- bool(v5::auth_reason_code reason_code,
- v5::properties props)
- >;
- // Original handlers
- /**
- * @brief Close handler
- *
- * This handler is called if the client called `disconnect()` and the server closed the socket cleanly.
- * If the socket is closed by other reasons, error_handler is called.
- */
- using close_handler = std::function<void()>;
- /**
- * @brief Error handler
- *
- * This handler is called if the socket is closed without client's `disconnect()` call.
- *
- * @param ec error code
- */
- using error_handler = std::function<void(error_code ec)>;
- /**
- * @brief Publish response sent handler
- * This function is called just after puback sent on QoS1, or pubcomp sent on QoS2.
- * @param packet_id
- * packet identifier<BR>
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901026<BR>
- * 2.2.1 Packet Identifier
- */
- using pub_res_sent_handler = std::function<void(packet_id_t packet_id)>;
- /**
- * @brief Serialize publish handler
- * You can serialize the publish message.
- * To restore the message, use restore_serialized_message().
- * @param msg publish message
- */
- using serialize_publish_message_handler = std::function<void(basic_publish_message<sizeof(packet_id_t)> msg)>;
- /**
- * @brief Serialize publish handler
- * You can serialize the publish message.
- * To restore the message, use restore_serialized_message().
- * @param msg v5::publish message
- */
- using serialize_v5_publish_message_handler = std::function<void(v5::basic_publish_message<sizeof(packet_id_t)> msg)>;
- /**
- * @brief Serialize publish handler
- * You can serialize the publish message.
- * To restore the message, use restore_serialized_message().
- * @param packet_id packet identifier of the serializing message
- * @param data pointer to the serializing message
- * @param size size of the serializing message
- */
- using serialize_publish_handler = std::function<void(packet_id_t packet_id, char const* data, std::size_t size)>;
- /**
- * @brief Serialize pubrel handler
- * You can serialize the pubrel message.
- * If your storage has already had the publish message that has the same packet_id,
- * then you need to replace the publish message to pubrel message.
- * To restore the message, use restore_serialized_message().
- * @param msg pubrel message
- */
- using serialize_pubrel_message_handler = std::function<void(basic_pubrel_message<sizeof(packet_id_t)> msg)>;
- /**
- * @brief Serialize pubrel handler
- * You can serialize the pubrel message.
- * If your storage has already had the publish message that has the same packet_id,
- * then you need to replace the publish message to pubrel message.
- * To restore the message, use restore_serialized_message().
- * @param msg pubrel message
- */
- using serialize_v5_pubrel_message_handler = std::function<void(v5::basic_pubrel_message<sizeof(packet_id_t)> msg)>;
- /**
- * @brief Serialize pubrel handler
- * You can serialize the pubrel message.
- * If your storage has already had the publish message that has the same packet_id,
- * then you need to replace the publish message to pubrel message.
- * To restore the message, use restore_serialized_message().
- * @param packet_id packet identifier of the serializing message
- * @param data pointer to the serializing message
- * @param size size of the serializing message
- */
- using serialize_pubrel_handler = std::function<void(packet_id_t packet_id, char const* data, std::size_t size)>;
- /**
- * @brief Remove serialized message
- * @param packet_id packet identifier of the removing message
- */
- using serialize_remove_handler = std::function<void(packet_id_t packet_id)>;
- /**
- * @brief Pre-send handler
- * This handler is called when any mqtt control packet is decided to send.
- */
- using pre_send_handler = std::function<void()>;
- /**
- * @brief is valid length handler
- * This handler is called when remaining length is received.
- * @param control_packet_type control_packet_type that has variable length
- * @param remaining length
- * @return true if check is success, otherwise false
- */
- using is_valid_length_handler =
- std::function<bool(control_packet_type packet_type, std::size_t remaining_length)>;
- /**
- * @brief next read handler
- * This handler is called when the current mqtt message has been processed.
- * @param func A callback function that is called when async operation will finish.
- */
- using mqtt_message_processed_handler =
- std::function<void(any session_life_keeper)>;
- // MQTT Common handlers
- /**
- * @brief Set pingreq handler
- * @param h handler
- */
- void set_pingreq_handler(pingreq_handler h = pingreq_handler()) {
- h_pingreq_ = force_move(h);
- }
- /**
- * @brief Set pingresp handler
- * @param h handler
- */
- void set_pingresp_handler(pingresp_handler h = pingresp_handler()) {
- h_pingresp_ = force_move(h);
- }
- /**
- * @brief Get pingreq handler
- * @return handler
- */
- pingreq_handler const& get_pingreq_handler() const {
- return h_pingreq_;
- }
- /**
- * @brief Get pingresp handler
- * @return handler
- */
- pingresp_handler const& get_pingresp_handler() const {
- return h_pingresp_;
- }
- // MQTT v3_1_1 handlers
- /**
- * @brief Set connect handler
- * @param h handler
- */
- void set_connect_handler(connect_handler h = connect_handler()) {
- h_connect_ = force_move(h);
- }
- /**
- * @brief Set connack handler
- * @param h handler
- */
- void set_connack_handler(connack_handler h = connack_handler()) {
- h_connack_ = force_move(h);
- }
- /**
- * @brief Set publish handler
- * @param h handler
- */
- void set_publish_handler(publish_handler h = publish_handler()) {
- h_publish_ = force_move(h);
- }
- /**
- * @brief Set puback handler
- * @param h handler
- */
- void set_puback_handler(puback_handler h = puback_handler()) {
- h_puback_ = force_move(h);
- }
- /**
- * @brief Set pubrec handler
- * @param h handler
- */
- void set_pubrec_handler(pubrec_handler h = pubrec_handler()) {
- h_pubrec_ = force_move(h);
- }
- /**
- * @brief Set pubrel handler
- * @param h handler
- */
- void set_pubrel_handler(pubrel_handler h = pubrel_handler()) {
- h_pubrel_ = force_move(h);
- }
- /**
- * @brief Set pubcomp handler
- * @param h handler
- */
- void set_pubcomp_handler(pubcomp_handler h = pubcomp_handler()) {
- h_pubcomp_ = force_move(h);
- }
- /**
- * @brief Set subscribe handler
- * @param h handler
- */
- void set_subscribe_handler(subscribe_handler h = subscribe_handler()) {
- h_subscribe_ = force_move(h);
- }
- /**
- * @brief Set suback handler
- * @param h handler
- */
- void set_suback_handler(suback_handler h = suback_handler()) {
- h_suback_ = force_move(h);
- }
- /**
- * @brief Set unsubscribe handler
- * @param h handler
- */
- void set_unsubscribe_handler(unsubscribe_handler h = unsubscribe_handler()) {
- h_unsubscribe_ = force_move(h);
- }
- /**
- * @brief Set unsuback handler
- * @param h handler
- */
- void set_unsuback_handler(unsuback_handler h = unsuback_handler()) {
- h_unsuback_ = force_move(h);
- }
- /**
- * @brief Set disconnect handler
- * @param h handler
- */
- void set_disconnect_handler(disconnect_handler h = disconnect_handler()) {
- h_disconnect_ = force_move(h);
- }
- /**
- * @brief Get connect handler
- * @return handler
- */
- connect_handler const& get_connect_handler() const {
- return h_connect_;
- }
- /**
- * @brief Get connack handler
- * @return handler
- */
- connack_handler const& get_connack_handler() const {
- return h_connack_;
- }
- /**
- * @brief Set publish handler
- * @return handler
- */
- publish_handler const& get_publish_handler() const {
- return h_publish_;
- }
- /**
- * @brief Get puback handler
- * @return handler
- */
- puback_handler const& get_puback_handler() const {
- return h_puback_;
- }
- /**
- * @brief Get pubrec handler
- * @return handler
- */
- pubrec_handler const& get_pubrec_handler() const {
- return h_pubrec_;
- }
- /**
- * @brief Get pubrel handler
- * @return handler
- */
- pubrel_handler const& get_pubrel_handler() const {
- return h_pubrel_;
- }
- /**
- * @brief Get pubcomp handler
- * @return handler
- */
- pubcomp_handler const& get_pubcomp_handler() const {
- return h_pubcomp_;
- }
- /**
- * @brief Get subscribe handler
- * @return handler
- */
- subscribe_handler const& get_subscribe_handler() const {
- return h_subscribe_;
- }
- /**
- * @brief Get suback handler
- * @return handler
- */
- suback_handler const& get_suback_handler() const {
- return h_suback_;
- }
- /**
- * @brief Get unsubscribe handler
- * @return handler
- */
- unsubscribe_handler const& get_unsubscribe_handler() const {
- return h_unsubscribe_;
- }
- /**
- * @brief Get unsuback handler
- * @return handler
- */
- unsuback_handler const& get_unsuback_handler() const {
- return h_unsuback_;
- }
- /**
- * @brief Get disconnect handler
- * @return handler
- */
- disconnect_handler const& get_disconnect_handler() const {
- return h_disconnect_;
- }
- // MQTT v5 handlers
- /**
- * @brief Set connect handler
- * @param h handler
- */
- void set_v5_connect_handler(v5_connect_handler h = v5_connect_handler()) {
- h_v5_connect_ = force_move(h);
- }
- /**
- * @brief Set connack handler
- * @param h handler
- */
- void set_v5_connack_handler(v5_connack_handler h = v5_connack_handler()) {
- h_v5_connack_ = force_move(h);
- }
- /**
- * @brief Set publish handler
- * @param h handler
- */
- void set_v5_publish_handler(v5_publish_handler h = v5_publish_handler()) {
- h_v5_publish_ = force_move(h);
- }
- /**
- * @brief Set puback handler
- * @param h handler
- */
- void set_v5_puback_handler(v5_puback_handler h = v5_puback_handler()) {
- h_v5_puback_ = force_move(h);
- }
- /**
- * @brief Set pubrec handler
- * @param h handler
- */
- void set_v5_pubrec_handler(v5_pubrec_handler h = v5_pubrec_handler()) {
- h_v5_pubrec_ = force_move(h);
- }
- /**
- * @brief Set pubrel handler
- * @param h handler
- */
- void set_v5_pubrel_handler(v5_pubrel_handler h = v5_pubrel_handler()) {
- h_v5_pubrel_ = force_move(h);
- }
- /**
- * @brief Set pubcomp handler
- * @param h handler
- */
- void set_v5_pubcomp_handler(v5_pubcomp_handler h = v5_pubcomp_handler()) {
- h_v5_pubcomp_ = force_move(h);
- }
- /**
- * @brief Set subscribe handler
- * @param h handler
- */
- void set_v5_subscribe_handler(v5_subscribe_handler h = v5_subscribe_handler()) {
- h_v5_subscribe_ = force_move(h);
- }
- /**
- * @brief Set suback handler
- * @param h handler
- */
- void set_v5_suback_handler(v5_suback_handler h = v5_suback_handler()) {
- h_v5_suback_ = force_move(h);
- }
- /**
- * @brief Set unsubscribe handler
- * @param h handler
- */
- void set_v5_unsubscribe_handler(v5_unsubscribe_handler h = v5_unsubscribe_handler()) {
- h_v5_unsubscribe_ = force_move(h);
- }
- /**
- * @brief Set unsuback handler
- * @param h handler
- */
- void set_v5_unsuback_handler(v5_unsuback_handler h = v5_unsuback_handler()) {
- h_v5_unsuback_ = force_move(h);
- }
- /**
- * @brief Set disconnect handler
- * @param h handler
- */
- void set_v5_disconnect_handler(v5_disconnect_handler h = v5_disconnect_handler()) {
- h_v5_disconnect_ = force_move(h);
- }
- /**
- * @brief Set auth handler
- * @param h handler
- */
- void set_v5_auth_handler(v5_auth_handler h = v5_auth_handler()) {
- h_v5_auth_ = force_move(h);
- }
- /**
- * @brief Get connect handler
- * @return handler
- */
- v5_connect_handler const& get_v5_connect_handler() const {
- return h_v5_connect_;
- }
- /**
- * @brief Get connack handler
- * @return handler
- */
- v5_connack_handler const& get_v5_connack_handler() const {
- return h_v5_connack_;
- }
- /**
- * @brief Set publish handler
- * @return handler
- */
- v5_publish_handler const& get_v5_publish_handler() const {
- return h_v5_publish_;
- }
- /**
- * @brief Get puback handler
- * @return handler
- */
- v5_puback_handler const& get_v5_puback_handler() const {
- return h_v5_puback_;
- }
- /**
- * @brief Get pubrec handler
- * @return handler
- */
- v5_pubrec_handler const& get_v5__handler() const {
- return h_v5_pubrec_;
- }
- /**
- * @brief Get pubrel handler
- * @return handler
- */
- v5_pubrel_handler const& get_v5_pubrel_handler() const {
- return h_v5_pubrel_;
- }
- /**
- * @brief Get pubcomp handler
- * @return handler
- */
- v5_pubcomp_handler const& get_v5_pubcomp_handler() const {
- return h_v5_pubcomp_;
- }
- /**
- * @brief Get subscribe handler
- * @return handler
- */
- v5_subscribe_handler const& get_v5_subscribe_handler() const {
- return h_v5_subscribe_;
- }
- /**
- * @brief Get suback handler
- * @return handler
- */
- v5_suback_handler const& get_v5_suback_handler() const {
- return h_v5_suback_;
- }
- /**
- * @brief Get unsubscribe handler
- * @return handler
- */
- v5_unsubscribe_handler const& get_v5_unsubscribe_handler() const {
- return h_v5_unsubscribe_;
- }
- /**
- * @brief Get unsuback handler
- * @return handler
- */
- v5_unsuback_handler const& get_v5_unsuback_handler() const {
- return h_v5_unsuback_;
- }
- /**
- * @brief Get disconnect handler
- * @return handler
- */
- v5_disconnect_handler const& get_v5_disconnect_handler() const {
- return h_v5_disconnect_;
- }
- /**
- * @brief Get auth handler
- * @return handler
- */
- v5_auth_handler const& get_v5_auth_handler() const {
- return h_v5_auth_;
- }
- // Original handlers
- /**
- * @brief Set pubcomp handler
- * @param h handler
- */
- void set_pub_res_sent_handler(pub_res_sent_handler h = pub_res_sent_handler()) {
- h_pub_res_sent_ = force_move(h);
- }
- /**
- * @brief Set serialize handlers
- * @param h_publish serialize handler for publish message
- * @param h_pubrel serialize handler for pubrel message
- * @param h_remove remove handler for serialized message
- */
- void set_serialize_handlers(
- serialize_publish_message_handler h_publish,
- serialize_pubrel_message_handler h_pubrel,
- serialize_remove_handler h_remove) {
- h_serialize_publish_ = force_move(h_publish);
- h_serialize_pubrel_ = force_move(h_pubrel);
- h_serialize_remove_ = force_move(h_remove);
- }
- /**
- * @brief Set serialize handlers
- * @param h_publish serialize handler for publish message
- * @param h_pubrel serialize handler for pubrel message
- * @param h_remove remove handler for serialized message
- */
- void set_v5_serialize_handlers(
- serialize_v5_publish_message_handler h_publish,
- serialize_v5_pubrel_message_handler h_pubrel,
- serialize_remove_handler h_remove) {
- h_serialize_v5_publish_ = force_move(h_publish);
- h_serialize_v5_pubrel_ = force_move(h_pubrel);
- h_serialize_remove_ = force_move(h_remove);
- }
- /**
- * @brief Set serialize handlers
- * @param h_publish serialize handler for publish message
- * @param h_pubrel serialize handler for pubrel message
- * @param h_remove remove handler for serialized message
- */
- void set_serialize_handlers(
- serialize_publish_handler h_publish,
- serialize_pubrel_handler h_pubrel,
- serialize_remove_handler h_remove) {
- h_serialize_publish_ =
- [h_publish = force_move(h_publish)]
- (basic_publish_message<sizeof(packet_id_t)> msg) {
- if (h_publish) {
- auto buf = msg.continuous_buffer();
- h_publish(msg.packet_id(), buf.data(), buf.size());
- }
- };
- h_serialize_pubrel_ =
- [h_pubrel = force_move(h_pubrel)]
- (basic_pubrel_message<sizeof(packet_id_t)> msg) {
- if (h_pubrel) {
- auto buf = msg.continuous_buffer();
- h_pubrel(msg.packet_id(), buf.data(), buf.size());
- }
- };
- h_serialize_remove_ = force_move(h_remove);
- }
- /**
- * @brief Set serialize handlers
- * @param h_publish serialize handler for publish message
- * @param h_pubrel serialize handler for pubrel message
- * @param h_remove remove handler for serialized message
- */
- void set_v5_serialize_handlers(
- serialize_publish_handler h_publish,
- serialize_pubrel_handler h_pubrel,
- serialize_remove_handler h_remove) {
- h_serialize_v5_publish_ =
- [h_publish = force_move(h_publish)]
- (v5::basic_publish_message<sizeof(packet_id_t)> msg) {
- if (h_publish) {
- auto buf = msg.continuous_buffer();
- h_publish(msg.packet_id(), buf.data(), buf.size());
- }
- };
- h_serialize_v5_pubrel_ =
- [h_pubrel = force_move(h_pubrel)]
- (v5::basic_pubrel_message<sizeof(packet_id_t)> msg) {
- if (h_pubrel) {
- auto buf = msg.continuous_buffer();
- h_pubrel(msg.packet_id(), buf.data(), buf.size());
- }
- };
- h_serialize_remove_ = force_move(h_remove);
- }
- /**
- * @brief Clear serialize handlers
- */
- void set_serialize_handlers() {
- h_serialize_publish_ = serialize_publish_message_handler();
- h_serialize_pubrel_ = serialize_pubrel_message_handler();
- h_serialize_v5_publish_ = serialize_v5_publish_message_handler();
- h_serialize_v5_pubrel_ = serialize_v5_pubrel_message_handler();
- h_serialize_remove_ = serialize_remove_handler();
- }
- /**
- * @brief Set pre-send handler
- * @param h handler
- */
- void set_pre_send_handler(pre_send_handler h = pre_send_handler()) {
- h_pre_send_ = force_move(h);
- }
- /**
- * @brief Set check length handler
- * @param h handler
- */
- void set_is_valid_length_handler(is_valid_length_handler h = is_valid_length_handler()) {
- h_is_valid_length_ = force_move(h);
- }
- /**
- * @brief Get publish response sent handler
- * @return handler
- */
- pub_res_sent_handler const& get_pub_res_sent_handler() const {
- return h_pub_res_sent_;
- }
- /**
- * @brief Get serialize publish handler
- * @return handler
- */
- serialize_publish_message_handler const& get_serialize_publish_message_handler() const {
- return h_serialize_publish_;
- }
- /**
- * @brief Get serialize pubrel handler
- * @return handler
- */
- serialize_pubrel_message_handler const& get_serialize_pubrel_message_handler() const {
- return h_serialize_pubrel_;
- }
- /**
- * @brief Get serialize publish handler
- * @return handler
- */
- serialize_v5_publish_message_handler const& get_serialize_v5_publish_message_handler() const {
- return h_serialize_v5_publish_;
- }
- /**
- * @brief Get serialize pubrel handler
- * @return handler
- */
- serialize_v5_pubrel_message_handler const& get_serialize_v5_pubrel_message_handler() const {
- return h_serialize_v5_pubrel_;
- }
- /**
- * @brief Get serialize remove handler
- * @return handler
- */
- serialize_remove_handler const& get_serialize_remove_handler() const {
- return h_serialize_remove_;
- }
- /**
- * @brief Get pre-send handler
- * @return handler
- */
- pre_send_handler const& get_pre_send_handler() const {
- return h_pre_send_;
- }
- /**
- * @brief Get check length handler
- * @return handler
- */
- is_valid_length_handler const& get_is_valid_length_handler() const {
- return h_is_valid_length_;
- }
- /**
- * @brief Set custom mqtt_message_processed_handler.
- * The default setting is calling async_read_control_packet_type().
- * (See endpoint() constructor).
- * The typical usecase of this function is delaying the next
- * message reading timing.
- * In order to do that
- * 1) store func parameter of the mqtt_message_processed_handler.
- * 2) call async_read_next_message with the stored func if
- * you are ready to read the next mqtt message.
- * @param h mqtt_message_processed_handler.
- */
- void set_mqtt_message_processed_handler(
- mqtt_message_processed_handler h = mqtt_message_processed_handler()) {
- if (h) {
- h_mqtt_message_processed_ = force_move(h);
- }
- else {
- h_mqtt_message_processed_ = {};
- }
- }
- /**
- * @brief Get mqtt_message_processed_handler.
- * @return mqtt_message_processed_handler.
- */
- mqtt_message_processed_handler get_mqtt_message_processed_handler() const {
- return h_mqtt_message_processed_;
- }
- /**
- * @brief Set close handler
- * @param h handler
- */
- void set_close_handler(close_handler h = close_handler()) {
- h_close_ = force_move(h);
- }
- /**
- * @brief Set error handler
- * @param h handler
- */
- void set_error_handler(error_handler h = error_handler()) {
- h_error_ = force_move(h);
- }
- /**
- * @brief Get close handler
- * @return handler
- */
- close_handler get_close_handler() const {
- return h_close_;
- }
- /**
- * @brief Get error handler
- * @return handler
- */
- error_handler get_error_handler() const {
- return h_error_;
- }
- private:
- // MQTT common handlers
- pingreq_handler h_pingreq_;
- pingresp_handler h_pingresp_;
- // MQTT v3_1_1 handlers
- connect_handler h_connect_;
- connack_handler h_connack_;
- publish_handler h_publish_;
- puback_handler h_puback_;
- pubrec_handler h_pubrec_;
- pubrel_handler h_pubrel_;
- pubcomp_handler h_pubcomp_;
- subscribe_handler h_subscribe_;
- suback_handler h_suback_;
- unsubscribe_handler h_unsubscribe_;
- unsuback_handler h_unsuback_;
- disconnect_handler h_disconnect_;
- // MQTT v5 handlers
- v5_connect_handler h_v5_connect_;
- v5_connack_handler h_v5_connack_;
- v5_publish_handler h_v5_publish_;
- v5_puback_handler h_v5_puback_;
- v5_pubrec_handler h_v5_pubrec_;
- v5_pubrel_handler h_v5_pubrel_;
- v5_pubcomp_handler h_v5_pubcomp_;
- v5_subscribe_handler h_v5_subscribe_;
- v5_suback_handler h_v5_suback_;
- v5_unsubscribe_handler h_v5_unsubscribe_;
- v5_unsuback_handler h_v5_unsuback_;
- v5_disconnect_handler h_v5_disconnect_;
- v5_auth_handler h_v5_auth_;
- // original handlers
- close_handler h_close_;
- error_handler h_error_;
- pub_res_sent_handler h_pub_res_sent_;
- serialize_publish_message_handler h_serialize_publish_;
- serialize_v5_publish_message_handler h_serialize_v5_publish_;
- serialize_pubrel_message_handler h_serialize_pubrel_;
- serialize_v5_pubrel_message_handler h_serialize_v5_pubrel_;
- serialize_remove_handler h_serialize_remove_;
- pre_send_handler h_pre_send_;
- is_valid_length_handler h_is_valid_length_;
- mqtt_message_processed_handler h_mqtt_message_processed_;
- }; // callable_overlay
- } // namespace MQTT_NS
- #endif // MQTT_CALLABLE_OVERLAY_HPP
|