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 "dbus/object_path.h"
     16 #include "dbus/property.h"
     17 
     18 namespace chromeos {
     19 
     20 // FakeBluetoothAdapterClient simulates the behavior of the Bluetooth Daemon
     21 // adapter objects and is used both in test cases in place of a mock and on
     22 // the Linux desktop.
     23 class CHROMEOS_EXPORT FakeBluetoothAdapterClient
     24     : public BluetoothAdapterClient {
     25  public:
     26   struct Properties : public BluetoothAdapterClient::Properties {
     27     explicit Properties(const PropertyChangedCallback & callback);
     28     virtual ~Properties();
     29 
     30     // dbus::PropertySet override
     31     virtual void Get(dbus::PropertyBase* property,
     32                      dbus::PropertySet::GetCallback callback) OVERRIDE;
     33     virtual void GetAll() OVERRIDE;
     34     virtual void Set(dbus::PropertyBase* property,
     35                      dbus::PropertySet::SetCallback callback) OVERRIDE;
     36   };
     37 
     38   FakeBluetoothAdapterClient();
     39   virtual ~FakeBluetoothAdapterClient();
     40 
     41   // BluetoothAdapterClient overrides
     42   virtual void Init(dbus::Bus* bus) 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   // Sets the current simulation timeout interval.
     60   void SetSimulationIntervalMs(int interval_ms);
     61 
     62   // Mark the adapter and second adapter as visible or invisible.
     63   void SetVisible(bool visible);
     64   void SetSecondVisible(bool visible);
     65 
     66   // Object path, name and addresses of the adapters we emulate.
     67   static const char kAdapterPath[];
     68   static const char kAdapterName[];
     69   static const char kAdapterAddress[];
     70 
     71   static const char kSecondAdapterPath[];
     72   static const char kSecondAdapterName[];
     73   static const char kSecondAdapterAddress[];
     74 
     75  private:
     76   // Property callback passed when we create Properties* structures.
     77   void OnPropertyChanged(const std::string& property_name);
     78 
     79   // Posts the delayed task represented by |callback| onto the current
     80   // message loop to be executed after |simulation_interval_ms_| milliseconds.
     81   void PostDelayedTask(const base::Closure& callback);
     82 
     83   // List of observers interested in event notifications from us.
     84   ObserverList<Observer> observers_;
     85 
     86   // Static properties we return.
     87   scoped_ptr<Properties> properties_;
     88   scoped_ptr<Properties> second_properties_;
     89 
     90   // Whether the adapter and second adapter should be visible or not.
     91   bool visible_;
     92   bool second_visible_;
     93 
     94   // Number of times we've been asked to discover.
     95   int discovering_count_;
     96 
     97   // Current timeout interval used when posting delayed tasks.
     98   int simulation_interval_ms_;
     99 };
    100 
    101 }  // namespace chromeos
    102 
    103 #endif  // CHROMEOS_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_
    104