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