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

Side by Side Diff: dbus/bus.h

Issue 7702001: Reuse existing object proxies and exported objects, if these exist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-upload 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 | « no previous file | dbus/bus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 5
6 #ifndef DBUS_BUS_H_ 6 #ifndef DBUS_BUS_H_
7 #define DBUS_BUS_H_ 7 #define DBUS_BUS_H_
8 #pragma once 8 #pragma once
9 9
10 #include <map>
10 #include <set> 11 #include <set>
11 #include <string> 12 #include <string>
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/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/tracked_objects.h" 18 #include "base/tracked_objects.h"
18 19
19 class MessageLoop; 20 class MessageLoop;
(...skipping 28 matching lines...) Expand all
48 // 49 //
49 // BLOCKING CALLS 50 // BLOCKING CALLS
50 // 51 //
51 // Functions that issue blocking calls are marked "BLOCKING CALL" and 52 // Functions that issue blocking calls are marked "BLOCKING CALL" and
52 // these functions should be called in the D-Bus thread (if 53 // these functions should be called in the D-Bus thread (if
53 // supplied). AssertOnDBusThread() is placed in these functions. 54 // supplied). AssertOnDBusThread() is placed in these functions.
54 // 55 //
55 // Note that it's hard to tell if a libdbus function is actually blocking 56 // Note that it's hard to tell if a libdbus function is actually blocking
56 // or not (ex. dbus_bus_request_name() internally calls 57 // or not (ex. dbus_bus_request_name() internally calls
57 // dbus_connection_send_with_reply_and_block(), which is a blocking 58 // dbus_connection_send_with_reply_and_block(), which is a blocking
58 // call). To err on the side, we consider all libdbus functions that deal 59 // call). To err on the safe side, we consider all libdbus functions that
59 // with the connection to dbus-damoen to be blocking. 60 // deal with the connection to dbus-damoen to be blocking.
60 // 61 //
61 // EXAMPLE USAGE: 62 // EXAMPLE USAGE:
62 // 63 //
63 // Synchronous method call: 64 // Synchronous method call:
64 // 65 //
65 // dbus::Bus::Options options; 66 // dbus::Bus::Options options;
66 // // Set up the bus options here. 67 // // Set up the bus options here.
67 // ... 68 // ...
68 // dbus::Bus bus(options); 69 // dbus::Bus bus(options);
69 // 70 //
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 }; 158 };
158 159
159 // Called when shutdown is done. Used for Shutdown(). 160 // Called when shutdown is done. Used for Shutdown().
160 typedef base::Callback<void ()> OnShutdownCallback; 161 typedef base::Callback<void ()> OnShutdownCallback;
161 162
162 // Creates a Bus object. The actual connection will be established when 163 // Creates a Bus object. The actual connection will be established when
163 // Connect() is called. 164 // Connect() is called.
164 explicit Bus(const Options& options); 165 explicit Bus(const Options& options);
165 166
166 // Gets the object proxy for the given service name and the object path. 167 // Gets the object proxy for the given service name and the object path.
167 // The caller must not delete the returned object. The bus will own the 168 // The caller must not delete the returned object.
168 // object. Never returns NULL. 169 //
170 // Returns an existing object proxy if the bus object already owns the
171 // object proxy for the given service name and the object path.
172 // Never returns NULL.
173 //
174 // The bus will own all object proxies created by the bus, to ensure
175 // that the object proxies are detached from remote objects at the
176 // shutdown time of the bus.
169 // 177 //
170 // The object proxy is used to call methods of remote objects, and 178 // The object proxy is used to call methods of remote objects, and
171 // receive signals from them. 179 // receive signals from them.
172 // 180 //
173 // |service_name| looks like "org.freedesktop.NetworkManager", and 181 // |service_name| looks like "org.freedesktop.NetworkManager", and
174 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0". 182 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0".
175 // 183 //
176 // Must be called in the origin thread. 184 // Must be called in the origin thread.
177 virtual ObjectProxy* GetObjectProxy(const std::string& service_name, 185 virtual ObjectProxy* GetObjectProxy(const std::string& service_name,
178 const std::string& object_path); 186 const std::string& object_path);
179 187
180 // Gets the exported object for the given service name and the object 188 // Gets the exported object for the given service name and the object
181 // path. The caller must not delete the returned object. The bus will 189 // path. The caller must not delete the returned object.
182 // own the object. Never returns NULL. 190 //
191 // Returns an existing exported object if the bus object already owns
192 // the exported object for the given service name and the object path.
193 // Never returns NULL.
194 //
195 // The bus will own all exported objects created by the bus, to ensure
196 // that the exported objects are unregistered at the shutdown time of
197 // the bus.
183 // 198 //
184 // The exported object is used to export methods of local objects, and 199 // The exported object is used to export methods of local objects, and
185 // send signal from them. 200 // send signal from them.
186 // 201 //
187 // Must be called in the origin thread. 202 // Must be called in the origin thread.
188 virtual ExportedObject* GetExportedObject(const std::string& service_name, 203 virtual ExportedObject* GetExportedObject(const std::string& service_name,
189 const std::string& object_path); 204 const std::string& object_path);
190 205
191 // Shuts down the bus and blocks until it's done. More specifically, this 206 // Shuts down the bus and blocks until it's done. More specifically, this
192 // function does the following: 207 // function does the following:
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 base::PlatformThreadId origin_thread_id_; 424 base::PlatformThreadId origin_thread_id_;
410 base::PlatformThreadId dbus_thread_id_; 425 base::PlatformThreadId dbus_thread_id_;
411 426
412 std::set<std::string> owned_service_names_; 427 std::set<std::string> owned_service_names_;
413 // The following sets are used to check if rules/object_paths/filters 428 // The following sets are used to check if rules/object_paths/filters
414 // are properly cleaned up before destruction of the bus object. 429 // are properly cleaned up before destruction of the bus object.
415 std::set<std::string> match_rules_added_; 430 std::set<std::string> match_rules_added_;
416 std::set<std::string> registered_object_paths_; 431 std::set<std::string> registered_object_paths_;
417 std::set<DBusHandleMessageFunction> filter_functions_added_; 432 std::set<DBusHandleMessageFunction> filter_functions_added_;
418 433
419 std::vector<scoped_refptr<dbus::ObjectProxy> > object_proxies_; 434 // ObjectProxyTable is used to hold the object proxies created by the
420 std::vector<scoped_refptr<dbus::ExportedObject> > exported_objects_; 435 // bus object. Key is a concatenated string of service name + object path,
436 // like "org.chromium.TestService/org/chromium/TestObject".
437 typedef std::map<std::string,
438 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable;
439 ObjectProxyTable object_proxy_table_;
440
441 // ExportedObjectTable is used to hold the exported objects created by
442 // the bus object. Key is a concatenated string of service name +
443 // object path, like "org.chromium.TestService/org/chromium/TestObject".
444 typedef std::map<std::string,
445 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable;
446 ExportedObjectTable exported_object_table_;
421 447
422 bool async_operations_are_set_up_; 448 bool async_operations_are_set_up_;
423 449
424 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and 450 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and
425 // OnAddTimeout()/OnRemoveTimeou() are balanced. 451 // OnAddTimeout()/OnRemoveTimeou() are balanced.
426 int num_pending_watches_; 452 int num_pending_watches_;
427 int num_pending_timeouts_; 453 int num_pending_timeouts_;
428 454
429 DISALLOW_COPY_AND_ASSIGN(Bus); 455 DISALLOW_COPY_AND_ASSIGN(Bus);
430 }; 456 };
431 457
432 } // namespace dbus 458 } // namespace dbus
433 459
434 #endif // DBUS_BUS_H_ 460 #endif // DBUS_BUS_H_
OLDNEW
« no previous file with comments | « no previous file | dbus/bus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698