callback.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 v2.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-v20.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. */
  52. virtual void connected(const string& /*cause*/) {}
  53. /**
  54. * This method is called when the connection to the server is lost.
  55. */
  56. virtual void connection_lost(const string& /*cause*/) {}
  57. /**
  58. * This method is called when a message arrives from the server.
  59. */
  60. virtual void message_arrived(const_message_ptr /*msg*/) {}
  61. /**
  62. * Called when delivery for a message has been completed, and all
  63. * acknowledgments have been received.
  64. */
  65. virtual void delivery_complete(delivery_token_ptr /*tok*/) {}
  66. };
  67. /** Smart/shared pointer to a callback object */
  68. using callback_ptr = callback::ptr_t;
  69. /** Smart/shared pointer to a const callback object */
  70. using const_callback_ptr = callback::const_ptr_t;
  71. /////////////////////////////////////////////////////////////////////////////
  72. // end namespace mqtt
  73. }
  74. #endif // __mqtt_callback_h