buffet: Move commands/dbus_* our of libweave
This code is owned by buffet now.
BUG=brillo:1245
TEST='FEATURES=test emerge-gizmo buffet'
Change-Id: I148336aba06a89167539fdd8d987080ec4cda82d
Reviewed-on: https://chromium-review.googlesource.com/287126
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/dbus_command_dispatcher.cc b/buffet/dbus_command_dispatcher.cc
new file mode 100644
index 0000000..39e106b
--- /dev/null
+++ b/buffet/dbus_command_dispatcher.cc
@@ -0,0 +1,36 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "buffet/dbus_command_dispatcher.h"
+
+#include <chromeos/dbus/exported_object_manager.h>
+
+#include "buffet/dbus_command_proxy.h"
+#include "buffet/dbus_constants.h"
+#include "weave/command.h"
+
+using chromeos::dbus_utils::AsyncEventSequencer;
+using chromeos::dbus_utils::ExportedObjectManager;
+
+namespace buffet {
+
+DBusCommandDispacher::DBusCommandDispacher(
+ const base::WeakPtr<ExportedObjectManager>& object_manager,
+ weave::Commands* command_manager)
+ : object_manager_{object_manager} {
+ command_manager->AddOnCommandAddedCallback(base::Bind(
+ &DBusCommandDispacher::OnCommandAdded, weak_ptr_factory_.GetWeakPtr()));
+}
+
+void DBusCommandDispacher::OnCommandAdded(weave::Command* command) {
+ if (!object_manager_)
+ return;
+ std::unique_ptr<DBusCommandProxy> proxy{new DBusCommandProxy(
+ object_manager_.get(), object_manager_->GetBus(), command,
+ buffet::kCommandServicePathPrefix + std::to_string(++next_id_))};
+ proxy->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction());
+ command->AddObserver(proxy.release());
+}
+
+} // namespace buffet