OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
Marie Janssen
2015/04/21 18:15:10
2015 and no (c) here and elsewhere on new files.
rkc
2015/04/23 19:32:17
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_H_ | |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/observer_list.h" | |
16 #include "device/bluetooth/bluetooth_export.h" | |
17 | |
18 namespace device { | |
19 | |
20 // BluetoothAdvertisement represents an advertisement which advertises over the | |
21 // LE channel during its lifetime. | |
22 class DEVICE_BLUETOOTH_EXPORT BluetoothAdvertisement | |
23 : public base::RefCounted<BluetoothAdvertisement> { | |
24 public: | |
25 // Possible types of error raised while registering or unregistering | |
26 // advertisements. | |
27 enum ErrorCode { | |
28 ERROR_ALREADY_EXISTS, // An advertisement is already registered. | |
29 ERROR_DOES_NOT_EXIST, // Unregistering an advertisement which is not | |
30 // registered. | |
31 ERROR_INVALID_LENGTH, // Advertisement is not of an in valid length. | |
Marie Janssen
2015/04/21 18:15:10
nit: Comment has double negative / doesn't make se
rkc
2015/04/23 19:32:16
Done.
| |
32 INVALID_ERROR_CODE | |
33 }; | |
34 | |
35 // Type of advertisement. | |
36 enum AdvertisementType { | |
37 ADVERTISEMENT_TYPE_BROADCAST, | |
Marie Janssen
2015/04/21 18:15:09
Add some comments here about how broadcast adverti
rkc
2015/04/23 19:32:16
Done.
| |
38 ADVERTISEMENT_TYPE_PERIPHERAL | |
39 }; | |
40 | |
41 using UUIDList = std::vector<std::string>; | |
42 using ManufacturerData = std::map<uint16_t, std::vector<uint8_t>>; | |
43 using ServiceData = std::map<std::string, std::vector<uint8_t>>; | |
44 | |
45 // Structure that holds the data for an advertisement. | |
Marie Janssen
2015/04/21 18:15:10
I don't like this design. It's basically holding
rkc
2015/04/23 19:32:17
Done.
| |
46 class Data { | |
47 public: | |
48 Data(AdvertisementType type, | |
49 scoped_ptr<UUIDList> service_uuids, | |
50 scoped_ptr<ManufacturerData> manufacturer_data, | |
51 scoped_ptr<UUIDList> solicit_uuids, | |
52 scoped_ptr<ServiceData> service_data); | |
53 ~Data(); | |
54 | |
55 AdvertisementType type() { return type_; } | |
56 scoped_ptr<UUIDList> service_uuids() { return service_uuids_.Pass(); } | |
57 scoped_ptr<ManufacturerData> manufacturer_data() { | |
58 return manufacturer_data_.Pass(); | |
59 } | |
60 scoped_ptr<UUIDList> solicit_uuids() { return solicit_uuids_.Pass(); } | |
61 scoped_ptr<ServiceData> service_data() { return service_data_.Pass(); } | |
62 | |
63 private: | |
64 Data(); | |
65 | |
66 AdvertisementType type_; | |
67 scoped_ptr<UUIDList> service_uuids_; | |
68 scoped_ptr<ManufacturerData> manufacturer_data_; | |
69 scoped_ptr<UUIDList> solicit_uuids_; | |
70 scoped_ptr<ServiceData> service_data_; | |
Marie Janssen
2015/04/21 18:15:09
Please add the IncludeTXPower new property too.
rkc
2015/04/23 19:32:17
I don't see this property in the service_constants
armansito
2015/04/23 20:13:25
How is that related to what goes into the high-lev
rkc
2015/04/24 20:04:58
Done.
| |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(Data); | |
73 }; | |
74 | |
75 // Interface for observing changes to this advertisement. | |
76 class Observer { | |
77 public: | |
78 virtual ~Observer() {} | |
79 // Called when this advertisement is released and is no longer advertising. | |
80 virtual void AdvertisementReleased( | |
81 BluetoothAdvertisement* advertisement) = 0; | |
82 }; | |
83 | |
84 // Adds and removes observers for events for this advertisement. | |
85 void AddObserver(BluetoothAdvertisement::Observer* observer); | |
86 void RemoveObserver(BluetoothAdvertisement::Observer* observer); | |
87 | |
88 // Unregisters this advertisement. Called on destruction of this object | |
89 // automatically but can be called directly to explicitly unregister this | |
90 // object. | |
91 typedef base::Closure SuccessCallback; | |
92 typedef base::Callback<void(ErrorCode)> ErrorCallback; | |
93 virtual void Unregister(const SuccessCallback& success_callback, | |
94 const ErrorCallback& error_callback) = 0; | |
95 | |
96 protected: | |
97 friend class base::RefCounted<BluetoothAdvertisement>; | |
98 | |
99 BluetoothAdvertisement(); | |
100 // The destructor will unregister this advertisement. | |
101 virtual ~BluetoothAdvertisement(); | |
102 | |
103 // List of observers interested in event notifications from us. Objects in | |
104 // |observers_| are expected to outlive a BluetoothAdvertisement object. | |
105 ObserverList<BluetoothAdvertisement::Observer> observers_; | |
106 | |
107 private: | |
108 DISALLOW_COPY_AND_ASSIGN(BluetoothAdvertisement); | |
109 }; | |
110 | |
111 } // namespace device | |
112 | |
113 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_H_ | |
OLD | NEW |