Remove D-Bus dependency from Manager
Here are the main changes:
1. Cleanup Manager::CreateService and Manager::RemoveService API
to remove D-Bus dependency.
1. Use refptr for Service since it will be maintained by both
Manager and its adaptor.
2. Move the monitoring of the service creator/owner to the adaptor,
since the DBusServiceWatcher is D-Bus specific.
Bug: 24194427
TEST=Start AP service on Brillo board, stop weaved, verify service
is destroyed and removed from apmanager.
TEST=Verify device setup works on Brillo board.
TEST=Verify apmanager does not crash on restart.
TEST=Run unittests on both Brillo and Chrome OS.
Change-Id: I33fd4eec2c1adf12830484ca087bd9dd56767288
diff --git a/manager.h b/manager.h
index 06a9c3b..578a1db 100644
--- a/manager.h
+++ b/manager.h
@@ -17,52 +17,43 @@
#ifndef APMANAGER_MANAGER_H_
#define APMANAGER_MANAGER_H_
-#include <map>
#include <string>
#include <vector>
#include <base/macros.h>
-#include <brillo/dbus/dbus_service_watcher.h>
#include "apmanager/device_info.h"
#include "apmanager/firewall_manager.h"
+#include "apmanager/manager_adaptor_interface.h"
#include "apmanager/service.h"
#include "apmanager/shill_manager.h"
-#include "dbus_bindings/org.chromium.apmanager.Manager.h"
namespace apmanager {
class ControlInterface;
-class Manager : public org::chromium::apmanager::ManagerAdaptor,
- public org::chromium::apmanager::ManagerInterface {
+class Manager {
public:
- template<typename T>
- using DBusMethodResponse = brillo::dbus_utils::DBusMethodResponse<T>;
-
explicit Manager(ControlInterface* control_interface);
virtual ~Manager();
- // Implementation of ManagerInterface.
- // Handles calls to org.chromium.apmanager.Manager.CreateService().
- virtual bool CreateService(brillo::ErrorPtr* error,
- dbus::Message* message,
- dbus::ObjectPath* out_service);
- // Handles calls to org.chromium.apmanager.Manager.RemoveService().
- virtual bool RemoveService(brillo::ErrorPtr* error,
- dbus::Message* message,
- const dbus::ObjectPath& in_service);
+ // Register this object to the RPC interface asynchronously.
+ void RegisterAsync(const base::Callback<void(bool)>& completion_callback);
- // Register DBus object.
- void RegisterAsync(
- brillo::dbus_utils::ExportedObjectManager* object_manager,
- const scoped_refptr<dbus::Bus>& bus,
- const base::Callback<void(bool)>& completion_callback);
+ // Create and return a new Service instance. The newly created instance
+ // will be added to the service list, it will only get deleted via
+ // RemoveService.
+ scoped_refptr<Service> CreateService();
+
+ // Remove |service| from the service list. Return true if service is found
+ // and deleted from the list, false otherwise. |error| will be populated
+ // on failure.
+ bool RemoveService(const scoped_refptr<Service>& service, Error* error);
virtual void Start();
virtual void Stop();
- virtual void RegisterDevice(scoped_refptr<Device> device);
+ virtual void RegisterDevice(const scoped_refptr<Device>& device);
// Return an unuse device with AP interface mode support.
virtual scoped_refptr<Device> GetAvailableDevice();
@@ -94,18 +85,9 @@
private:
friend class ManagerTest;
- // This is invoked when the owner of an AP service disappeared.
- void OnAPServiceOwnerDisappeared(int service_identifier);
-
ControlInterface* control_interface_;
int service_identifier_;
- std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_;
- scoped_refptr<dbus::Bus> bus_;
- std::vector<std::unique_ptr<Service>> services_;
std::vector<scoped_refptr<Device>> devices_;
- // DBus service watchers for the owner of AP services.
- using DBusServiceWatcher = brillo::dbus_utils::DBusServiceWatcher;
- std::map<int, std::unique_ptr<DBusServiceWatcher>> service_watchers_;
DeviceInfo device_info_;
// Manager for communicating with shill (connection manager).
@@ -113,6 +95,12 @@
// Manager for communicating with remote firewall service.
FirewallManager firewall_manager_;
+ // Put the service list after ShillManager and FirewallManager, since both
+ // are needed for tearing down an active/running Service.
+ std::vector<scoped_refptr<Service>> services_;
+
+ std::unique_ptr<ManagerAdaptorInterface> adaptor_;
+
DISALLOW_COPY_AND_ASSIGN(Manager);
};