Fix translation extraction failure.
[chromium-blink-merge.git] / chromeos / dbus / privet_daemon_manager_client.h
blob8c490d8edeff1dfbad593b1671ab1a9651ae984b
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.
5 #ifndef CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_
8 #include <string>
9 #include <vector>
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"
18 namespace chromeos {
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 PairingInfo();
28 ~PairingInfo();
30 // Returns the value of the pairing code; not necessarily a printable
31 // string.
32 const std::vector<uint8_t>& code() const { return code_; }
33 void set_code(const uint8_t* data, size_t length) {
34 code_.assign(data, data + length);
37 // Returns the selected type of pairing (e.g. "pinCode", "embeddedCode").
38 const std::string& mode() const { return mode_; }
39 void set_mode(const std::string& mode) { mode_ = mode; }
41 // Returns a unique identifier representing the pairing session.
42 const std::string& session_id() const { return session_id_; }
43 void set_session_id(const std::string& id) { session_id_ = id; }
45 // Resets the values to empty values.
46 void Clear();
48 private:
49 std::vector<uint8_t> code_;
50 std::string mode_;
51 std::string session_id_;
54 class PairingInfoProperty : public dbus::PropertyBase {
55 public:
56 bool PopValueFromReader(dbus::MessageReader* reader) override;
57 void AppendSetValueToWriter(dbus::MessageWriter* writer) override;
58 void ReplaceValueWithSetValue() override;
60 const PairingInfo& value() const { return value_; }
62 private:
63 PairingInfo value_;
66 // Structure of properties associated with a privet Manager.
67 class Properties : public dbus::PropertySet {
68 public:
69 Properties(dbus::ObjectProxy* object_proxy,
70 const std::string& interface_name,
71 const PropertyChangedCallback& callback);
72 ~Properties() override;
74 // State of WiFi bootstrapping.
75 // Values are "disabled", "waiting", "connecting", "monitoring".
76 const std::string& wifi_bootstrap_state() const {
77 return wifi_bootstrap_state_.value();
80 // State of GCD bootstrapping.
81 // Values are "disabled", "offline", "connecting", "waiting", "registering",
82 // "online".
83 const std::string& gcd_boostrap_state() const {
84 return gcd_bootstrap_state_.value();
87 // State of device pairing.
88 const PairingInfo& pairing_info() const { return pairing_info_.value(); }
90 // Concise note describing a peer. Suitable for display to the user.
91 const std::string& description() const { return description_.value(); }
93 // Concise name describing a peer. Suitable for display to the user.
94 const std::string& name() const { return name_.value(); }
96 private:
97 dbus::Property<std::string> wifi_bootstrap_state_;
98 dbus::Property<std::string> gcd_bootstrap_state_;
99 PairingInfoProperty pairing_info_;
100 dbus::Property<std::string> description_;
101 dbus::Property<std::string> name_;
103 DISALLOW_COPY_AND_ASSIGN(Properties);
106 // Interface for observing changes from a privet daemon.
107 class Observer {
108 public:
109 virtual ~Observer();
111 // Called when the manager has been added.
112 virtual void ManagerAdded() = 0;
114 // Called when the manager has been removed.
115 virtual void ManagerRemoved() = 0;
117 // Called when the manager has a change in value of the property named
118 // |property_name|. Valid values are "Description", "GCDBootstrapState",
119 // "Name", "PairingInfo", "WiFiBootstrapState".
120 virtual void ManagerPropertyChanged(const std::string& property_name) = 0;
123 ~PrivetDaemonManagerClient() override;
125 // Factory function, creates a new instance which is owned by the caller.
126 // For normal usage, access the singleton via DBusThreadManager::Get().
127 static PrivetDaemonManagerClient* Create();
129 // Adds and removes observers for events on all privet daemon events.
130 virtual void AddObserver(Observer* observer) = 0;
131 virtual void RemoveObserver(Observer* observer) = 0;
133 // Calls SetDescription method.
134 // |callback| is called with its |call_status| argument set to
135 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise,
136 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE.
137 virtual void SetDescription(const std::string& description,
138 const VoidDBusMethodCallback& callback) = 0;
140 // Obtains the properties for the manager any values should be
141 // copied if needed.
142 virtual const Properties* GetProperties() = 0;
144 protected:
145 // Create() should be used instead.
146 PrivetDaemonManagerClient();
148 private:
149 DISALLOW_COPY_AND_ASSIGN(PrivetDaemonManagerClient);
152 } // namespace chromeos
154 #endif // CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_