response_options.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // response_options.cpp
  2. /*******************************************************************************
  3. * Copyright (c) 2019 Frank Pagliughi <fpagliughi@mindspring.com>
  4. *
  5. * All rights reserved. This program and the accompanying materials
  6. * are made available under the terms of the Eclipse Public License v1.0
  7. * and Eclipse Distribution License v1.0 which accompany this distribution.
  8. *
  9. * The Eclipse Public License is available at
  10. * http://www.eclipse.org/legal/epl-v10.html
  11. * and the Eclipse Distribution License is available at
  12. * http://www.eclipse.org/org/documents/edl-v10.php.
  13. *
  14. * Contributors:
  15. * Frank Pagliughi - initial implementation and documentation
  16. *******************************************************************************/
  17. #include "mqtt/response_options.h"
  18. namespace mqtt {
  19. /////////////////////////////////////////////////////////////////////////////
  20. response_options::response_options(int mqttVersion /*=MQTTVERSION_DEFAULT*/)
  21. : opts_(MQTTAsync_responseOptions_initializer)
  22. {
  23. if (mqttVersion < MQTTVERSION_5) {
  24. opts_.onSuccess = &token::on_success;
  25. opts_.onFailure = &token::on_failure;
  26. }
  27. else {
  28. opts_.onSuccess5 = &token::on_success5;
  29. opts_.onFailure5 = &token::on_failure5;
  30. }
  31. }
  32. response_options::response_options(const token_ptr& tok,
  33. int mqttVersion /*=MQTTVERSION_DEFAULT*/)
  34. : response_options(mqttVersion)
  35. {
  36. set_token(tok);
  37. }
  38. void response_options::set_token(const token_ptr& tok)
  39. {
  40. tok_ = tok;
  41. opts_.context = tok.get();
  42. }
  43. void response_options::set_subscribe_options(const subscribe_options& opts)
  44. {
  45. opts_.subscribeOptions = opts.opts_;
  46. }
  47. void response_options::set_subscribe_options(const std::vector<subscribe_options>& opts)
  48. {
  49. subOpts_.clear();
  50. for (const auto& opt : opts)
  51. subOpts_.push_back(opt.opts_);
  52. opts_.subscribeOptionsCount = int(opts.size());
  53. opts_.subscribeOptionsList = const_cast<MQTTSubscribe_options*>(subOpts_.data());
  54. }
  55. /////////////////////////////////////////////////////////////////////////////
  56. delivery_response_options::delivery_response_options(int mqttVersion /*=MQTTVERSION_DEFAULT*/)
  57. : opts_(MQTTAsync_responseOptions_initializer)
  58. {
  59. if (mqttVersion < MQTTVERSION_5) {
  60. opts_.onSuccess = &delivery_token::on_success;
  61. opts_.onFailure = &delivery_token::on_failure;
  62. }
  63. else {
  64. opts_.onSuccess5 = &delivery_token::on_success5;
  65. opts_.onFailure5 = &delivery_token::on_failure5;
  66. }
  67. }
  68. delivery_response_options::delivery_response_options(const delivery_token_ptr& tok,
  69. int mqttVersion /*=MQTTVERSION_DEFAULT*/)
  70. : delivery_response_options(mqttVersion)
  71. {
  72. set_token(tok);
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // end namespace 'mqtt'
  76. }