summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/fake_nfc_manager_client.h
blob: 98dc8b5c9ffed140fbc03e0cf58a32f050fecb2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_DBUS_FAKE_NFC_MANAGER_CLIENT_H_
#define CHROMEOS_DBUS_FAKE_NFC_MANAGER_CLIENT_H_

#include <set>
#include <string>

#include "base/observer_list.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/nfc_manager_client.h"
#include "dbus/property.h"

namespace chromeos {

// FakeNfcManagerClient simulates the behavior of the NFC Daemon manager object
// and is used both in test cases in place of a mock and on the Linux desktop.
class CHROMEOS_EXPORT FakeNfcManagerClient : public NfcManagerClient {
 public:
  struct Properties : public NfcManagerClient::Properties {
    explicit Properties(const PropertyChangedCallback& callback);
    virtual ~Properties();

    // dbus::PropertySet overrides.
    virtual void Get(dbus::PropertyBase* property,
                     dbus::PropertySet::GetCallback callback) override;
    virtual void GetAll() override;
    virtual void Set(dbus::PropertyBase* property,
                     dbus::PropertySet::SetCallback callback) override;
  };

  FakeNfcManagerClient();
  virtual ~FakeNfcManagerClient();

  // NfcManagerClient overrides.
  virtual void Init(dbus::Bus* bus) override;
  virtual void AddObserver(Observer* observer) override;
  virtual void RemoveObserver(Observer* observer) override;
  virtual Properties* GetProperties() override;

  // Methods to simulate adapters getting added and removed.
  void AddAdapter(const std::string& adapter_path);
  void RemoveAdapter(const std::string& adapter_path);

  // Default path of an adapter that is simulated for testing.
  static const char kDefaultAdapterPath[];

 private:
  // Property callback passed when we create Properties* structures.
  void OnPropertyChanged(const std::string& property_name);

  // List of observers interested in event notifications.
  ObserverList<Observer> observers_;

  // Set containing the currently simulated adapters.
  std::set<dbus::ObjectPath> adapters_;

  // Fake properties object. This gets updated whenever AddAdapter or
  // RemoveAdapter gets called.
  scoped_ptr<Properties> properties_;

  DISALLOW_COPY_AND_ASSIGN(FakeNfcManagerClient);
};

}  // namespace chromeos

#endif  // CHROMEOS_DBUS_FAKE_NFC_MANAGER_CLIENT_H_