Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 1 | // 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 Vakulenko | 420e49f | 2014-12-01 17:53:27 -0800 | [diff] [blame] | 10 | #include "buffet/dbus_constants.h" |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 11 | |
| 12 | using chromeos::dbus_utils::AsyncEventSequencer; |
| 13 | using chromeos::dbus_utils::ExportedObjectManager; |
| 14 | |
| 15 | namespace buffet { |
| 16 | |
| 17 | DBusCommandDispacher::DBusCommandDispacher( |
| 18 | const scoped_refptr<dbus::Bus>& bus, |
| 19 | ExportedObjectManager* object_manager) |
Anton Muhin | 5191e81 | 2014-10-30 17:49:48 +0400 | [diff] [blame] | 20 | : bus_(bus), next_id_(0) { |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 21 | if (object_manager) |
| 22 | object_manager_ = object_manager->AsWeakPtr(); |
| 23 | } |
| 24 | |
| 25 | void DBusCommandDispacher::OnCommandAdded(CommandInstance* command_instance) { |
| 26 | auto proxy = CreateDBusCommandProxy(command_instance); |
| 27 | proxy->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction()); |
Anton Muhin | b66a930 | 2014-11-10 22:15:22 +0400 | [diff] [blame] | 28 | command_instance->AddProxy(std::move(proxy)); |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | void DBusCommandDispacher::OnCommandRemoved(CommandInstance* command_instance) { |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 34 | std::unique_ptr<DBusCommandProxy> DBusCommandDispacher::CreateDBusCommandProxy( |
Anton Muhin | 5191e81 | 2014-10-30 17:49:48 +0400 | [diff] [blame] | 35 | CommandInstance* command_instance) { |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 36 | return std::unique_ptr<DBusCommandProxy>( |
Anton Muhin | 5191e81 | 2014-10-30 17:49:48 +0400 | [diff] [blame] | 37 | new DBusCommandProxy(object_manager_.get(), |
| 38 | bus_, |
| 39 | command_instance, |
| 40 | dbus_constants::kCommandServicePathPrefix + |
| 41 | std::to_string(++next_id_))); |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | } // namespace buffet |