Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_ | |
| 6 #define CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback.h" | |
|
hashimoto
2015/03/19 08:00:23
nit: Seems unused.
dtapuska
2015/03/19 18:04:24
Done.
| |
| 13 #include "base/macros.h" | |
| 14 #include "base/values.h" | |
|
hashimoto
2015/03/19 08:00:23
ditto.
dtapuska
2015/03/19 18:04:24
Done.
| |
| 15 #include "chromeos/chromeos_export.h" | |
| 16 #include "chromeos/dbus/dbus_client.h" | |
| 17 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 18 #include "dbus/object_path.h" | |
| 19 #include "dbus/property.h" | |
| 20 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 // PrivetDaemonManagerClient is used to communicate with the | |
| 24 // privetd service. All methods should be called from | |
| 25 // the origin thread which initializes the DBusThreadManager instance. | |
| 26 class CHROMEOS_EXPORT PrivetDaemonManagerClient : public DBusClient { | |
| 27 public: | |
| 28 struct PairingInfoVariant { | |
| 29 enum class Type { | |
| 30 BLOB, | |
| 31 STRING, | |
| 32 }; | |
| 33 Type type; | |
| 34 std::string string; | |
| 35 std::vector<uint8_t> blob; | |
| 36 | |
| 37 bool operator==( | |
|
hashimoto
2015/03/19 08:00:23
Our style guide disallows operator overloading in
dtapuska
2015/03/19 18:04:24
It was used in the test case; which is permitted b
| |
| 38 const chromeos::PrivetDaemonManagerClient::PairingInfoVariant& other) | |
| 39 const { | |
| 40 return type == other.type && string == other.string && blob == other.blob; | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 class PairingInfoVariantMapProperty : public dbus::PropertyBase { | |
| 45 public: | |
| 46 using PairingInfoVariantMap = | |
| 47 std::map<std::string, | |
| 48 chromeos::PrivetDaemonManagerClient::PairingInfoVariant>; | |
|
hashimoto
2015/03/19 08:00:23
nit: "chromeos::PrivetDaemonManagerClient::" is no
dtapuska
2015/03/19 18:04:24
Done.
| |
| 49 | |
| 50 bool PopValueFromReader(dbus::MessageReader* reader) override; | |
| 51 void AppendSetValueToWriter(dbus::MessageWriter* writer) override; | |
| 52 void ReplaceValueWithSetValue() override; | |
| 53 void ReplaceSetValueForTesting(const PairingInfoVariantMap& value); | |
| 54 | |
| 55 const PairingInfoVariantMap& value() const { return value_; } | |
| 56 | |
| 57 private: | |
| 58 PairingInfoVariantMap value_; | |
| 59 PairingInfoVariantMap set_value_; | |
|
hashimoto
2015/03/19 08:00:23
It seems this member is non-empty only in tests.
I
dtapuska
2015/03/19 18:04:24
The PropertyBase makes special use of set_value vs
hashimoto
2015/03/20 06:41:48
What I'm curious about is if there is any chance A
dtapuska
2015/03/20 13:47:55
Done.
| |
| 60 }; | |
| 61 | |
| 62 // Structure of properties associated with a privet Manager. | |
| 63 class ManagerProperties : public dbus::PropertySet { | |
|
hashimoto
2015/03/19 08:00:23
nit: PrivetDaemonManagerClient::ManagerProperties
dtapuska
2015/03/19 18:04:24
Done.
| |
| 64 public: | |
| 65 ManagerProperties(dbus::ObjectProxy* object_proxy, | |
| 66 const std::string& interface_name, | |
| 67 const PropertyChangedCallback& callback); | |
| 68 ~ManagerProperties() override; | |
| 69 | |
| 70 // State of WiFi bootstrapping. | |
| 71 // Values are "disabled", "waiting", "connecting", "monitoring". | |
| 72 const std::string& wifi_bootstrap_state() const { | |
| 73 return wifi_bootstrap_state_.value(); | |
| 74 } | |
| 75 | |
| 76 // State of GCD bootstrapping. | |
| 77 // Values are "disabled", "offline", "connecting", "waiting", "registering", | |
| 78 // "online". | |
| 79 const std::string& gcd_boostrap_state() const { | |
| 80 return gcd_bootstrap_state_.value(); | |
| 81 } | |
| 82 | |
| 83 // State of device pairing. The map will contain the following keys. | |
|
hashimoto
2015/03/19 08:00:23
Why don't you just provide getter methods for each
dtapuska
2015/03/19 18:04:24
Done.
| |
| 84 // "sessionId" - ID of the pairing session; generated by device | |
| 85 // "mode" - Selected type of pairing from /privet/v3/pairing/start | |
| 86 // (e.g. "pinCode" or "embeddedCode") | |
| 87 // "code" - The pin code or embedded code as appropriate to the | |
| 88 // "mode" value. See design document. | |
|
hashimoto
2015/03/19 08:00:23
Please add a URL to a publicly available document.
dtapuska
2015/03/19 18:04:24
Adjusted comments per class rewrite.
| |
| 89 const std::map<std::string, PairingInfoVariant>& pairing_info() const { | |
|
hashimoto
2015/03/19 08:00:23
nit: Please use the typedef above.
dtapuska
2015/03/19 18:04:24
Done.
| |
| 90 return pairing_info_.value(); | |
| 91 } | |
| 92 | |
| 93 // Concise note describing a peer. Suitable for display to the user. | |
| 94 const std::string& description() const { return description_.value(); } | |
| 95 | |
| 96 // Concise name describing a peer. Suitable for display to the user. | |
| 97 const std::string& name() const { return name_.value(); } | |
| 98 | |
| 99 private: | |
| 100 dbus::Property<std::string> wifi_bootstrap_state_; | |
| 101 dbus::Property<std::string> gcd_bootstrap_state_; | |
| 102 PairingInfoVariantMapProperty pairing_info_; | |
| 103 dbus::Property<std::string> description_; | |
| 104 dbus::Property<std::string> name_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(ManagerProperties); | |
| 107 }; | |
| 108 | |
| 109 // Interface for observing changes from a apmanager daemon. | |
| 110 class Observer { | |
| 111 public: | |
| 112 virtual ~Observer(); | |
| 113 | |
| 114 // Called when the manager has been added. | |
| 115 virtual void ManagerAdded() = 0; | |
| 116 | |
| 117 // Called when the manager has been removed. | |
| 118 virtual void ManagerRemoved() = 0; | |
| 119 | |
| 120 // Called when the manager has a change in value of the property named | |
| 121 // |property_name|. | |
| 122 virtual void ManagerPropertyChanged(const std::string& property_name) = 0; | |
| 123 }; | |
| 124 | |
| 125 ~PrivetDaemonManagerClient() override; | |
| 126 | |
| 127 // Factory function, creates a new instance which is owned by the caller. | |
| 128 // For normal usage, access the singleton via DBusThreadManager::Get(). | |
| 129 static PrivetDaemonManagerClient* Create(); | |
| 130 | |
| 131 // Adds and removes observers for events on all apmanager | |
| 132 // events. | |
| 133 virtual void AddObserver(Observer* observer) = 0; | |
| 134 virtual void RemoveObserver(Observer* observer) = 0; | |
| 135 | |
| 136 // Calls SetDescription method. | |
| 137 // |callback| is called with its |call_status| argument set to | |
| 138 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 139 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 140 virtual void SetDescription(const std::string& description, | |
| 141 const VoidDBusMethodCallback& callback) = 0; | |
| 142 | |
| 143 // Obtains the properties for the manager any values should be | |
| 144 // copied if needed. | |
| 145 virtual const ManagerProperties* GetManagerProperties() = 0; | |
| 146 | |
| 147 protected: | |
| 148 // Create() should be used instead. | |
| 149 PrivetDaemonManagerClient(); | |
| 150 | |
| 151 private: | |
| 152 DISALLOW_COPY_AND_ASSIGN(PrivetDaemonManagerClient); | |
| 153 }; | |
| 154 | |
| 155 } // namespace chromeos | |
| 156 | |
| 157 #endif // CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_ | |
| OLD | NEW |