1 // Copyright 2014 The Chromium 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.
5 #include "chromeos/dbus/privet_daemon_client.h"
8 #include "base/callback.h"
9 #include "base/logging.h"
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
13 #include "dbus/object_proxy.h"
18 // The PrivetClient implementation used in production.
19 class PrivetClientImpl
: public PrivetDaemonClient
{
22 ~PrivetClientImpl() override
;
24 // DBusClient overrides:
25 void Init(dbus::Bus
* bus
) override
;
27 // PrivetClient overrides:
28 void GetSetupStatus(const GetSetupStatusCallback
& callback
) override
;
31 // Called when the setup status changes.
32 void OnSetupStatusChanged(dbus::Signal
* signal
);
34 // Called when the object is connected to the signal.
35 void OnSignalConnected(const std::string
& interface_name
,
36 const std::string
& signal_name
,
39 dbus::ObjectProxy
* privetd_proxy_
;
40 base::WeakPtrFactory
<PrivetClientImpl
> weak_ptr_factory_
;
42 DISALLOW_COPY_AND_ASSIGN(PrivetClientImpl
);
45 PrivetClientImpl::PrivetClientImpl()
46 : privetd_proxy_(nullptr), weak_ptr_factory_(this) {
49 PrivetClientImpl::~PrivetClientImpl() {
52 void PrivetClientImpl::GetSetupStatus(const GetSetupStatusCallback
& callback
) {
53 // TODO(jamescook): Implement this.
54 callback
.Run(privetd::kSetupCompleted
);
57 void PrivetClientImpl::Init(dbus::Bus
* bus
) {
59 bus
->GetObjectProxy(privetd::kPrivetdServiceName
,
60 dbus::ObjectPath(privetd::kPrivetdServicePath
));
62 privetd_proxy_
->ConnectToSignal(
63 privetd::kPrivetdInterface
, privetd::kSetupStatusChangedSignal
,
64 base::Bind(&PrivetClientImpl::OnSetupStatusChanged
,
65 weak_ptr_factory_
.GetWeakPtr()),
66 base::Bind(&PrivetClientImpl::OnSignalConnected
,
67 weak_ptr_factory_
.GetWeakPtr()));
70 void PrivetClientImpl::OnSetupStatusChanged(dbus::Signal
* signal
) {
71 // TODO(jamescook): Implement this.
74 void PrivetClientImpl::OnSignalConnected(const std::string
& interface_name
,
75 const std::string
& signal_name
,
77 LOG_IF(ERROR
, !success
) << "Failed to connect to " << signal_name
;
82 //////////////////////////////////////////////////////////////////////////////
84 PrivetDaemonClient::PrivetDaemonClient() {
87 PrivetDaemonClient::~PrivetDaemonClient() {
91 PrivetDaemonClient
* PrivetDaemonClient::Create() {
92 return new PrivetClientImpl();
95 } // namespace chromeos