QBtServiceAdvertiser.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * QBtServiceAdvertiser.h
  3. *
  4. *
  5. * Author: Ftylitakis Nikolaos
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. #ifndef QBTSERVICEADVERTISER_H_
  20. #define QBTSERVICEADVERTISER_H_
  21. #include <QBtGlobal.h>
  22. #include <QtCore/QObject>
  23. #include <QBtTypes.h>
  24. QBT_NAMESPACE_BEGIN
  25. //forward declaration
  26. class QBtServiceAdvertiserPrivate;
  27. /**
  28. * Class responsible to advertise a given bluetooth service.
  29. *
  30. * After the instantiation of the class, startAdvertising(const QBtService&) can be callled
  31. * to start advertising the given bluetooth service. If successfull then
  32. * advertisingStarted(const QBtService&) signal is emitted.
  33. *
  34. * At any time stopAdvertising() can be called to stop the advertising and remove the
  35. * registered service from the SDP database. If successfull then advertisingStopped()
  36. * is emitted.
  37. *
  38. * If user wants to temporarily deactive the service advertisement then he can call
  39. * updateAvailability(bool) (instead of the stopAdvertising() that stops the advertising
  40. * permanently).
  41. *
  42. * In case of error, error(ErrorCodes) signal is emitted.
  43. *
  44. * For integrity reasons, at destruction stops the advertising
  45. * causing the service to be deleted from the SDP database.
  46. *
  47. * NOTE: Currently there is no implementation on the Windows platform so
  48. * after the intatiation of this object, any call to any function will
  49. * emit an error(QBtServiceAdvertiser::FeatureNotSupported) signal.
  50. */
  51. class DLL_EXPORT QBtServiceAdvertiser : public QObject
  52. {
  53. Q_OBJECT
  54. public:
  55. enum ErrorCodes
  56. {
  57. FeatureNotSupported
  58. };
  59. public:
  60. QBtServiceAdvertiser(QObject* parent);
  61. ~QBtServiceAdvertiser();
  62. /**
  63. * Starts the service advertiser.
  64. *
  65. * @param service the service class that contains all the necessery
  66. * information for transmitting the service
  67. */
  68. void startAdvertising(const QBtService& service);
  69. /**
  70. * Stops the transmittion of the service running (if any)
  71. */
  72. void stopAdvertising();
  73. /**
  74. * Change the availability of the service.
  75. * @param aAvailable If true, the service is transmitted.
  76. */
  77. void updateAvailability(bool aAvailable);
  78. signals:
  79. /**
  80. * The signal is emitted if the transmittion of the service is started
  81. * @param service A reference to an object containing all the info of the service being transmitted.
  82. */
  83. void advertisingStarted(const QBtService& service);
  84. /**
  85. * The signal is emitted when the transmittion of the service ends.
  86. */
  87. void advertisingStopped();
  88. /**
  89. *
  90. * Emitted in case of error (not implemented).
  91. */
  92. void error (QBtServiceAdvertiser::ErrorCodes code);
  93. private:
  94. // The service to advertise
  95. QBtService* _localService;
  96. //pointer to implementation
  97. QBtServiceAdvertiserPrivate *_implPtr;
  98. friend class QBtServiceAdvertiserPrivate;
  99. };
  100. QBT_NAMESPACE_END
  101. //Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtServiceAdvertiser))
  102. #endif /* QBTSERVICEADVERTISER_H_ */