summaryrefslogtreecommitdiff
path: root/gatouuid.h
blob: 08d03051834a8d28f595aa063581813c4ca41fdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef GATOUUID_H
#define GATOUUID_H

#include <QtCore/QDebug>
#include <QtCore/QtEndian>
#include <QtCore/QUuid>
#include "libgato_global.h"

class GatoUUIDPrivate;

struct gatouint128
{
	quint8 data[16];
};

template<>
inline LIBGATO_EXPORT gatouint128 qFromLittleEndian<gatouint128>(const uchar *src)
{
	gatouint128 dest;
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
	for (int i = 0; i < 16; i++) {
		dest.data[i] = src[i];
	}
#else
	for (int i = 0; i < 16; i++) {
		dest.data[i] = src[15 - i];
	}
#endif
	return dest;
}

template<>
inline LIBGATO_EXPORT void qToLittleEndian<gatouint128>(gatouint128 src, uchar *dest)
{
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
	for (int i = 0; i < 16; i++) {
		dest[i] = src.data[i];
	}
#else
	for (int i = 0; i < 16; i++) {
		dest[i] = src.data[15 - i];
	}
#endif
}

class LIBGATO_EXPORT GatoUUID : public QUuid
{
public:
	enum GattUuid {
		GattGenericAccessProfile = 0x1800,
		GattGenericAttributeProfile = 0x1801,
		GattPrimaryService = 0x2800,
		GattSecondaryService = 0x2801,
		GattInclude = 0x2802,
		GattCharacteristic = 0x2803,
		GattCharacteristicExtendedProperties = 0x2900,
		GattCharacteristicUserDescription = 0x2901,
		GattClientCharacteristicConfiguration = 0x2902,
		GattServerCharacteristicConfiguration = 0x2903,
		GattCharacteristicFormat = 0x2904,
		GattCharacteristicAggregateFormat = 0x2905,
		GattDeviceName = 0x2A00,
		GattAppearance = 0x2A01,
		GattPeripheralPrivacyFlag = 0x2A02,
		GattReconnectionAddress = 0x2A03,
		GattPeripheralPreferredConnectionParameters = 0x2A04,
		GattServiceChanged = 0x2A05
	};

	GatoUUID();
	GatoUUID(GattUuid uuid);
	explicit GatoUUID(quint16 uuid);
	explicit GatoUUID(quint32 uuid);
	explicit GatoUUID(gatouint128 uuid);
	explicit GatoUUID(const QString &uuid);
	GatoUUID(const GatoUUID &o);
	GatoUUID(const QUuid &uuid);
	~GatoUUID();

	int minimumSize() const;

	quint16 toUInt16(bool *ok = 0) const;
	quint32 toUInt32(bool *ok = 0) const;
	gatouint128 toUInt128() const;
};

LIBGATO_EXPORT QDebug operator<<(QDebug debug, const GatoUUID &uuid);

LIBGATO_EXPORT QDataStream & operator<<(QDataStream &s, const gatouint128 &u);
LIBGATO_EXPORT QDataStream & operator>>(QDataStream &s, gatouint128 &u);

LIBGATO_EXPORT uint qHash(const GatoUUID &a);

#endif // GATOUUID_H