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 // TODO(satorux): | 5 // TODO(satorux): |
6 // - Handle "disconnected" signal. | 6 // - Handle "disconnected" signal. |
7 | 7 |
8 #include "dbus/bus.h" | 8 #include "dbus/bus.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 // The class is used for watching the file descriptor used for D-Bus | 27 // The class is used for watching the file descriptor used for D-Bus |
28 // communication. | 28 // communication. |
29 class Watch : public base::MessagePumpLibevent::Watcher { | 29 class Watch : public base::MessagePumpLibevent::Watcher { |
30 public: | 30 public: |
31 Watch(DBusWatch* watch) | 31 Watch(DBusWatch* watch) |
32 : raw_watch_(watch) { | 32 : raw_watch_(watch) { |
33 dbus_watch_set_data(raw_watch_, this, NULL); | 33 dbus_watch_set_data(raw_watch_, this, NULL); |
34 } | 34 } |
35 | 35 |
36 ~Watch() { | 36 virtual ~Watch() { |
37 dbus_watch_set_data(raw_watch_, NULL, NULL); | 37 dbus_watch_set_data(raw_watch_, NULL, NULL); |
38 } | 38 } |
39 | 39 |
40 // Returns true if the underlying file descriptor is ready to be watched. | 40 // Returns true if the underlying file descriptor is ready to be watched. |
41 bool IsReadyToBeWatched() { | 41 bool IsReadyToBeWatched() { |
42 return dbus_watch_get_enabled(raw_watch_); | 42 return dbus_watch_get_enabled(raw_watch_); |
43 } | 43 } |
44 | 44 |
45 // Starts watching the underlying file descriptor. | 45 // Starts watching the underlying file descriptor. |
46 void StartWatching() { | 46 void StartWatching() { |
(...skipping 20 matching lines...) Expand all Loading... |
67 CHECK(success) << "Unable to allocate memory"; | 67 CHECK(success) << "Unable to allocate memory"; |
68 } | 68 } |
69 | 69 |
70 // Stops watching the underlying file descriptor. | 70 // Stops watching the underlying file descriptor. |
71 void StopWatching() { | 71 void StopWatching() { |
72 file_descriptor_watcher_.StopWatchingFileDescriptor(); | 72 file_descriptor_watcher_.StopWatchingFileDescriptor(); |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 // Implement MessagePumpLibevent::Watcher. | 76 // Implement MessagePumpLibevent::Watcher. |
77 virtual void OnFileCanReadWithoutBlocking(int file_descriptor) { | 77 virtual void OnFileCanReadWithoutBlocking(int file_descriptor) OVERRIDE { |
78 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_READABLE); | 78 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_READABLE); |
79 CHECK(success) << "Unable to allocate memory"; | 79 CHECK(success) << "Unable to allocate memory"; |
80 } | 80 } |
81 | 81 |
82 // Implement MessagePumpLibevent::Watcher. | 82 // Implement MessagePumpLibevent::Watcher. |
83 virtual void OnFileCanWriteWithoutBlocking(int file_descriptor) { | 83 virtual void OnFileCanWriteWithoutBlocking(int file_descriptor) OVERRIDE { |
84 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_WRITABLE); | 84 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_WRITABLE); |
85 CHECK(success) << "Unable to allocate memory"; | 85 CHECK(success) << "Unable to allocate memory"; |
86 } | 86 } |
87 | 87 |
88 DBusWatch* raw_watch_; | 88 DBusWatch* raw_watch_; |
89 base::MessagePumpLibevent::FileDescriptorWatcher file_descriptor_watcher_; | 89 base::MessagePumpLibevent::FileDescriptorWatcher file_descriptor_watcher_; |
90 }; | 90 }; |
91 | 91 |
92 // The class is used for monitoring the timeout used for D-Bus method | 92 // The class is used for monitoring the timeout used for D-Bus method |
93 // calls. | 93 // calls. |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 } | 830 } |
831 | 831 |
832 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, | 832 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, |
833 DBusDispatchStatus status, | 833 DBusDispatchStatus status, |
834 void* data) { | 834 void* data) { |
835 Bus* self = static_cast<Bus*>(data); | 835 Bus* self = static_cast<Bus*>(data); |
836 self->OnDispatchStatusChanged(connection, status); | 836 self->OnDispatchStatusChanged(connection, status); |
837 } | 837 } |
838 | 838 |
839 } // namespace dbus | 839 } // namespace dbus |
OLD | NEW |