| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 else if (flags & DBUS_WATCH_READABLE) | 67 else if (flags & DBUS_WATCH_READABLE) |
| 68 mode = base::MessageLoopForIO::WATCH_READ; | 68 mode = base::MessageLoopForIO::WATCH_READ; |
| 69 else if (flags & DBUS_WATCH_WRITABLE) | 69 else if (flags & DBUS_WATCH_WRITABLE) |
| 70 mode = base::MessageLoopForIO::WATCH_WRITE; | 70 mode = base::MessageLoopForIO::WATCH_WRITE; |
| 71 else | 71 else |
| 72 NOTREACHED(); | 72 NOTREACHED(); |
| 73 | 73 |
| 74 const bool persistent = true; // Watch persistently. | 74 const bool persistent = true; // Watch persistently. |
| 75 const bool success = base::MessageLoopForIO::current()->WatchFileDescriptor( | 75 const bool success = base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 76 file_descriptor, persistent, mode, &file_descriptor_watcher_, this); | 76 file_descriptor, persistent, mode, &file_descriptor_watcher_, this); |
| 77 CHECK(success) << "Unable to allocate memory"; | 77 // Unable to allocate memory |
| 78 CHECK(success); |
| 78 } | 79 } |
| 79 | 80 |
| 80 // Stops watching the underlying file descriptor. | 81 // Stops watching the underlying file descriptor. |
| 81 void StopWatching() { | 82 void StopWatching() { |
| 82 file_descriptor_watcher_.StopWatchingFileDescriptor(); | 83 file_descriptor_watcher_.StopWatchingFileDescriptor(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 private: | 86 private: |
| 86 // Implement MessagePumpLibevent::Watcher. | 87 // Implement MessagePumpLibevent::Watcher. |
| 87 void OnFileCanReadWithoutBlocking(int file_descriptor) override { | 88 void OnFileCanReadWithoutBlocking(int file_descriptor) override { |
| 88 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_READABLE); | 89 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_READABLE); |
| 89 CHECK(success) << "Unable to allocate memory"; | 90 // Unable to allocate memory |
| 91 CHECK(success); |
| 90 } | 92 } |
| 91 | 93 |
| 92 // Implement MessagePumpLibevent::Watcher. | 94 // Implement MessagePumpLibevent::Watcher. |
| 93 void OnFileCanWriteWithoutBlocking(int file_descriptor) override { | 95 void OnFileCanWriteWithoutBlocking(int file_descriptor) override { |
| 94 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_WRITABLE); | 96 const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_WRITABLE); |
| 95 CHECK(success) << "Unable to allocate memory"; | 97 // Unable to allocate memory |
| 98 CHECK(success); |
| 96 } | 99 } |
| 97 | 100 |
| 98 DBusWatch* raw_watch_; | 101 DBusWatch* raw_watch_; |
| 99 base::MessagePumpLibevent::FileDescriptorWatcher file_descriptor_watcher_; | 102 base::MessagePumpLibevent::FileDescriptorWatcher file_descriptor_watcher_; |
| 100 }; | 103 }; |
| 101 | 104 |
| 102 // The class is used for monitoring the timeout used for D-Bus method | 105 // The class is used for monitoring the timeout used for D-Bus method |
| 103 // calls. | 106 // calls. |
| 104 // | 107 // |
| 105 // Unlike Watch, Timeout is a ref counted object, to ensure that |this| of | 108 // Unlike Watch, Timeout is a ref counted object, to ensure that |this| of |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 void HandleTimeout() { | 164 void HandleTimeout() { |
| 162 // If the timeout is marked completed, we should do nothing. This can | 165 // If the timeout is marked completed, we should do nothing. This can |
| 163 // occur if this function is called after Bus::OnRemoveTimeout(). | 166 // occur if this function is called after Bus::OnRemoveTimeout(). |
| 164 if (is_completed) | 167 if (is_completed) |
| 165 return; | 168 return; |
| 166 // Skip if monitoring is canceled. | 169 // Skip if monitoring is canceled. |
| 167 if (!monitoring_is_active_) | 170 if (!monitoring_is_active_) |
| 168 return; | 171 return; |
| 169 | 172 |
| 170 const bool success = dbus_timeout_handle(raw_timeout_); | 173 const bool success = dbus_timeout_handle(raw_timeout_); |
| 171 CHECK(success) << "Unable to allocate memory"; | 174 // Unable to allocate memory |
| 175 CHECK(success); |
| 172 } | 176 } |
| 173 | 177 |
| 174 DBusTimeout* raw_timeout_; | 178 DBusTimeout* raw_timeout_; |
| 175 bool monitoring_is_active_; | 179 bool monitoring_is_active_; |
| 176 bool is_completed; | 180 bool is_completed; |
| 177 }; | 181 }; |
| 178 | 182 |
| 179 } // namespace | 183 } // namespace |
| 180 | 184 |
| 181 Bus::Options::Options() | 185 Bus::Options::Options() |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 // Process all the incoming data if any, so that OnDispatchStatus() will | 630 // Process all the incoming data if any, so that OnDispatchStatus() will |
| 627 // be called when the incoming data is ready. | 631 // be called when the incoming data is ready. |
| 628 ProcessAllIncomingDataIfAny(); | 632 ProcessAllIncomingDataIfAny(); |
| 629 | 633 |
| 630 bool success = dbus_connection_set_watch_functions(connection_, | 634 bool success = dbus_connection_set_watch_functions(connection_, |
| 631 &Bus::OnAddWatchThunk, | 635 &Bus::OnAddWatchThunk, |
| 632 &Bus::OnRemoveWatchThunk, | 636 &Bus::OnRemoveWatchThunk, |
| 633 &Bus::OnToggleWatchThunk, | 637 &Bus::OnToggleWatchThunk, |
| 634 this, | 638 this, |
| 635 NULL); | 639 NULL); |
| 636 CHECK(success) << "Unable to allocate memory"; | 640 // Unable to allocate memory |
| 641 CHECK(success); |
| 637 | 642 |
| 638 success = dbus_connection_set_timeout_functions(connection_, | 643 success = dbus_connection_set_timeout_functions(connection_, |
| 639 &Bus::OnAddTimeoutThunk, | 644 &Bus::OnAddTimeoutThunk, |
| 640 &Bus::OnRemoveTimeoutThunk, | 645 &Bus::OnRemoveTimeoutThunk, |
| 641 &Bus::OnToggleTimeoutThunk, | 646 &Bus::OnToggleTimeoutThunk, |
| 642 this, | 647 this, |
| 643 NULL); | 648 NULL); |
| 644 CHECK(success) << "Unable to allocate memory"; | 649 // Unable to allocate memory |
| 650 CHECK(success); |
| 645 | 651 |
| 646 dbus_connection_set_dispatch_status_function( | 652 dbus_connection_set_dispatch_status_function( |
| 647 connection_, | 653 connection_, |
| 648 &Bus::OnDispatchStatusChangedThunk, | 654 &Bus::OnDispatchStatusChangedThunk, |
| 649 this, | 655 this, |
| 650 NULL); | 656 NULL); |
| 651 | 657 |
| 652 async_operations_set_up_ = true; | 658 async_operations_set_up_ = true; |
| 653 | 659 |
| 654 return true; | 660 return true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 665 } | 671 } |
| 666 | 672 |
| 667 void Bus::SendWithReply(DBusMessage* request, | 673 void Bus::SendWithReply(DBusMessage* request, |
| 668 DBusPendingCall** pending_call, | 674 DBusPendingCall** pending_call, |
| 669 int timeout_ms) { | 675 int timeout_ms) { |
| 670 DCHECK(connection_); | 676 DCHECK(connection_); |
| 671 AssertOnDBusThread(); | 677 AssertOnDBusThread(); |
| 672 | 678 |
| 673 const bool success = dbus_connection_send_with_reply( | 679 const bool success = dbus_connection_send_with_reply( |
| 674 connection_, request, pending_call, timeout_ms); | 680 connection_, request, pending_call, timeout_ms); |
| 675 CHECK(success) << "Unable to allocate memory"; | 681 // Unable to allocate memory |
| 682 CHECK(success); |
| 676 } | 683 } |
| 677 | 684 |
| 678 void Bus::Send(DBusMessage* request, uint32_t* serial) { | 685 void Bus::Send(DBusMessage* request, uint32_t* serial) { |
| 679 DCHECK(connection_); | 686 DCHECK(connection_); |
| 680 AssertOnDBusThread(); | 687 AssertOnDBusThread(); |
| 681 | 688 |
| 682 const bool success = dbus_connection_send(connection_, request, serial); | 689 const bool success = dbus_connection_send(connection_, request, serial); |
| 683 CHECK(success) << "Unable to allocate memory"; | 690 // Unable to allocate memory |
| 691 CHECK(success); |
| 684 } | 692 } |
| 685 | 693 |
| 686 void Bus::AddFilterFunction(DBusHandleMessageFunction filter_function, | 694 void Bus::AddFilterFunction(DBusHandleMessageFunction filter_function, |
| 687 void* user_data) { | 695 void* user_data) { |
| 688 DCHECK(connection_); | 696 DCHECK(connection_); |
| 689 AssertOnDBusThread(); | 697 AssertOnDBusThread(); |
| 690 | 698 |
| 691 std::pair<DBusHandleMessageFunction, void*> filter_data_pair = | 699 std::pair<DBusHandleMessageFunction, void*> filter_data_pair = |
| 692 std::make_pair(filter_function, user_data); | 700 std::make_pair(filter_function, user_data); |
| 693 if (filter_functions_added_.find(filter_data_pair) != | 701 if (filter_functions_added_.find(filter_data_pair) != |
| 694 filter_functions_added_.end()) { | 702 filter_functions_added_.end()) { |
| 695 VLOG(1) << "Filter function already exists: " << filter_function | 703 VLOG(1) << "Filter function already exists: " << filter_function |
| 696 << " with associated data: " << user_data; | 704 << " with associated data: " << user_data; |
| 697 return; | 705 return; |
| 698 } | 706 } |
| 699 | 707 |
| 700 const bool success = dbus_connection_add_filter( | 708 const bool success = dbus_connection_add_filter( |
| 701 connection_, filter_function, user_data, NULL); | 709 connection_, filter_function, user_data, NULL); |
| 702 CHECK(success) << "Unable to allocate memory"; | 710 // Unable to allocate memory |
| 711 CHECK(success); |
| 703 filter_functions_added_.insert(filter_data_pair); | 712 filter_functions_added_.insert(filter_data_pair); |
| 704 } | 713 } |
| 705 | 714 |
| 706 void Bus::RemoveFilterFunction(DBusHandleMessageFunction filter_function, | 715 void Bus::RemoveFilterFunction(DBusHandleMessageFunction filter_function, |
| 707 void* user_data) { | 716 void* user_data) { |
| 708 DCHECK(connection_); | 717 DCHECK(connection_); |
| 709 AssertOnDBusThread(); | 718 AssertOnDBusThread(); |
| 710 | 719 |
| 711 std::pair<DBusHandleMessageFunction, void*> filter_data_pair = | 720 std::pair<DBusHandleMessageFunction, void*> filter_data_pair = |
| 712 std::make_pair(filter_function, user_data); | 721 std::make_pair(filter_function, user_data); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 if (registered_object_paths_.find(object_path) == | 800 if (registered_object_paths_.find(object_path) == |
| 792 registered_object_paths_.end()) { | 801 registered_object_paths_.end()) { |
| 793 LOG(ERROR) << "Requested to unregister an unknown object path: " | 802 LOG(ERROR) << "Requested to unregister an unknown object path: " |
| 794 << object_path.value(); | 803 << object_path.value(); |
| 795 return; | 804 return; |
| 796 } | 805 } |
| 797 | 806 |
| 798 const bool success = dbus_connection_unregister_object_path( | 807 const bool success = dbus_connection_unregister_object_path( |
| 799 connection_, | 808 connection_, |
| 800 object_path.value().c_str()); | 809 object_path.value().c_str()); |
| 801 CHECK(success) << "Unable to allocate memory"; | 810 // Unable to allocate memory |
| 811 CHECK(success); |
| 802 registered_object_paths_.erase(object_path); | 812 registered_object_paths_.erase(object_path); |
| 803 } | 813 } |
| 804 | 814 |
| 805 void Bus::ShutdownOnDBusThreadAndBlockInternal() { | 815 void Bus::ShutdownOnDBusThreadAndBlockInternal() { |
| 806 AssertOnDBusThread(); | 816 AssertOnDBusThread(); |
| 807 | 817 |
| 808 ShutdownAndBlock(); | 818 ShutdownAndBlock(); |
| 809 on_shutdown_.Signal(); | 819 on_shutdown_.Signal(); |
| 810 } | 820 } |
| 811 | 821 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 kNameOwnerChangedSignal)) { | 1219 kNameOwnerChangedSignal)) { |
| 1210 Bus* self = static_cast<Bus*>(data); | 1220 Bus* self = static_cast<Bus*>(data); |
| 1211 self->OnServiceOwnerChanged(message); | 1221 self->OnServiceOwnerChanged(message); |
| 1212 } | 1222 } |
| 1213 // Always return unhandled to let others, e.g. ObjectProxies, handle the same | 1223 // Always return unhandled to let others, e.g. ObjectProxies, handle the same |
| 1214 // signal. | 1224 // signal. |
| 1215 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 1225 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 1216 } | 1226 } |
| 1217 | 1227 |
| 1218 } // namespace dbus | 1228 } // namespace dbus |
| OLD | NEW |