Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / device / bluetooth / bluetooth_gatt_descriptor.h
index 9c0a1d2..e98ef29 100644 (file)
@@ -2,19 +2,18 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef DEVICE_BLUETOOTH_GATT_DESCRIPTOR_H_
-#define DEVICE_BLUETOOTH_GATT_DESCRIPTOR_H_
+#ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_
+#define DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_
 
 #include <vector>
 
 #include "base/basictypes.h"
 #include "base/callback.h"
-#include "device/bluetooth/bluetooth_utils.h"
+#include "device/bluetooth/bluetooth_gatt_characteristic.h"
+#include "device/bluetooth/bluetooth_uuid.h"
 
 namespace device {
 
-class BluetoothGattCharacteristic;
-
 // BluetoothGattDescriptor represents a local or remote GATT characteristic
 // descriptor. A GATT characteristic descriptor provides further information
 // about a characteristic's value. They can be used to describe the
@@ -36,7 +35,7 @@ class BluetoothGattDescriptor {
   //    - Reliable Write: 0x0001
   //    - Writable Auxiliaries: 0x0002
   //
-  static const bluetooth_utils::UUID kCharacteristicExtendedPropertiesUuid;
+  static const BluetoothUUID& CharacteristicExtendedPropertiesUuid();
 
   // The "Characteristic User Description" descriptor defines a UTF-8 string of
   // variable size that is a user textual description of the associated
@@ -44,7 +43,7 @@ class BluetoothGattDescriptor {
   // per characteristic. This descriptor can be written to if the "Writable
   // Auxiliaries" bit of the Characteristic Properties (via the "Characteristic
   // Extended Properties" descriptor) has been set.
-  static const bluetooth_utils::UUID kCharacteristicUserDescriptionUuid;
+  static const BluetoothUUID& CharacteristicUserDescriptionUuid();
 
   // The "Client Characteristic Configuration" descriptor defines how the
   // characteristic may be configured by a specific client. A server-side
@@ -58,7 +57,7 @@ class BluetoothGattDescriptor {
   //    - Notification: 0x0001
   //    - Indication: 0x0002
   //
-  static const bluetooth_utils::UUID kClientCharacteristicConfigurationUuid;
+  static const BluetoothUUID& ClientCharacteristicConfigurationUuid();
 
   // The "Server Characteristic Configuration" descriptor defines how the
   // characteristic may be configured for the server. There is one instance
@@ -71,7 +70,7 @@ class BluetoothGattDescriptor {
   //    - Default: 0x0000
   //    - Broadcast: 0x0001
   //
-  static const bluetooth_utils::UUID kServerCharacteristicConfigurationUuid;
+  static const BluetoothUUID& ServerCharacteristicConfigurationUuid();
 
   // The "Characteristic Presentation Format" declaration defines the format of
   // the Characteristic Value. The value is composed of 7 octets which are
@@ -81,7 +80,7 @@ class BluetoothGattDescriptor {
   // than one declaration of this descriptor exists for a characteristic, then a
   // "Characteristic Aggregate Format" descriptor must also exist for that
   // characteristic.
-  static const bluetooth_utils::UUID kCharacteristicPresentationFormatUuid;
+  static const BluetoothUUID& CharacteristicPresentationFormatUuid();
 
   // The "Characteristic Aggregate Format" descriptor defines the format of an
   // aggragated characteristic value. In GATT's underlying protocol, ATT, each
@@ -103,40 +102,15 @@ class BluetoothGattDescriptor {
   // Similarly for local characteristics, implementations DO NOT need to create
   // an instance of BluetoothGattDescriptor for this descriptor as this will be
   // handled by the subsystem.
-  static const bluetooth_utils::UUID kCharacteristicAggregateFormatUuid;
-
-  // Interface for observing changes from a BluetoothGattDescriptor.
-  // Properties of remote characteristic desciptors are received asynchonously.
-  // The Observer interface can be used to be notified when the initial values
-  // of a characteristic descriptor are received as well as when successive
-  // changes occur during its life cycle.
-  class Observer {
-   public:
-    // Called when the UUID of |descriptor| has changed.
-    virtual void UuidChanged(
-        BluetoothGattDescriptor* descriptor,
-        const bluetooth_utils::UUID& uuid) {}
-
-    // Called when the current value of |descriptor| has changed.
-    virtual void ValueChanged(
-        BluetoothGattDescriptor* descriptor,
-        const std::vector<uint8>& value) {}
-  };
+  static const BluetoothUUID& CharacteristicAggregateFormatUuid();
 
   // The ErrorCallback is used by methods to asynchronously report errors.
-  typedef base::Callback<void(const std::string&)> ErrorCallback;
+  typedef base::Closure ErrorCallback;
 
   // The ValueCallback is used to return the value of a remote characteristic
   // descriptor upon a read request.
   typedef base::Callback<void(const std::vector<uint8>&)> ValueCallback;
 
-  // Adds and removes observers for events on this GATT characteristic
-  // descriptor. If monitoring multiple descriptors, check the |descriptor|
-  // parameter of observer methods to determine which characteristic is issuing
-  // the event.
-  virtual void AddObserver(Observer* observer) = 0;
-  virtual void RemoveObserver(Observer* observer) = 0;
-
   // Constructs a BluetoothGattDescriptor that can be associated with a local
   // GATT characteristic when the adapter is in the peripheral role. To
   // associate the returned descriptor with a characteristic, add it to a local
@@ -153,19 +127,37 @@ class BluetoothGattDescriptor {
   // |kCharacteristicPresentationFormat| are supported for locally hosted
   // descriptors. This method will return NULL if |uuid| is any one of the
   // unsupported predefined descriptor UUIDs.
-  static BluetoothGattDescriptor* Create(const bluetooth_utils::UUID& uuid,
-                                         const std::vector<uint8>& value);
+  static BluetoothGattDescriptor* Create(
+      const BluetoothUUID& uuid,
+      const std::vector<uint8>& value,
+      BluetoothGattCharacteristic::Permissions permissions);
+
+  // Identifier used to uniquely identify a GATT descriptorobject. This is
+  // different from the descriptor UUID: while multiple descriptors with the
+  // same UUID can exist on a Bluetooth device, the identifier returned from
+  // this method is unique among all descriptors of a device. The contents of
+  // the identifier are platform specific.
+  virtual std::string GetIdentifier() const = 0;
 
   // The Bluetooth-specific UUID of the characteristic descriptor.
-  virtual const bluetooth_utils::UUID& GetUuid() const = 0;
+  virtual BluetoothUUID GetUUID() const = 0;
 
   // Returns true, if this characteristic descriptor is hosted locally. If
   // false, then this instance represents a remote descriptor.
   virtual bool IsLocal() const = 0;
 
+  // Returns the value of the descriptor. For remote descriptors, this is the
+  // most recently cached value of the remote descriptor. For local descriptors
+  // this is the most recently updated value or the value retrieved from the
+  // delegate.
+  virtual const std::vector<uint8>& GetValue() const = 0;
+
   // Returns a pointer to the GATT characteristic that this characteristic
   // descriptor belongs to.
-  virtual const BluetoothGattCharacteristic* GetCharacteristic() const = 0;
+  virtual BluetoothGattCharacteristic* GetCharacteristic() const = 0;
+
+  // Returns the bitmask of characteristic descriptor attribute permissions.
+  virtual BluetoothGattCharacteristic::Permissions GetPermissions() const = 0;
 
   // Sends a read request to a remote characteristic descriptor to read its
   // value. |callback| is called to return the read value on success and
@@ -174,12 +166,11 @@ class BluetoothGattDescriptor {
                                     const ErrorCallback& error_callback) = 0;
 
   // Sends a write request to a remote characteristic descriptor, to modify the
-  // value of the descriptor starting at offset |offset| with the new value
-  // |new_value|. |callback| is called to signal success and |error_callback|
-  // for failures. This method only applies to remote descriptors and will fail
-  // for those that are locally hosted.
+  // value of the descriptor with the new value |new_value|. |callback| is
+  // called to signal success and |error_callback| for failures. This method
+  // only applies to remote descriptors and will fail for those that are locally
+  // hosted.
   virtual void WriteRemoteDescriptor(
-      int offset,
       const std::vector<uint8>& new_value,
       const base::Closure& callback,
       const ErrorCallback& error_callback) = 0;
@@ -194,4 +185,4 @@ class BluetoothGattDescriptor {
 
 }  // namespace device
 
-#endif  // DEVICE_BLUETOOTH_GATT_DESCRIPTOR_H_
+#endif  // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_