summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/nfc_property_set.h
blob: 4b5016ad759ea65b7044aa20b7debfdd37925962 (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
// Copyright 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_NFC_PROPERTY_SET_H_
#define CHROMEOS_DBUS_NFC_PROPERTY_SET_H_

#include <string>

#include "base/callback.h"
#include "base/macros.h"
#include "dbus/message.h"
#include "dbus/object_proxy.h"
#include "dbus/property.h"

namespace chromeos {

// neard doesn't use the standard D-Bus interfaces for property access and
// instead defines property accessor methods in each D-Bus interface. This
// class customizes dbus::PropertySet to generate the correct method call to
// get all properties, connect to the correct signal and parse it correctly.
class NfcPropertySet : public dbus::PropertySet {
 public:
  NfcPropertySet(dbus::ObjectProxy* object_proxy,
                 const std::string& interface,
                 const PropertyChangedCallback& callback);

  // Destructor; we don't hold on to any references or memory that needs
  // explicit clean-up, but clang thinks we might.
  ~NfcPropertySet() override;

  // Caches |callback| so that it will be invoked after a call to GetAll()
  // has successfully received all existing properties from the remote object.
  void SetAllPropertiesReceivedCallback(const base::Closure& callback);

  // dbus::PropertySet overrides
  void ConnectSignals() override;
  void Get(dbus::PropertyBase* property, GetCallback callback) override;
  void GetAll() override;
  void OnGetAll(dbus::Response* response) override;
  void Set(dbus::PropertyBase* property, SetCallback callback) override;
  void ChangedReceived(dbus::Signal* signal) override;

 protected:
  const base::Closure& on_get_all_callback() { return on_get_all_callback_; }

 private:
  void OnGetAllError(dbus::ErrorResponse* response);

  // Optional callback used to notify clients when all properties were received
  // after a call to GetAll.
  base::Closure on_get_all_callback_;

  base::WeakPtrFactory<NfcPropertySet> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(NfcPropertySet);
};

}  // namespace chromeos

#endif  // CHROMEOS_DBUS_NFC_PROPERTY_SET_H_