1 // Copyright (c) 2013 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/services/display_power_service_provider.h"
8 #include "dbus/message.h"
14 void RunConfigurationCallback(
15 dbus::MethodCall
* method_call
,
16 dbus::ExportedObject::ResponseSender response_sender
,
18 response_sender
.Run(dbus::Response::FromMethodCall(method_call
));
23 DisplayPowerServiceProvider::DisplayPowerServiceProvider(
24 scoped_ptr
<Delegate
> delegate
)
25 : delegate_(delegate
.Pass()),
26 weak_ptr_factory_(this) {
29 DisplayPowerServiceProvider::~DisplayPowerServiceProvider() {}
31 void DisplayPowerServiceProvider::Start(
32 scoped_refptr
<dbus::ExportedObject
> exported_object
) {
33 exported_object
->ExportMethod(
34 kLibCrosServiceInterface
,
36 base::Bind(&DisplayPowerServiceProvider::SetDisplayPower
,
37 weak_ptr_factory_
.GetWeakPtr()),
38 base::Bind(&DisplayPowerServiceProvider::OnExported
,
39 weak_ptr_factory_
.GetWeakPtr()));
40 exported_object
->ExportMethod(
41 kLibCrosServiceInterface
,
42 kSetDisplaySoftwareDimming
,
43 base::Bind(&DisplayPowerServiceProvider::SetDisplaySoftwareDimming
,
44 weak_ptr_factory_
.GetWeakPtr()),
45 base::Bind(&DisplayPowerServiceProvider::OnExported
,
46 weak_ptr_factory_
.GetWeakPtr()));
49 void DisplayPowerServiceProvider::OnExported(const std::string
& interface_name
,
50 const std::string
& method_name
,
53 LOG(ERROR
) << "Failed to export " << interface_name
<< "."
58 void DisplayPowerServiceProvider::SetDisplayPower(
59 dbus::MethodCall
* method_call
,
60 dbus::ExportedObject::ResponseSender response_sender
) {
61 dbus::MessageReader
reader(method_call
);
63 Delegate::ResponseCallback callback
=
64 base::Bind(&RunConfigurationCallback
, method_call
, response_sender
);
65 if (reader
.PopInt32(&int_state
)) {
66 DisplayPowerState state
= static_cast<DisplayPowerState
>(int_state
);
67 delegate_
->SetDisplayPower(state
, callback
);
69 LOG(ERROR
) << "Unable to parse " << kSetDisplayPower
<< " request";
74 void DisplayPowerServiceProvider::SetDisplaySoftwareDimming(
75 dbus::MethodCall
* method_call
,
76 dbus::ExportedObject::ResponseSender response_sender
) {
77 dbus::MessageReader
reader(method_call
);
79 if (reader
.PopBool(&dimmed
)) {
80 delegate_
->SetDimming(dimmed
);
82 LOG(ERROR
) << "Unable to parse " << kSetDisplaySoftwareDimming
85 response_sender
.Run(dbus::Response::FromMethodCall(method_call
));
88 } // namespace chromeos