-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdbus_wrapper.cc
40 lines (33 loc) · 1.33 KB
/
dbus_wrapper.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2017 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 "hammerd/dbus_wrapper.h"
#include <base/strings/string_number_conversions.h>
#include <chromeos/dbus/service_constants.h>
namespace hammerd {
DBusWrapper::DBusWrapper() {
dbus::Bus::Options options;
options.bus_type = dbus::Bus::SYSTEM;
bus_ = new dbus::Bus(options);
CHECK(bus_->Connect()) << "Failed to connect to system bus.";
CHECK(bus_->RequestOwnershipAndBlock(kHammerdServiceName,
dbus::Bus::REQUIRE_PRIMARY))
<< "Failed to request ownership.";
exported_object_ =
bus_->GetExportedObject(dbus::ObjectPath(kHammerdServicePath));
}
void DBusWrapper::SendSignal(const std::string& signal_name) {
SendSignalWithArg(signal_name, nullptr, 0);
}
void DBusWrapper::SendSignalWithArg(const std::string& signal_name,
const uint8_t* values,
size_t length) {
LOG(INFO) << "Send the DBus signal: " << signal_name;
dbus::Signal signal(kHammerdInterface, signal_name);
if (length > 0) {
dbus::MessageWriter writer(&signal);
writer.AppendArrayOfBytes(values, length);
}
exported_object_->SendSignal(&signal);
}
} // namespace hammerd