Home | History | Annotate | Download | only in dbus
      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_DESCRIPTOR_CLIENT_H_
      6 #define CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback.h"
     12 #include "chromeos/chromeos_export.h"
     13 #include "chromeos/dbus/dbus_client.h"
     14 #include "dbus/object_path.h"
     15 #include "dbus/property.h"
     16 
     17 namespace chromeos {
     18 
     19 // BluetoothGattDescriptorClient is used to communicate with remote GATT
     20 // characteristic descriptor objects exposed by the Bluetooth daemon.
     21 class CHROMEOS_EXPORT BluetoothGattDescriptorClient : public DBusClient {
     22  public:
     23   // Structure of properties associated with GATT descriptors.
     24   struct Properties : public dbus::PropertySet {
     25     // The 128-bit characteristic descriptor UUID. [read-only]
     26     dbus::Property<std::string> uuid;
     27 
     28     // Object path of the GATT characteristic the descriptor belongs to.
     29     // [read-only]
     30     dbus::Property<dbus::ObjectPath> characteristic;
     31 
     32     Properties(dbus::ObjectProxy* object_proxy,
     33                const std::string& interface_name,
     34                const PropertyChangedCallback& callback);
     35     virtual ~Properties();
     36   };
     37 
     38   // Interface for observing changes from a remote GATT characteristic
     39   // descriptor.
     40   class Observer {
     41    public:
     42     virtual ~Observer() {}
     43 
     44     // Called when the GATT descriptor with object path |object_path| is added
     45     // to the system.
     46     virtual void GattDescriptorAdded(const dbus::ObjectPath& object_path) {}
     47 
     48     // Called when the GATT descriptor with object path |object_path| is removed
     49     // from the system.
     50     virtual void GattDescriptorRemoved(const dbus::ObjectPath& object_path) {}
     51 
     52     // Called when the GATT descriptor with object path |object_path| has a
     53     // change in the value of the property named |property_name|.
     54     virtual void GattDescriptorPropertyChanged(
     55         const dbus::ObjectPath& object_path,
     56         const std::string& property_name) {}
     57   };
     58 
     59   // Callbacks used to report the result of asynchronous methods.
     60   typedef base::Callback<void(const std::string& error_name,
     61                               const std::string& error_message)> ErrorCallback;
     62   typedef base::Callback<void(const std::vector<uint8>& value)> ValueCallback;
     63 
     64   virtual ~BluetoothGattDescriptorClient();
     65 
     66   // Adds and removes observers for events on all remote GATT descriptors. Check
     67   // the |object_path| parameter of observer methods to determine which GATT
     68   // descriptor is issuing the event.
     69   virtual void AddObserver(Observer* observer) = 0;
     70   virtual void RemoveObserver(Observer* observer) = 0;
     71 
     72   // Returns the list of GATT descriptor object paths known to the system.
     73   virtual std::vector<dbus::ObjectPath> GetDescriptors() = 0;
     74 
     75   // Obtain the properties for the GATT descriptor with object path
     76   // |object_path|. Values should be copied if needed.
     77   virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
     78 
     79   // Issues a request to read the value of GATT descriptor with object path
     80   // |object_path| and returns the value in |callback| on success. On error,
     81   // invokes |error_callback|.
     82   virtual void ReadValue(const dbus::ObjectPath& object_path,
     83                          const ValueCallback& callback,
     84                          const ErrorCallback& error_callback) = 0;
     85 
     86   // Issues a request to write the value of GATT descriptor with object path
     87   // |object_path| with value |value|. Invokes |callback| on success and
     88   // |error_callback| on failure.
     89   virtual void WriteValue(const dbus::ObjectPath& object_path,
     90                           const std::vector<uint8>& value,
     91                           const base::Closure& callback,
     92                           const ErrorCallback& error_callback) = 0;
     93 
     94   // Creates the instance.
     95   static BluetoothGattDescriptorClient* Create();
     96 
     97   // Constants used to indicate exceptional error conditions.
     98   static const char kNoResponseError[];
     99   static const char kUnknownDescriptorError[];
    100 
    101  protected:
    102   BluetoothGattDescriptorClient();
    103 
    104  private:
    105   DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptorClient);
    106 };
    107 
    108 }  // namespace chromeos
    109 
    110 #endif  // CHROMEOS_DBUS_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_
    111