- add sources.
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / bluetooth_device_client.h
1 // Copyright 2013 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_DEVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_DEVICE_CLIENT_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/observer_list.h"
13 #include "base/values.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_client.h"
16 #include "chromeos/dbus/dbus_client_implementation_type.h"
17 #include "dbus/object_path.h"
18 #include "dbus/property.h"
19
20 namespace chromeos {
21
22 // BluetoothDeviceClient is used to communicate with objects representing
23 // remote Bluetooth Devices.
24 class CHROMEOS_EXPORT BluetoothDeviceClient : public DBusClient {
25  public:
26   // Structure of properties associated with bluetooth devices.
27   struct Properties : public dbus::PropertySet {
28     // The Bluetooth device address of the device. Read-only.
29     dbus::Property<std::string> address;
30
31     // The Bluetooth friendly name of the device. Read-only, to give a
32     // different local name, use the |alias| property.
33     dbus::Property<std::string> name;
34
35     // Proposed icon name for the device according to the freedesktop.org
36     // icon naming specification. Read-only.
37     dbus::Property<std::string> icon;
38
39     // The Bluetooth class of the device. Read-only.
40     dbus::Property<uint32> bluetooth_class;
41
42     // The GAP external appearance of the device. Read-only.
43     dbus::Property<uint16> appearance;
44
45     // Unique numeric identifier for the vendor of the device. Read-only.
46     dbus::Property<uint16> vendor;
47
48     // List of 128-bit UUIDs that represent the available remote services.
49     // Read-only.
50     dbus::Property<std::vector<std::string> > uuids;
51
52     // Indicates that the device is currently paired. Read-only.
53     dbus::Property<bool> paired;
54
55     // Indicates that the device is currently connected. Read-only.
56     dbus::Property<bool> connected;
57
58     // Whether the device is trusted, and connections should be always
59     // accepted and attempted when the device is visible.
60     dbus::Property<bool> trusted;
61
62     // Whether the device is blocked, connections will be always rejected
63     // and the device will not be visible.
64     dbus::Property<bool> blocked;
65
66     // Local alias for the device, if not set, is equal to |name|.
67     dbus::Property<std::string> alias;
68
69     // Object path of the adapter the device belongs to. Read-only.
70     dbus::Property<dbus::ObjectPath> adapter;
71
72     // Indicates whether the device is likely to only support pre-2.1
73     // PIN Code pairing rather than 2.1 Secure Simple Pairing, this can
74     // give false positives. Read-only.
75     dbus::Property<bool> legacy_pairing;
76
77     // Remote Device ID information in Linux kernel modalias format. Read-only.
78     dbus::Property<std::string> modalias;
79
80     // Received signal strength indicator. Read-only.
81     dbus::Property<int16> rssi;
82
83     Properties(dbus::ObjectProxy* object_proxy,
84                const std::string& interface_name,
85                const PropertyChangedCallback& callback);
86     virtual ~Properties();
87   };
88
89   // Interface for observing changes from a remote bluetooth device.
90   class Observer {
91    public:
92     virtual ~Observer() {}
93
94     // Called when the remote device with object path |object_path| is added
95     // to the set of known devices.
96     virtual void DeviceAdded(const dbus::ObjectPath& object_path) {}
97
98     // Called when the remote device with object path |object_path| is removed
99     // from the set of known devices.
100     virtual void DeviceRemoved(const dbus::ObjectPath& object_path) {}
101
102     // Called when the device with object path |object_path| has a
103     // change in value of the property named |property_name|.
104     virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path,
105                                        const std::string& property_name) {}
106   };
107
108   virtual ~BluetoothDeviceClient();
109
110   // Adds and removes observers for events on all remote bluetooth
111   // devices. Check the |object_path| parameter of observer methods to
112   // determine which device is issuing the event.
113   virtual void AddObserver(Observer* observer) = 0;
114   virtual void RemoveObserver(Observer* observer) = 0;
115
116   // Returns the list of device object paths associated with the given adapter
117   // identified by the D-Bus object path |adapter_path|.
118   virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter(
119       const dbus::ObjectPath& adapter_path) = 0;
120
121   // Obtain the properties for the device with object path |object_path|,
122   // any values should be copied if needed.
123   virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
124
125   // The ErrorCallback is used by device methods to indicate failure.
126   // It receives two arguments: the name of the error in |error_name| and
127   // an optional message in |error_message|.
128   typedef base::Callback<void(const std::string& error_name,
129                               const std::string& error_message)> ErrorCallback;
130
131   // Connects to the device with object path |object_path|, connecting any
132   // profiles that can be connected to and have been flagged as auto-connected;
133   // may be used to connect additional profiles for an already connected device,
134   // and succeeds if at least one profile is connected.
135   virtual void Connect(const dbus::ObjectPath& object_path,
136                        const base::Closure& callback,
137                        const ErrorCallback& error_callback) = 0;
138
139   // Disconnects the device with object path |object_path|, terminating
140   // the low-level ACL connection and any profiles using it.
141   virtual void Disconnect(const dbus::ObjectPath& object_path,
142                           const base::Closure& callback,
143                           const ErrorCallback& error_callback) = 0;
144
145   // Connects to the profile |uuid| on the device with object path
146   // |object_path|, provided that the profile has been registered with a
147   // handler on the local device.
148   virtual void ConnectProfile(const dbus::ObjectPath& object_path,
149                               const std::string& uuid,
150                               const base::Closure& callback,
151                               const ErrorCallback& error_callback) = 0;
152
153   // Disconnects from the profile |uuid| on the device with object path
154   // |object_path|.
155   virtual void DisconnectProfile(const dbus::ObjectPath& object_path,
156                                  const std::string& uuid,
157                                  const base::Closure& callback,
158                                  const ErrorCallback& error_callback) = 0;
159
160   // Initiates pairing with the device with object path |object_path| and
161   // retrieves all SDP records or GATT primary services. An agent must be
162   // registered to handle the pairing request.
163   virtual void Pair(const dbus::ObjectPath& object_path,
164                     const base::Closure& callback,
165                     const ErrorCallback& error_callback) = 0;
166
167   // Cancels an in-progress pairing with the device with object path
168   // |object_path| initiated by Pair().
169   virtual void CancelPairing(const dbus::ObjectPath& object_path,
170                              const base::Closure& callback,
171                              const ErrorCallback& error_callback) = 0;
172
173   // Creates the instance.
174   static BluetoothDeviceClient* Create(DBusClientImplementationType type);
175
176   // Constants used to indicate exceptional error conditions.
177   static const char kNoResponseError[];
178   static const char kUnknownDeviceError[];
179
180  protected:
181   BluetoothDeviceClient();
182
183  private:
184   DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClient);
185 };
186
187 }  // namespace chromeos
188
189 #endif  // CHROMEOS_DBUS_BLUETOOTH_DEVICE_CLIENT_H_