Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -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/dbus_command_dispatcher.h" |
| 6 | |
| 7 | #include <chromeos/dbus/exported_object_manager.h> |
| 8 | |
| 9 | #include "buffet/dbus_command_proxy.h" |
| 10 | #include "buffet/dbus_constants.h" |
| 11 | #include "weave/command.h" |
| 12 | |
| 13 | using chromeos::dbus_utils::AsyncEventSequencer; |
| 14 | using chromeos::dbus_utils::ExportedObjectManager; |
| 15 | |
| 16 | namespace buffet { |
| 17 | |
| 18 | DBusCommandDispacher::DBusCommandDispacher( |
| 19 | const base::WeakPtr<ExportedObjectManager>& object_manager, |
| 20 | weave::Commands* command_manager) |
| 21 | : object_manager_{object_manager} { |
| 22 | command_manager->AddOnCommandAddedCallback(base::Bind( |
| 23 | &DBusCommandDispacher::OnCommandAdded, weak_ptr_factory_.GetWeakPtr())); |
| 24 | } |
| 25 | |
| 26 | void DBusCommandDispacher::OnCommandAdded(weave::Command* command) { |
| 27 | if (!object_manager_) |
| 28 | return; |
| 29 | std::unique_ptr<DBusCommandProxy> proxy{new DBusCommandProxy( |
| 30 | object_manager_.get(), object_manager_->GetBus(), command, |
| 31 | buffet::kCommandServicePathPrefix + std::to_string(++next_id_))}; |
| 32 | proxy->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction()); |
Vitaly Buka | f6027cb | 2015-07-31 16:20:48 -0700 | [diff] [blame^] | 33 | // DBusCommandProxy::DBusCommandProxy() subscribe itself to weave::Command |
| 34 | // notifications. When weave::Command is being destroyed it sends |
| 35 | // ::OnCommandDestroyed() and DBusCommandProxy deletes itself. |
| 36 | proxy.release(); |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | } // namespace buffet |