Chromium Code Reviews| Index: chromeos/dbus/leadership_daemon_manager_client.h |
| diff --git a/chromeos/dbus/leadership_daemon_manager_client.h b/chromeos/dbus/leadership_daemon_manager_client.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4bd1f0bcb2f7a7fb70711c92232fc07d1bbfb407 |
| --- /dev/null |
| +++ b/chromeos/dbus/leadership_daemon_manager_client.h |
| @@ -0,0 +1,133 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +#ifndef CHROMEOS_DBUS_LEADERSHIP_DAEMON_MANAGER_CLIENT_H_ |
| +#define CHROMEOS_DBUS_LEADERSHIP_DAEMON_MANAGER_CLIENT_H_ |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/values.h" |
| +#include "chromeos/chromeos_export.h" |
| +#include "chromeos/dbus/dbus_client.h" |
| +#include "chromeos/dbus/dbus_method_call_status.h" |
| +#include "dbus/object_path.h" |
| +#include "dbus/property.h" |
| + |
| +namespace chromeos { |
| + |
| +// LeadershipDaemonManagerClient is used to communicate with the |
| +// 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.
|
| +// service. All methods should be called from the origin thread which |
| +// initializes the DBusThreadManager instance. |
| +class CHROMEOS_EXPORT LeadershipDaemonManagerClient : public DBusClient { |
| + public: |
| + // Structure of properties associated with advertised groups. |
| + struct GroupProperties : public dbus::PropertySet { |
| + GroupProperties(dbus::ObjectProxy* object_proxy, |
| + const std::string& interface_name, |
| + const PropertyChangedCallback& callback); |
| + ~GroupProperties() override; |
| + |
| + 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.
|
| + const std::vector<std::string>& GroupMembers() const { |
|
Ben Chan
2015/02/12 22:05:35
ditto
dtapuska
2015/02/12 22:45:23
Done.
|
| + return group_members_.value(); |
| + } |
| + |
| + private: |
| + 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.
|
| + dbus::Property<std::vector<std::string>> group_members_; |
| + }; |
| + |
| + // Interface for observing changes from a leadership daemon. |
| + class Observer { |
| + public: |
| + virtual ~Observer() {} |
| + |
| + // Called when the group with object path |object_path| is added to the |
| + // system. |
| + 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
|
| + |
| + // Called when the group with object path |object_path| is removed from |
| + // the system. |
| + virtual void GroupRemoved(const dbus::ObjectPath& object_path) {} |
| + |
| + // Called when the manager has been added. |
| + 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.
|
| + |
| + // Called when the manager has been removed. |
| + virtual void ManagerRemoved() {} |
| + |
| + // Called when the adapter with object path |object_path| has a |
| + // change in value of the property named |property_name|. |
| + virtual void GroupPropertyChanged(const dbus::ObjectPath& object_path, |
| + const std::string& property_name) {} |
| + }; |
| + |
| + ~LeadershipDaemonManagerClient() override; |
| + |
| + // Factory function, creates a new instance which is owned by the caller. |
| + // For normal usage, access the singleton via DBusThreadManager::Get(). |
| + static LeadershipDaemonManagerClient* Create(); |
| + |
| + // Adds and removes observers for events on all leadership group |
| + // events. Check the |object_path| parameter of observer methods to |
| + // determine which group is issuing the event. |
| + virtual void AddObserver(Observer* observer) = 0; |
| + virtual void RemoveObserver(Observer* observer) = 0; |
| + |
| + // Calls JoinGroup method. |
| + // |callback| is called with its |call_status| argument set to |
| + // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, |
| + // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. |
| + virtual void JoinGroup(const std::string& group, |
| + const base::DictionaryValue& options, |
| + const StringDBusMethodCallback& callback) = 0; |
| + |
| + // Calls LeaveGroup method. |
| + // |callback| is called with its |call_status| argument set to |
| + // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, |
| + // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. |
| + virtual void LeaveGroup(const std::string& object_path, |
| + const VoidDBusMethodCallback& callback) = 0; |
| + |
| + // Calls SetScore method. |
| + // |callback| is called with its |call_status| argument set to |
| + // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, |
| + // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. |
| + virtual void SetScore(const std::string& object_path, |
| + int score, |
| + const VoidDBusMethodCallback& callback) = 0; |
| + |
| + // Calls PokeLeader method. |
| + // |callback| is called with its |call_status| argument set to |
| + // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, |
| + // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. |
| + virtual void PokeLeader(const std::string& object_path, |
| + const VoidDBusMethodCallback& callback) = 0; |
| + |
| + // Calls Ping method. |
| + // |callback| is called with its |call_status| argument set to |
| + // DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise, |
| + // |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE. |
| + virtual void Ping(const StringDBusMethodCallback& callback) = 0; |
| + |
| + // 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.
|
| + // 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.
|
| + virtual GroupProperties* GetGroupProperties( |
| + const dbus::ObjectPath& object_path) = 0; |
| + |
| + protected: |
| + // Create() should be used instead. |
| + LeadershipDaemonManagerClient(); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(LeadershipDaemonManagerClient); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROMEOS_DBUS_LEADERSHIP_DAEMON_MANAGER_CLIENT_H_ |