OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ |
6 #define CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ | 6 #define CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
| 10 #include <utility> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chromeos/chromeos_export.h" | 15 #include "chromeos/chromeos_export.h" |
15 #include "chromeos/dbus/dbus_client.h" | 16 #include "chromeos/dbus/dbus_client.h" |
16 #include "chromeos/dbus/dbus_method_call_status.h" | 17 #include "chromeos/dbus/dbus_method_call_status.h" |
| 18 #include "dbus/property.h" |
17 | 19 |
18 namespace chromeos { | 20 namespace chromeos { |
19 | 21 |
20 // PeerDaemonManagerClient is used to communicate with the PeerDaemon Manager | 22 // PeerDaemonManagerClient is used to communicate with the PeerDaemon Manager |
21 // service. All methods should be called from the origin thread which | 23 // service. All methods should be called from the origin thread which |
22 // initializes the DBusThreadManager instance. | 24 // initializes the DBusThreadManager instance. |
23 class CHROMEOS_EXPORT PeerDaemonManagerClient : public DBusClient { | 25 class CHROMEOS_EXPORT PeerDaemonManagerClient : public DBusClient { |
24 public: | 26 public: |
| 27 class ManagerProperties : public dbus::PropertySet { |
| 28 public: |
| 29 ManagerProperties(dbus::ObjectProxy* object_proxy, |
| 30 const PropertyChangedCallback& callback); |
| 31 ~ManagerProperties() override; |
| 32 |
| 33 dbus::Property<std::vector<std::string>> monitored_technologies; |
| 34 |
| 35 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(ManagerProperties); |
| 37 }; |
| 38 |
| 39 class ServiceProperties : public dbus::PropertySet { |
| 40 public: |
| 41 ServiceProperties(dbus::ObjectProxy* object_proxy, |
| 42 const PropertyChangedCallback& callback); |
| 43 ~ServiceProperties() override; |
| 44 |
| 45 dbus::Property<std::string> service_id; |
| 46 dbus::Property<std::map<std::string, std::string>> service_info; |
| 47 dbus::Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>> |
| 48 ip_infos; |
| 49 |
| 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(ServiceProperties); |
| 52 }; |
| 53 |
| 54 class PeerProperties : public dbus::PropertySet { |
| 55 public: |
| 56 PeerProperties(dbus::ObjectProxy* object_proxy, |
| 57 const PropertyChangedCallback& callback); |
| 58 ~PeerProperties() override; |
| 59 |
| 60 dbus::Property<std::string> uuid; |
| 61 dbus::Property<uint64_t> last_seen; |
| 62 |
| 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(PeerProperties); |
| 65 }; |
| 66 |
| 67 // Interface for observing changes from a leadership daemon. |
| 68 class Observer { |
| 69 public: |
| 70 virtual ~Observer() {} |
| 71 |
| 72 // Called when the peer daemon manager is added. |
| 73 virtual void ManagerAdded() {} |
| 74 |
| 75 // Called when the peer daemon manager is removed; perhaps on a process |
| 76 // crash of the peer daemon. |
| 77 virtual void ManagerRemoved() {} |
| 78 |
| 79 // Called when the manager changes a property value. |
| 80 virtual void ManagerPropertyChanged(const std::string& property_name) {} |
| 81 |
| 82 // Called when the service with object path |object_path| is added to the |
| 83 // system. |
| 84 virtual void ServiceAdded(const dbus::ObjectPath& object_path) {} |
| 85 |
| 86 // Called when the service with object path |object_path| is removed from |
| 87 // the system. |
| 88 virtual void ServiceRemoved(const dbus::ObjectPath& object_path) {} |
| 89 |
| 90 // Called when the service with object path |object_path| changes a |
| 91 // property value. |
| 92 virtual void ServicePropertyChanged(const dbus::ObjectPath& object_path, |
| 93 const std::string& property_name) {} |
| 94 |
| 95 // Called when the peer with object path |object_path| is added to the |
| 96 // system. |
| 97 virtual void PeerAdded(const dbus::ObjectPath& object_path) {} |
| 98 |
| 99 // Called when the peer with object path |object_path| is removed from |
| 100 // the system. |
| 101 virtual void PeerRemoved(const dbus::ObjectPath& object_path) {} |
| 102 |
| 103 // Called when the peer with object path |object_path| changes a |
| 104 // property value. |
| 105 virtual void PeerPropertyChanged(const dbus::ObjectPath& object_path, |
| 106 const std::string& property_name) {} |
| 107 }; |
| 108 |
25 ~PeerDaemonManagerClient() override; | 109 ~PeerDaemonManagerClient() override; |
26 | 110 |
27 // Factory function, creates a new instance which is owned by the caller. | 111 // Factory function, creates a new instance which is owned by the caller. |
28 // For normal usage, access the singleton via DBusThreadManager::Get(). | 112 // For normal usage, access the singleton via DBusThreadManager::Get(). |
29 static PeerDaemonManagerClient* Create(); | 113 static PeerDaemonManagerClient* Create(); |
30 | 114 |
| 115 // Adds and removes observers for events on all peer events. |
| 116 virtual void AddObserver(Observer* observer) = 0; |
| 117 virtual void RemoveObserver(Observer* observer) = 0; |
| 118 |
| 119 // Retrieves a list of all the services. |
| 120 virtual std::vector<dbus::ObjectPath> GetServices() = 0; |
| 121 |
| 122 // Retrieves a list of all the peers. |
| 123 virtual std::vector<dbus::ObjectPath> GetPeers() = 0; |
| 124 |
| 125 // Obtains the properties for the service with object path |object_path|, |
| 126 // any values should be copied if needed. |
| 127 virtual ServiceProperties* GetServiceProperties( |
| 128 const dbus::ObjectPath& object_path) = 0; |
| 129 |
| 130 // Obtains the properties for the peer with object path |object_path|, |
| 131 // any values should be copied if needed. |
| 132 virtual PeerProperties* GetPeerProperties( |
| 133 const dbus::ObjectPath& object_path) = 0; |
| 134 |
31 // Calls StartMonitoring method. | 135 // Calls StartMonitoring method. |
32 // |callback| is called with its |call_status| argument set to | 136 // |callback| is called with its |call_status| argument set to |
33 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | 137 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, |
34 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | 138 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. |
35 virtual void StartMonitoring( | 139 virtual void StartMonitoring( |
36 const std::vector<std::string>& requested_technologies, | 140 const std::vector<std::string>& requested_technologies, |
37 const base::DictionaryValue& options, | 141 const base::DictionaryValue& options, |
38 const StringDBusMethodCallback& callback) = 0; | 142 const StringDBusMethodCallback& callback) = 0; |
39 | 143 |
40 // Calls StopMonitoring method. | 144 // Calls StopMonitoring method. |
(...skipping 30 matching lines...) Expand all Loading... |
71 // Create() should be used instead. | 175 // Create() should be used instead. |
72 PeerDaemonManagerClient(); | 176 PeerDaemonManagerClient(); |
73 | 177 |
74 private: | 178 private: |
75 DISALLOW_COPY_AND_ASSIGN(PeerDaemonManagerClient); | 179 DISALLOW_COPY_AND_ASSIGN(PeerDaemonManagerClient); |
76 }; | 180 }; |
77 | 181 |
78 } // namespace chromeos | 182 } // namespace chromeos |
79 | 183 |
80 #endif // CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ | 184 #endif // CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ |
OLD | NEW |