当前位置: 首页>>代码示例>>Python>>正文


Python SessionBus.request_name方法代码示例

本文整理汇总了Python中dbus.SessionBus.request_name方法的典型用法代码示例。如果您正苦于以下问题:Python SessionBus.request_name方法的具体用法?Python SessionBus.request_name怎么用?Python SessionBus.request_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dbus.SessionBus的用法示例。


在下文中一共展示了SessionBus.request_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import request_name [as 别名]
class VoltiSession:
    def __init__(self, app_name):
        log.Notice("running init")
        self.app_name = app_name
        self.bus = SessionBus(mainloop = DBusGMainLoop() )

    def check(self):
        log.Notice("running check")
        return self.bus.request_name(self.app_name) != bus.REQUEST_NAME_REPLY_PRIMARY_OWNER
开发者ID:zerkalica,项目名称:volti-lite,代码行数:11,代码来源:voltisession.py

示例2: __new__

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import request_name [as 别名]
    def __new__(cls, name, bus=None, allow_replacement=False , replace_existing=False, do_not_queue=False):
        """Constructor, which may either return an existing cached object
        or a new object.

        :Parameters:
            `name` : str
                The well-known name to be advertised
            `bus` : dbus.Bus
                A Bus on which this service will be advertised.

                Omitting this parameter or setting it to None has been
                deprecated since version 0.82.1. For backwards compatibility,
                if this is done, the global shared connection to the session
                bus will be used.

            `allow_replacement` : bool
                If True, other processes trying to claim the same well-known
                name will take precedence over this one.
            `replace_existing` : bool
                If True, this process can take over the well-known name
                from other processes already holding it.
            `do_not_queue` : bool
                If True, this service will not be placed in the queue of
                services waiting for the requested name if another service
                already holds it.
        """
        validate_bus_name(name, allow_well_known=True, allow_unique=False)

        # if necessary, get default bus (deprecated)
        if bus is None:
            import warnings
            warnings.warn('Omitting the "bus" parameter to '
                          'dbus.service.BusName.__init__ is deprecated',
                          DeprecationWarning, stacklevel=2)
            bus = SessionBus()

        # see if this name is already defined, return it if so
        # FIXME: accessing internals of Bus
        if name in bus._bus_names:
            return bus._bus_names[name]

        # otherwise register the name
        name_flags = (
            (allow_replacement and _dbus_bindings.NAME_FLAG_ALLOW_REPLACEMENT or 0) |
            (replace_existing and _dbus_bindings.NAME_FLAG_REPLACE_EXISTING or 0) |
            (do_not_queue and _dbus_bindings.NAME_FLAG_DO_NOT_QUEUE or 0))

        retval = bus.request_name(name, name_flags)

        # TODO: more intelligent tracking of bus name states?
        if retval == _dbus_bindings.REQUEST_NAME_REPLY_PRIMARY_OWNER:
            pass
        elif retval == _dbus_bindings.REQUEST_NAME_REPLY_IN_QUEUE:
            # queueing can happen by default, maybe we should
            # track this better or let the user know if they're
            # queued or not?
            pass
        elif retval == _dbus_bindings.REQUEST_NAME_REPLY_EXISTS:
            raise NameExistsException(name)
        elif retval == _dbus_bindings.REQUEST_NAME_REPLY_ALREADY_OWNER:
            # if this is a shared bus which is being used by someone
            # else in this process, this can happen legitimately
            pass
        else:
            raise RuntimeError('requesting bus name %s returned unexpected value %s' % (name, retval))

        # and create the object
        bus_name = object.__new__(cls)
        bus_name._bus = bus
        bus_name._name = name

        # cache instance (weak ref only)
        # FIXME: accessing Bus internals again
        bus._bus_names[name] = bus_name

        return bus_name
开发者ID:kovidgoyal,项目名称:calibre,代码行数:78,代码来源:dbus_service.py


注:本文中的dbus.SessionBus.request_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。