summaryrefslogtreecommitdiff
path: root/gatocharacteristic.cpp
blob: a95c4a2ccf5ea70e10121853a3db92f4e49d1ee8 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 *  libgato - A GATT/ATT library for use with Bluez
 *
 *  Copyright (C) 2013 Javier S. Pedro <maemo@javispedro.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <QtCore/QSharedData>

#include "gatocharacteristic.h"
#include "gatodescriptor.h"

struct GatoCharacteristicPrivate : public QSharedData
{
	GatoUUID uuid;
	GatoHandle start;
	GatoHandle end;
	GatoCharacteristic::Properties properties;
	GatoHandle value_handle;
	QMap<GatoHandle, GatoDescriptor> descriptors;
	QHash<GatoUUID, GatoHandle> desc_uuids;
};

GatoCharacteristic::GatoCharacteristic()
    : d(new GatoCharacteristicPrivate)
{
	d->start = 0;
	d->end = 0;
	d->properties = 0;
	d->value_handle = 0;
}

GatoCharacteristic::GatoCharacteristic(const GatoCharacteristic &o)
    : d(o.d)
{
}

GatoCharacteristic::~GatoCharacteristic()
{
}

bool GatoCharacteristic::isNull() const
{
	return d->start == 0 || d->end == 0 || d->uuid.isNull();
}

GatoUUID GatoCharacteristic::uuid() const
{
	return d->uuid;
}

void GatoCharacteristic::setUuid(const GatoUUID &uuid)
{
	d->uuid = uuid;
}

GatoCharacteristic::Properties GatoCharacteristic::properties() const
{
	return d->properties;
}

void GatoCharacteristic::setProperties(GatoCharacteristic::Properties props)
{
	d->properties = props;
}

GatoHandle GatoCharacteristic::startHandle() const
{
	return d->start;
}

void GatoCharacteristic::setStartHandle(GatoHandle handle)
{
	d->start = handle;
}

GatoHandle GatoCharacteristic::endHandle() const
{
	return d->end;
}

void GatoCharacteristic::setEndHandle(GatoHandle handle)
{
	d->end = handle;
}

GatoHandle GatoCharacteristic::valueHandle() const
{
	return d->value_handle;
}

void GatoCharacteristic::setValueHandle(GatoHandle handle)
{
	d->value_handle = handle;
}

QList<GatoDescriptor> GatoCharacteristic::descriptors() const
{
	return d->descriptors.values();
}

bool GatoCharacteristic::containsDescriptor(GatoUUID uuid) const
{
	return d->desc_uuids.contains(uuid);
}

bool GatoCharacteristic::containsDescriptor(GatoHandle handle) const
{
	return d->descriptors.contains(handle);
}

GatoDescriptor GatoCharacteristic::getDescriptor(GatoUUID uuid) const
{
	return d->descriptors.value(d->desc_uuids.value(uuid));
}

GatoDescriptor GatoCharacteristic::getDescriptor(GatoHandle handle) const
{
	return d->descriptors.value(handle);
}

void GatoCharacteristic::addDescriptor(const GatoDescriptor &descriptor)
{
	d->descriptors.insert(descriptor.handle(), descriptor);
	d->desc_uuids.insert(descriptor.uuid(), descriptor.handle());
}

void GatoCharacteristic::removeDescriptor(const GatoDescriptor &descriptor)
{
	d->descriptors.remove(descriptor.handle());
	d->desc_uuids.remove(descriptor.uuid());
}

void GatoCharacteristic::clearDescriptors()
{
	d->descriptors.clear();
	d->desc_uuids.clear();
}

GatoCharacteristic &GatoCharacteristic::operator=(const GatoCharacteristic &o)
{
	if (this != &o) {
		d = o.d;
	}
	return *this;
}