Commit ab7987e2 authored by dtapuska's avatar dtapuska Committed by Commit bot

privetd: Expose dbus API

privetd is a chromeos service that handles device bootstrapping
and setup.
Expose an API to provide events from the privetd dbus.

BUG=467018

Review URL: https://codereview.chromium.org/996013003

Cr-Commit-Position: refs/heads/master@{#321621}
parent 9dd3e61d
......@@ -178,6 +178,8 @@
'dbus/fake_peer_daemon_manager_client.h',
'dbus/fake_permission_broker_client.cc',
'dbus/fake_permission_broker_client.h',
'dbus/fake_privet_daemon_manager_client.cc',
'dbus/fake_privet_daemon_manager_client.h',
'dbus/fake_shill_device_client.cc',
'dbus/fake_shill_device_client.h',
'dbus/fake_shill_ipconfig_client.cc',
......@@ -232,6 +234,8 @@
'dbus/power_manager_client.h',
'dbus/power_policy_controller.cc',
'dbus/power_policy_controller.h',
'dbus/privet_daemon_manager_client.cc',
'dbus/privet_daemon_manager_client.h',
'dbus/services/console_service_provider.cc',
'dbus/services/console_service_provider.h',
'dbus/services/cros_dbus_service.cc',
......@@ -457,6 +461,7 @@
'dbus/modem_messaging_client_unittest.cc',
'dbus/nfc_client_unittest.cc',
'dbus/power_policy_controller_unittest.cc',
'dbus/privet_daemon_manager_client_unittest.cc',
'dbus/services/cros_dbus_service_unittest.cc',
'dbus/services/proxy_resolution_service_provider_unittest.cc',
'dbus/shill_client_unittest_base.cc',
......
......@@ -56,6 +56,7 @@
#include "chromeos/dbus/fake_nfc_tag_client.h"
#include "chromeos/dbus/fake_peer_daemon_manager_client.h"
#include "chromeos/dbus/fake_permission_broker_client.h"
#include "chromeos/dbus/fake_privet_daemon_manager_client.h"
#include "chromeos/dbus/fake_shill_device_client.h"
#include "chromeos/dbus/fake_shill_ipconfig_client.h"
#include "chromeos/dbus/fake_shill_manager_client.h"
......@@ -80,6 +81,7 @@
#include "chromeos/dbus/permission_broker_client.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/dbus/power_policy_controller.h"
#include "chromeos/dbus/privet_daemon_manager_client.h"
#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/dbus/shill_device_client.h"
#include "chromeos/dbus/shill_ipconfig_client.h"
......@@ -119,6 +121,7 @@ const struct {
{ "peer_daemon", DBusClientBundle::PEER_DAEMON },
{ "permission_broker", DBusClientBundle::PERMISSION_BROKER },
{ "power_manager", DBusClientBundle::POWER_MANAGER },
{ "privet_daemon", DBusClientBundle::PRIVET_DAEMON },
{ "session_manager", DBusClientBundle::SESSION_MANAGER },
{ "sms", DBusClientBundle::SMS },
{ "system_clock", DBusClientBundle::SYSTEM_CLOCK },
......@@ -281,6 +284,11 @@ DBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask)
else
permission_broker_client_.reset(new FakePermissionBrokerClient);
if (!IsUsingStub(PRIVET_DAEMON))
privet_daemon_manager_client_.reset(PrivetDaemonManagerClient::Create());
else
privet_daemon_manager_client_.reset(new FakePrivetDaemonManagerClient);
if (!IsUsingStub(LEADERSHIP_DAEMON)) {
leadership_daemon_manager_client_.reset(
LeadershipDaemonManagerClient::Create());
......
......@@ -49,6 +49,7 @@ class NfcTagClient;
class NfcRecordClient;
class PeerDaemonManagerClient;
class PermissionBrokerClient;
class PrivetDaemonManagerClient;
class SystemClockClient;
class PowerManagerClient;
class SessionManagerClient;
......@@ -89,6 +90,7 @@ class CHROMEOS_EXPORT DBusClientBundle {
LEADERSHIP_DAEMON = 1 << 20,
METRONOME = 1 << 21,
AP_MANAGER = 1 << 22,
PRIVET_DAEMON = 1 << 23,
};
explicit DBusClientBundle(DBusClientTypeMask unstub_client_mask);
......@@ -251,6 +253,10 @@ class CHROMEOS_EXPORT DBusClientBundle {
return permission_broker_client_.get();
}
PrivetDaemonManagerClient* privet_daemon_manager_client() {
return privet_daemon_manager_client_.get();
}
SystemClockClient* system_clock_client() {
return system_clock_client_.get();
}
......@@ -300,6 +306,7 @@ class CHROMEOS_EXPORT DBusClientBundle {
scoped_ptr<LorgnetteManagerClient> lorgnette_manager_client_;
scoped_ptr<MetronomeClient> metronome_client_;
scoped_ptr<PeerDaemonManagerClient> peer_daemon_manager_client_;
scoped_ptr<PrivetDaemonManagerClient> privet_daemon_manager_client_;
scoped_ptr<ShillDeviceClient> shill_device_client_;
scoped_ptr<ShillIPConfigClient> shill_ipconfig_client_;
scoped_ptr<ShillManagerClient> shill_manager_client_;
......
......@@ -41,6 +41,7 @@
#include "chromeos/dbus/peer_daemon_manager_client.h"
#include "chromeos/dbus/permission_broker_client.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/dbus/privet_daemon_manager_client.h"
#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/dbus/shill_device_client.h"
#include "chromeos/dbus/shill_ipconfig_client.h"
......@@ -280,6 +281,10 @@ PowerManagerClient* DBusThreadManager::GetPowerManagerClient() {
return client_bundle_->power_manager_client();
}
PrivetDaemonManagerClient* DBusThreadManager::GetPrivetDaemonManagerClient() {
return client_bundle_->privet_daemon_manager_client();
}
SessionManagerClient* DBusThreadManager::GetSessionManagerClient() {
return client_bundle_->session_manager_client();
}
......@@ -323,6 +328,7 @@ void DBusThreadManager::InitializeClients() {
GetModemMessagingClient()->Init(GetSystemBus());
GetPermissionBrokerClient()->Init(GetSystemBus());
GetPeerDaemonManagerClient()->Init(GetSystemBus());
GetPrivetDaemonManagerClient()->Init(GetSystemBus());
GetPowerManagerClient()->Init(GetSystemBus());
GetSessionManagerClient()->Init(GetSystemBus());
GetShillDeviceClient()->Init(GetSystemBus());
......@@ -659,6 +665,12 @@ void DBusThreadManagerSetter::SetPermissionBrokerClient(
client.Pass();
}
void DBusThreadManagerSetter::SetPrivetDaemonManagerClient(
scoped_ptr<PrivetDaemonManagerClient> client) {
DBusThreadManager::Get()->client_bundle_->privet_daemon_manager_client_ =
client.Pass();
}
void DBusThreadManagerSetter::SetPowerManagerClient(
scoped_ptr<PowerManagerClient> client) {
DBusThreadManager::Get()->client_bundle_->power_manager_client_ =
......
......@@ -58,6 +58,7 @@ class NfcTagClient;
class PeerDaemonManagerClient;
class PermissionBrokerClient;
class PowerManagerClient;
class PrivetDaemonManagerClient;
class SessionManagerClient;
class ShillDeviceClient;
class ShillIPConfigClient;
......@@ -150,6 +151,7 @@ class CHROMEOS_EXPORT DBusThreadManager {
NfcTagClient* GetNfcTagClient();
PeerDaemonManagerClient* GetPeerDaemonManagerClient();
PermissionBrokerClient* GetPermissionBrokerClient();
PrivetDaemonManagerClient* GetPrivetDaemonManagerClient();
PowerManagerClient* GetPowerManagerClient();
SessionManagerClient* GetSessionManagerClient();
ShillDeviceClient* GetShillDeviceClient();
......@@ -249,6 +251,8 @@ class CHROMEOS_EXPORT DBusThreadManagerSetter {
void SetNfcTagClient(scoped_ptr<NfcTagClient> client);
void SetPeerDaemonManagerClient(scoped_ptr<PeerDaemonManagerClient> client);
void SetPermissionBrokerClient(scoped_ptr<PermissionBrokerClient> client);
void SetPrivetDaemonManagerClient(
scoped_ptr<PrivetDaemonManagerClient> client);
void SetPowerManagerClient(scoped_ptr<PowerManagerClient> client);
void SetSessionManagerClient(scoped_ptr<SessionManagerClient> client);
void SetSMSClient(scoped_ptr<SMSClient> client);
......
// Copyright 2015 The Chromium 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 "chromeos/dbus/fake_privet_daemon_manager_client.h"
#include "base/message_loop/message_loop.h"
namespace chromeos {
FakePrivetDaemonManagerClient::FakePrivetDaemonManagerClient() {
}
FakePrivetDaemonManagerClient::~FakePrivetDaemonManagerClient() {
}
void FakePrivetDaemonManagerClient::Init(dbus::Bus* bus) {
}
void FakePrivetDaemonManagerClient::AddObserver(Observer* observer) {
}
void FakePrivetDaemonManagerClient::RemoveObserver(Observer* observer) {
}
void FakePrivetDaemonManagerClient::SetDescription(
const std::string& description,
const VoidDBusMethodCallback& callback) {
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
const PrivetDaemonManagerClient::Properties*
FakePrivetDaemonManagerClient::GetProperties() {
return nullptr;
}
} // namespace chromeos
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_FAKE_PRIVET_DAEMON_MANAGER_CLIENT_H_
#define CHROMEOS_DBUS_FAKE_PRIVET_DAEMON_MANAGER_CLIENT_H_
#include "chromeos/dbus/privet_daemon_manager_client.h"
namespace chromeos {
// A fake implementation of PrivetDaemonManagerClient. Invokes callbacks
// immediately.
class FakePrivetDaemonManagerClient : public PrivetDaemonManagerClient {
public:
FakePrivetDaemonManagerClient();
~FakePrivetDaemonManagerClient() override;
// DBusClient overrides:
void Init(dbus::Bus* bus) override;
// PrivetDaemonManagerClient overrides:
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
void SetDescription(const std::string& description,
const VoidDBusMethodCallback& callback) override;
const Properties* GetProperties() override;
private:
DISALLOW_COPY_AND_ASSIGN(FakePrivetDaemonManagerClient);
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_FAKE_PRIVET_DAEMON_MANAGER_CLIENT_H_
// Copyright 2015 The Chromium 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 "chromeos/dbus/privet_daemon_manager_client.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/observer_list.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_manager.h"
#include "dbus/object_proxy.h"
namespace chromeos {
namespace {
// TODO(benchan): Move these constants to system_api.
const char kManagerInterfaceName[] = "org.chromium.privetd.Manager";
const char kPrivetdManagerPath[] = "/org/chromium/privetd/Manager";
const char kPrivetdServiceName[] = "org.chromium.privetd";
const char kPrivetdServicePath[] = "/org/chromium/privetd";
const char kSetDescriptionMethod[] = "SetDescription";
const char kDescriptionProperty[] = "Description";
const char kGCDBootstrapStateProperty[] = "GCDBootstrapState";
const char kNameProperty[] = "Name";
const char kPairingInfoCodeProperty[] = "code";
const char kPairingInfoModeProperty[] = "mode";
const char kPairingInfoProperty[] = "PairingInfo";
const char kPairingInfoSessionIdProperty[] = "sessionId";
const char kWiFiBootstrapStateProperty[] = "WiFiBootstrapState";
// The PrivetDaemonManagerClient implementation used in production.
class PrivetDaemonManagerClientImpl : public PrivetDaemonManagerClient,
public dbus::ObjectManager::Interface {
public:
PrivetDaemonManagerClientImpl();
~PrivetDaemonManagerClientImpl() override;
// PrivetDaemonManagerClient overrides.
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
void SetDescription(const std::string& description,
const VoidDBusMethodCallback& callback) override;
const Properties* GetProperties() override;
// DBusClient overrides.
void Init(dbus::Bus* bus) override;
// dbus::ObjectManager::Interface overrides.
dbus::PropertySet* CreateProperties(
dbus::ObjectProxy* object_proxy,
const dbus::ObjectPath& object_path,
const std::string& interface_name) override;
void ObjectAdded(const dbus::ObjectPath& object_path,
const std::string& interface_name) override;
void ObjectRemoved(const dbus::ObjectPath& object_path,
const std::string& interface_name) override;
private:
// Called by dbus::PropertySet when a property value is changed,
// either by result of a signal or response to a GetAll() or Get()
// call. Informs observers.
void OnManagerPropertyChanged(const std::string& property_name);
void OnVoidDBusMethod(const VoidDBusMethodCallback& callback,
dbus::Response* response);
// List of observers interested in event notifications from us.
ObserverList<Observer> observers_;
dbus::ObjectManager* object_manager_;
base::WeakPtrFactory<PrivetDaemonManagerClientImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PrivetDaemonManagerClientImpl);
};
PrivetDaemonManagerClientImpl::PrivetDaemonManagerClientImpl()
: object_manager_(nullptr), weak_ptr_factory_(this) {
}
PrivetDaemonManagerClientImpl::~PrivetDaemonManagerClientImpl() {
if (object_manager_) {
object_manager_->UnregisterInterface(kManagerInterfaceName);
}
}
void PrivetDaemonManagerClientImpl::AddObserver(Observer* observer) {
DCHECK(observer);
observers_.AddObserver(observer);
}
void PrivetDaemonManagerClientImpl::RemoveObserver(Observer* observer) {
DCHECK(observer);
observers_.RemoveObserver(observer);
}
void PrivetDaemonManagerClientImpl::SetDescription(
const std::string& description,
const VoidDBusMethodCallback& callback) {
dbus::ObjectProxy* object_proxy =
object_manager_->GetObjectProxy(dbus::ObjectPath(kPrivetdManagerPath));
if (!object_proxy) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&PrivetDaemonManagerClientImpl::OnVoidDBusMethod,
weak_ptr_factory_.GetWeakPtr(), callback, nullptr));
return;
}
dbus::MethodCall method_call(kManagerInterfaceName, kSetDescriptionMethod);
dbus::MessageWriter writer(&method_call);
writer.AppendString(description);
object_proxy->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&PrivetDaemonManagerClientImpl::OnVoidDBusMethod,
weak_ptr_factory_.GetWeakPtr(), callback));
}
const PrivetDaemonManagerClient::Properties*
PrivetDaemonManagerClientImpl::GetProperties() {
return static_cast<Properties*>(object_manager_->GetProperties(
dbus::ObjectPath(kPrivetdManagerPath), kManagerInterfaceName));
}
void PrivetDaemonManagerClientImpl::Init(dbus::Bus* bus) {
object_manager_ = bus->GetObjectManager(
kPrivetdServiceName, dbus::ObjectPath(kPrivetdServicePath));
object_manager_->RegisterInterface(kManagerInterfaceName, this);
}
dbus::PropertySet* PrivetDaemonManagerClientImpl::CreateProperties(
dbus::ObjectProxy* object_proxy,
const dbus::ObjectPath& object_path,
const std::string& interface_name) {
dbus::PropertySet* properties = nullptr;
if (interface_name == kManagerInterfaceName) {
properties = new Properties(
object_proxy, interface_name,
base::Bind(&PrivetDaemonManagerClientImpl::OnManagerPropertyChanged,
weak_ptr_factory_.GetWeakPtr()));
} else {
NOTREACHED() << "Unhandled interface name " << interface_name;
}
return properties;
}
void PrivetDaemonManagerClientImpl::ObjectAdded(
const dbus::ObjectPath& object_path,
const std::string& interface_name) {
if (interface_name == kManagerInterfaceName) {
FOR_EACH_OBSERVER(Observer, observers_, ManagerAdded());
} else {
NOTREACHED() << "Unhandled interface name " << interface_name;
}
}
void PrivetDaemonManagerClientImpl::ObjectRemoved(
const dbus::ObjectPath& object_path,
const std::string& interface_name) {
if (interface_name == kManagerInterfaceName) {
FOR_EACH_OBSERVER(Observer, observers_, ManagerRemoved());
} else {
NOTREACHED() << "Unhandled interface name " << interface_name;
}
}
void PrivetDaemonManagerClientImpl::OnManagerPropertyChanged(
const std::string& property_name) {
FOR_EACH_OBSERVER(Observer, observers_,
ManagerPropertyChanged(property_name));
}
void PrivetDaemonManagerClientImpl::OnVoidDBusMethod(
const VoidDBusMethodCallback& callback,
dbus::Response* response) {
callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE);
}
} // namespace
void PrivetDaemonManagerClient::PairingInfo::Clear() {
code_.clear();
mode_.clear();
session_id_.clear();
}
bool PrivetDaemonManagerClient::PairingInfoProperty::PopValueFromReader(
dbus::MessageReader* reader) {
dbus::MessageReader variant_reader(nullptr);
dbus::MessageReader array_reader(nullptr);
value_.Clear();
if (!reader->PopVariant(&variant_reader) ||
!variant_reader.PopArray(&array_reader)) {
return false;
}
while (array_reader.HasMoreData()) {
dbus::MessageReader dict_entry_reader(nullptr);
if (!array_reader.PopDictEntry(&dict_entry_reader))
return false;
std::string key;
if (!dict_entry_reader.PopString(&key))
return false;
dbus::MessageReader field_reader(nullptr);
if (!dict_entry_reader.PopVariant(&field_reader))
return false;
if (field_reader.GetDataSignature() == "s") {
std::string string_value;
if (!field_reader.PopString(&string_value))
return false;
if (key == kPairingInfoSessionIdProperty) {
value_.set_session_id(string_value);
} else if (key == kPairingInfoModeProperty) {
value_.set_mode(string_value);
}
} else if (field_reader.GetDataSignature() == "ay") {
const uint8* bytes = nullptr;
size_t length = 0;
if (!field_reader.PopArrayOfBytes(&bytes, &length))
return false;
if (key == kPairingInfoCodeProperty)
value_.set_code(bytes, length);
}
}
return true;
}
PrivetDaemonManagerClient::PairingInfo::PairingInfo() {
}
PrivetDaemonManagerClient::PairingInfo::~PairingInfo() {
}
void PrivetDaemonManagerClient::PairingInfoProperty::AppendSetValueToWriter(
dbus::MessageWriter* writer) {
NOTIMPLEMENTED();
}
void PrivetDaemonManagerClient::PairingInfoProperty::
ReplaceValueWithSetValue() {
NOTIMPLEMENTED();
}
PrivetDaemonManagerClient::Properties::Properties(
dbus::ObjectProxy* object_proxy,
const std::string& interface_name,
const PropertyChangedCallback& callback)
: dbus::PropertySet(object_proxy, interface_name, callback) {
RegisterProperty(kWiFiBootstrapStateProperty, &wifi_bootstrap_state_);
RegisterProperty(kGCDBootstrapStateProperty, &gcd_bootstrap_state_);
RegisterProperty(kPairingInfoProperty, &pairing_info_);
RegisterProperty(kDescriptionProperty, &description_);
RegisterProperty(kNameProperty, &name_);
}
PrivetDaemonManagerClient::Properties::~Properties() {
}
PrivetDaemonManagerClient::Observer::~Observer() {
}
PrivetDaemonManagerClient::PrivetDaemonManagerClient() {
}
PrivetDaemonManagerClient::~PrivetDaemonManagerClient() {
}
// static
PrivetDaemonManagerClient* PrivetDaemonManagerClient::Create() {
return new PrivetDaemonManagerClientImpl();
}
} // namespace chromeos
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_
#define CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/dbus_client.h"
#include "chromeos/dbus/dbus_method_call_status.h"
#include "dbus/object_path.h"
#include "dbus/property.h"
namespace chromeos {
// PrivetDaemonManagerClient is used to communicate with the
// privetd service. All methods should be called from
// the origin thread which initializes the DBusThreadManager instance.
class CHROMEOS_EXPORT PrivetDaemonManagerClient : public DBusClient {
public:
class PairingInfo {
public:
PairingInfo();
~PairingInfo();
// Returns the value of the pairing code; not necessarily a printable
// string.
const std::vector<uint8_t>& code() const { return code_; }
void set_code(const uint8_t* data, size_t length) {
code_.assign(data, data + length);
}
// Returns the selected type of pairing (e.g. "pinCode", "embeddedCode").
const std::string& mode() const { return mode_; }
void set_mode(const std::string& mode) { mode_ = mode; }
// Returns a unique identifier representing the pairing session.
const std::string& session_id() const { return session_id_; }
void set_session_id(const std::string& id) { session_id_ = id; }
// Resets the values to empty values.
void Clear();
private:
std::vector<uint8_t> code_;
std::string mode_;
std::string session_id_;
};
class PairingInfoProperty : public dbus::PropertyBase {
public:
bool PopValueFromReader(dbus::MessageReader* reader) override;
void AppendSetValueToWriter(dbus::MessageWriter* writer) override;
void ReplaceValueWithSetValue() override;
const PairingInfo& value() const { return value_; }
private:
PairingInfo value_;
};
// Structure of properties associated with a privet Manager.
class Properties : public dbus::PropertySet {
public:
Properties(dbus::ObjectProxy* object_proxy,
const std::string& interface_name,
const PropertyChangedCallback& callback);
~Properties() override;
// State of WiFi bootstrapping.
// Values are "disabled", "waiting", "connecting", "monitoring".
const std::string& wifi_bootstrap_state() const {
return wifi_bootstrap_state_.value();
}
// State of GCD bootstrapping.
// Values are "disabled", "offline", "connecting", "waiting", "registering",
// "online".
const std::string& gcd_boostrap_state() const {
return gcd_bootstrap_state_.value();
}
// State of device pairing.
const PairingInfo& pairing_info() const { return pairing_info_.value(); }
// Concise note describing a peer. Suitable for display to the user.
const std::string& description() const { return description_.value(); }
// Concise name describing a peer. Suitable for display to the user.
const std::string& name() const { return name_.value(); }
private:
dbus::Property<std::string> wifi_bootstrap_state_;
dbus::Property<std::string> gcd_bootstrap_state_;
PairingInfoProperty pairing_info_;
dbus::Property<std::string> description_;
dbus::Property<std::string> name_;
DISALLOW_COPY_AND_ASSIGN(Properties);
};
// Interface for observing changes from a privet daemon.
class Observer {
public:
virtual ~Observer();
// Called when the manager has been added.
virtual void ManagerAdded() = 0;
// Called when the manager has been removed.
virtual void ManagerRemoved() = 0;
// Called when the manager has a change in value of the property named
// |property_name|. Valid values are "Description", "GCDBootstrapState",
// "Name", "PairingInfo", "WiFiBootstrapState".
virtual void ManagerPropertyChanged(const std::string& property_name) = 0;
};
~PrivetDaemonManagerClient() override;
// Factory function, creates a new instance which is owned by the caller.
// For normal usage, access the singleton via DBusThreadManager::Get().
static PrivetDaemonManagerClient* Create();
// Adds and removes observers for events on all privet daemon events.
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
// Calls SetDescription method.
// |callback| is called with its |call_status| argument set to
// DBUS_METHOD_CALL_SUCCESS if the method call succeeds. Otherwise,
// |callback| is called with |call_status| set to DBUS_METHOD_CALL_FAILURE.
virtual void SetDescription(const std::string& description,
const VoidDBusMethodCallback& callback) = 0;
// Obtains the properties for the manager any values should be
// copied if needed.
virtual const Properties* GetProperties() = 0;
protected:
// Create() should be used instead.
PrivetDaemonManagerClient();
private:
DISALLOW_COPY_AND_ASSIGN(PrivetDaemonManagerClient);
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_PRIVET_DAEMON_MANAGER_CLIENT_H_
// Copyright 2015 The Chromium 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 "chromeos/dbus/privet_daemon_manager_client.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "dbus/message.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
TEST(PrivetDaemonManagerClientTest, ReadPairingInfo) {
scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
dbus::MessageWriter writer(message.get());
dbus::MessageWriter variant_writer(nullptr);
dbus::MessageWriter variant_array_writer(nullptr);
dbus::MessageWriter struct_entry_writer(nullptr);
writer.OpenVariant("a{sv}", &variant_writer);
variant_writer.OpenArray("{sv}", &variant_array_writer);
const uint8_t code_value[] = {0x67, 0x12, 0x23, 0x45, 0x64};
variant_array_writer.OpenDictEntry(&struct_entry_writer);
struct_entry_writer.AppendString("code");
dbus::MessageWriter struct_field_writer(nullptr);
struct_entry_writer.OpenVariant("ay", &struct_field_writer);
struct_field_writer.AppendArrayOfBytes(code_value, arraysize(code_value));
struct_entry_writer.CloseContainer(&struct_field_writer);
variant_array_writer.CloseContainer(&struct_entry_writer);
const char* string_items[] = {"mode", "sessionId"};
for (size_t i = 0; i < arraysize(string_items); ++i) {
variant_array_writer.OpenDictEntry(&struct_entry_writer);
struct_entry_writer.AppendString(string_items[i]);
struct_entry_writer.AppendVariantOfString(base::UintToString(i + 1));
variant_array_writer.CloseContainer(&struct_entry_writer);
}
writer.CloseContainer(&variant_writer);
variant_writer.CloseContainer(&variant_array_writer);
dbus::MessageReader reader(message.get());
PrivetDaemonManagerClient::PairingInfoProperty pairing_info;
EXPECT_TRUE(pairing_info.PopValueFromReader(&reader));
EXPECT_EQ(
std::vector<uint8_t>(code_value, code_value + arraysize(code_value)),
pairing_info.value().code());
EXPECT_EQ("1", pairing_info.value().mode());
EXPECT_EQ("2", pairing_info.value().session_id());
}
} // namespace chromeos
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment