• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
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 CHROMEOS_DBUS_BLUETOOTH_GATT_SERVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_GATT_SERVICE_CLIENT_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "chromeos/chromeos_export.h"
12 #include "chromeos/dbus/dbus_client.h"
13 #include "dbus/object_path.h"
14 #include "dbus/property.h"
15 
16 namespace chromeos {
17 
18 // BluetoothGattServiceClient is used to communicate with remote GATT service
19 // objects exposed by the Bluetooth daemon.
20 class CHROMEOS_EXPORT BluetoothGattServiceClient : public DBusClient {
21  public:
22   // Structure of properties associated with GATT services.
23   struct Properties : public dbus::PropertySet {
24     // The 128-bit service UUID. [read-only]
25     dbus::Property<std::string> uuid;
26 
27     // Object path of the Bluetooth device that the GATT service belongs to.
28     dbus::Property<dbus::ObjectPath> device;
29 
30     // Whether or not this service is a primary service.
31     dbus::Property<bool> primary;
32 
33     // Array of object paths representing the included services of this service.
34     // [read-only]
35     dbus::Property<std::vector<dbus::ObjectPath> > includes;
36 
37     Properties(dbus::ObjectProxy* object_proxy,
38                const std::string& interface_name,
39                const PropertyChangedCallback& callback);
40     virtual ~Properties();
41   };
42 
43   // Interface for observing changes from a remote GATT service.
44   class Observer {
45    public:
~Observer()46     virtual ~Observer() {}
47 
48     // Called when the GATT service with object path |object_path| is added to
49     // the system.
GattServiceAdded(const dbus::ObjectPath & object_path)50     virtual void GattServiceAdded(const dbus::ObjectPath& object_path) {}
51 
52     // Called when the GATT service with object path |object_path| is removed
53     // from the system.
GattServiceRemoved(const dbus::ObjectPath & object_path)54     virtual void GattServiceRemoved(const dbus::ObjectPath& object_path) {}
55 
56     // Called when the GATT service with object path |object_path| has a change
57     // in the value of the property named |property_name|.
GattServicePropertyChanged(const dbus::ObjectPath & object_path,const std::string & property_name)58     virtual void GattServicePropertyChanged(const dbus::ObjectPath& object_path,
59                                             const std::string& property_name) {}
60   };
61 
62   virtual ~BluetoothGattServiceClient();
63 
64   // Adds and removes observers for events on all remote GATT services. Check
65   // the |object_path| parameter of observer methods to determine which GATT
66   // service is issuing the event.
67   virtual void AddObserver(Observer* observer) = 0;
68   virtual void RemoveObserver(Observer* observer) = 0;
69 
70   // Returns the list of GATT service object paths known to the system.
71   virtual std::vector<dbus::ObjectPath> GetServices() = 0;
72 
73   // Obtain the properties for the GATT service with object path |object_path|.
74   // Values should be copied if needed.
75   virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
76 
77   // Creates the instance.
78   static BluetoothGattServiceClient* Create();
79 
80  protected:
81   BluetoothGattServiceClient();
82 
83  private:
84   DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceClient);
85 };
86 
87 }  // namespace chromeos
88 
89 #endif  // CHROMEOS_DBUS_BLUETOOTH_GATT_SERVICE_CLIENT_H_
90