blob: 457ea8811c8c76ec7e4c59f65dcc10e0a559eb7e [file] [log] [blame]
Alex Vakulenko95110752014-09-03 16:27:21 -07001// Copyright 2014 The Chromium OS 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#include "buffet/commands/dbus_command_dispatcher.h"
6
7#include <chromeos/dbus/exported_object_manager.h>
8
9#include "buffet/commands/command_instance.h"
Alex Vakulenko420e49f2014-12-01 17:53:27 -080010#include "buffet/dbus_constants.h"
Alex Vakulenko95110752014-09-03 16:27:21 -070011
12using chromeos::dbus_utils::AsyncEventSequencer;
13using chromeos::dbus_utils::ExportedObjectManager;
14
15namespace buffet {
16
17DBusCommandDispacher::DBusCommandDispacher(
18 const scoped_refptr<dbus::Bus>& bus,
19 ExportedObjectManager* object_manager)
Anton Muhin5191e812014-10-30 17:49:48 +040020 : bus_(bus), next_id_(0) {
Alex Vakulenko95110752014-09-03 16:27:21 -070021 if (object_manager)
22 object_manager_ = object_manager->AsWeakPtr();
23}
24
25void DBusCommandDispacher::OnCommandAdded(CommandInstance* command_instance) {
26 auto proxy = CreateDBusCommandProxy(command_instance);
27 proxy->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction());
Anton Muhinb66a9302014-11-10 22:15:22 +040028 command_instance->AddProxy(std::move(proxy));
Alex Vakulenko95110752014-09-03 16:27:21 -070029}
30
31void DBusCommandDispacher::OnCommandRemoved(CommandInstance* command_instance) {
Alex Vakulenko95110752014-09-03 16:27:21 -070032}
33
Alex Vakulenko95110752014-09-03 16:27:21 -070034std::unique_ptr<DBusCommandProxy> DBusCommandDispacher::CreateDBusCommandProxy(
Anton Muhin5191e812014-10-30 17:49:48 +040035 CommandInstance* command_instance) {
Alex Vakulenko95110752014-09-03 16:27:21 -070036 return std::unique_ptr<DBusCommandProxy>(
Anton Muhin5191e812014-10-30 17:49:48 +040037 new DBusCommandProxy(object_manager_.get(),
38 bus_,
39 command_instance,
40 dbus_constants::kCommandServicePathPrefix +
41 std::to_string(++next_id_)));
Alex Vakulenko95110752014-09-03 16:27:21 -070042}
43
44} // namespace buffet