Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: dbus/property.cc

Issue 1368713002: dbus: add support for synchronous PropertySet::Get (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dbus/property.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "dbus/property.h" 5 #include "dbus/property.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (property->is_valid()) { 126 if (property->is_valid()) {
127 property->set_valid(false); 127 property->set_valid(false);
128 NotifyPropertyChanged(property->name()); 128 NotifyPropertyChanged(property->name());
129 } 129 }
130 } 130 }
131 131
132 if (!callback.is_null()) 132 if (!callback.is_null())
133 callback.Run(response); 133 callback.Run(response);
134 } 134 }
135 135
136 bool PropertySet::GetAndBlock(PropertyBase* property) {
137 MethodCall method_call(kPropertiesInterface, kPropertiesGet);
138 MessageWriter writer(&method_call);
139 writer.AppendString(interface());
140 writer.AppendString(property->name());
141
142 DCHECK(object_proxy_);
143 scoped_ptr<dbus::Response> response(
144 object_proxy_->CallMethodAndBlock(&method_call,
145 ObjectProxy::TIMEOUT_USE_DEFAULT));
146
147 if (!response.get()) {
148 LOG(WARNING) << property->name() << ": GetAndBlock: failed.";
149 return false;
150 }
151
152 MessageReader reader(response.get());
153 if (property->PopValueFromReader(&reader)) {
154 property->set_valid(true);
155 NotifyPropertyChanged(property->name());
156 } else {
157 if (property->is_valid()) {
158 property->set_valid(false);
159 NotifyPropertyChanged(property->name());
160 }
161 }
162 return true;
163 }
164
136 void PropertySet::GetAll() { 165 void PropertySet::GetAll() {
137 MethodCall method_call(kPropertiesInterface, kPropertiesGetAll); 166 MethodCall method_call(kPropertiesInterface, kPropertiesGetAll);
138 MessageWriter writer(&method_call); 167 MessageWriter writer(&method_call);
139 writer.AppendString(interface()); 168 writer.AppendString(interface());
140 169
141 DCHECK(object_proxy_); 170 DCHECK(object_proxy_);
142 object_proxy_->CallMethod(&method_call, 171 object_proxy_->CallMethod(&method_call,
143 ObjectProxy::TIMEOUT_USE_DEFAULT, 172 ObjectProxy::TIMEOUT_USE_DEFAULT,
144 base::Bind(&PropertySet::OnGetAll, 173 base::Bind(&PropertySet::OnGetAll,
145 weak_ptr_factory_.GetWeakPtr())); 174 weak_ptr_factory_.GetWeakPtr()));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 bool PropertySet::SetAndBlock(PropertyBase* property) { 206 bool PropertySet::SetAndBlock(PropertyBase* property) {
178 MethodCall method_call(kPropertiesInterface, kPropertiesSet); 207 MethodCall method_call(kPropertiesInterface, kPropertiesSet);
179 MessageWriter writer(&method_call); 208 MessageWriter writer(&method_call);
180 writer.AppendString(interface()); 209 writer.AppendString(interface());
181 writer.AppendString(property->name()); 210 writer.AppendString(property->name());
182 property->AppendSetValueToWriter(&writer); 211 property->AppendSetValueToWriter(&writer);
183 212
184 DCHECK(object_proxy_); 213 DCHECK(object_proxy_);
185 scoped_ptr<dbus::Response> response( 214 scoped_ptr<dbus::Response> response(
186 object_proxy_->CallMethodAndBlock(&method_call, 215 object_proxy_->CallMethodAndBlock(&method_call,
187 ObjectProxy::TIMEOUT_USE_DEFAULT)); 216 ObjectProxy::TIMEOUT_USE_DEFAULT));
188 if (response.get()) 217 if (response.get())
189 return true; 218 return true;
190 return false; 219 return false;
191 } 220 }
192 221
193 void PropertySet::OnSet(PropertyBase* property, 222 void PropertySet::OnSet(PropertyBase* property,
194 SetCallback callback, 223 SetCallback callback,
195 Response* response) { 224 Response* response) {
196 LOG_IF(WARNING, !response) << property->name() << ": Set: failed."; 225 LOG_IF(WARNING, !response) << property->name() << ": Set: failed.";
197 if (!callback.is_null()) 226 if (!callback.is_null())
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 template class Property<double>; 671 template class Property<double>;
643 template class Property<std::string>; 672 template class Property<std::string>;
644 template class Property<ObjectPath>; 673 template class Property<ObjectPath>;
645 template class Property<std::vector<std::string> >; 674 template class Property<std::vector<std::string> >;
646 template class Property<std::vector<ObjectPath> >; 675 template class Property<std::vector<ObjectPath> >;
647 template class Property<std::vector<uint8> >; 676 template class Property<std::vector<uint8> >;
648 template class Property<std::map<std::string, std::string>>; 677 template class Property<std::map<std::string, std::string>>;
649 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; 678 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>;
650 679
651 } // namespace dbus 680 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/property.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698