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