Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_LEADERSHIP_DAEMON_MANAGER_CLIENT_H_ | |
| 5 #define CHROMEOS_DBUS_LEADERSHIP_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 // LeadershipDaemonManagerClient is used to communicate with the | |
| 23 // LeadershipDaemon Manager | |
|
Ben Chan
2015/02/12 22:05:35
just personal feeling, perhaps "leaderd's Manager"
dtapuska
2015/02/12 22:45:23
Done.
| |
| 24 // service. All methods should be called from the origin thread which | |
| 25 // initializes the DBusThreadManager instance. | |
| 26 class CHROMEOS_EXPORT LeadershipDaemonManagerClient : public DBusClient { | |
| 27 public: | |
| 28 // Structure of properties associated with advertised groups. | |
| 29 struct GroupProperties : public dbus::PropertySet { | |
| 30 GroupProperties(dbus::ObjectProxy* object_proxy, | |
| 31 const std::string& interface_name, | |
| 32 const PropertyChangedCallback& callback); | |
| 33 ~GroupProperties() override; | |
| 34 | |
| 35 const std::string& LeaderUUID() const { return leaderUUID_.value(); } | |
|
Ben Chan
2015/02/12 22:05:35
style: trivial / inline getter should be named as
dtapuska
2015/02/12 22:45:23
Done.
| |
| 36 const std::vector<std::string>& GroupMembers() const { | |
|
Ben Chan
2015/02/12 22:05:35
ditto
dtapuska
2015/02/12 22:45:23
Done.
| |
| 37 return group_members_.value(); | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 dbus::Property<std::string> leaderUUID_; | |
|
Ben Chan
2015/02/12 22:05:35
style: it should be named |leader_uuid_|
dtapuska
2015/02/12 22:45:23
Done.
| |
| 42 dbus::Property<std::vector<std::string>> group_members_; | |
| 43 }; | |
| 44 | |
| 45 // Interface for observing changes from a leadership daemon. | |
| 46 class Observer { | |
| 47 public: | |
| 48 virtual ~Observer() {} | |
| 49 | |
| 50 // Called when the group with object path |object_path| is added to the | |
| 51 // system. | |
| 52 virtual void GroupAdded(const dbus::ObjectPath& object_path) {} | |
|
Ben Chan
2015/02/12 22:05:35
no sure the convention here (I guess it's probably
dtapuska
2015/02/12 22:45:23
The observers in bluetooth don't use the On prefix
| |
| 53 | |
| 54 // Called when the group with object path |object_path| is removed from | |
| 55 // the system. | |
| 56 virtual void GroupRemoved(const dbus::ObjectPath& object_path) {} | |
| 57 | |
| 58 // Called when the manager has been added. | |
| 59 virtual void ManagerAdded() {} | |
|
Ben Chan
2015/02/12 22:05:35
nit: group related methods together, i.e.
Manager
dtapuska
2015/02/12 22:45:23
Done.
| |
| 60 | |
| 61 // Called when the manager has been removed. | |
| 62 virtual void ManagerRemoved() {} | |
| 63 | |
| 64 // Called when the adapter with object path |object_path| has a | |
| 65 // change in value of the property named |property_name|. | |
| 66 virtual void GroupPropertyChanged(const dbus::ObjectPath& object_path, | |
| 67 const std::string& property_name) {} | |
| 68 }; | |
| 69 | |
| 70 ~LeadershipDaemonManagerClient() override; | |
| 71 | |
| 72 // Factory function, creates a new instance which is owned by the caller. | |
| 73 // For normal usage, access the singleton via DBusThreadManager::Get(). | |
| 74 static LeadershipDaemonManagerClient* Create(); | |
| 75 | |
| 76 // Adds and removes observers for events on all leadership group | |
| 77 // events. Check the |object_path| parameter of observer methods to | |
| 78 // determine which group is issuing the event. | |
| 79 virtual void AddObserver(Observer* observer) = 0; | |
| 80 virtual void RemoveObserver(Observer* observer) = 0; | |
| 81 | |
| 82 // Calls JoinGroup method. | |
| 83 // |callback| is called with its |call_status| argument set to | |
| 84 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 85 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 86 virtual void JoinGroup(const std::string& group, | |
| 87 const base::DictionaryValue& options, | |
| 88 const StringDBusMethodCallback& callback) = 0; | |
| 89 | |
| 90 // Calls LeaveGroup method. | |
| 91 // |callback| is called with its |call_status| argument set to | |
| 92 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 93 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 94 virtual void LeaveGroup(const std::string& object_path, | |
| 95 const VoidDBusMethodCallback& callback) = 0; | |
| 96 | |
| 97 // Calls SetScore method. | |
| 98 // |callback| is called with its |call_status| argument set to | |
| 99 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 100 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 101 virtual void SetScore(const std::string& object_path, | |
| 102 int score, | |
| 103 const VoidDBusMethodCallback& callback) = 0; | |
| 104 | |
| 105 // Calls PokeLeader method. | |
| 106 // |callback| is called with its |call_status| argument set to | |
| 107 // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, | |
| 108 // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. | |
| 109 virtual void PokeLeader(const std::string& object_path, | |
| 110 const VoidDBusMethodCallback& callback) = 0; | |
| 111 | |
| 112 // Calls Ping 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 Ping(const StringDBusMethodCallback& callback) = 0; | |
| 117 | |
| 118 // Obtain the properties for the group with object path |object_path|, | |
|
Ben Chan
2015/02/12 22:05:35
Obtains
dtapuska
2015/02/12 22:45:23
Done.
| |
| 119 // any values should be copied if needed. | |
|
Ben Chan
2015/02/12 22:05:35
This comment seems to imply ownership of the retur
dtapuska
2015/02/12 22:45:23
Done.
| |
| 120 virtual GroupProperties* GetGroupProperties( | |
| 121 const dbus::ObjectPath& object_path) = 0; | |
| 122 | |
| 123 protected: | |
| 124 // Create() should be used instead. | |
| 125 LeadershipDaemonManagerClient(); | |
| 126 | |
| 127 private: | |
| 128 DISALLOW_COPY_AND_ASSIGN(LeadershipDaemonManagerClient); | |
| 129 }; | |
| 130 | |
| 131 } // namespace chromeos | |
| 132 | |
| 133 #endif // CHROMEOS_DBUS_LEADERSHIP_DAEMON_MANAGER_CLIENT_H_ | |
| OLD | NEW |