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" |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 10 | #include "buffet/commands/dbus_command_proxy.h" |
Alex Vakulenko | 420e49f | 2014-12-01 17:53:27 -0800 | [diff] [blame] | 11 | #include "buffet/dbus_constants.h" |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 12 | |
| 13 | using chromeos::dbus_utils::AsyncEventSequencer; |
| 14 | using chromeos::dbus_utils::ExportedObjectManager; |
| 15 | |
| 16 | namespace buffet { |
| 17 | |
| 18 | DBusCommandDispacher::DBusCommandDispacher( |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 19 | const base::WeakPtr<ExportedObjectManager>& object_manager) |
| 20 | : object_manager_{object_manager} { |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | void DBusCommandDispacher::OnCommandAdded(CommandInstance* command_instance) { |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 24 | if (!object_manager_) |
| 25 | return; |
| 26 | std::unique_ptr<DBusCommandProxy> proxy{new DBusCommandProxy( |
| 27 | object_manager_.get(), object_manager_->GetBus(), command_instance, |
| 28 | dbus_constants::kCommandServicePathPrefix + std::to_string(++next_id_))}; |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 29 | proxy->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction()); |
Anton Muhin | b66a930 | 2014-11-10 22:15:22 +0400 | [diff] [blame] | 30 | command_instance->AddProxy(std::move(proxy)); |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 33 | } // namespace buffet |