diff options
author | zqiu <zqiu@chromium.org> | 2015-07-07 19:08:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-08 02:09:15 +0000 |
commit | f63bfe5e62af1e37616239b8ff7754ec8e836cc1 (patch) | |
tree | 06b4093c38bd2f21b065ad83c077480b93c89e7e /dbus | |
parent | b372398531cba1b6a917a996e50f8ddf2e033d55 (diff) | |
download | chromium_src-f63bfe5e62af1e37616239b8ff7754ec8e836cc1.zip chromium_src-f63bfe5e62af1e37616239b8ff7754ec8e836cc1.tar.gz chromium_src-f63bfe5e62af1e37616239b8ff7754ec8e836cc1.tar.bz2 |
dbus: expose bus connection unique name
Add an API to Bus class to expose the unique name of the bus connection.
The function will return an empty string if bus connection is not
established.
BUG=chromium:507718
TEST=unittest
Review URL: https://codereview.chromium.org/1222073003
Cr-Commit-Position: refs/heads/master@{#337732}
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/bus.cc | 6 | ||||
-rw-r--r-- | dbus/bus.h | 4 | ||||
-rw-r--r-- | dbus/bus_unittest.cc | 20 |
3 files changed, 30 insertions, 0 deletions
diff --git a/dbus/bus.cc b/dbus/bus.cc index 9fbd821..3a4fe21 100644 --- a/dbus/bus.cc +++ b/dbus/bus.cc @@ -1020,6 +1020,12 @@ void Bus::UnlistenForServiceOwnerChangeInternal( RemoveFilterFunction(Bus::OnServiceOwnerChangedFilter, this); } +std::string Bus::GetConnectionName() { + if (!connection_) + return ""; + return dbus_bus_get_unique_name(connection_); +} + dbus_bool_t Bus::OnAddWatch(DBusWatch* raw_watch) { AssertOnDBusThread(); @@ -586,6 +586,10 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> { const std::string& service_name, const GetServiceOwnerCallback& callback); + // Return the unique name of the bus connnection if it is connected to + // D-BUS. Otherwise, return an empty string. + std::string GetConnectionName(); + // Returns true if the bus is connected to D-Bus. bool is_connected() { return connection_ != NULL; } diff --git a/dbus/bus_unittest.cc b/dbus/bus_unittest.cc index 1e84fa5..27d9bb2 100644 --- a/dbus/bus_unittest.cc +++ b/dbus/bus_unittest.cc @@ -394,4 +394,24 @@ TEST(BusTest, ListenForServiceOwnerChange) { EXPECT_TRUE(bus->shutdown_completed()); } +TEST(BusTest, GetConnectionName) { + Bus::Options options; + scoped_refptr<Bus> bus = new Bus(options); + + // Connection name is empty since bus is not connected. + EXPECT_FALSE(bus->is_connected()); + EXPECT_TRUE(bus->GetConnectionName().empty()); + + // Connect bus to D-Bus. + bus->Connect(); + + // Connection name is not empty after connection is established. + EXPECT_TRUE(bus->is_connected()); + EXPECT_FALSE(bus->GetConnectionName().empty()); + + // Shut down synchronously. + bus->ShutdownAndBlock(); + EXPECT_TRUE(bus->shutdown_completed()); +} + } // namespace dbus |