Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / chromeos / dbus / peer_daemon_manager_client.h
bloba3cad81450a626043f0051bb531a5f65b933fe30
1 // Copyright 2014 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_PEER_DAEMON_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_
8 #include <map>
9 #include <string>
10 #include <utility>
11 #include <vector>
13 #include "base/macros.h"
14 #include "base/values.h"
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/property.h"
20 namespace chromeos {
22 // PeerDaemonManagerClient is used to communicate with the PeerDaemon Manager
23 // service. All methods should be called from the origin thread which
24 // initializes the DBusThreadManager instance.
25 class CHROMEOS_EXPORT PeerDaemonManagerClient : public DBusClient {
26 public:
27 class ManagerProperties : public dbus::PropertySet {
28 public:
29 ManagerProperties(dbus::ObjectProxy* object_proxy,
30 const PropertyChangedCallback& callback);
31 ~ManagerProperties() override;
33 const std::vector<std::string>& monitored_technologies() const {
34 return monitored_technologies_.value();
37 private:
38 dbus::Property<std::vector<std::string>> monitored_technologies_;
40 DISALLOW_COPY_AND_ASSIGN(ManagerProperties);
43 class ServiceProperties : public dbus::PropertySet {
44 public:
45 ServiceProperties(dbus::ObjectProxy* object_proxy,
46 const PropertyChangedCallback& callback);
47 ~ServiceProperties() override;
49 const std::string& service_id() const { return service_id_.value(); }
50 const std::map<std::string, std::string>& service_info() const {
51 return service_info_.value();
53 const std::vector<std::pair<std::vector<uint8_t>, uint16_t>>& ip_infos()
54 const {
55 return ip_infos_.value();
58 private:
59 dbus::Property<std::string> service_id_;
60 dbus::Property<std::map<std::string, std::string>> service_info_;
61 dbus::Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>
62 ip_infos_;
64 DISALLOW_COPY_AND_ASSIGN(ServiceProperties);
67 class PeerProperties : public dbus::PropertySet {
68 public:
69 PeerProperties(dbus::ObjectProxy* object_proxy,
70 const PropertyChangedCallback& callback);
71 ~PeerProperties() override;
73 const std::string& uuid() const { return uuid_.value(); }
74 uint64_t last_seen() const { return last_seen_.value(); }
76 private:
77 dbus::Property<std::string> uuid_;
78 dbus::Property<uint64_t> last_seen_;
80 DISALLOW_COPY_AND_ASSIGN(PeerProperties);
83 // Interface for observing changes from a leadership daemon.
84 class Observer {
85 public:
86 virtual ~Observer() {}
88 // Called when the peer daemon manager is added.
89 virtual void ManagerAdded() {}
91 // Called when the peer daemon manager is removed; perhaps on a process
92 // crash of the peer daemon.
93 virtual void ManagerRemoved() {}
95 // Called when the manager changes a property value.
96 virtual void ManagerPropertyChanged(const std::string& property_name) {}
98 // Called when the service with object path |object_path| is added to the
99 // system.
100 virtual void ServiceAdded(const dbus::ObjectPath& object_path) {}
102 // Called when the service with object path |object_path| is removed from
103 // the system.
104 virtual void ServiceRemoved(const dbus::ObjectPath& object_path) {}
106 // Called when the service with object path |object_path| changes a
107 // property value.
108 virtual void ServicePropertyChanged(const dbus::ObjectPath& object_path,
109 const std::string& property_name) {}
111 // Called when the peer with object path |object_path| is added to the
112 // system.
113 virtual void PeerAdded(const dbus::ObjectPath& object_path) {}
115 // Called when the peer with object path |object_path| is removed from
116 // the system.
117 virtual void PeerRemoved(const dbus::ObjectPath& object_path) {}
119 // Called when the peer with object path |object_path| changes a
120 // property value.
121 virtual void PeerPropertyChanged(const dbus::ObjectPath& object_path,
122 const std::string& property_name) {}
125 ~PeerDaemonManagerClient() override;
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 PeerDaemonManagerClient* Create();
131 // Adds and removes observers for events on all peer events.
132 virtual void AddObserver(Observer* observer) = 0;
133 virtual void RemoveObserver(Observer* observer) = 0;
135 // Retrieves a list of all the services.
136 virtual std::vector<dbus::ObjectPath> GetServices() = 0;
138 // Retrieves a list of all the peers.
139 virtual std::vector<dbus::ObjectPath> GetPeers() = 0;
141 // Obtains the properties for the service with object path |object_path|,
142 // any values should be copied if needed.
143 virtual ServiceProperties* GetServiceProperties(
144 const dbus::ObjectPath& object_path) = 0;
146 // Obtains the properties for the peer with object path |object_path|,
147 // any values should be copied if needed.
148 virtual PeerProperties* GetPeerProperties(
149 const dbus::ObjectPath& object_path) = 0;
151 // Calls StartMonitoring method.
152 // |callback| is called with its |call_status| argument set to
153 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise,
154 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE.
155 virtual void StartMonitoring(
156 const std::vector<std::string>& requested_technologies,
157 const base::DictionaryValue& options,
158 const StringDBusMethodCallback& callback) = 0;
160 // Calls StopMonitoring method.
161 // |callback| is called with its |call_status| argument set to
162 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise,
163 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE.
164 virtual void StopMonitoring(const std::string& monitoring_token,
165 const VoidDBusMethodCallback& callback) = 0;
167 // Calls ExposeService method.
168 // |callback| is called with its |call_status| argument set to
169 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise,
170 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE.
171 virtual void ExposeService(
172 const std::string& service_id,
173 const std::map<std::string, std::string>& service_info,
174 const base::DictionaryValue& options,
175 const StringDBusMethodCallback& callback) = 0;
177 // Calls RemoveExposedService method.
178 // |callback| is called with its |call_status| argument set to
179 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise,
180 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE.
181 virtual void RemoveExposedService(const std::string& service_token,
182 const VoidDBusMethodCallback& callback) = 0;
184 // Calls Ping method.
185 // |callback| is called with its |call_status| argument set to
186 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise,
187 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE.
188 virtual void Ping(const StringDBusMethodCallback& callback) = 0;
190 protected:
191 // Create() should be used instead.
192 PeerDaemonManagerClient();
194 private:
195 DISALLOW_COPY_AND_ASSIGN(PeerDaemonManagerClient);
198 } // namespace chromeos
200 #endif // CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_