1
# Copyright 2012 Canonical
2
# Author: Thomi Richards
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
"""Initialise dbus once using glib mainloop."""
10
from __future__ import absolute_import
13
from dbus.mainloop.glib import DBusGMainLoop
15
_glib_loop_set = False
17
def get_session_bus():
18
"""This function returns a session bus that has had the DBus GLib main loop
23
if not _glib_loop_set:
25
# DBus has an annoying bug where we need to initialise it with the gobject main
26
# loop *before* it's initialised anywhere else. This module exists so we can
27
# initialise the dbus module once, and once only.
28
DBusGMainLoop(set_as_default=True)
30
# create a global session bus object:
31
return dbus.SessionBus()