| 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 void ReplaceSetValueForTesting(const PairingInfo& value); |
| 57 |
| 58 const PairingInfo& value() const { return value_; } |
| 59 |
| 60 private: |
| 61 PairingInfo value_; |
| 62 PairingInfo set_value_; |
| 63 }; |
| 64 |
| 65 // Structure of properties associated with a privet Manager. |
| 66 class Properties : public dbus::PropertySet { |
| 67 public: |
| 68 Properties(dbus::ObjectProxy* object_proxy, |
| 69 const std::string& interface_name, |
| 70 const PropertyChangedCallback& callback); |
| 71 ~Properties() override; |
| 72 |
| 73 // State of WiFi bootstrapping. |
| 74 // Values are "disabled", "waiting", "connecting", "monitoring". |
| 75 const std::string& wifi_bootstrap_state() const { |
| 76 return wifi_bootstrap_state_.value(); |
| 77 } |
| 78 |
| 79 // State of GCD bootstrapping. |
| 80 // Values are "disabled", "offline", "connecting", "waiting", "registering", |
| 81 // "online". |
| 82 const std::string& gcd_boostrap_state() const { |
| 83 return gcd_bootstrap_state_.value(); |
| 84 } |
| 85 |
| 86 // State of device pairing. |
| 87 const PairingInfo& pairing_info() const { return pairing_info_.value(); } |
| 88 |
| 89 // Concise note describing a peer. Suitable for display to the user. |
| 90 const std::string& description() const { return description_.value(); } |
| 91 |
| 92 // Concise name describing a peer. Suitable for display to the user. |
| 93 const std::string& name() const { return name_.value(); } |
| 94 |
| 95 private: |
| 96 dbus::Property<std::string> wifi_bootstrap_state_; |
| 97 dbus::Property<std::string> gcd_bootstrap_state_; |
| 98 PairingInfoProperty pairing_info_; |
| 99 dbus::Property<std::string> description_; |
| 100 dbus::Property<std::string> name_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(Properties); |
| 103 }; |
| 104 |
| 105 // Interface for observing changes from a apmanager daemon. |
| 106 class Observer { |
| 107 public: |
| 108 virtual ~Observer(); |
| 109 |
| 110 // Called when the manager has been added. |
| 111 virtual void ManagerAdded() = 0; |
| 112 |
| 113 // Called when the manager has been removed. |
| 114 virtual void ManagerRemoved() = 0; |
| 115 |
| 116 // Called when the manager has a change in value of the property named |
| 117 // |property_name|. |
| 118 virtual void ManagerPropertyChanged(const std::string& property_name) = 0; |
| 119 }; |
| 120 |
| 121 ~PrivetDaemonManagerClient() override; |
| 122 |
| 123 // Factory function, creates a new instance which is owned by the caller. |
| 124 // For normal usage, access the singleton via DBusThreadManager::Get(). |
| 125 static PrivetDaemonManagerClient* Create(); |
| 126 |
| 127 // Adds and removes observers for events on all apmanager |
| 128 // events. |
| 129 virtual void AddObserver(Observer* observer) = 0; |
| 130 virtual void RemoveObserver(Observer* observer) = 0; |
| 131 |
| 132 // Calls SetDescription method. |
| 133 // |callback| is called with its |call_status| argument set to |
| 134 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, |
| 135 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. |
| 136 virtual void SetDescription(const std::string& description, |
| 137 const VoidDBusMethodCallback& callback) = 0; |
| 138 |
| 139 // Obtains the properties for the manager any values should be |
| 140 // copied if needed. |
| 141 virtual const Properties* GetProperties() = 0; |
| 142 |
| 143 protected: |
| 144 // Create() should be used instead. |
| 145 PrivetDaemonManagerClient(); |
| 146 |
| 147 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(PrivetDaemonManagerClient); |
| 149 }; |
| 150 |
| 151 } // namespace chromeos |
| 152 |
| 153 #endif // CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_ |
| OLD | NEW |