Change pp::NetAddress_Dev to use bool instead of PP_Bool.
[chromium-blink-merge.git] / dbus / bus.h
blob220ed78af86ca844853fa35ddbe59afea34209ed
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
3 // found in the LICENSE file.
5 #ifndef DBUS_BUS_H_
6 #define DBUS_BUS_H_
8 #include <dbus/dbus.h>
10 #include <map>
11 #include <set>
12 #include <string>
13 #include <utility>
14 #include <vector>
16 #include "base/callback.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/synchronization/waitable_event.h"
19 #include "base/threading/platform_thread.h"
20 #include "dbus/dbus_export.h"
21 #include "dbus/object_path.h"
23 namespace base {
24 class SequencedTaskRunner;
25 class SingleThreadTaskRunner;
28 namespace tracked_objects {
29 class Location;
32 namespace dbus {
34 class ExportedObject;
35 class ObjectManager;
36 class ObjectProxy;
38 // Bus is used to establish a connection with D-Bus, create object
39 // proxies, and export objects.
41 // For asynchronous operations such as an asynchronous method call, the
42 // bus object will use a task runner to monitor the underlying file
43 // descriptor used for D-Bus communication. By default, the bus will use
44 // the current thread's task runner. If |dbus_task_runner| option is
45 // specified, the bus will use that task runner instead.
47 // THREADING
49 // In the D-Bus library, we use the two threads:
51 // - The origin thread: the thread that created the Bus object.
52 // - The D-Bus thread: the thread servicing |dbus_task_runner|.
54 // The origin thread is usually Chrome's UI thread. The D-Bus thread is
55 // usually a dedicated thread for the D-Bus library.
57 // BLOCKING CALLS
59 // Functions that issue blocking calls are marked "BLOCKING CALL" and
60 // these functions should be called in the D-Bus thread (if
61 // supplied). AssertOnDBusThread() is placed in these functions.
63 // Note that it's hard to tell if a libdbus function is actually blocking
64 // or not (ex. dbus_bus_request_name() internally calls
65 // dbus_connection_send_with_reply_and_block(), which is a blocking
66 // call). To err on the safe side, we consider all libdbus functions that
67 // deal with the connection to dbus-daemon to be blocking.
69 // SHUTDOWN
71 // The Bus object must be shut down manually by ShutdownAndBlock() and
72 // friends. We require the manual shutdown to make the operation explicit
73 // rather than doing it silently in the destructor.
75 // EXAMPLE USAGE:
77 // Synchronous method call:
79 // dbus::Bus::Options options;
80 // // Set up the bus options here.
81 // ...
82 // dbus::Bus bus(options);
84 // dbus::ObjectProxy* object_proxy =
85 // bus.GetObjectProxy(service_name, object_path);
87 // dbus::MethodCall method_call(interface_name, method_name);
88 // scoped_ptr<dbus::Response> response(
89 // object_proxy.CallMethodAndBlock(&method_call, timeout_ms));
90 // if (response.get() != NULL) { // Success.
91 // ...
92 // }
94 // Asynchronous method call:
96 // void OnResponse(dbus::Response* response) {
97 // // response is NULL if the method call failed.
98 // if (!response)
99 // return;
100 // }
102 // ...
103 // object_proxy.CallMethod(&method_call, timeout_ms,
104 // base::Bind(&OnResponse));
106 // Exporting a method:
108 // void Echo(dbus::MethodCall* method_call,
109 // dbus::ExportedObject::ResponseSender response_sender) {
110 // // Do something with method_call.
111 // Response* response = Response::FromMethodCall(method_call);
112 // // Build response here.
113 // // Can send an immediate response here to implement a synchronous service
114 // // or store the response_sender and send a response later to implement an
115 // // asynchronous service.
116 // response_sender.Run(response);
117 // }
119 // void OnExported(const std::string& interface_name,
120 // const ObjectPath& object_path,
121 // bool success) {
122 // // success is true if the method was exported successfully.
123 // }
125 // ...
126 // dbus::ExportedObject* exported_object =
127 // bus.GetExportedObject(service_name, object_path);
128 // exported_object.ExportMethod(interface_name, method_name,
129 // base::Bind(&Echo),
130 // base::Bind(&OnExported));
132 // WHY IS THIS A REF COUNTED OBJECT?
134 // Bus is a ref counted object, to ensure that |this| of the object is
135 // alive when callbacks referencing |this| are called. However, after the
136 // bus is shut down, |connection_| can be NULL. Hence, callbacks should
137 // not rely on that |connection_| is alive.
138 class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
139 public:
140 // Specifies the bus type. SESSION is used to communicate with per-user
141 // services like GNOME applications. SYSTEM is used to communicate with
142 // system-wide services like NetworkManager. CUSTOM_ADDRESS is used to
143 // communicate with an user specified address.
144 enum BusType {
145 SESSION = DBUS_BUS_SESSION,
146 SYSTEM = DBUS_BUS_SYSTEM,
147 CUSTOM_ADDRESS,
150 // Specifies the connection type. PRIVATE should usually be used unless
151 // you are sure that SHARED is safe for you, which is unlikely the case
152 // in Chrome.
154 // PRIVATE gives you a private connection, that won't be shared with
155 // other Bus objects.
157 // SHARED gives you a connection shared among other Bus objects, which
158 // is unsafe if the connection is shared with multiple threads.
159 enum ConnectionType {
160 PRIVATE,
161 SHARED,
164 // Specifies whether the GetServiceOwnerAndBlock call should report or
165 // suppress errors.
166 enum GetServiceOwnerOption {
167 REPORT_ERRORS,
168 SUPPRESS_ERRORS,
171 // Options used to create a Bus object.
172 struct CHROME_DBUS_EXPORT Options {
173 Options();
174 ~Options();
176 BusType bus_type; // SESSION by default.
177 ConnectionType connection_type; // PRIVATE by default.
178 // If dbus_task_runner is set, the bus object will use that
179 // task runner to process asynchronous operations.
181 // The thread servicing the task runner should meet the following
182 // requirements:
183 // 1) Already running.
184 // 2) Has a MessageLoopForIO.
185 scoped_refptr<base::SequencedTaskRunner> dbus_task_runner;
187 // Specifies the server addresses to be connected. If you want to
188 // communicate with non dbus-daemon such as ibus-daemon, set |bus_type| to
189 // CUSTOM_ADDRESS, and |address| to the D-Bus server address you want to
190 // connect to. The format of this address value is the dbus address style
191 // which is described in
192 // http://dbus.freedesktop.org/doc/dbus-specification.html#addresses
194 // EXAMPLE USAGE:
195 // dbus::Bus::Options options;
196 // options.bus_type = CUSTOM_ADDRESS;
197 // options.address.assign("unix:path=/tmp/dbus-XXXXXXX");
198 // // Set up other options
199 // dbus::Bus bus(options);
201 // // Do something.
203 std::string address;
205 // If the connection with dbus-daemon is closed, |disconnected_callback|
206 // will be called on the origin thread. This is also called when the
207 // disonnection by ShutdownAndBlock. |disconnected_callback| can be null
208 // callback
209 base::Closure disconnected_callback;
212 // Creates a Bus object. The actual connection will be established when
213 // Connect() is called.
214 explicit Bus(const Options& options);
216 // Called when an ownership request is complete.
217 // Parameters:
218 // - the requested service name.
219 // - whether ownership has been obtained or not.
220 typedef base::Callback<void (const std::string&, bool)> OnOwnershipCallback;
222 // Called when GetServiceOwner() completes.
223 // |service_owner| is the return value from GetServiceOwnerAndBlock().
224 typedef base::Callback<void (const std::string& service_owner)>
225 GetServiceOwnerCallback;
227 // TODO(satorux): Remove the service name parameter as the caller of
228 // RequestOwnership() knows the service name.
230 // Gets the object proxy for the given service name and the object path.
231 // The caller must not delete the returned object.
233 // Returns an existing object proxy if the bus object already owns the
234 // object proxy for the given service name and the object path.
235 // Never returns NULL.
237 // The bus will own all object proxies created by the bus, to ensure
238 // that the object proxies are detached from remote objects at the
239 // shutdown time of the bus.
241 // The object proxy is used to call methods of remote objects, and
242 // receive signals from them.
244 // |service_name| looks like "org.freedesktop.NetworkManager", and
245 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0".
247 // Must be called in the origin thread.
248 virtual ObjectProxy* GetObjectProxy(const std::string& service_name,
249 const ObjectPath& object_path);
251 // Same as above, but also takes a bitfield of ObjectProxy::Options.
252 // See object_proxy.h for available options.
253 virtual ObjectProxy* GetObjectProxyWithOptions(
254 const std::string& service_name,
255 const ObjectPath& object_path,
256 int options);
258 // Removes the previously created object proxy for the given service
259 // name and the object path and releases its memory.
261 // If and object proxy for the given service name and object was
262 // created with GetObjectProxy, this function removes it from the
263 // bus object and detaches the ObjectProxy, invalidating any pointer
264 // previously acquired for it with GetObjectProxy. A subsequent call
265 // to GetObjectProxy will return a new object.
267 // All the object proxies are detached from remote objects at the
268 // shutdown time of the bus, but they can be detached early to reduce
269 // memory footprint and used match rules for the bus connection.
271 // |service_name| looks like "org.freedesktop.NetworkManager", and
272 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0".
273 // |callback| is called when the object proxy is successfully removed and
274 // detached.
276 // The function returns true when there is an object proxy matching the
277 // |service_name| and |object_path| to remove, and calls |callback| when it
278 // is removed. Otherwise, it returns false and the |callback| function is
279 // never called. The |callback| argument must not be null.
281 // Must be called in the origin thread.
282 virtual bool RemoveObjectProxy(const std::string& service_name,
283 const ObjectPath& object_path,
284 const base::Closure& callback);
286 // Same as above, but also takes a bitfield of ObjectProxy::Options.
287 // See object_proxy.h for available options.
288 virtual bool RemoveObjectProxyWithOptions(
289 const std::string& service_name,
290 const ObjectPath& object_path,
291 int options,
292 const base::Closure& callback);
294 // Gets the exported object for the given object path.
295 // The caller must not delete the returned object.
297 // Returns an existing exported object if the bus object already owns
298 // the exported object for the given object path. Never returns NULL.
300 // The bus will own all exported objects created by the bus, to ensure
301 // that the exported objects are unregistered at the shutdown time of
302 // the bus.
304 // The exported object is used to export methods of local objects, and
305 // send signal from them.
307 // Must be called in the origin thread.
308 virtual ExportedObject* GetExportedObject(const ObjectPath& object_path);
310 // Unregisters the exported object for the given object path |object_path|.
312 // Getting an exported object for the same object path after this call
313 // will return a new object, method calls on any remaining copies of the
314 // previous object will not be called.
316 // Must be called in the origin thread.
317 virtual void UnregisterExportedObject(const ObjectPath& object_path);
320 // Gets an object manager for the given remote object path |object_path|
321 // exported by the service |service_name|.
323 // Returns an existing object manager if the bus object already owns a
324 // matching object manager, never returns NULL.
326 // The caller must not delete the returned object, the bus retains ownership
327 // of all object managers.
329 // Must be called in the origin thread.
330 virtual ObjectManager* GetObjectManager(const std::string& service_name,
331 const ObjectPath& object_path);
333 // Unregisters the object manager for the given remote object path
334 // |object_path| exported by the srevice |service_name|.
336 // Getting an object manager for the same remote object after this call
337 // will return a new object, method calls on any remaining copies of the
338 // previous object are not permitted.
340 // Must be called in the origin thread.
341 virtual void RemoveObjectManager(const std::string& service_name,
342 const ObjectPath& object_path);
344 // Instructs all registered object managers to retrieve their set of managed
345 // objects from their respective remote objects. There is no need to call this
346 // manually, this is called automatically by the D-Bus thread manager once
347 // implementation classes are registered.
348 virtual void GetManagedObjects();
350 // Shuts down the bus and blocks until it's done. More specifically, this
351 // function does the following:
353 // - Unregisters the object paths
354 // - Releases the service names
355 // - Closes the connection to dbus-daemon.
357 // This function can be called multiple times and it is no-op for the 2nd time
358 // calling.
360 // BLOCKING CALL.
361 virtual void ShutdownAndBlock();
363 // Similar to ShutdownAndBlock(), but this function is used to
364 // synchronously shut down the bus that uses the D-Bus thread. This
365 // function is intended to be used at the very end of the browser
366 // shutdown, where it makes more sense to shut down the bus
367 // synchronously, than trying to make it asynchronous.
369 // BLOCKING CALL, but must be called in the origin thread.
370 virtual void ShutdownOnDBusThreadAndBlock();
372 // Returns true if the shutdown has been completed.
373 bool shutdown_completed() { return shutdown_completed_; }
376 // The public functions below are not intended to be used in client
377 // code. These are used to implement ObjectProxy and ExportedObject.
380 // Connects the bus to the dbus-daemon.
381 // Returns true on success, or the bus is already connected.
383 // BLOCKING CALL.
384 virtual bool Connect();
386 // Disconnects the bus from the dbus-daemon.
387 // Safe to call multiple times and no operation after the first call.
388 // Do not call for shared connection it will be released by libdbus.
390 // BLOCKING CALL.
391 virtual void ClosePrivateConnection();
393 // Requests the ownership of the service name given by |service_name|.
394 // See also RequestOwnershipAndBlock().
396 // |on_ownership_callback| is called when the service name is obtained
397 // or failed to be obtained, in the origin thread.
399 // Must be called in the origin thread.
400 virtual void RequestOwnership(const std::string& service_name,
401 OnOwnershipCallback on_ownership_callback);
403 // Requests the ownership of the given service name.
404 // Returns true on success, or the the service name is already obtained.
406 // BLOCKING CALL.
407 virtual bool RequestOwnershipAndBlock(const std::string& service_name);
409 // Releases the ownership of the given service name.
410 // Returns true on success.
412 // BLOCKING CALL.
413 virtual bool ReleaseOwnership(const std::string& service_name);
415 // Sets up async operations.
416 // Returns true on success, or it's already set up.
417 // This function needs to be called before starting async operations.
419 // BLOCKING CALL.
420 virtual bool SetUpAsyncOperations();
422 // Sends a message to the bus and blocks until the response is
423 // received. Used to implement synchronous method calls.
425 // BLOCKING CALL.
426 virtual DBusMessage* SendWithReplyAndBlock(DBusMessage* request,
427 int timeout_ms,
428 DBusError* error);
430 // Requests to send a message to the bus. The reply is handled with
431 // |pending_call| at a later time.
433 // BLOCKING CALL.
434 virtual void SendWithReply(DBusMessage* request,
435 DBusPendingCall** pending_call,
436 int timeout_ms);
438 // Requests to send a message to the bus. The message serial number will
439 // be stored in |serial|.
441 // BLOCKING CALL.
442 virtual void Send(DBusMessage* request, uint32* serial);
444 // Adds the message filter function. |filter_function| will be called
445 // when incoming messages are received. Returns true on success.
447 // When a new incoming message arrives, filter functions are called in
448 // the order that they were added until the the incoming message is
449 // handled by a filter function.
451 // The same filter function associated with the same user data cannot be
452 // added more than once. Returns false for this case.
454 // BLOCKING CALL.
455 virtual bool AddFilterFunction(DBusHandleMessageFunction filter_function,
456 void* user_data);
458 // Removes the message filter previously added by AddFilterFunction().
459 // Returns true on success.
461 // BLOCKING CALL.
462 virtual bool RemoveFilterFunction(DBusHandleMessageFunction filter_function,
463 void* user_data);
465 // Adds the match rule. Messages that match the rule will be processed
466 // by the filter functions added by AddFilterFunction().
468 // You cannot specify which filter function to use for a match rule.
469 // Instead, you should check if an incoming message is what you are
470 // interested in, in the filter functions.
472 // The same match rule can be added more than once and should be removed
473 // as many times as it was added.
475 // The match rule looks like:
476 // "type='signal', interface='org.chromium.SomeInterface'".
478 // See "Message Bus Message Routing" section in the D-Bus specification
479 // for details about match rules:
480 // http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing
482 // BLOCKING CALL.
483 virtual void AddMatch(const std::string& match_rule, DBusError* error);
485 // Removes the match rule previously added by AddMatch().
486 // Returns false if the requested match rule is unknown or has already been
487 // removed. Otherwise, returns true and sets |error| accordingly.
489 // BLOCKING CALL.
490 virtual bool RemoveMatch(const std::string& match_rule, DBusError* error);
492 // Tries to register the object path. Returns true on success.
493 // Returns false if the object path is already registered.
495 // |message_function| in |vtable| will be called every time when a new
496 // |message sent to the object path arrives.
498 // The same object path must not be added more than once.
500 // See also documentation of |dbus_connection_try_register_object_path| at
501 // http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html
503 // BLOCKING CALL.
504 virtual bool TryRegisterObjectPath(const ObjectPath& object_path,
505 const DBusObjectPathVTable* vtable,
506 void* user_data,
507 DBusError* error);
509 // Unregister the object path.
511 // BLOCKING CALL.
512 virtual void UnregisterObjectPath(const ObjectPath& object_path);
514 // Posts |task| to the task runner of the D-Bus thread. On completion, |reply|
515 // is posted to the origin thread.
516 virtual void PostTaskToDBusThreadAndReply(
517 const tracked_objects::Location& from_here,
518 const base::Closure& task,
519 const base::Closure& reply);
521 // Posts the task to the task runner of the thread that created the bus.
522 virtual void PostTaskToOriginThread(
523 const tracked_objects::Location& from_here,
524 const base::Closure& task);
526 // Posts the task to the task runner of the D-Bus thread. If D-Bus
527 // thread is not supplied, the task runner of the origin thread will be
528 // used.
529 virtual void PostTaskToDBusThread(
530 const tracked_objects::Location& from_here,
531 const base::Closure& task);
533 // Posts the delayed task to the task runner of the D-Bus thread. If
534 // D-Bus thread is not supplied, the task runner of the origin thread
535 // will be used.
536 virtual void PostDelayedTaskToDBusThread(
537 const tracked_objects::Location& from_here,
538 const base::Closure& task,
539 base::TimeDelta delay);
541 // Returns true if the bus has the D-Bus thread.
542 virtual bool HasDBusThread();
544 // Check whether the current thread is on the origin thread (the thread
545 // that created the bus). If not, DCHECK will fail.
546 virtual void AssertOnOriginThread();
548 // Check whether the current thread is on the D-Bus thread. If not,
549 // DCHECK will fail. If the D-Bus thread is not supplied, it calls
550 // AssertOnOriginThread().
551 virtual void AssertOnDBusThread();
553 // Gets the owner for |service_name| via org.freedesktop.DBus.GetNameOwner.
554 // Returns the owner name, if any, or an empty string on failure.
555 // |options| specifies where to printing error messages or not.
557 // BLOCKING CALL.
558 virtual std::string GetServiceOwnerAndBlock(const std::string& service_name,
559 GetServiceOwnerOption options);
561 // A non-blocking version of GetServiceOwnerAndBlock().
562 // Must be called in the origin thread.
563 virtual void GetServiceOwner(const std::string& service_name,
564 const GetServiceOwnerCallback& callback);
566 // Whenever the owner for |service_name| changes, run |callback| with the
567 // name of the new owner. If the owner goes away, then |callback| receives
568 // an empty string.
570 // Any unique (service_name, callback) can be used. Duplicate are ignored.
571 // |service_name| must not be empty and |callback| must not be null.
573 // Must be called in the origin thread.
574 virtual void ListenForServiceOwnerChange(
575 const std::string& service_name,
576 const GetServiceOwnerCallback& callback);
578 // Stop listening for |service_name| owner changes for |callback|.
579 // Any unique (service_name, callback) can be used. Non-registered callbacks
580 // for a given service name are ignored.
581 // |service_name| must not be empty and |callback| must not be null.
583 // Must be called in the origin thread.
584 virtual void UnlistenForServiceOwnerChange(
585 const std::string& service_name,
586 const GetServiceOwnerCallback& callback);
588 // Returns true if the bus is connected to D-Bus.
589 bool is_connected() { return connection_ != NULL; }
591 protected:
592 // This is protected, so we can define sub classes.
593 virtual ~Bus();
595 private:
596 friend class base::RefCountedThreadSafe<Bus>;
598 // Helper function used for RemoveObjectProxy().
599 void RemoveObjectProxyInternal(scoped_refptr<dbus::ObjectProxy> object_proxy,
600 const base::Closure& callback);
602 // Helper function used for UnregisterExportedObject().
603 void UnregisterExportedObjectInternal(
604 scoped_refptr<dbus::ExportedObject> exported_object);
606 // Helper function used for ShutdownOnDBusThreadAndBlock().
607 void ShutdownOnDBusThreadAndBlockInternal();
609 // Helper function used for RequestOwnership().
610 void RequestOwnershipInternal(const std::string& service_name,
611 OnOwnershipCallback on_ownership_callback);
613 // Helper function used for GetServiceOwner().
614 void GetServiceOwnerInternal(const std::string& service_name,
615 const GetServiceOwnerCallback& callback);
617 // Helper function used for ListenForServiceOwnerChange().
618 void ListenForServiceOwnerChangeInternal(
619 const std::string& service_name,
620 const GetServiceOwnerCallback& callback);
622 // Helper function used for UnListenForServiceOwnerChange().
623 void UnlistenForServiceOwnerChangeInternal(
624 const std::string& service_name,
625 const GetServiceOwnerCallback& callback);
627 // Processes the all incoming data to the connection, if any.
629 // BLOCKING CALL.
630 void ProcessAllIncomingDataIfAny();
632 // Called when a watch object is added. Used to start monitoring the
633 // file descriptor used for D-Bus communication.
634 dbus_bool_t OnAddWatch(DBusWatch* raw_watch);
636 // Called when a watch object is removed.
637 void OnRemoveWatch(DBusWatch* raw_watch);
639 // Called when the "enabled" status of |raw_watch| is toggled.
640 void OnToggleWatch(DBusWatch* raw_watch);
642 // Called when a timeout object is added. Used to start monitoring
643 // timeout for method calls.
644 dbus_bool_t OnAddTimeout(DBusTimeout* raw_timeout);
646 // Called when a timeout object is removed.
647 void OnRemoveTimeout(DBusTimeout* raw_timeout);
649 // Called when the "enabled" status of |raw_timeout| is toggled.
650 void OnToggleTimeout(DBusTimeout* raw_timeout);
652 // Called when the dispatch status (i.e. if any incoming data is
653 // available) is changed.
654 void OnDispatchStatusChanged(DBusConnection* connection,
655 DBusDispatchStatus status);
657 // Called when the connection is diconnected.
658 void OnConnectionDisconnected(DBusConnection* connection);
660 // Called when a service owner change occurs.
661 void OnServiceOwnerChanged(DBusMessage* message);
663 // Callback helper functions. Redirects to the corresponding member function.
664 static dbus_bool_t OnAddWatchThunk(DBusWatch* raw_watch, void* data);
665 static void OnRemoveWatchThunk(DBusWatch* raw_watch, void* data);
666 static void OnToggleWatchThunk(DBusWatch* raw_watch, void* data);
667 static dbus_bool_t OnAddTimeoutThunk(DBusTimeout* raw_timeout, void* data);
668 static void OnRemoveTimeoutThunk(DBusTimeout* raw_timeout, void* data);
669 static void OnToggleTimeoutThunk(DBusTimeout* raw_timeout, void* data);
670 static void OnDispatchStatusChangedThunk(DBusConnection* connection,
671 DBusDispatchStatus status,
672 void* data);
674 // Calls OnConnectionDisconnected if the Disconnected signal is received.
675 static DBusHandlerResult OnConnectionDisconnectedFilter(
676 DBusConnection* connection,
677 DBusMessage* message,
678 void* user_data);
680 // Calls OnServiceOwnerChanged for a NameOwnerChanged signal.
681 static DBusHandlerResult OnServiceOwnerChangedFilter(
682 DBusConnection* connection,
683 DBusMessage* message,
684 void* user_data);
686 const BusType bus_type_;
687 const ConnectionType connection_type_;
688 scoped_refptr<base::SequencedTaskRunner> dbus_task_runner_;
689 base::WaitableEvent on_shutdown_;
690 DBusConnection* connection_;
692 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_;
693 base::PlatformThreadId origin_thread_id_;
695 std::set<std::string> owned_service_names_;
696 // The following sets are used to check if rules/object_paths/filters
697 // are properly cleaned up before destruction of the bus object.
698 // Since it's not an error to add the same match rule twice, the repeated
699 // match rules are counted in a map.
700 std::map<std::string, int> match_rules_added_;
701 std::set<ObjectPath> registered_object_paths_;
702 std::set<std::pair<DBusHandleMessageFunction, void*> >
703 filter_functions_added_;
705 // ObjectProxyTable is used to hold the object proxies created by the
706 // bus object. Key is a pair; the first part is a concatenated string of
707 // service name + object path, like
708 // "org.chromium.TestService/org/chromium/TestObject".
709 // The second part is the ObjectProxy::Options for the proxy.
710 typedef std::map<std::pair<std::string, int>,
711 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable;
712 ObjectProxyTable object_proxy_table_;
714 // ExportedObjectTable is used to hold the exported objects created by
715 // the bus object. Key is a concatenated string of service name +
716 // object path, like "org.chromium.TestService/org/chromium/TestObject".
717 typedef std::map<const dbus::ObjectPath,
718 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable;
719 ExportedObjectTable exported_object_table_;
721 // ObjectManagerTable is used to hold the object managers created by the
722 // bus object. Key is a concatenated string of service name + object path,
723 // like "org.chromium.TestService/org/chromium/TestObject".
724 typedef std::map<std::string,
725 scoped_refptr<dbus::ObjectManager> > ObjectManagerTable;
726 ObjectManagerTable object_manager_table_;
728 // A map of NameOwnerChanged signals to listen for and the callbacks to run
729 // on the origin thread when the owner changes.
730 // Only accessed on the DBus thread.
731 // Key: Service name
732 // Value: Vector of callbacks. Unique and expected to be small. Not using
733 // std::set here because base::Callbacks don't have a '<' operator.
734 typedef std::map<std::string, std::vector<GetServiceOwnerCallback> >
735 ServiceOwnerChangedListenerMap;
736 ServiceOwnerChangedListenerMap service_owner_changed_listener_map_;
738 bool async_operations_set_up_;
739 bool shutdown_completed_;
741 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and
742 // OnAddTimeout()/OnRemoveTimeou() are balanced.
743 int num_pending_watches_;
744 int num_pending_timeouts_;
746 std::string address_;
747 base::Closure on_disconnected_closure_;
749 DISALLOW_COPY_AND_ASSIGN(Bus);
752 } // namespace dbus
754 #endif // DBUS_BUS_H_