OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/nfc_property_set.h" | 5 #include "chromeos/dbus/nfc_property_set.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "third_party/cros_system_api/dbus/service_constants.h" | 8 #include "third_party/cros_system_api/dbus/service_constants.h" |
9 | 9 |
10 namespace chromeos { | 10 namespace chromeos { |
11 | 11 |
12 NfcPropertySet::NfcPropertySet(dbus::ObjectProxy* object_proxy, | 12 NfcPropertySet::NfcPropertySet(dbus::ObjectProxy* object_proxy, |
13 const std::string& interface, | 13 const std::string& interface, |
14 const PropertyChangedCallback& callback) | 14 const PropertyChangedCallback& callback) |
15 : dbus::PropertySet(object_proxy, interface, callback) { | 15 : dbus::PropertySet(object_proxy, interface, callback) { |
16 } | 16 } |
17 | 17 |
| 18 NfcPropertySet::~NfcPropertySet() { |
| 19 } |
| 20 |
18 void NfcPropertySet::ConnectSignals() { | 21 void NfcPropertySet::ConnectSignals() { |
19 object_proxy()->ConnectToSignal( | 22 object_proxy()->ConnectToSignal( |
20 interface(), | 23 interface(), |
21 nfc_common::kPropertyChangedSignal, | 24 nfc_common::kPropertyChangedSignal, |
22 base::Bind(&dbus::PropertySet::ChangedReceived, GetWeakPtr()), | 25 base::Bind(&dbus::PropertySet::ChangedReceived, GetWeakPtr()), |
23 base::Bind(&dbus::PropertySet::ChangedConnected, GetWeakPtr())); | 26 base::Bind(&dbus::PropertySet::ChangedConnected, GetWeakPtr())); |
24 } | 27 } |
25 | 28 |
| 29 void NfcPropertySet::SetAllPropertiesReceivedCallback( |
| 30 const base::Closure& callback) { |
| 31 on_get_all_callback_ = callback; |
| 32 } |
| 33 |
26 void NfcPropertySet::Get(dbus::PropertyBase* property, | 34 void NfcPropertySet::Get(dbus::PropertyBase* property, |
27 GetCallback callback) { | 35 GetCallback callback) { |
28 NOTREACHED() << "neard does not implement Get for properties."; | 36 NOTREACHED() << "neard does not implement Get for properties."; |
29 } | 37 } |
30 | 38 |
31 void NfcPropertySet::GetAll() { | 39 void NfcPropertySet::GetAll() { |
32 dbus::MethodCall method_call( | 40 dbus::MethodCall method_call( |
33 interface(), nfc_common::kGetProperties); | 41 interface(), nfc_common::kGetProperties); |
34 object_proxy()->CallMethod(&method_call, | 42 object_proxy()->CallMethod(&method_call, |
35 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 43 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
36 base::Bind(&dbus::PropertySet::OnGetAll, | 44 base::Bind(&dbus::PropertySet::OnGetAll, |
37 GetWeakPtr())); | 45 GetWeakPtr())); |
38 } | 46 } |
39 | 47 |
| 48 void NfcPropertySet::OnGetAll(dbus::Response* response) { |
| 49 // First invoke the superclass implementation. If the call to GetAll was |
| 50 // successful, this will invoke the PropertyChangedCallback passed to the |
| 51 // constructor for each individual property received through the call and |
| 52 // make sure that the values of the properties have been cached. This way, |
| 53 // all received properties will be available when |on_get_all_callback_| is |
| 54 // run. |
| 55 dbus::PropertySet::OnGetAll(response); |
| 56 if (response) { |
| 57 VLOG(2) << "NfcPropertySet::GetAll returned successfully."; |
| 58 if (!on_get_all_callback_.is_null()) |
| 59 on_get_all_callback_.Run(); |
| 60 } |
| 61 } |
| 62 |
40 void NfcPropertySet::Set(dbus::PropertyBase* property, | 63 void NfcPropertySet::Set(dbus::PropertyBase* property, |
41 SetCallback callback) { | 64 SetCallback callback) { |
42 dbus::MethodCall method_call( | 65 dbus::MethodCall method_call( |
43 interface(), nfc_common::kSetProperty); | 66 interface(), nfc_common::kSetProperty); |
| 67 dbus::MessageWriter writer(&method_call); |
| 68 writer.AppendString(property->name()); |
| 69 property->AppendSetValueToWriter(&writer); |
44 object_proxy()->CallMethod(&method_call, | 70 object_proxy()->CallMethod(&method_call, |
45 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 71 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
46 base::Bind(&dbus::PropertySet::OnSet, | 72 base::Bind(&dbus::PropertySet::OnSet, |
47 GetWeakPtr(), | 73 GetWeakPtr(), |
48 property, | 74 property, |
49 callback)); | 75 callback)); |
50 } | 76 } |
51 | 77 |
52 void NfcPropertySet::ChangedReceived(dbus::Signal* signal) { | 78 void NfcPropertySet::ChangedReceived(dbus::Signal* signal) { |
53 DCHECK(signal); | 79 DCHECK(signal); |
54 dbus::MessageReader reader(signal); | 80 dbus::MessageReader reader(signal); |
55 UpdatePropertyFromReader(&reader); | 81 UpdatePropertyFromReader(&reader); |
56 } | 82 } |
57 | 83 |
58 } // namespace chromeos | 84 } // namespace chromeos |
OLD | NEW |