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

Side by Side Diff: src/common/chromeos/dbus/dbus.cc

Issue 500008: Two changes to the DBus C++ library. (Closed)
Patch Set: Created 11 years 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
« no previous file with comments | « src/common/chromeos/dbus/dbus.h ('k') | no next file » | 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) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS 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 "chromeos/dbus/dbus.h" 5 #include "chromeos/dbus/dbus.h"
6 6
7 #include <dbus/dbus.h> 7 #include <dbus/dbus.h>
8 #include <dbus/dbus-glib-lowlevel.h> 8 #include <dbus/dbus-glib-lowlevel.h>
9 #include <base/logging.h> 9 #include <base/logging.h>
10 10
(...skipping 26 matching lines...) Expand all
37 &Resetter(&error).lvalue()); 37 &Resetter(&error).lvalue());
38 CHECK(result); 38 CHECK(result);
39 // Set to not exit when when system bus is disconnected. 39 // Set to not exit when when system bus is disconnected.
40 // This fixes the problem where when the dbus daemon is stopped, exit is 40 // This fixes the problem where when the dbus daemon is stopped, exit is
41 // called which kills Chrome. 41 // called which kills Chrome.
42 ::dbus_connection_set_exit_on_disconnect( 42 ::dbus_connection_set_exit_on_disconnect(
43 ::dbus_g_connection_get_connection(result), FALSE); 43 ::dbus_g_connection_get_connection(result), FALSE);
44 return BusConnection(result); 44 return BusConnection(result);
45 } 45 }
46 46
47 BusConnection GetPrivateBusConnection(const char* address) {
48 // Since dbus-glib does not have an API like dbus_g_connection_open_private(),
49 // we have to implement our own.
50
51 // We have to call _dbus_g_value_types_init() to register standard marshalers
52 // just like as dbus_g_bus_get() and dbus_g_connection_open() do, but the
53 // function is not exported. So we call GetPrivateBusConnection() which calls
54 // dbus_g_bus_get() here instead. Note that if we don't call
55 // _dbus_g_value_types_init(), we might get "WARNING **: No demarshaller
56 // registered for type xxxxx" error and might not be able to handle incoming
57 // signals nor method calls.
58 GetSystemBusConnection();
59
60 ::DBusGConnection* result = NULL;
61 ::DBusConnection* raw_connection
62 = ::dbus_connection_open_private(address, NULL);
63 CHECK(raw_connection);
64
65 ::dbus_connection_setup_with_g_main(raw_connection, NULL);
66 // A reference count of |raw_connection| is transferred to |result|. You don't
67 // have to (and should not) unref the |raw_connection|.
68 result = ::dbus_connection_get_g_connection(raw_connection);
69 CHECK(result);
70
71 ::dbus_connection_set_exit_on_disconnect(
72 ::dbus_g_connection_get_connection(result), FALSE);
73
74 // TODO(yusukes): We should call dbus_connection_close() for private
75 // connections.
76 return BusConnection(result);
77 }
78
47 bool RetrieveProperties(const Proxy& proxy, 79 bool RetrieveProperties(const Proxy& proxy,
48 const char* interface, 80 const char* interface,
49 glib::ScopedHashTable* result) { 81 glib::ScopedHashTable* result) {
50 glib::ScopedError error; 82 glib::ScopedError error;
51 83
52 if (!::dbus_g_proxy_call(proxy.gproxy(), "GetAll", &Resetter(&error).lvalue(), 84 if (!::dbus_g_proxy_call(proxy.gproxy(), "GetAll", &Resetter(&error).lvalue(),
53 G_TYPE_STRING, interface, G_TYPE_INVALID, 85 G_TYPE_STRING, interface, G_TYPE_INVALID,
54 ::dbus_g_type_get_map("GHashTable", G_TYPE_STRING, 86 ::dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
55 G_TYPE_VALUE), 87 G_TYPE_VALUE),
56 &Resetter(result).lvalue(), G_TYPE_INVALID)) { 88 &Resetter(result).lvalue(), G_TYPE_INVALID)) {
57 LOG(WARNING) << "RetrieveProperties failed: " 89 LOG(WARNING) << "RetrieveProperties failed: "
58 << (error->message ? error->message : "Unknown Error."); 90 << (error->message ? error->message : "Unknown Error.");
59 return false; 91 return false;
60 } 92 }
61 return true; 93 return true;
62 } 94 }
63 95
96 /* static */
97 Proxy::value_type Proxy::GetGProxy(const BusConnection& connection,
98 const char* name,
99 const char* path,
100 const char* interface,
101 bool connect_to_name_owner) {
102 value_type result = NULL;
103 if (connect_to_name_owner) {
104 glib::ScopedError error;
105 result = ::dbus_g_proxy_new_for_name_owner(connection.object_,
106 name,
107 path,
108 interface,
109 &Resetter(&error).lvalue());
110 if (!result) {
111 LOG(ERROR) << "Failed to construct proxy: "
112 << (error->message ? error->message : "Unknown Error")
113 << ": " << path;
114 }
115 } else {
116 result = ::dbus_g_proxy_new_for_name(connection.object_,
117 name,
118 path,
119 interface);
120 if (!result) {
121 LOG(ERROR) << "Failed to construct proxy: " << path;
122 }
123 }
124 return result;
125 }
64 126
65 } // namespace dbus 127 } // namespace dbus
66 } // namespace chromeos 128 } // namespace chromeos
OLDNEW
« no previous file with comments | « src/common/chromeos/dbus/dbus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698