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