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 #include "dbus/bus.h" | 5 #include "dbus/bus.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // The class is used for watching the file descriptor used for D-Bus | 41 // The class is used for watching the file descriptor used for D-Bus |
42 // communication. | 42 // communication. |
43 class Watch : public base::MessagePumpLibevent::Watcher { | 43 class Watch : public base::MessagePumpLibevent::Watcher { |
44 public: | 44 public: |
45 explicit Watch(DBusWatch* watch) | 45 explicit Watch(DBusWatch* watch) |
46 : raw_watch_(watch) { | 46 : raw_watch_(watch) { |
47 dbus_watch_set_data(raw_watch_, this, NULL); | 47 dbus_watch_set_data(raw_watch_, this, NULL); |
48 } | 48 } |
49 | 49 |
50 virtual ~Watch() { | 50 ~Watch() override { dbus_watch_set_data(raw_watch_, NULL, NULL); } |
51 dbus_watch_set_data(raw_watch_, NULL, NULL); | |
52 } | |
53 | 51 |
54 // Returns true if the underlying file descriptor is ready to be watched. | 52 // Returns true if the underlying file descriptor is ready to be watched. |
55 bool IsReadyToBeWatched() { | 53 bool IsReadyToBeWatched() { |
56 return dbus_watch_get_enabled(raw_watch_); | 54 return dbus_watch_get_enabled(raw_watch_); |
57 } | 55 } |
58 | 56 |
59 // Starts watching the underlying file descriptor. | 57 // Starts watching the underlying file descriptor. |
60 void StartWatching() { | 58 void StartWatching() { |
61 const int file_descriptor = dbus_watch_get_unix_fd(raw_watch_); | 59 const int file_descriptor = dbus_watch_get_unix_fd(raw_watch_); |
62 const int flags = dbus_watch_get_flags(raw_watch_); | 60 const int flags = dbus_watch_get_flags(raw_watch_); |
(...skipping 14 matching lines...) Expand all Loading... |
77 CHECK(success) << "Unable to allocate memory"; | 75 CHECK(success) << "Unable to allocate memory"; |
78 } | 76 } |
79 | 77 |
80 // Stops watching the underlying file descriptor. | 78 // Stops watching the underlying file descriptor. |
81 void StopWatching() { | 79 void StopWatching() { |
82 file_descriptor_watcher_.StopWatchingFileDescriptor(); | 80 file_descriptor_watcher_.StopWatchingFileDescriptor(); |
83 } | 81 } |
84 | 82 |
85 private: | 83 private: |
86 // Implement MessagePumpLibevent::Watcher. | 84 // Implement MessagePumpLibevent::Watcher. |
87 virtual void OnFileCanReadWithoutBlocking(int file_descriptor) override { | 85 void OnFileCanReadWithoutBlocking(int file_descriptor) override { |
88 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_READABLE); | 86 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_READABLE); |
89 CHECK(success) << "Unable to allocate memory"; | 87 CHECK(success) << "Unable to allocate memory"; |
90 } | 88 } |
91 | 89 |
92 // Implement MessagePumpLibevent::Watcher. | 90 // Implement MessagePumpLibevent::Watcher. |
93 virtual void OnFileCanWriteWithoutBlocking(int file_descriptor) override { | 91 void OnFileCanWriteWithoutBlocking(int file_descriptor) override { |
94 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_WRITABLE); | 92 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_WRITABLE); |
95 CHECK(success) << "Unable to allocate memory"; | 93 CHECK(success) << "Unable to allocate memory"; |
96 } | 94 } |
97 | 95 |
98 DBusWatch* raw_watch_; | 96 DBusWatch* raw_watch_; |
99 base::MessagePumpLibevent::FileDescriptorWatcher file_descriptor_watcher_; | 97 base::MessagePumpLibevent::FileDescriptorWatcher file_descriptor_watcher_; |
100 }; | 98 }; |
101 | 99 |
102 // The class is used for monitoring the timeout used for D-Bus method | 100 // The class is used for monitoring the timeout used for D-Bus method |
103 // calls. | 101 // calls. |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 kNameOwnerChangedSignal)) { | 1206 kNameOwnerChangedSignal)) { |
1209 Bus* self = static_cast<Bus*>(data); | 1207 Bus* self = static_cast<Bus*>(data); |
1210 self->OnServiceOwnerChanged(message); | 1208 self->OnServiceOwnerChanged(message); |
1211 } | 1209 } |
1212 // Always return unhandled to let others, e.g. ObjectProxies, handle the same | 1210 // Always return unhandled to let others, e.g. ObjectProxies, handle the same |
1213 // signal. | 1211 // signal. |
1214 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 1212 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
1215 } | 1213 } |
1216 | 1214 |
1217 } // namespace dbus | 1215 } // namespace dbus |
OLD | NEW |