callback.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /////////////////////////////////////////////////////////////////////////////
  2. /// @file callback.h
  3. /// Declaration of MQTT callback class
  4. /// @date May 1, 2013
  5. /// @author Frank Pagliughi
  6. /////////////////////////////////////////////////////////////////////////////
  7. /*******************************************************************************
  8. * Copyright (c) 2013-2019 Frank Pagliughi <fpagliughi@mindspring.com>
  9. *
  10. * All rights reserved. This program and the accompanying materials
  11. * are made available under the terms of the Eclipse Public License v1.0
  12. * and Eclipse Distribution License v1.0 which accompany this distribution.
  13. *
  14. * The Eclipse Public License is available at
  15. * http://www.eclipse.org/legal/epl-v10.html
  16. * and the Eclipse Distribution License is available at
  17. * http://www.eclipse.org/org/documents/edl-v10.php.
  18. *
  19. * Contributors:
  20. * Frank Pagliughi - initial implementation and documentation
  21. *******************************************************************************/
  22. #ifndef __mqtt_callback_h
  23. #define __mqtt_callback_h
  24. #include "MQTTAsync.h"
  25. #include "mqtt/delivery_token.h"
  26. #include "mqtt/types.h"
  27. #include <vector>
  28. #include <memory>
  29. namespace mqtt {
  30. /////////////////////////////////////////////////////////////////////////////
  31. /**
  32. * Provides a mechanism for tracking the completion of an asynchronous
  33. * action.
  34. */
  35. class callback
  36. {
  37. public:
  38. /** Smart/shared pointer to an object of this type */
  39. using ptr_t = std::shared_ptr<callback>;
  40. /** Smart/shared pointer to a const object of this type */
  41. using const_ptr_t = std::shared_ptr<const callback>;
  42. /**
  43. * Virtual destructor.
  44. */
  45. virtual ~callback() {}
  46. /**
  47. * This method is called when the client is connected.
  48. * Note that, in response to an initial connect(), the token from the
  49. * connect call is also signaled with an on_success(). That occurs just
  50. * before this is called.
  51. * @param cause
  52. */
  53. virtual void connected(const string& /*cause*/) {}
  54. /**
  55. * This method is called when the connection to the server is lost.
  56. * @param cause
  57. */
  58. virtual void connection_lost(const string& /*cause*/) {}
  59. /**
  60. * This method is called when a message arrives from the server.
  61. * @param msg The message
  62. */
  63. virtual void message_arrived(const_message_ptr /*msg*/) {}
  64. /**
  65. * Called when delivery for a message has been completed, and all
  66. * acknowledgments have been received.
  67. * @param tok The token tracking the message delivery.
  68. */
  69. virtual void delivery_complete(delivery_token_ptr /*tok*/) {}
  70. };
  71. /** Smart/shared pointer to a callback object */
  72. using callback_ptr = callback::ptr_t;
  73. /** Smart/shared pointer to a const callback object */
  74. using const_callback_ptr = callback::const_ptr_t;
  75. /////////////////////////////////////////////////////////////////////////////
  76. // end namespace mqtt
  77. }
  78. #endif // __mqtt_callback_h