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 <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "chromeos/chromeos_export.h" | |
| 13 #include "chromeos/dbus/dbus_client.h" | |
| 14 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 15 #include "dbus/object_path.h" | |
| 16 #include "dbus/property.h" | |
| 17 | |
| 18 namespace chromeos { | |
| 19 | |
| 20 // PrivetDaemonManagerClient is used to communicate with the | |
| 21 // privetd service. All methods should be called from | |
| 22 // the origin thread which initializes the DBusThreadManager instance. | |
| 23 class CHROMEOS_EXPORT PrivetDaemonManagerClient : public DBusClient { | |
| 24 public: | |
| 25 class PairingInfo { | |
| 26 public: | |
| 27 // Returns the value of the pairing code; not necessarily a printable | |
| 28 // string. | |
| 29 const std::vector<uint8_t>& code() const { return code_; } | |
| 30 void set_code(const uint8_t* data, size_t length) { | |
| 31 code_.assign(data, data + length); | |
| 32 } | |
| 33 | |
| 34 // Returns the selected type of pairing (e.g. "pinCode", "embeddedCode"). | |
| 35 const std::string& mode() const { return mode_; } | |
| 36 void set_mode(const std::string& mode) { mode_ = mode; } | |
| 37 | |
| 38 // Returns a unique identifier representing the pairing session. | |
| 39 const std::string& session_id() const { return session_id_; } | |
| 40 void set_session_id(const std::string& id) { session_id_ = id; } | |
| 41 | |
| 42 // Resets the values to empty values. | |
| 43 void Clear(); | |
| 44 | |
| 45 private: | |
| 46 std::vector<uint8_t> code_; | |
| 47 std::string mode_; | |
| 48 std::string session_id_; | |
| 49 }; | |
| 50 | |
| 51 class PairingInfoProperty : public dbus::PropertyBase { | |
| 52 public: | |
| 53 bool PopValueFromReader(dbus::MessageReader* reader) override; | |
| 54 void AppendSetValueToWriter(dbus::MessageWriter* writer) override; | |
| 55 void ReplaceValueWithSetValue() override; | |
| 56 | |
| 57 const PairingInfo& value() const { return value_; } | |
| 58 | |
| 59 private: | |
| 60 PairingInfo value_; | |
| 61 }; | |
| 62 | |
| 63 // Structure of properties associated with a privet Manager. | |
| 64 class Properties : public dbus::PropertySet { | |
| 65 public: | |
| 66 Properties(dbus::ObjectProxy* object_proxy, | |
| 67 const std::string& interface_name, | |
| 68 const PropertyChangedCallback& callback); | |
| 69 ~Properties() override; | |
| 70 | |
| 71 // State of WiFi bootstrapping. | |
| 72 // Values are "disabled", "waiting", "connecting", "monitoring". | |
| 73 const std::string& wifi_bootstrap_state() const { | |
| 74 return wifi_bootstrap_state_.value(); | |
| 75 } | |
| 76 | |
| 77 // State of GCD bootstrapping. | |
| 78 // Values are "disabled", "offline", "connecting", "waiting", "registering", | |
| 79 // "online". | |
| 80 const std::string& gcd_boostrap_state() const { | |
| 81 return gcd_bootstrap_state_.value(); | |
| 82 } | |
| 83 | |
| 84 // State of device pairing. | |
| 85 const PairingInfo& pairing_info() const { return pairing_info_.value(); } | |
| 86 | |
| 87 // Concise note describing a peer. Suitable for display to the user. | |
| 88 const std::string& description() const { return description_.value(); } | |
| 89 | |
| 90 // Concise name describing a peer. Suitable for display to the user. | |
| 91 const std::string& name() const { return name_.value(); } | |
| 92 | |
| 93 private: | |
| 94 dbus::Property<std::string> wifi_bootstrap_state_; | |
| 95 dbus::Property<std::string> gcd_bootstrap_state_; | |
| 96 PairingInfoProperty pairing_info_; | |
| 97 dbus::Property<std::string> description_; | |
| 98 dbus::Property<std::string> name_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(Properties); | |
| 101 }; | |
| 102 | |
| 103 // Interface for observing changes from a apmanager daemon. | |
|
hashimoto
2015/03/20 15:22:57
nit: Why is "apmanager daemon" mentioned here and
dtapuska
2015/03/20 15:38:34
Done.
| |
| 104 class Observer { | |
| 105 public: | |
| 106 virtual ~Observer(); | |
| 107 | |
| 108 // Called when the manager has been added. | |
| 109 virtual void ManagerAdded() = 0; | |
| 110 | |
| 111 // Called when the manager has been removed. | |
| 112 virtual void ManagerRemoved() = 0; | |
| 113 | |
| 114 // Called when the manager has a change in value of the property named | |
| 115 // |property_name|. | |
| 116 virtual void ManagerPropertyChanged(const std::string& property_name) = 0; | |
| 117 }; | |
| 118 | |
| 119 ~PrivetDaemonManagerClient() override; | |
| 120 | |
| 121 // Factory function, creates a new instance which is owned by the caller. | |
| 122 // For normal usage, access the singleton via DBusThreadManager::Get(). | |
| 123 static PrivetDaemonManagerClient* Create(); | |
| 124 | |
| 125 // Adds and removes observers for events on all apmanager | |
| 126 // events. | |
| 127 virtual void AddObserver(Observer* observer) = 0; | |
| 128 virtual void RemoveObserver(Observer* observer) = 0; | |
| 129 | |
| 130 // Calls SetDescription method. | |
| 131 // |callback| is called with its |call_status| argument set to | |
| 132 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 133 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 134 virtual void SetDescription(const std::string& description, | |
| 135 const VoidDBusMethodCallback& callback) = 0; | |
| 136 | |
| 137 // Obtains the properties for the manager any values should be | |
| 138 // copied if needed. | |
| 139 virtual const Properties* GetProperties() = 0; | |
| 140 | |
| 141 protected: | |
| 142 // Create() should be used instead. | |
| 143 PrivetDaemonManagerClient(); | |
| 144 | |
| 145 private: | |
| 146 DISALLOW_COPY_AND_ASSIGN(PrivetDaemonManagerClient); | |
| 147 }; | |
| 148 | |
| 149 } // namespace chromeos | |
| 150 | |
| 151 #endif // CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_ | |
| OLD | NEW |