Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: dbus/bus.cc

Issue 7745044: Minor cleanups and improvements for the D-Bus library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dbus/bus.h ('k') | dbus/dbus.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // - Collect metrics (ex. # of method calls, method call time, etc.) 7 // - Collect metrics (ex. # of method calls, method call time, etc.)
8 8
9 #include "dbus/bus.h" 9 #include "dbus/bus.h"
10 10
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 175 }
176 176
177 Bus::Bus(const Options& options) 177 Bus::Bus(const Options& options)
178 : bus_type_(options.bus_type), 178 : bus_type_(options.bus_type),
179 connection_type_(options.connection_type), 179 connection_type_(options.connection_type),
180 dbus_thread_(options.dbus_thread), 180 dbus_thread_(options.dbus_thread),
181 connection_(NULL), 181 connection_(NULL),
182 origin_loop_(MessageLoop::current()), 182 origin_loop_(MessageLoop::current()),
183 origin_thread_id_(base::PlatformThread::CurrentId()), 183 origin_thread_id_(base::PlatformThread::CurrentId()),
184 dbus_thread_id_(base::kInvalidThreadId), 184 dbus_thread_id_(base::kInvalidThreadId),
185 async_operations_are_set_up_(false), 185 async_operations_set_up_(false),
186 num_pending_watches_(0), 186 num_pending_watches_(0),
187 num_pending_timeouts_(0) { 187 num_pending_timeouts_(0) {
188 if (dbus_thread_) { 188 if (dbus_thread_) {
189 dbus_thread_id_ = dbus_thread_->thread_id(); 189 dbus_thread_id_ = dbus_thread_->thread_id();
190 DCHECK(dbus_thread_->IsRunning()) 190 DCHECK(dbus_thread_->IsRunning())
191 << "The D-Bus thread should be running"; 191 << "The D-Bus thread should be running";
192 DCHECK_EQ(MessageLoop::TYPE_IO, 192 DCHECK_EQ(MessageLoop::TYPE_IO,
193 dbus_thread_->message_loop()->type()) 193 dbus_thread_->message_loop()->type())
194 << "The D-Bus thread should have an MessageLoopForIO attached"; 194 << "The D-Bus thread should have an MessageLoopForIO attached";
195 } 195 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 LOG(ERROR) << "Failed to release the onwership of " << service_name << ": " 363 LOG(ERROR) << "Failed to release the onwership of " << service_name << ": "
364 << (error.is_set() ? error.message() : ""); 364 << (error.is_set() ? error.message() : "");
365 return false; 365 return false;
366 } 366 }
367 } 367 }
368 368
369 bool Bus::SetUpAsyncOperations() { 369 bool Bus::SetUpAsyncOperations() {
370 DCHECK(connection_); 370 DCHECK(connection_);
371 AssertOnDBusThread(); 371 AssertOnDBusThread();
372 372
373 if (async_operations_are_set_up_) 373 if (async_operations_set_up_)
374 return true; 374 return true;
375 375
376 // Process all the incoming data if any, so that OnDispatchStatus() will 376 // Process all the incoming data if any, so that OnDispatchStatus() will
377 // be called when the incoming data is ready. 377 // be called when the incoming data is ready.
378 ProcessAllIncomingDataIfAny(); 378 ProcessAllIncomingDataIfAny();
379 379
380 bool success = dbus_connection_set_watch_functions(connection_, 380 bool success = dbus_connection_set_watch_functions(connection_,
381 &Bus::OnAddWatchThunk, 381 &Bus::OnAddWatchThunk,
382 &Bus::OnRemoveWatchThunk, 382 &Bus::OnRemoveWatchThunk,
383 &Bus::OnToggleWatchThunk, 383 &Bus::OnToggleWatchThunk,
384 this, 384 this,
385 NULL); 385 NULL);
386 CHECK(success) << "Unable to allocate memory"; 386 CHECK(success) << "Unable to allocate memory";
387 387
388 // TODO(satorux): Timeout is not yet implemented. 388 // TODO(satorux): Timeout is not yet implemented.
389 success = dbus_connection_set_timeout_functions(connection_, 389 success = dbus_connection_set_timeout_functions(connection_,
390 &Bus::OnAddTimeoutThunk, 390 &Bus::OnAddTimeoutThunk,
391 &Bus::OnRemoveTimeoutThunk, 391 &Bus::OnRemoveTimeoutThunk,
392 &Bus::OnToggleTimeoutThunk, 392 &Bus::OnToggleTimeoutThunk,
393 this, 393 this,
394 NULL); 394 NULL);
395 CHECK(success) << "Unable to allocate memory"; 395 CHECK(success) << "Unable to allocate memory";
396 396
397 dbus_connection_set_dispatch_status_function( 397 dbus_connection_set_dispatch_status_function(
398 connection_, 398 connection_,
399 &Bus::OnDispatchStatusChangedThunk, 399 &Bus::OnDispatchStatusChangedThunk,
400 this, 400 this,
401 NULL); 401 NULL);
402 402
403 async_operations_are_set_up_ = true; 403 async_operations_set_up_ = true;
404 404
405 return true; 405 return true;
406 } 406 }
407 407
408 DBusMessage* Bus::SendWithReplyAndBlock(DBusMessage* request, 408 DBusMessage* Bus::SendWithReplyAndBlock(DBusMessage* request,
409 int timeout_ms, 409 int timeout_ms,
410 DBusError* error) { 410 DBusError* error) {
411 DCHECK(connection_); 411 DCHECK(connection_);
412 AssertOnDBusThread(); 412 AssertOnDBusThread();
413 413
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 match_rules_added_.erase(match_rule); 493 match_rules_added_.erase(match_rule);
494 } 494 }
495 495
496 bool Bus::TryRegisterObjectPath(const std::string& object_path, 496 bool Bus::TryRegisterObjectPath(const std::string& object_path,
497 const DBusObjectPathVTable* vtable, 497 const DBusObjectPathVTable* vtable,
498 void* user_data, 498 void* user_data,
499 DBusError* error) { 499 DBusError* error) {
500 DCHECK(connection_); 500 DCHECK(connection_);
501 AssertOnDBusThread(); 501 AssertOnDBusThread();
502 502
503 DCHECK(registered_object_paths_.find(object_path) == 503 if (registered_object_paths_.find(object_path) !=
504 registered_object_paths_.end()) 504 registered_object_paths_.end()) {
505 << "Object path already registered: " << object_path; 505 LOG(ERROR) << "Object path already registered: " << object_path;
506 return false;
507 }
506 508
507 const bool success = dbus_connection_try_register_object_path( 509 const bool success = dbus_connection_try_register_object_path(
508 connection_, 510 connection_,
509 object_path.c_str(), 511 object_path.c_str(),
510 vtable, 512 vtable,
511 user_data, 513 user_data,
512 error); 514 error);
513 if (success) 515 if (success)
514 registered_object_paths_.insert(object_path); 516 registered_object_paths_.insert(object_path);
515 return success; 517 return success;
516 } 518 }
517 519
518 void Bus::UnregisterObjectPath(const std::string& object_path) { 520 void Bus::UnregisterObjectPath(const std::string& object_path) {
519 DCHECK(connection_); 521 DCHECK(connection_);
520 AssertOnDBusThread(); 522 AssertOnDBusThread();
521 523
522 DCHECK(registered_object_paths_.find(object_path) != 524 if (registered_object_paths_.find(object_path) ==
523 registered_object_paths_.end()) 525 registered_object_paths_.end()) {
524 << "Requested to unregister an unknown object path: " << object_path; 526 LOG(ERROR) << "Requested to unregister an unknown object path: "
527 << object_path;
528 return;
529 }
525 530
526 const bool success = dbus_connection_unregister_object_path( 531 const bool success = dbus_connection_unregister_object_path(
527 connection_, 532 connection_,
528 object_path.c_str()); 533 object_path.c_str());
529 CHECK(success) << "Unable to allocate memory"; 534 CHECK(success) << "Unable to allocate memory";
530 registered_object_paths_.erase(object_path); 535 registered_object_paths_.erase(object_path);
531 } 536 }
532 537
533 void Bus::ShutdownInternal(OnShutdownCallback callback) { 538 void Bus::ShutdownInternal(OnShutdownCallback callback) {
534 AssertOnDBusThread(); 539 AssertOnDBusThread();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 } 710 }
706 711
707 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, 712 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection,
708 DBusDispatchStatus status, 713 DBusDispatchStatus status,
709 void* data) { 714 void* data) {
710 Bus* self = static_cast<Bus*>(data); 715 Bus* self = static_cast<Bus*>(data);
711 return self->OnDispatchStatusChanged(connection, status); 716 return self->OnDispatchStatusChanged(connection, status);
712 } 717 }
713 718
714 } // namespace dbus 719 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/bus.h ('k') | dbus/dbus.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698