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

Side by Side Diff: dbus/property.h

Issue 893663002: Enhance the DBus interface for peerd (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix minor nits Created 5 years, 10 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 | « chromeos/dbus/peer_daemon_manager_client.cc ('k') | dbus/property.cc » ('j') | 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 #ifndef DBUS_PROPERTY_H_ 5 #ifndef DBUS_PROPERTY_H_
6 #define DBUS_PROPERTY_H_ 6 #define DBUS_PROPERTY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility>
11 #include <vector>
10 12
11 #include "base/basictypes.h" 13 #include "base/basictypes.h"
12 #include "base/bind.h" 14 #include "base/bind.h"
13 #include "base/callback.h" 15 #include "base/callback.h"
14 #include "dbus/dbus_export.h" 16 #include "dbus/dbus_export.h"
15 #include "dbus/message.h" 17 #include "dbus/message.h"
16 #include "dbus/object_proxy.h" 18 #include "dbus/object_proxy.h"
17 19
18 // D-Bus objects frequently provide sets of properties accessed via a 20 // D-Bus objects frequently provide sets of properties accessed via a
19 // standard interface of method calls and signals to obtain the current value, 21 // standard interface of method calls and signals to obtain the current value,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // if (property_name == properties.version.name()) { 153 // if (property_name == properties.version.name()) {
152 // // Handle version property changing 154 // // Handle version property changing
153 // } 155 // }
154 // } 156 // }
155 const std::string& name() const { return name_; } 157 const std::string& name() const { return name_; }
156 158
157 // Method used by PropertySet to retrieve the value from a MessageReader, 159 // Method used by PropertySet to retrieve the value from a MessageReader,
158 // no knowledge of the contained type is required, this method returns 160 // no knowledge of the contained type is required, this method returns
159 // true if its expected type was found, false if not. 161 // true if its expected type was found, false if not.
160 // Implementation provided by specialization. 162 // Implementation provided by specialization.
161 virtual bool PopValueFromReader(MessageReader*) = 0; 163 virtual bool PopValueFromReader(MessageReader* reader) = 0;
162 164
163 // Method used by PropertySet to append the set value to a MessageWriter, 165 // Method used by PropertySet to append the set value to a MessageWriter,
164 // no knowledge of the contained type is required. 166 // no knowledge of the contained type is required.
165 // Implementation provided by specialization. 167 // Implementation provided by specialization.
166 virtual void AppendSetValueToWriter(MessageWriter* writer) = 0; 168 virtual void AppendSetValueToWriter(MessageWriter* writer) = 0;
167 169
168 // Method used by test and stub implementations of dbus::PropertySet::Set 170 // Method used by test and stub implementations of dbus::PropertySet::Set
169 // to replace the property value with the set value without using a 171 // to replace the property value with the set value without using a
170 // dbus::MessageReader. 172 // dbus::MessageReader.
171 virtual void ReplaceValueWithSetValue() = 0; 173 virtual void ReplaceValueWithSetValue() = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 void RegisterProperty(const std::string& name, PropertyBase* property); 224 void RegisterProperty(const std::string& name, PropertyBase* property);
223 225
224 // Connects property change notification signals to the object, generally 226 // Connects property change notification signals to the object, generally
225 // called immediately after the object is created and before calls to other 227 // called immediately after the object is created and before calls to other
226 // methods. Sub-classes may override to use different D-Bus signals. 228 // methods. Sub-classes may override to use different D-Bus signals.
227 virtual void ConnectSignals(); 229 virtual void ConnectSignals();
228 230
229 // Methods connected by ConnectSignals() and called by dbus:: when 231 // Methods connected by ConnectSignals() and called by dbus:: when
230 // a property is changed. Sub-classes may override if the property 232 // a property is changed. Sub-classes may override if the property
231 // changed signal provides different arguments. 233 // changed signal provides different arguments.
232 virtual void ChangedReceived(Signal*); 234 virtual void ChangedReceived(Signal* signal);
233 virtual void ChangedConnected(const std::string& interface_name, 235 virtual void ChangedConnected(const std::string& interface_name,
234 const std::string& signal_name, 236 const std::string& signal_name,
235 bool success); 237 bool success);
236 238
237 // Callback for Get() method, |success| indicates whether or not the 239 // Callback for Get() method, |success| indicates whether or not the
238 // value could be retrived, if true the new value can be obtained by 240 // value could be retrived, if true the new value can be obtained by
239 // calling value() on the property. 241 // calling value() on the property.
240 typedef base::Callback<void(bool success)> GetCallback; 242 typedef base::Callback<void(bool success)> GetCallback;
241 243
242 // Requests an updated value from the remote object for |property| 244 // Requests an updated value from the remote object for |property|
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 // request, however the new value may not be available depending on the 371 // request, however the new value may not be available depending on the
370 // remote object. 372 // remote object.
371 virtual void Set(const T& value, dbus::PropertySet::SetCallback callback) { 373 virtual void Set(const T& value, dbus::PropertySet::SetCallback callback) {
372 set_value_ = value; 374 set_value_ = value;
373 property_set()->Set(this, callback); 375 property_set()->Set(this, callback);
374 } 376 }
375 377
376 // Method used by PropertySet to retrieve the value from a MessageReader, 378 // Method used by PropertySet to retrieve the value from a MessageReader,
377 // no knowledge of the contained type is required, this method returns 379 // no knowledge of the contained type is required, this method returns
378 // true if its expected type was found, false if not. 380 // true if its expected type was found, false if not.
379 bool PopValueFromReader(MessageReader*) override; 381 bool PopValueFromReader(MessageReader* reader) override;
380 382
381 // Method used by PropertySet to append the set value to a MessageWriter, 383 // Method used by PropertySet to append the set value to a MessageWriter,
382 // no knowledge of the contained type is required. 384 // no knowledge of the contained type is required.
383 // Implementation provided by specialization. 385 // Implementation provided by specialization.
384 void AppendSetValueToWriter(MessageWriter* writer) override; 386 void AppendSetValueToWriter(MessageWriter* writer) override;
385 387
386 // Method used by test and stub implementations of dbus::PropertySet::Set 388 // Method used by test and stub implementations of dbus::PropertySet::Set
387 // to replace the property value with the set value without using a 389 // to replace the property value with the set value without using a
388 // dbus::MessageReader. 390 // dbus::MessageReader.
389 void ReplaceValueWithSetValue() override { 391 void ReplaceValueWithSetValue() override {
390 value_ = set_value_; 392 value_ = set_value_;
391 property_set()->NotifyPropertyChanged(name()); 393 property_set()->NotifyPropertyChanged(name());
392 } 394 }
393 395
394 // Method used by test and stub implementations to directly set the 396 // Method used by test and stub implementations to directly set the
395 // value of a property. 397 // value of a property.
396 void ReplaceValue(const T& value) { 398 void ReplaceValue(const T& value) {
397 value_ = value; 399 value_ = value;
398 property_set()->NotifyPropertyChanged(name()); 400 property_set()->NotifyPropertyChanged(name());
399 } 401 }
400 402
403 // Method used by test and stub implementations to directly set the
404 // |set_value_| of a property.
405 void ReplaceSetValueForTesting(const T& value) { set_value_ = value; }
406
401 private: 407 private:
402 // Current cached value of the property. 408 // Current cached value of the property.
403 T value_; 409 T value_;
404 410
405 // Replacement value of the property. 411 // Replacement value of the property.
406 T set_value_; 412 T set_value_;
407 }; 413 };
408 414
409 template <> Property<uint8>::Property(); 415 template <> Property<uint8>::Property();
410 template <> bool Property<uint8>::PopValueFromReader(MessageReader* reader); 416 template <> bool Property<uint8>::PopValueFromReader(MessageReader* reader);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 template <> void Property<std::vector<ObjectPath> >::AppendSetValueToWriter( 484 template <> void Property<std::vector<ObjectPath> >::AppendSetValueToWriter(
479 MessageWriter* writer); 485 MessageWriter* writer);
480 extern template class Property<std::vector<ObjectPath> >; 486 extern template class Property<std::vector<ObjectPath> >;
481 487
482 template <> bool Property<std::vector<uint8> >::PopValueFromReader( 488 template <> bool Property<std::vector<uint8> >::PopValueFromReader(
483 MessageReader* reader); 489 MessageReader* reader);
484 template <> void Property<std::vector<uint8> >::AppendSetValueToWriter( 490 template <> void Property<std::vector<uint8> >::AppendSetValueToWriter(
485 MessageWriter* writer); 491 MessageWriter* writer);
486 extern template class Property<std::vector<uint8> >; 492 extern template class Property<std::vector<uint8> >;
487 493
494 template <>
495 bool Property<std::map<std::string, std::string>>::PopValueFromReader(
496 MessageReader* reader);
497 template <>
498 void Property<std::map<std::string, std::string>>::AppendSetValueToWriter(
499 MessageWriter* writer);
500 extern template class Property<std::map<std::string, std::string>>;
501
502 template <>
503 bool Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>::
504 PopValueFromReader(MessageReader* reader);
505 template <>
506 void Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>::
507 AppendSetValueToWriter(MessageWriter* writer);
508 extern template class Property<
509 std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>;
510
488 } // namespace dbus 511 } // namespace dbus
489 512
490 #endif // DBUS_PROPERTY_H_ 513 #endif // DBUS_PROPERTY_H_
OLDNEW
« no previous file with comments | « chromeos/dbus/peer_daemon_manager_client.cc ('k') | dbus/property.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698