OLD | NEW |
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 #ifndef DBUS_BUS_H_ | 5 #ifndef DBUS_BUS_H_ |
6 #define DBUS_BUS_H_ | 6 #define DBUS_BUS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
| 12 #include <utility> |
12 #include <dbus/dbus.h> | 13 #include <dbus/dbus.h> |
13 | 14 |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
17 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
18 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
19 | 20 |
20 class MessageLoop; | 21 class MessageLoop; |
21 | 22 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 DBusPendingCall** pending_call, | 278 DBusPendingCall** pending_call, |
278 int timeout_ms); | 279 int timeout_ms); |
279 | 280 |
280 // Requests to send a message to the bus. The message serial number will | 281 // Requests to send a message to the bus. The message serial number will |
281 // be stored in |serial|. | 282 // be stored in |serial|. |
282 // | 283 // |
283 // BLOCKING CALL. | 284 // BLOCKING CALL. |
284 virtual void Send(DBusMessage* request, uint32* serial); | 285 virtual void Send(DBusMessage* request, uint32* serial); |
285 | 286 |
286 // Adds the message filter function. |filter_function| will be called | 287 // Adds the message filter function. |filter_function| will be called |
287 // when incoming messages are received. | 288 // when incoming messages are received. Returns true on success. |
288 // | 289 // |
289 // When a new incoming message arrives, filter functions are called in | 290 // When a new incoming message arrives, filter functions are called in |
290 // the order that they were added until the the incoming message is | 291 // the order that they were added until the the incoming message is |
291 // handled by a filter function. | 292 // handled by a filter function. |
292 // | 293 // |
293 // The same filter function must not be added more than once. | 294 // The same filter function associated with the same user data cannot be |
| 295 // added more than once. Returns false for this case. |
294 // | 296 // |
295 // BLOCKING CALL. | 297 // BLOCKING CALL. |
296 virtual void AddFilterFunction(DBusHandleMessageFunction filter_function, | 298 virtual bool AddFilterFunction(DBusHandleMessageFunction filter_function, |
297 void* user_data); | 299 void* user_data); |
298 | 300 |
299 // Removes the message filter previously added by AddFilterFunction(). | 301 // Removes the message filter previously added by AddFilterFunction(). |
| 302 // Returns true on success. |
300 // | 303 // |
301 // BLOCKING CALL. | 304 // BLOCKING CALL. |
302 virtual void RemoveFilterFunction(DBusHandleMessageFunction filter_function, | 305 virtual bool RemoveFilterFunction(DBusHandleMessageFunction filter_function, |
303 void* user_data); | 306 void* user_data); |
304 | 307 |
305 // Adds the match rule. Messages that match the rule will be processed | 308 // Adds the match rule. Messages that match the rule will be processed |
306 // by the filter functions added by AddFilterFunction(). | 309 // by the filter functions added by AddFilterFunction(). |
307 // | 310 // |
308 // You cannot specify which filter function to use for a match rule. | 311 // You cannot specify which filter function to use for a match rule. |
309 // Instead, you should check if an incoming message is what you are | 312 // Instead, you should check if an incoming message is what you are |
310 // interested in, in the filter functions. | 313 // interested in, in the filter functions. |
311 // | 314 // |
312 // The same match rule must not be added more than once. | 315 // The same match rule must not be added more than once. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 DBusConnection* connection_; | 440 DBusConnection* connection_; |
438 | 441 |
439 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 442 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
440 base::PlatformThreadId origin_thread_id_; | 443 base::PlatformThreadId origin_thread_id_; |
441 | 444 |
442 std::set<std::string> owned_service_names_; | 445 std::set<std::string> owned_service_names_; |
443 // The following sets are used to check if rules/object_paths/filters | 446 // The following sets are used to check if rules/object_paths/filters |
444 // are properly cleaned up before destruction of the bus object. | 447 // are properly cleaned up before destruction of the bus object. |
445 std::set<std::string> match_rules_added_; | 448 std::set<std::string> match_rules_added_; |
446 std::set<std::string> registered_object_paths_; | 449 std::set<std::string> registered_object_paths_; |
447 std::set<DBusHandleMessageFunction> filter_functions_added_; | 450 std::set<std::pair<DBusHandleMessageFunction, void*> > |
| 451 filter_functions_added_; |
448 | 452 |
449 // ObjectProxyTable is used to hold the object proxies created by the | 453 // ObjectProxyTable is used to hold the object proxies created by the |
450 // bus object. Key is a concatenated string of service name + object path, | 454 // bus object. Key is a concatenated string of service name + object path, |
451 // like "org.chromium.TestService/org/chromium/TestObject". | 455 // like "org.chromium.TestService/org/chromium/TestObject". |
452 typedef std::map<std::string, | 456 typedef std::map<std::string, |
453 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; | 457 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; |
454 ObjectProxyTable object_proxy_table_; | 458 ObjectProxyTable object_proxy_table_; |
455 | 459 |
456 // ExportedObjectTable is used to hold the exported objects created by | 460 // ExportedObjectTable is used to hold the exported objects created by |
457 // the bus object. Key is a concatenated string of service name + | 461 // the bus object. Key is a concatenated string of service name + |
458 // object path, like "org.chromium.TestService/org/chromium/TestObject". | 462 // object path, like "org.chromium.TestService/org/chromium/TestObject". |
459 typedef std::map<std::string, | 463 typedef std::map<std::string, |
460 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable; | 464 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable; |
461 ExportedObjectTable exported_object_table_; | 465 ExportedObjectTable exported_object_table_; |
462 | 466 |
463 bool async_operations_set_up_; | 467 bool async_operations_set_up_; |
464 bool shutdown_completed_; | 468 bool shutdown_completed_; |
465 | 469 |
466 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and | 470 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and |
467 // OnAddTimeout()/OnRemoveTimeou() are balanced. | 471 // OnAddTimeout()/OnRemoveTimeou() are balanced. |
468 int num_pending_watches_; | 472 int num_pending_watches_; |
469 int num_pending_timeouts_; | 473 int num_pending_timeouts_; |
470 | 474 |
471 DISALLOW_COPY_AND_ASSIGN(Bus); | 475 DISALLOW_COPY_AND_ASSIGN(Bus); |
472 }; | 476 }; |
473 | 477 |
474 } // namespace dbus | 478 } // namespace dbus |
475 | 479 |
476 #endif // DBUS_BUS_H_ | 480 #endif // DBUS_BUS_H_ |
OLD | NEW |