blob: e1b3426d74fcb221f638d06ff5042361ea5488dd [file] [log] [blame]
Chris Sosa45d9f102014-03-24 11:18:54 -07001// 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 Wiley90016242014-04-01 17:33:29 -070010#include <dbus/object_path.h>
Chris Sosa45d9f102014-03-24 11:18:54 -070011
Christopher Wiley90016242014-04-01 17:33:29 -070012#include "buffet/async_event_sequencer.h"
Christopher Wileyeb19fa02014-03-27 13:27:30 -070013#include "buffet/dbus_constants.h"
Christopher Wiley90016242014-04-01 17:33:29 -070014#include "buffet/dbus_utils.h"
Christopher Wileyeb19fa02014-03-27 13:27:30 -070015
16using ::std::string;
17
Chris Sosa45d9f102014-03-24 11:18:54 -070018namespace buffet {
19
Christopher Wiley90016242014-04-01 17:33:29 -070020DBusManager::DBusManager(dbus::Bus* bus)
21 : bus_(bus),
22 exported_object_(bus->GetExportedObject(
23 dbus::ObjectPath(dbus_constants::kRootServicePath))) { }
Chris Sosa45d9f102014-03-24 11:18:54 -070024
Christopher Wiley90016242014-04-01 17:33:29 -070025DBusManager::~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 Sosa45d9f102014-03-24 11:18:54 -070032}
33
Christopher Wiley90016242014-04-01 17:33:29 -070034void DBusManager::Init(const OnInitFinish& cb) {
35 scoped_refptr<dbus_utils::AsyncEventSequencer> sequencer(
36 new dbus_utils::AsyncEventSequencer());
37 exported_object_->ExportMethod(
Christopher Wileyeb19fa02014-03-27 13:27:30 -070038 dbus_constants::kRootInterface, dbus_constants::kRootTestMethod,
Christopher Wiley90016242014-04-01 17:33:29 -070039 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 Sosa45d9f102014-03-24 11:18:54 -070046}
47
48scoped_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