QBtUuid.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef QBTUUID_H
  2. #define QBTUUID_H
  3. #include <QBtGlobal.h>
  4. #include <QtCore/QString>
  5. QBT_NAMESPACE_BEGIN
  6. /**
  7. * This class represents a UUID for Bluetooth, either in short format (16 or 32-bits) or full (128-bit).
  8. *
  9. */
  10. class DLL_EXPORT QBtUuid : public QObject
  11. {
  12. Q_OBJECT
  13. public:
  14. /**
  15. * Constructs an empty instance.
  16. */
  17. QBtUuid (QObject* parent=NULL);
  18. /**
  19. * Constructs an instance from a string representation.
  20. *
  21. * Valid formats:
  22. * XXXX
  23. * XXXXXXXX
  24. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  25. */
  26. QBtUuid (const QString & uuid);
  27. /**
  28. * Constructs an instance from a short uuid representation, a 16-bit or 32-bit value.
  29. */
  30. explicit QBtUuid (uint uuid);
  31. /**
  32. * Copy constructor
  33. */
  34. QBtUuid(const QBtUuid& uuid);
  35. public:
  36. /**
  37. * Sets as short UUID based on the supplied value. Assumed to be a 16-bit or 32-bit hexadecimal number.
  38. */
  39. void set (uint uuid);
  40. /**
  41. * Sets the uuid from a string representation.
  42. *
  43. * Valid formats:
  44. * XXXX
  45. * XXXXXXXX
  46. * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  47. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  48. */
  49. void set (const QString & uuid);
  50. /**
  51. * If short uuid, returns the equivalent uint. If full uuid, returns 0.
  52. *
  53. */
  54. uint get() const;
  55. /**
  56. * If this is a full uuid, splits it four 32-bit values. If this is a short
  57. * uuid, all values are set to zero.
  58. *
  59. */
  60. void get (uint & highWord1, uint & highWord2, uint & lowWord1, uint & lowWord2) const;
  61. /**
  62. * If short format, returns the equivalent uint. If full uuid, returns 0.
  63. *
  64. */
  65. bool isFull () const;
  66. /**
  67. * Returns true if this is an empty instance.
  68. *
  69. */
  70. bool isNull () const;
  71. /**
  72. * Returns a string representation.
  73. *
  74. */
  75. QString toString() const;
  76. /**
  77. * Resets to a null UUID.
  78. */
  79. void clear();
  80. /**
  81. *
  82. */
  83. bool operator == (const QBtUuid & obj) const;
  84. /**
  85. *
  86. */
  87. bool operator != (const QBtUuid & obj) const;
  88. /**
  89. *
  90. */
  91. QBtUuid& operator=(class QBtUuid const &uuid);
  92. private:
  93. QString _uuid;
  94. };
  95. #ifdef Q_OS_SYMBIAN
  96. #include <bttypes.h>
  97. /**
  98. * A simple utility function to convert to the symbian native type.
  99. *
  100. */
  101. inline TUUID QBtUuidToSymbianUuid (const QBtUuid & value)
  102. {
  103. if (value.isFull() == false)
  104. {
  105. return TUUID (value.get() );
  106. }
  107. else
  108. {
  109. uint highWord1, highWord2, lowWord1, lowWord2;
  110. value.get (highWord1, highWord2, lowWord1, lowWord2);
  111. return TUUID (highWord1, highWord2, lowWord1, lowWord2);
  112. }
  113. }
  114. #endif
  115. QBT_NAMESPACE_END
  116. Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtUuid))
  117. #endif // QBTUUID_H