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 | |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 5 | #include "buffet/dbus_command_dispatcher.h" |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 6 | |
| 7 | #include <chromeos/dbus/exported_object_manager.h> |
| 8 | |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 9 | #include "buffet/dbus_command_proxy.h" |
Alex Vakulenko | 420e49f | 2014-12-01 17:53:27 -0800 | [diff] [blame] | 10 | #include "buffet/dbus_constants.h" |
Vitaly Buka | 12affd8 | 2015-07-23 18:45:35 -0700 | [diff] [blame] | 11 | #include "weave/command.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 | |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 16 | namespace buffet { |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 17 | |
| 18 | DBusCommandDispacher::DBusCommandDispacher( |
Vitaly Buka | 12affd8 | 2015-07-23 18:45:35 -0700 | [diff] [blame] | 19 | const base::WeakPtr<ExportedObjectManager>& object_manager, |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 20 | weave::Commands* command_manager) |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 21 | : object_manager_{object_manager} { |
Vitaly Buka | 12affd8 | 2015-07-23 18:45:35 -0700 | [diff] [blame] | 22 | command_manager->AddOnCommandAddedCallback(base::Bind( |
| 23 | &DBusCommandDispacher::OnCommandAdded, weak_ptr_factory_.GetWeakPtr())); |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 26 | void DBusCommandDispacher::OnCommandAdded(weave::Command* command) { |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 27 | if (!object_manager_) |
| 28 | return; |
| 29 | std::unique_ptr<DBusCommandProxy> proxy{new DBusCommandProxy( |
Vitaly Buka | 12affd8 | 2015-07-23 18:45:35 -0700 | [diff] [blame] | 30 | object_manager_.get(), object_manager_->GetBus(), command, |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 31 | buffet::kCommandServicePathPrefix + std::to_string(++next_id_))}; |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 32 | proxy->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction()); |
Vitaly Buka | 12affd8 | 2015-07-23 18:45:35 -0700 | [diff] [blame] | 33 | command->AddObserver(proxy.release()); |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 36 | } // namespace buffet |