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_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_
      6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/bind.h"
     11 #include "base/callback.h"
     12 #include "base/observer_list.h"
     13 #include "chromeos/chromeos_export.h"
     14 #include "chromeos/dbus/bluetooth_adapter_client.h"
     15 #include "chromeos/dbus/dbus_client_implementation_type.h"
     16 #include "dbus/object_path.h"
     17 #include "dbus/property.h"
     18 
     19 namespace chromeos {
     20 
     21 // FakeBluetoothAdapterClient simulates the behavior of the Bluetooth Daemon
     22 // adapter objects and is used both in test cases in place of a mock and on
     23 // the Linux desktop.
     24 class CHROMEOS_EXPORT FakeBluetoothAdapterClient
     25     : public BluetoothAdapterClient {
     26  public:
     27   struct Properties : public BluetoothAdapterClient::Properties {
     28     explicit Properties(const PropertyChangedCallback & callback);
     29     virtual ~Properties();
     30 
     31     // dbus::PropertySet override
     32     virtual void Get(dbus::PropertyBase* property,
     33                      dbus::PropertySet::GetCallback callback) OVERRIDE;
     34     virtual void GetAll() OVERRIDE;
     35     virtual void Set(dbus::PropertyBase* property,
     36                      dbus::PropertySet::SetCallback callback) OVERRIDE;
     37   };
     38 
     39   FakeBluetoothAdapterClient();
     40   virtual ~FakeBluetoothAdapterClient();
     41 
     42   // BluetoothAdapterClient override
     43   virtual void AddObserver(Observer* observer) OVERRIDE;
     44   virtual void RemoveObserver(Observer* observer) OVERRIDE;
     45   virtual std::vector<dbus::ObjectPath> GetAdapters() OVERRIDE;
     46   virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
     47       OVERRIDE;
     48   virtual void StartDiscovery(const dbus::ObjectPath& object_path,
     49                               const base::Closure& callback,
     50                               const ErrorCallback& error_callback) OVERRIDE;
     51   virtual void StopDiscovery(const dbus::ObjectPath& object_path,
     52                              const base::Closure& callback,
     53                              const ErrorCallback& error_callback) OVERRIDE;
     54   virtual void RemoveDevice(const dbus::ObjectPath& object_path,
     55                             const dbus::ObjectPath& device_path,
     56                             const base::Closure& callback,
     57                             const ErrorCallback& error_callback) OVERRIDE;
     58 
     59   // Mark the adapter and second adapter as visible or invisible.
     60   void SetVisible(bool visible);
     61   void SetSecondVisible(bool visible);
     62 
     63   // Object path, name and addresses of the adapters we emulate.
     64   static const char kAdapterPath[];
     65   static const char kAdapterName[];
     66   static const char kAdapterAddress[];
     67 
     68   static const char kSecondAdapterPath[];
     69   static const char kSecondAdapterName[];
     70   static const char kSecondAdapterAddress[];
     71 
     72  private:
     73   // Property callback passed when we create Properties* structures.
     74   void OnPropertyChanged(const std::string& property_name);
     75 
     76   // List of observers interested in event notifications from us.
     77   ObserverList<Observer> observers_;
     78 
     79   // Static properties we return.
     80   scoped_ptr<Properties> properties_;
     81   scoped_ptr<Properties> second_properties_;
     82 
     83   // Whether the adapter and second adapter should be visible or not.
     84   bool visible_;
     85   bool second_visible_;
     86 
     87   // Number of times we've been asked to discover.
     88   int discovering_count_;
     89 };
     90 
     91 }  // namespace chromeos
     92 
     93 #endif  // CHROMEOS_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_
     94