OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ | 5 #ifndef CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ |
6 #define CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ | 6 #define CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "chromeos/chromeos_export.h" | 10 #include "chromeos/chromeos_export.h" |
11 #include "dbus/message.h" | 11 #include "dbus/message.h" |
12 | 12 |
13 namespace dbus { | 13 namespace dbus { |
14 | 14 |
15 class Bus; | 15 class Bus; |
16 class ObjectProxy; | 16 class ObjectProxy; |
17 class ScopedDBusError; | |
17 | 18 |
18 } // namespace dbus | 19 } // namespace dbus |
19 | 20 |
20 namespace chromeos { | 21 namespace chromeos { |
21 | 22 |
22 // A utility class to call D-Bus methods in a synchronous (blocking) way. | 23 // A utility class to call D-Bus methods in a synchronous (blocking) way. |
23 // Note: Blocking the thread until it returns is not a good idea in most cases. | 24 // Note: Blocking the thread until it returns is not a good idea in most cases. |
24 // Avoid using this class as hard as you can. | 25 // Avoid using this class as hard as you can. |
25 class CHROMEOS_EXPORT BlockingMethodCaller { | 26 class CHROMEOS_EXPORT BlockingMethodCaller { |
26 public: | 27 public: |
27 BlockingMethodCaller(dbus::Bus* bus, dbus::ObjectProxy* proxy); | 28 BlockingMethodCaller(dbus::Bus* bus, dbus::ObjectProxy* proxy); |
28 virtual ~BlockingMethodCaller(); | 29 virtual ~BlockingMethodCaller(); |
29 | 30 |
30 // Calls the method and blocks until it returns. | 31 // Calls the method and blocks until it returns. |
31 std::unique_ptr<dbus::Response> CallMethodAndBlock( | 32 std::unique_ptr<dbus::Response> CallMethodAndBlock( |
32 dbus::MethodCall* method_call); | 33 dbus::MethodCall* method_call); |
33 | 34 |
35 // Calls the method and blocks until it returns. Populates the |error| and | |
36 // returns null in case of an error. | |
37 std::unique_ptr<dbus::Response> CallMethodAndBlockWithError( | |
38 dbus::MethodCall* method_call, | |
39 dbus::ScopedDBusError* error); | |
Daniel Erat
2017/04/20 21:06:38
error_out
igorcov
2017/04/21 11:36:21
Done.
| |
40 | |
34 private: | 41 private: |
35 dbus::Bus* bus_; | 42 dbus::Bus* bus_; |
36 dbus::ObjectProxy* proxy_; | 43 dbus::ObjectProxy* proxy_; |
37 base::WaitableEvent on_blocking_method_call_; | 44 base::WaitableEvent on_blocking_method_call_; |
38 | 45 |
39 DISALLOW_COPY_AND_ASSIGN(BlockingMethodCaller); | 46 DISALLOW_COPY_AND_ASSIGN(BlockingMethodCaller); |
40 }; | 47 }; |
41 | 48 |
42 } // namespace chromeos | 49 } // namespace chromeos |
43 | 50 |
44 #endif // CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ | 51 #endif // CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ |
OLD | NEW |