def run(self): bus, loop = connect_to_session_bus() logger.info("Setting up DBus objects...") provider_list = [self.provider] session_list = [] # TODO: load sessions logger.debug("Constructing Service object") service_obj = Service(provider_list, session_list) logger.debug("Constructing ServiceWrapper") service_wrp = ServiceWrapper(service_obj, on_exit=lambda: loop.quit()) logger.info("Publishing all objects on DBus") service_wrp.publish_related_objects(bus) logger.info("Publishing all managed objects (events should fire there)") service_wrp.publish_managed_objects() logger.debug("Attempting to claim bus name: %s", self.ns.bus_name) bus_name = BusName(self.ns.bus_name, bus) logger.info( "PlainBox DBus service ready, claimed name: %s", bus_name.get_name()) try: loop.run() except KeyboardInterrupt: logger.warning(( "Main loop interrupted!" " It is recommended to call the Exit() method on the" " exported service object instead")) finally: logger.debug("Releasing %s", bus_name) # XXX: ugly but that's how one can reliably release a bus name del bus_name # Remove objects from the bus service_wrp.remove_from_connection() logger.debug("Closing %s", bus) bus.close() logger.debug("Main loop terminated, exiting...")
def run(self): bus, loop = connect_to_session_bus() logger.info("Setting up DBus objects...") session_list = [] # TODO: load sessions logger.debug("Constructing Service object") service_obj = Service(self.provider_list, session_list, self.config) logger.debug("Constructing ServiceWrapper") service_wrp = ServiceWrapper(service_obj, on_exit=lambda: loop.quit()) logger.info("Publishing all objects on DBus") service_wrp.publish_related_objects(bus) logger.info( "Publishing all managed objects (events should fire there)") service_wrp.publish_managed_objects() logger.debug("Attempting to claim bus name: %s", self.ns.bus_name) bus_name = BusName(self.ns.bus_name, bus) logger.info("PlainBox DBus service ready, claimed name: %s", bus_name.get_name()) try: loop.run() except KeyboardInterrupt: logger.warning( ("Main loop interrupted!" " It is recommended to call the Exit() method on the" " exported service object instead")) finally: logger.debug("Releasing %s", bus_name) # XXX: ugly but that's how one can reliably release a bus name del bus_name # Remove objects from the bus service_wrp.remove_from_connection() logger.debug("Closing %s", bus) bus.close() logger.debug("Main loop terminated, exiting...")
def __init__(self): bus = dbus.SessionBus() bus_name = BusName('org.participatoryculture.dtv.onetime', bus=bus, do_not_queue=True) dbus.service.Object.__init__( self, bus_name=bus_name, object_path='/org/participatoryculture/dtv/OneTime')
def __init__(self, manager): from SCRIBES.Globals import session_bus as session from SCRIBES.Globals import SCRIBES_SAVE_PROCESS_DBUS_PATH bus_name = BusName(dbus_service, bus=session) Object.__init__(self, bus_name, SCRIBES_SAVE_PROCESS_DBUS_PATH) self.__manager = manager manager.connect("is-ready", self.__is_ready_cb) manager.connect("saved-data", self.__saved_data_cb) manager.connect("error", self.__error_cb)
def __init__(self, manager): from SCRIBES.Globals import session_bus from dbus.exceptions import NameExistsException try: bus_name = BusName(DBUS_SERVICE, bus=session_bus, do_not_queue=True) Object.__init__(self, bus_name, DBUS_PATH) self.__manager = manager except NameExistsException: manager.quit()
def __init__(self, name: str, obj_path: str) -> None: bus = dbus.SessionBus() bus_name = BusName(name, bus=bus, allow_replacement=True, replace_existing=True) super().__init__(bus_name=bus_name, obj_path=obj_path) self.bus_name = bus_name self.bus = bus self.managed_objects = [] # type: List[PropertiesObject]
def __init__(self, manager): from SCRIBES.Globals import session_bus from dbus.exceptions import NameExistsException try: bus_name = BusName(indexer_dbus_service, bus=session_bus, do_not_queue=True) Object.__init__(self, bus_name, indexer_dbus_path) self.__manager = manager manager.connect("finished", self.__finished_cb) except NameExistsException: manager.quit()
def register_phonehome_object(self, phonehome_object_path): """Registers the bus name and a new phonehome object in this one. :param phonehome_object_path: The object path tho publish the desired PhoneHome Object. Format: /xxx/... :return: None """ self.logger.debug("Registering new DBus name '%s'", PHONEHOME_DBUS_NAME) bus = BusName(PHONEHOME_DBUS_NAME, bus=SystemBus()) self.logger.debug("Registering new PhoneHome Object '%s' in the Bus", phonehome_object_path) self.dbus_phonehome_objects[phonehome_object_path] = DbusPhoneHomeObject(self.logger, bus, phonehome_object_path)
def __init__(self, manager): from Globals import session_bus from dbus.exceptions import NameExistsException try: service_name = "net.sourceforge.Scribes" object_path = "/net/sourceforge/Scribes" bus_name = BusName(service_name, bus=session_bus, do_not_queue=True) Object.__init__(self, bus_name, object_path) self.__manager = manager except NameExistsException: print "ERROR! Another instances of Scribes is already running. Cannot run more than one instance of Scribes. Killing this instance!" manager.force_quit()
def __init__(self, bus): def player_message_cb(bus, message): if gst.MESSAGE_EOS == message.type: self.__player.set_state(gst.STATE_NULL) return True if gst.MESSAGE_ERROR == message.type: print message.structure and message.structure.to_string() or '' self.__player.set_state(gst.STATE_NULL) return True if gst.MESSAGE_STATE_CHANGED == message.type: if message.src == self.__player: self.StateChanged(*self.GetState()) self.__favorites.set_state(*self.GetState()) return True if gst.MESSAGE_TAG == message.type: valid_types = float, int, str, unicode tags = [(k, v) for k, v in dict(message.structure).items() if isinstance(v, valid_types)] self.StreamTagsChanged(dict(tags)) return True return True self.__data_stage = 0 self.__player = Player() self.__player.get_bus().add_watch(player_message_cb) self.__httplib = Http(cache=get_cache_filename()) self.__favorites = Favorites() self.__stations = list() self.__stream_tags = dict() proxy = SessionBus().get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications') self.__notifications = Interface(proxy, 'org.freedesktop.Notifications') self.__notify_id = 0 name = BusName(Service.name, bus) super(Service, self).__init__(bus, '/', name) self.__loop = MainLoop(None, True) Thread(target=self.__load).start()
def main(): file_path = Path("./ocean3.mp4") size = Size(800, 600) print("Starting streamer... ", flush=True) mainloop = GLib.MainLoop() DBusGMainLoop(set_as_default=True) bus = BusConnection(getenv("DBUS_ADDRESS") or DBUS_ADDRESS) bus_name = BusName(BUS_NAME, bus) StreamerObject(bus, bus_name, file_path, size) mainloop.run()
def init( commands, # type: CommandRegistry winman # type: WindowManager ): # type: (...) -> Tuple[Optional[BusName], Optional[QuickTile]] """Initialize the DBus backend""" try: DBusGMainLoop(set_as_default=True) sess_bus = SessionBus() except DBusException: logging.warn("Could not connect to the D-Bus Session Bus.") return None, None dbus_name = BusName("com.ssokolow.QuickTile", sess_bus) dbus_obj = QuickTile(sess_bus, commands, winman) return dbus_name, dbus_obj
def init( commands: CommandRegistry, winman: WindowManager, ) -> Optional[Tuple[BusName, QuickTile]]: """Initialize the DBus backend This handles hooking D-Bus into the Glib main loop, connecting to the session bus, and creating a :class:`QuickTile` instance.""" try: DBusGMainLoop(set_as_default=True) sess_bus = SessionBus() except DBusException: logging.warning("Could not connect to the D-Bus Session Bus.") return None dbus_name = BusName("com.ssokolow.QuickTile", sess_bus) dbus_obj = QuickTile(sess_bus, commands, winman) return dbus_name, dbus_obj
def __init__(self, manager): from SCRIBES.Globals import session_bus bus_name = BusName(indexer_dbus_service, bus=session_bus) Object.__init__(self, bus_name, indexer_dbus_path) self.__manager = manager manager.connect("finished", self.__finished_cb)
def __init__(self, uid): bus_name = BusName('.'.join([DBUS_NS, uid]), bus=SessionBus()) self.dbus_uid = uid self.dbus_path = '/vim' dbus.service.Object.__init__(self, bus_name, self.dbus_path)
class Server(SingleTestsImpl, TestsImpl, SignalTestsImpl): def triggered_by_client(self, parameter1, parameter2, sender, sender_path): # Called when the client emits TestSignals.Trigger from any object. logger.info('signal/callback: Triggered by client (%s:%s): (%r,%r)', sender, sender_path, parameter1, parameter2) tested_things.add(INTERFACE_SIGNAL_TESTS + '.Trigger') dbus.Interface(dbus.SessionBus().get_object(sender, sender_path), INTERFACE_CALLBACK_TESTS).Response( parameter1, parameter2) logger.info('signal/callback: Sent Response') if __name__ == '__main__': bus = SessionBus() bus_name = BusName(CROSS_TEST_BUS_NAME, bus=bus) loop = gobject.MainLoop() obj = Server(bus_name, CROSS_TEST_PATH, loop.quit) objects[CROSS_TEST_PATH] = obj bus.add_signal_receiver(obj.triggered_by_client, signal_name='Trigger', dbus_interface=INTERFACE_SIGNAL_TESTS, named_service=None, path=None, sender_keyword='sender', path_keyword='sender_path', utf8_strings=True) logger.info("running...") loop.run() logger.info("main loop exited.")
import dbus, dbus.service, gobject from dbus.mainloop.glib import DBusGMainLoop from dbus.service import BusName bus = dbus.SessionBus(mainloop=DBusGMainLoop()) class Test(dbus.service.Object): def __init__(self, path): dbus.service.Object.__init__(self, bus, path) x = dbus.Boolean(1) @dbus.service.signal(dbus_interface='org.gnome.ScreenSaver', signature='b') def ActiveChanged(self, y): print "emmitting...", repr(y) return True name = BusName(name="org.gnome.ScreenSaver", bus=bus) app = gobject.MainLoop() t = Test('/org/gnome/ScreenSaver') gobject.timeout_add(1, t.ActiveChanged, dbus.Boolean(1)) gobject.timeout_add(5000, t.ActiveChanged, dbus.Boolean(0)) gobject.timeout_add(5001, app.quit) app.run()
def __init__(self, processor): from Globals import session_bus as session bus_name = BusName(dbus_service, bus=session) Object.__init__(self, bus_name, dbus_path) self.__processor = processor
def __init__(self, plugin_manager, application_context): bus_name = BusName(application_context.dbus_unique_bus_name, dbus.SessionBus()) super(PluginManagerDBusInterface, self).__init__(bus_name, '/PluginManager') self._plugin_manager = plugin_manager
def __init__(self, named_bus_name): bus_name = BusName(named_bus_name, dbus.SessionBus()) super(ApplicationDBusInterface, self).__init__(bus_name, '/Application')
def __init__(self, bus_name: BusName, obj_path: str) -> None: if not hasattr(self, 'app'): self.app = Qubes() self.events_dispatcher = EventsDispatcher(self.app) super().__init__(bus_name=bus_name, object_path=obj_path) self.bus = bus_name.get_bus()