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
18namespace 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.
23class 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  // 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