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

Side by Side Diff: chromeos/dbus/privet_daemon_manager_client.h

Issue 996013003: privetd: Expose dbus API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
(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 #ifndef CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_
wtc 2015/03/17 17:31:05 Nit: add a blank line before this line.
dtapuska 2015/03/18 14:28:54 Done.
5 #define CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_
6
7 #include <map>
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/values.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_client.h"
16 #include "chromeos/dbus/dbus_method_call_status.h"
17 #include "dbus/object_path.h"
18 #include "dbus/property.h"
19
20 namespace chromeos {
21
22 // PrivetDaemonManagerClient is used to communicate with the
23 // privetd service. All methods should be called from
24 // the origin thread which initializes the DBusThreadManager instance.
25 class CHROMEOS_EXPORT PrivetDaemonManagerClient : public DBusClient {
26 public:
27 struct PairingInfoVariant {
28 enum class Type {
29 BLOB,
30 STRING,
31 };
32 Type type;
33 std::string string;
34 std::vector<uint8_t> blob;
wtc 2015/03/17 17:31:05 Nit: this is usually defined as a union in C code.
satorux1 2015/03/17 17:39:11 Do we need to have two different types for the sto
dtapuska 2015/03/18 14:28:54 Well yes they are an array of bytes (although one
dtapuska 2015/03/18 14:28:54 before C++ 11 you weren't allowed to put non-POD t
hashimoto 2015/03/19 08:00:22 How about replacing this map of variant with a cla
dtapuska 2015/03/19 18:04:24 I wasn't sure what would be the desired approach h
35 };
36
37 // Structure of properties associated with a privet Manager.
38 class ManagerProperties : public dbus::PropertySet {
39 public:
40 ManagerProperties(dbus::ObjectProxy* object_proxy,
41 const std::string& interface_name,
42 const PropertyChangedCallback& callback);
43 ~ManagerProperties() override;
44
45 // State of WiFi bootstrapping.
46 // Values are "disabled", "waiting", "connecting", "monitoring".
47 const std::string& wifi_bootstrap_state() const {
48 return wifi_bootstrap_state_.value();
49 }
50
51 // State of GCD bootstrapping.
52 // Values are "disabled", "offline", "connecting", "waiting", "registering",
53 // "online".
54 const std::string& gcd_boostrap_state() const {
55 return gcd_bootstrap_state_.value();
56 }
57
58 // State of device pairing. The map will contain the following keys.
59 // "sessionId" - ID of the pairing session; generated by device
60 // "mode" - Selected type of pairing from /privet/v3/pairing/start
61 // (e.g. "pinCode" or "embeddedCode")
62 // "code" - The pin code or embedded code as appropriate to the
63 // "mode" value. See design document.
64 const std::map<std::string, PairingInfoVariant>& pairing_info() const {
65 return pairing_info_.value();
66 }
67
68 // Concise note describing a peer. Suitable for display to the user.
69 const std::string& description() const { return description_.value(); }
70
71 // Concise name describing a peer. Suitable for display to the user.
72 const std::string& name() const { return name_.value(); }
wtc 2015/03/17 17:31:05 Just wanted to make sure you considered the issue
dtapuska 2015/03/18 14:28:54 These are coming from the dbus API.. I don't have
73
74 private:
75 dbus::Property<std::string> wifi_bootstrap_state_;
76 dbus::Property<std::string> gcd_bootstrap_state_;
77 dbus::Property<std::map<std::string, PairingInfoVariant>> pairing_info_;
78 dbus::Property<std::string> description_;
79 dbus::Property<std::string> name_;
80
81 DISALLOW_COPY_AND_ASSIGN(ManagerProperties);
82 };
83
84 // Interface for observing changes from a apmanager daemon.
85 class Observer {
86 public:
87 virtual ~Observer();
88
89 // Called when the manager has been added.
90 virtual void ManagerAdded();
91
92 // Called when the manager has been removed.
93 virtual void ManagerRemoved();
94
95 // Called when the manager has a change in value of the property named
96 // |property_name|.
97 virtual void ManagerPropertyChanged(const std::string& property_name);
wtc 2015/03/17 17:31:05 Should these methods be declared as abstract (= 0)
dtapuska 2015/03/18 14:28:54 According to Google C++ style likely. Although the
98 };
99
100 ~PrivetDaemonManagerClient() override;
101
102 // Factory function, creates a new instance which is owned by the caller.
103 // For normal usage, access the singleton via DBusThreadManager::Get().
104 static PrivetDaemonManagerClient* Create();
105
106 // Adds and removes observers for events on all apmanager
107 // events. Check the |object_path| parameter of observer methods to
wtc 2015/03/17 17:31:05 |object_path| is not used in the Observer interfac
dtapuska 2015/03/18 14:28:54 Done.
108 // determine which group is issuing the event.
109 virtual void AddObserver(Observer* observer) = 0;
110 virtual void RemoveObserver(Observer* observer) = 0;
111
112 // Calls SetDescription method.
113 // |callback| is called with its |call_status| argument set to
114 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise,
115 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE.
116 virtual void SetDescription(const std::string& description,
117 const VoidDBusMethodCallback& callback) = 0;
118
119 // Obtains the properties for the manager any values should be
120 // copied if needed.
121 virtual const ManagerProperties* GetManagerProperties() = 0;
122
123 protected:
124 // Create() should be used instead.
125 PrivetDaemonManagerClient();
126
127 private:
128 DISALLOW_COPY_AND_ASSIGN(PrivetDaemonManagerClient);
129 };
130
131 } // namespace chromeos
132
133 #endif // CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698