| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ | |
| 6 #define CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 #include <utility> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/macros.h" | |
| 16 #include "base/values.h" | |
| 17 #include "chromeos/chromeos_export.h" | |
| 18 #include "chromeos/dbus/dbus_client.h" | |
| 19 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 20 #include "dbus/property.h" | |
| 21 | |
| 22 namespace chromeos { | |
| 23 | |
| 24 // PeerDaemonManagerClient is used to communicate with the PeerDaemon Manager | |
| 25 // service. All methods should be called from the origin thread which | |
| 26 // initializes the DBusThreadManager instance. | |
| 27 class CHROMEOS_EXPORT PeerDaemonManagerClient : public DBusClient { | |
| 28 public: | |
| 29 class ManagerProperties : public dbus::PropertySet { | |
| 30 public: | |
| 31 ManagerProperties(dbus::ObjectProxy* object_proxy, | |
| 32 const PropertyChangedCallback& callback); | |
| 33 ~ManagerProperties() override; | |
| 34 | |
| 35 const std::vector<std::string>& monitored_technologies() const { | |
| 36 return monitored_technologies_.value(); | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 dbus::Property<std::vector<std::string>> monitored_technologies_; | |
| 41 | |
| 42 DISALLOW_COPY_AND_ASSIGN(ManagerProperties); | |
| 43 }; | |
| 44 | |
| 45 class ServiceProperties : public dbus::PropertySet { | |
| 46 public: | |
| 47 ServiceProperties(dbus::ObjectProxy* object_proxy, | |
| 48 const PropertyChangedCallback& callback); | |
| 49 ~ServiceProperties() override; | |
| 50 | |
| 51 const std::string& service_id() const { return service_id_.value(); } | |
| 52 const std::map<std::string, std::string>& service_info() const { | |
| 53 return service_info_.value(); | |
| 54 } | |
| 55 const std::vector<std::pair<std::vector<uint8_t>, uint16_t>>& ip_infos() | |
| 56 const { | |
| 57 return ip_infos_.value(); | |
| 58 } | |
| 59 | |
| 60 private: | |
| 61 dbus::Property<std::string> service_id_; | |
| 62 dbus::Property<std::map<std::string, std::string>> service_info_; | |
| 63 dbus::Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>> | |
| 64 ip_infos_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(ServiceProperties); | |
| 67 }; | |
| 68 | |
| 69 class PeerProperties : public dbus::PropertySet { | |
| 70 public: | |
| 71 PeerProperties(dbus::ObjectProxy* object_proxy, | |
| 72 const PropertyChangedCallback& callback); | |
| 73 ~PeerProperties() override; | |
| 74 | |
| 75 const std::string& uuid() const { return uuid_.value(); } | |
| 76 uint64_t last_seen() const { return last_seen_.value(); } | |
| 77 | |
| 78 private: | |
| 79 dbus::Property<std::string> uuid_; | |
| 80 dbus::Property<uint64_t> last_seen_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(PeerProperties); | |
| 83 }; | |
| 84 | |
| 85 // Interface for observing changes from a leadership daemon. | |
| 86 class Observer { | |
| 87 public: | |
| 88 virtual ~Observer() {} | |
| 89 | |
| 90 // Called when the peer daemon manager is added. | |
| 91 virtual void ManagerAdded() {} | |
| 92 | |
| 93 // Called when the peer daemon manager is removed; perhaps on a process | |
| 94 // crash of the peer daemon. | |
| 95 virtual void ManagerRemoved() {} | |
| 96 | |
| 97 // Called when the manager changes a property value. | |
| 98 virtual void ManagerPropertyChanged(const std::string& property_name) {} | |
| 99 | |
| 100 // Called when the service with object path |object_path| is added to the | |
| 101 // system. | |
| 102 virtual void ServiceAdded(const dbus::ObjectPath& object_path) {} | |
| 103 | |
| 104 // Called when the service with object path |object_path| is removed from | |
| 105 // the system. | |
| 106 virtual void ServiceRemoved(const dbus::ObjectPath& object_path) {} | |
| 107 | |
| 108 // Called when the service with object path |object_path| changes a | |
| 109 // property value. | |
| 110 virtual void ServicePropertyChanged(const dbus::ObjectPath& object_path, | |
| 111 const std::string& property_name) {} | |
| 112 | |
| 113 // Called when the peer with object path |object_path| is added to the | |
| 114 // system. | |
| 115 virtual void PeerAdded(const dbus::ObjectPath& object_path) {} | |
| 116 | |
| 117 // Called when the peer with object path |object_path| is removed from | |
| 118 // the system. | |
| 119 virtual void PeerRemoved(const dbus::ObjectPath& object_path) {} | |
| 120 | |
| 121 // Called when the peer with object path |object_path| changes a | |
| 122 // property value. | |
| 123 virtual void PeerPropertyChanged(const dbus::ObjectPath& object_path, | |
| 124 const std::string& property_name) {} | |
| 125 }; | |
| 126 | |
| 127 ~PeerDaemonManagerClient() override; | |
| 128 | |
| 129 // Factory function, creates a new instance which is owned by the caller. | |
| 130 // For normal usage, access the singleton via DBusThreadManager::Get(). | |
| 131 static PeerDaemonManagerClient* Create(); | |
| 132 | |
| 133 // Adds and removes observers for events on all peer events. | |
| 134 virtual void AddObserver(Observer* observer) = 0; | |
| 135 virtual void RemoveObserver(Observer* observer) = 0; | |
| 136 | |
| 137 // Retrieves a list of all the services. | |
| 138 virtual std::vector<dbus::ObjectPath> GetServices() = 0; | |
| 139 | |
| 140 // Retrieves a list of all the peers. | |
| 141 virtual std::vector<dbus::ObjectPath> GetPeers() = 0; | |
| 142 | |
| 143 // Obtains the properties for the service with object path |object_path|, | |
| 144 // any values should be copied if needed. | |
| 145 virtual ServiceProperties* GetServiceProperties( | |
| 146 const dbus::ObjectPath& object_path) = 0; | |
| 147 | |
| 148 // Obtains the properties for the peer with object path |object_path|, | |
| 149 // any values should be copied if needed. | |
| 150 virtual PeerProperties* GetPeerProperties( | |
| 151 const dbus::ObjectPath& object_path) = 0; | |
| 152 | |
| 153 // Calls StartMonitoring method. | |
| 154 // |callback| is called with its |call_status| argument set to | |
| 155 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 156 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 157 virtual void StartMonitoring( | |
| 158 const std::vector<std::string>& requested_technologies, | |
| 159 const base::DictionaryValue& options, | |
| 160 const StringDBusMethodCallback& callback) = 0; | |
| 161 | |
| 162 // Calls StopMonitoring method. | |
| 163 // |callback| is called with its |call_status| argument set to | |
| 164 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 165 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 166 virtual void StopMonitoring(const std::string& monitoring_token, | |
| 167 const VoidDBusMethodCallback& callback) = 0; | |
| 168 | |
| 169 // Calls ExposeService method. | |
| 170 // |callback| is called with its |call_status| argument set to | |
| 171 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 172 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 173 virtual void ExposeService( | |
| 174 const std::string& service_id, | |
| 175 const std::map<std::string, std::string>& service_info, | |
| 176 const base::DictionaryValue& options, | |
| 177 const StringDBusMethodCallback& callback) = 0; | |
| 178 | |
| 179 // Calls RemoveExposedService method. | |
| 180 // |callback| is called with its |call_status| argument set to | |
| 181 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 182 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 183 virtual void RemoveExposedService(const std::string& service_token, | |
| 184 const VoidDBusMethodCallback& callback) = 0; | |
| 185 | |
| 186 // Calls Ping method. | |
| 187 // |callback| is called with its |call_status| argument set to | |
| 188 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 189 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 190 virtual void Ping(const StringDBusMethodCallback& callback) = 0; | |
| 191 | |
| 192 protected: | |
| 193 // Create() should be used instead. | |
| 194 PeerDaemonManagerClient(); | |
| 195 | |
| 196 private: | |
| 197 DISALLOW_COPY_AND_ASSIGN(PeerDaemonManagerClient); | |
| 198 }; | |
| 199 | |
| 200 } // namespace chromeos | |
| 201 | |
| 202 #endif // CHROMEOS_DBUS_PEER_DAEMON_MANAGER_CLIENT_H_ | |
| OLD | NEW |