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 CHROME_BROWSER_CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ | 5 #ifndef CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ | 6 #define CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "chromeos/chromeos_export.h" |
11 | 12 |
12 namespace dbus { | 13 namespace dbus { |
13 | 14 |
14 class Bus; | 15 class Bus; |
15 class ObjectProxy; | 16 class ObjectProxy; |
16 class MethodCall; | 17 class MethodCall; |
17 class Response; | 18 class Response; |
18 | 19 |
19 } // namespace dbus | 20 } // namespace dbus |
20 | 21 |
21 namespace chromeos { | 22 namespace chromeos { |
22 | 23 |
23 // A utility class to call D-Bus methods in a synchronous (blocking) way. | 24 // A utility class to call D-Bus methods in a synchronous (blocking) way. |
24 // Note: Blocking the thread until it returns is not a good idea in most cases. | 25 // Note: Blocking the thread until it returns is not a good idea in most cases. |
25 // Avoid using this class as hard as you can. | 26 // Avoid using this class as hard as you can. |
26 class BlockingMethodCaller { | 27 class CHROMEOS_EXPORT BlockingMethodCaller { |
27 public: | 28 public: |
28 BlockingMethodCaller(dbus::Bus* bus, dbus::ObjectProxy* proxy); | 29 BlockingMethodCaller(dbus::Bus* bus, dbus::ObjectProxy* proxy); |
29 virtual ~BlockingMethodCaller(); | 30 virtual ~BlockingMethodCaller(); |
30 | 31 |
31 // Calls the method and blocks until it returns. | 32 // Calls the method and blocks until it returns. |
32 // The caller is responsible to delete the returned object. | 33 // The caller is responsible to delete the returned object. |
33 dbus::Response* CallMethodAndBlock(dbus::MethodCall* method_call); | 34 dbus::Response* CallMethodAndBlock(dbus::MethodCall* method_call); |
34 | 35 |
35 private: | 36 private: |
36 dbus::Bus* bus_; | 37 dbus::Bus* bus_; |
37 dbus::ObjectProxy* proxy_; | 38 dbus::ObjectProxy* proxy_; |
38 base::WaitableEvent on_blocking_method_call_; | 39 base::WaitableEvent on_blocking_method_call_; |
39 | 40 |
40 DISALLOW_COPY_AND_ASSIGN(BlockingMethodCaller); | 41 DISALLOW_COPY_AND_ASSIGN(BlockingMethodCaller); |
41 }; | 42 }; |
42 | 43 |
43 } // namespace chromeos | 44 } // namespace chromeos |
44 | 45 |
45 #endif // CHROME_BROWSER_CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ | 46 #endif // CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_ |
OLD | NEW |