class MSADbusService(service.Object): """ Clase Base para generar un servicio via DBUS. """ def __init__(self, set_as_default=True): DBusGMainLoop(set_as_default=set_as_default) self.session_bus = SessionBus() # WARNING, NO BORRAR la asignación a la variable name aunque ésta no se # use, sino Dbus restartea el servicio N veces una por cada reintento # del cliente. name = service.BusName(self.bus_name, self.session_bus) self._service_init() service.Object.__init__(self, self.session_bus, self.object_path) self._loop = MainLoop() try: self._loop.run() except KeyboardInterrupt: pass def quit(self): """ Cierra el servicio DBUS, útil para casos de reinicio. DEBE ser implementado por los hijos de esta clase. """ pass
def main(): print('starting D-Bus service at %s' % BUS_NAME) DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() name = dbus.service.BusName(BUS_NAME, bus) service = DBusService(bus=bus) print('call with: "dbus-send --session --print-reply --dest=%(busname)s %(object_path)s ' '%(busname)s.crash int32:123 string:foo boolean:true"' % {'busname': BUS_NAME, 'object_path': OBJECT_PATH}) loop = MainLoop() loop.run()
def on_message(_: Gst.Bus, message: Gst.Message, loop: GObject.MainLoop): message_type = message.type if message_type == Gst.MessageType.EOS: print("End of stream") loop.quit() elif message_type == Gst.MessageType.ERROR: err, debug = message.parse_error() print(err, debug) loop.quit() return True
def __init__(self, set_as_default=True): DBusGMainLoop(set_as_default=set_as_default) self.session_bus = SessionBus() # WARNING, NO BORRAR la asignación a la variable name aunque ésta no se # use, sino Dbus restartea el servicio N veces una por cada reintento # del cliente. name = service.BusName(self.bus_name, self.session_bus) self._service_init() service.Object.__init__(self, self.session_bus, self.object_path) self._loop = MainLoop() try: self._loop.run() except KeyboardInterrupt: pass
def main(): DBusGMainLoop( set_as_default = True ) service = GwnPhone() support_service = SupportService( service ) try: MainLoop().run() except KeyboardInterrupt: pass
def __init__(self): DBusGMainLoop(set_as_default=True) self.mem = 'ActiveChanged' self.dest = 'org.gnome.ScreenSaver' self.bus = dbus.SessionBus() self.loop = MainLoop() self.bus.add_signal_receiver(self.catch, self.mem, self.dest) self.paused_before = False self.purple_prev = None
def on_message(bus: Gst.Bus, message: Gst.Message, loop: GObject.MainLoop): mtype = message.type """ Gstreamer Message Types and how to parse https://lazka.github.io/pgi-docs/Gst-1.0/flags.html#Gst.MessageType """ if mtype == Gst.MessageType.EOS: print("End of stream") loop.quit() elif mtype == Gst.MessageType.ERROR: err, debug = message.parse_error() print(err, debug) loop.quit() elif mtype == Gst.MessageType.WARNING: err, debug = message.parse_warning() print(err, debug) return True
def main(): """The main entry point for the systemd service.""" DBusGMainLoop( set_as_default = True ) service = ManagerService() support_service = SupportService() try: logger.debug( 'entering main loop' ) MainLoop().run() except KeyboardInterrupt: pass
def pair(args): """ Pair to the specified device Args: args (dict): args parsed on the command line Returns: results (dict): return message and code of the operation """ def success(): try: device_manager.trust_device() device_manager.connect_device() format_results({'result': 'Success', 'code': ''}) finally: mainloop.quit() def error(err): try: if err == 'org.freedesktop.DBus.Error.NoReply' and self.dev: code = 'Timeout' device_manager.cancel_device() if err in ('org.bluez.Error.AuthenticationCanceled', 'org.bluez.Error.AuthenticationFailed', 'org.bluez.Error.AuthenticationRejected', 'org.bluez.Error.AuthenticationTimeout'): code = 'AuthenticationError' else: code = 'CreatingDeviceFailed' format_results({'result': 'Error', 'code': code}) finally: mainloop.quit() mainloop = MainLoop() device_manager = DeviceManager(args.device) device_manager.pair_device(success, error) mainloop.run()
try: n = notify2.Notification(head, desc) n.add_action("yes", "Yes", boolean_callback, uid) n.add_action("no", "No", boolean_callback, uid) n.connect("closed", click_callback) n.show() return 0 except: return 1 # Initialize a main loop dbusLoop = DBusGMainLoop(set_as_default=True) notify2.init("keystrokes", dbusLoop) loop = MainLoop() # Declare a name where our service can be reached try: bus_name = dbus.service.BusName("com.keystrokes.notifs", bus=dbus.SessionBus(), do_not_queue=True) DesktopNotification(bus_name) except dbus.exceptions.NameExistsException: # print("service is already running") logging.info("service is already running") sys.exit(1) # Run the loop try: loop.run()
self._connection = dbus.ObjectPath(value) else: raise ValueError('Read-only or nonexistent property') props[prop] = self._account_props()[prop] self.AccountPropertyChanged(props) elif iface == ACCOUNT_IFACE_AVATAR_IFACE: if prop == 'Avatar': self._avatar = dbus.Struct( (dbus.ByteArray(value[0]), unicode(value[1])), signature='ays') self.AvatarChanged() else: raise ValueError('Nonexistent property') else: raise ValueError('No such interface') if __name__ == '__main__': DBusGMainLoop(set_as_default=True) try: am = AccountManager() except dbus.NameExistsException: print >> sys.stderr, 'AccountManager already running' sys.exit(1) print "AccountManager running..." mainloop = MainLoop() mainloop.run()
elif prop == 'Connection': self._connection = dbus.ObjectPath(value) else: raise ValueError('Read-only or nonexistent property') props[prop] = self._account_props()[prop] self.AccountPropertyChanged(props) elif iface == ACCOUNT_IFACE_AVATAR_IFACE: if prop == 'Avatar': self._avatar = dbus.Struct( (dbus.ByteArray(value[0]), unicode(value[1])), signature='ays') self.AvatarChanged() else: raise ValueError('Nonexistent property') else: raise ValueError('No such interface') if __name__ == '__main__': DBusGMainLoop(set_as_default=True) try: am = AccountManager() except dbus.NameExistsException: print >> sys.stderr, 'AccountManager already running' sys.exit(1) print "AccountManager running..." mainloop = MainLoop() mainloop.run()