summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/bluetooth_media_client.h
blob: 1bb554785eec79a2ec1717d9e880b18acaca4e5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_DBUS_BLUETOOTH_MEDIA_CLIENT_H_
#define CHROMEOS_DBUS_BLUETOOTH_MEDIA_CLIENT_H_

#include <memory>
#include <string>
#include <vector>

#include "base/callback.h"
#include "base/values.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/dbus_client.h"
#include "dbus/object_path.h"
#include "dbus/property.h"

namespace chromeos {

// BluetoothMediaClient is used to communicate with the Media interface of a
// local Bluetooth adapter.
class CHROMEOS_EXPORT BluetoothMediaClient : public DBusClient {
 public:
  // Properties used to register a Media Endpoint.
  struct CHROMEOS_EXPORT EndpointProperties {
    EndpointProperties();
    ~EndpointProperties();

    // UUID of the profile implemented by the endpoint.
    std::string uuid;

    // Assigned codec value supported by the endpoint. The byte should match the
    // codec specification indicated by the UUID.
    // Since SBC codec is mandatory for A2DP, the default value of codec should
    // be 0x00.
    uint8_t codec;

    // Capabilities of the endpoints. The order of bytes should match the bit
    // arrangement in the specification indicated by the UUID.
    std::vector<uint8_t> capabilities;
  };

  class Observer {
   public:
    virtual ~Observer() {}

    // Called when the Media object with object path |object_path| is added to
    // the system.
    virtual void MediaAdded(const dbus::ObjectPath& object_path) {}

    // Called when the Media object with object path |object_path| is removed
    // from the system.
    virtual void MediaRemoved(const dbus::ObjectPath& object_path) {}
  };

  // Constants used to indicate exceptional error conditions.
  static const char kNoResponseError[];

  // The string representation for the 128-bit UUID for A2DP Sink.
  static const char kBluetoothAudioSinkUUID[];

  ~BluetoothMediaClient() override;

  // The ErrorCallback is used by media API methods to indicate failure.
  // It receives two arguments: the name of the error in |error_name| and
  // an optional message in |error_message|.
  typedef base::Callback<void(const std::string& error_name,
                              const std::string& error_message)> ErrorCallback;

  // Adds and removes observers for events on all Media objects. Check the
  // |object_path| parameter of observer methods to determine which Media object
  // is issuing the event.
  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;

  // Registers a media endpoint to sender at the D-Bus object path
  // |endpoint_path|. |properties| specifies profile UUID which the endpoint is
  // for, Codec implemented by the endpoint and the Capabilities of the
  // endpoint.
  virtual void RegisterEndpoint(const dbus::ObjectPath& object_path,
                                const dbus::ObjectPath& endpoint_path,
                                const EndpointProperties& properties,
                                const base::Closure& callback,
                                const ErrorCallback& error_callback) = 0;

  // Unregisters the media endpoint with the D-Bus object path |endpoint_path|.
  virtual void UnregisterEndpoint(const dbus::ObjectPath& object_path,
                                  const dbus::ObjectPath& endpoint_path,
                                  const base::Closure& callback,
                                  const ErrorCallback& error_callback) = 0;

  // TODO(mcchou): The RegisterPlayer and UnregisterPlayer methods are not
  // included, since they are not used. These two methods may be added later.

  static BluetoothMediaClient* Create();

 protected:
  BluetoothMediaClient();

 private:
  DISALLOW_COPY_AND_ASSIGN(BluetoothMediaClient);
};

}  // namespace chromeos

#endif  // CHROMEOS_DBUS_BLUETOOTH_MEDIA_CLIENT_H_