1// Copyright (c) 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_CRAS_AUDIO_CLIENT_H_
6#define CHROMEOS_DBUS_CRAS_AUDIO_CLIENT_H_
7
8#include "base/callback.h"
9#include "base/observer_list.h"
10#include "chromeos/chromeos_export.h"
11#include "chromeos/dbus/audio_node.h"
12#include "chromeos/dbus/dbus_client.h"
13#include "chromeos/dbus/volume_state.h"
14
15namespace chromeos {
16
17// CrasAudioClient is used to communicate with the cras audio dbus interface.
18class CHROMEOS_EXPORT CrasAudioClient : public DBusClient {
19 public:
20  // Interface for observing changes from the cras audio changes.
21  class Observer {
22   public:
23    // Called when cras audio client starts or re-starts, which happens when
24    // cros device powers up or restarted.
25    virtual void AudioClientRestarted();
26
27    // Called when audio output mute state changed to new state of |mute_on|.
28    virtual void OutputMuteChanged(bool mute_on);
29
30    // Called when audio input mute state changed to new state of |mute_on|.
31    virtual void InputMuteChanged(bool mute_on);
32
33    // Called when audio nodes change.
34    virtual void NodesChanged();
35
36    // Called when active audio output node changed to new node with |node_id|.
37    virtual void ActiveOutputNodeChanged(uint64 node_id);
38
39    // Called when active audio input node changed to new node with |node_id|.
40    virtual void ActiveInputNodeChanged(uint64 node_id);
41
42   protected:
43    virtual ~Observer();
44  };
45
46  virtual ~CrasAudioClient();
47
48  // Adds and removes the observer.
49  virtual void AddObserver(Observer* observer) = 0;
50  virtual void RemoveObserver(Observer* observer) = 0;
51  // Returns true if this object has the given observer.
52  virtual bool HasObserver(Observer* observer) = 0;
53
54  // GetVolumeStateCallback is used for GetVolumeState method. It receives
55  // 2 arguments, |volume_state| which containing both input and  output volume
56  // state data, and |success| which indicates whether or not the request
57  // succeeded.
58  typedef base::Callback<void(const VolumeState&, bool)> GetVolumeStateCallback;
59
60  // GetNodesCallback is used for GetNodes method. It receives 2 arguments,
61  // |audio_nodes| which containing a list of audio nodes data and
62  // |success| which indicates whether or not the request succeeded.
63  typedef base::Callback<void(const AudioNodeList&, bool)> GetNodesCallback;
64
65  // ErrorCallback is used for cras dbus method error response. It receives 2
66  // arguments, |error_name| indicates the dbus error name, and |error_message|
67  // contains the detailed dbus error message.
68  typedef base::Callback<void(const std::string&,
69                              const std::string&)> ErrorCallback;
70
71  // Gets the volume state, asynchronously.
72  virtual void GetVolumeState(const GetVolumeStateCallback& callback) = 0;
73
74  // Gets an array of audio input and output nodes.
75  virtual void GetNodes(const GetNodesCallback& callback,
76                        const ErrorCallback& error_callback) = 0;
77
78  // Sets output volume of the given |node_id| to |volume|, in the rage of
79  // [0, 100].
80  virtual void SetOutputNodeVolume(uint64 node_id, int32 volume) = 0;
81
82  // Sets output mute from user action.
83  virtual void SetOutputUserMute(bool mute_on) = 0;
84
85  // Sets input gain of the given |node_id| to |gain|, in the range of
86  // [0, 100].
87  virtual void SetInputNodeGain(uint64 node_id, int32 gain) = 0;
88
89  // Sets input mute state to |mute_on| value.
90  virtual void SetInputMute(bool mute_on) = 0;
91
92  // Sets the active output node to |node_id|.
93  virtual void SetActiveOutputNode(uint64 node_id) = 0;
94
95  // Sets the active input node to |node_id|.
96  virtual void SetActiveInputNode(uint64 node_id) = 0;
97
98  // Creates the instance.
99  static CrasAudioClient* Create();
100
101 protected:
102  // Create() should be used instead.
103  CrasAudioClient();
104
105 private:
106
107  DISALLOW_COPY_AND_ASSIGN(CrasAudioClient);
108};
109
110}  // namespace chromeos
111
112#endif  // CHROMEOS_DBUS_CRAS_AUDIO_CLIENT_H_
113