Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -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_manager.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <base/bind.h> |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 10 | #include <dbus/object_path.h> |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 11 | |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 12 | #include "buffet/async_event_sequencer.h" |
Christopher Wiley | eb19fa0 | 2014-03-27 13:27:30 -0700 | [diff] [blame] | 13 | #include "buffet/dbus_constants.h" |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 14 | #include "buffet/dbus_utils.h" |
Christopher Wiley | eb19fa0 | 2014-03-27 13:27:30 -0700 | [diff] [blame] | 15 | |
| 16 | using ::std::string; |
| 17 | |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 18 | namespace buffet { |
| 19 | |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 20 | DBusManager::DBusManager(dbus::Bus* bus) |
| 21 | : bus_(bus), |
| 22 | exported_object_(bus->GetExportedObject( |
| 23 | dbus::ObjectPath(dbus_constants::kRootServicePath))) { } |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 24 | |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 25 | DBusManager::~DBusManager() { |
| 26 | // Unregister ourselves from the Bus. This prevents the bus from calling |
| 27 | // our callbacks in between the Manager's death and the bus unregistering |
| 28 | // our exported object on shutdown. Unretained makes no promises of memory |
| 29 | // management. |
| 30 | exported_object_->Unregister(); |
| 31 | exported_object_ = nullptr; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 34 | void DBusManager::Init(const OnInitFinish& cb) { |
| 35 | scoped_refptr<dbus_utils::AsyncEventSequencer> sequencer( |
| 36 | new dbus_utils::AsyncEventSequencer()); |
| 37 | exported_object_->ExportMethod( |
Christopher Wiley | eb19fa0 | 2014-03-27 13:27:30 -0700 | [diff] [blame] | 38 | dbus_constants::kRootInterface, dbus_constants::kRootTestMethod, |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 39 | dbus_utils::GetExportableDBusMethod( |
| 40 | base::Bind(&DBusManager::HandleTestMethod, base::Unretained(this))), |
| 41 | sequencer->GetExportHandler( |
| 42 | dbus_constants::kRootInterface, dbus_constants::kRootTestMethod, |
| 43 | "Failed exporting DBusManager's test method", |
| 44 | true)); |
| 45 | sequencer->OnAllTasksCompletedCall({cb}); |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | scoped_ptr<dbus::Response> DBusManager::HandleTestMethod( |
| 49 | dbus::MethodCall* method_call) { |
| 50 | LOG(INFO) << "Received call to test method."; |
| 51 | return scoped_ptr<dbus::Response>(); |
| 52 | } |
| 53 | |
| 54 | } // namespace buffet |