~ubuntu-branches/ubuntu/gutsy/dbus-python/gutsy

« back to all changes in this revision

Viewing changes to dbus/bus.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-06-26 10:28:30 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070626102830-6rh3gy4nvtt1c5z2
Tags: 0.82.0-1ubuntu1
* Merge with Debian; remaining changes:
  - Build a python-dbus-dbg package.
  - debian/rules:
    - Don't remove intermediate stamp files.
    - Don't use optimization for the debug build.
  - debian/python-dbus.postinst:
    - Also remove stale .py[co] files from 2.5 python directories

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
                           DBUS_START_REPLY_SUCCESS, \
30
30
                           DBUS_START_REPLY_ALREADY_RUNNING, \
31
31
                           BUS_DAEMON_NAME, BUS_DAEMON_PATH, BUS_DAEMON_IFACE,\
32
 
                           HANDLER_RESULT_NOT_YET_HANDLED
 
32
                           HANDLER_RESULT_NOT_YET_HANDLED, \
 
33
                           NAME_FLAG_ALLOW_REPLACEMENT, \
 
34
                           NAME_FLAG_DO_NOT_QUEUE, \
 
35
                           NAME_FLAG_REPLACE_EXISTING, \
 
36
                           RELEASE_NAME_REPLY_NON_EXISTENT, \
 
37
                           RELEASE_NAME_REPLY_NOT_OWNER, \
 
38
                           RELEASE_NAME_REPLY_RELEASED, \
 
39
                           REQUEST_NAME_REPLY_ALREADY_OWNER, \
 
40
                           REQUEST_NAME_REPLY_EXISTS, \
 
41
                           REQUEST_NAME_REPLY_IN_QUEUE, \
 
42
                           REQUEST_NAME_REPLY_PRIMARY_OWNER
33
43
from dbus.connection import Connection
34
44
from dbus.exceptions import DBusException
35
45
 
51
61
    __slots__ = ('_match', '_pending_call')
52
62
 
53
63
    def __init__(self, bus_conn, bus_name, callback):
54
 
        validate_bus_name(bus_name, allow_unique=False)
 
64
        validate_bus_name(bus_name)
55
65
 
56
66
        def signal_cb(owned, old_owner, new_owner):
57
67
            callback(new_owner)
61
71
                callback('')
62
72
            else:
63
73
                logging.basicConfig()
64
 
                _logger.error('GetNameOwner(%s) failed:', bus_name,
 
74
                _logger.debug('GetNameOwner(%s) failed:', bus_name,
65
75
                              exc_info=(e.__class__, e, None))
66
76
 
67
77
        self._match = bus_conn.add_signal_receiver(signal_cb,
68
78
                                                   'NameOwnerChanged',
69
79
                                                   BUS_DAEMON_IFACE,
70
80
                                                   BUS_DAEMON_NAME,
71
 
                                                   BUS_DAEMON_PATH)
 
81
                                                   BUS_DAEMON_PATH,
 
82
                                                   arg0=bus_name)
72
83
        self._pending_call = bus_conn.call_async(BUS_DAEMON_NAME,
73
84
                                                 BUS_DAEMON_PATH,
74
85
                                                 BUS_DAEMON_IFACE,
89
100
class BusConnection(Connection):
90
101
    """A connection to a D-Bus daemon that implements the
91
102
    ``org.freedesktop.DBus`` pseudo-service.
 
103
 
 
104
    :Since: 0.81.0
92
105
    """
93
106
 
94
107
    TYPE_SESSION    = BUS_SESSION
133
146
                handler_function, signal_name, dbus_interface, bus_name,
134
147
                path, **keywords)
135
148
 
136
 
        # The bus daemon is special - its unique-name is org.freedesktop.DBus
137
 
        # rather than starting with :
138
 
        if (bus_name is not None
139
 
            and bus_name[:1] != ':'
140
 
            and bus_name != BUS_DAEMON_NAME):
141
 
            watch = self.watch_name_owner(bus_name,
142
 
                                          match.set_sender_name_owner)
 
149
        if (bus_name is not None and bus_name != BUS_DAEMON_NAME):
 
150
            if bus_name[:1] == ':':
 
151
                def callback(new_owner):
 
152
                    if new_owner == '':
 
153
                        match.remove()
 
154
            else:
 
155
                callback = match.set_sender_name_owner
 
156
            watch = self.watch_name_owner(bus_name, callback)
143
157
            self._signal_sender_matches[match] = watch
144
158
 
145
159
        self.add_match_string(str(match))
148
162
 
149
163
    def _clean_up_signal_match(self, match):
150
164
        # The signals lock is no longer held here (it was in <= 0.81.0)
151
 
        self.remove_match_string(str(match))
 
165
        self.remove_match_string_non_blocking(str(match))
152
166
        watch = self._signal_sender_matches.pop(match, None)
153
167
        if watch is not None:
154
168
            watch.cancel()
232
246
            `bus_name` : str
233
247
                A bus name, either unique or well-known
234
248
        :Returns: a `dbus.UInt32`
 
249
        :Since: 0.80.0
235
250
        """
236
251
        validate_bus_name(bus_name)
237
252
        return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
252
267
            second is either START_REPLY_SUCCESS or
253
268
            START_REPLY_ALREADY_RUNNING.
254
269
 
255
 
        :Raises DBusException: if the service could not be started.
 
270
        :Raises `DBusException`: if the service could not be started.
 
271
        :Since: 0.80.0
256
272
        """
257
273
        validate_bus_name(bus_name)
258
274
        return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
270
286
                The well-known name to be requested
271
287
            `flags` : dbus.UInt32
272
288
                A bitwise-OR of 0 or more of the flags
273
 
                `DBUS_NAME_FLAG_ALLOW_REPLACEMENT`,
274
 
                `DBUS_NAME_FLAG_REPLACE_EXISTING`
275
 
                and `DBUS_NAME_FLAG_DO_NOT_QUEUE`
276
 
        :Returns: `DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER`,
277
 
            `DBUS_REQUEST_NAME_REPLY_IN_QUEUE`,
278
 
            `DBUS_REQUEST_NAME_REPLY_EXISTS` or
279
 
            `DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER`
280
 
        :Raises DBusException: if the bus daemon cannot be contacted or
 
289
                `NAME_FLAG_ALLOW_REPLACEMENT`,
 
290
                `NAME_FLAG_REPLACE_EXISTING`
 
291
                and `NAME_FLAG_DO_NOT_QUEUE`
 
292
        :Returns: `REQUEST_NAME_REPLY_PRIMARY_OWNER`,
 
293
            `REQUEST_NAME_REPLY_IN_QUEUE`,
 
294
            `REQUEST_NAME_REPLY_EXISTS` or
 
295
            `REQUEST_NAME_REPLY_ALREADY_OWNER`
 
296
        :Raises `DBusException`: if the bus daemon cannot be contacted or
281
297
            returns an error.
282
298
        """
283
299
        validate_bus_name(name, allow_unique=False)
291
307
        :Parameters:
292
308
            `name` : str
293
309
                The well-known name to be released
294
 
        :Returns: `DBUS_RELEASE_NAME_REPLY_RELEASED`,
295
 
            `DBUS_RELEASE_NAME_REPLY_NON_EXISTENT`
296
 
            or `DBUS_RELEASE_NAME_REPLY_NOT_OWNER`
297
 
        :Raises DBusException: if the bus daemon cannot be contacted or
 
310
        :Returns: `RELEASE_NAME_REPLY_RELEASED`,
 
311
            `RELEASE_NAME_REPLY_NON_EXISTENT`
 
312
            or `RELEASE_NAME_REPLY_NOT_OWNER`
 
313
        :Raises `DBusException`: if the bus daemon cannot be contacted or
298
314
            returns an error.
299
315
        """
300
316
        validate_bus_name(name, allow_unique=False)
306
322
        """Return a list of all currently-owned names on the bus.
307
323
 
308
324
        :Returns: a dbus.Array of dbus.UTF8String
 
325
        :Since: 0.81.0
309
326
        """
310
327
        return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
311
328
                                  BUS_DAEMON_IFACE, 'ListNames',
315
332
        """Return a list of all names that can be activated on the bus.
316
333
 
317
334
        :Returns: a dbus.Array of dbus.UTF8String
 
335
        :Since: 0.81.0
318
336
        """
319
337
        return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
320
338
                                  BUS_DAEMON_IFACE, 'ListNames',
324
342
        """Return the unique connection name of the primary owner of the
325
343
        given name.
326
344
 
327
 
        :Raises DBusException: if the `bus_name` has no owner
 
345
        :Raises `DBusException`: if the `bus_name` has no owner
 
346
        :Since: 0.81.0
328
347
        """
329
348
        validate_bus_name(bus_name, allow_unique=False)
330
349
        return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
338
357
        `callback` will be called with one argument, which is either the
339
358
        unique connection name, or the empty string (meaning the name is
340
359
        not owned).
 
360
 
 
361
        :Since: 0.81.0
341
362
        """
342
363
        return NameOwnerWatch(self, bus_name, callback)
343
364
 
345
366
        """Return True iff the given bus name has an owner on this bus.
346
367
 
347
368
        :Parameters:
348
 
            `name` : str
 
369
            `bus_name` : str
349
370
                The bus name to look up
350
371
        :Returns: a `bool`
351
372
        """
360
381
        :Parameters:
361
382
            `rule` : str
362
383
                The match rule
363
 
        :Raises: `DBusException` on error.
 
384
        :Raises `DBusException`: on error.
 
385
        :Since: 0.80.0
364
386
        """
365
387
        self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
366
388
                           BUS_DAEMON_IFACE, 'AddMatch', 's', (rule,))
376
398
        :Parameters:
377
399
            `rule` : str
378
400
                The match rule
379
 
        :Raises: `DBusException` on error.
 
401
        :Raises `DBusException`: on error.
 
402
        :Since: 0.80.0
380
403
        """
381
404
        self.call_async(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
382
405
                        BUS_DAEMON_IFACE, 'AddMatch', 's', (rule,),
389
412
        :Parameters:
390
413
            `rule` : str
391
414
                The match rule
392
 
        :Raises: `DBusException` on error.
 
415
        :Raises `DBusException`: on error.
 
416
        :Since: 0.80.0
393
417
        """
394
418
        self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
395
419
                           BUS_DAEMON_IFACE, 'RemoveMatch', 's', (rule,))
403
427
        :Parameters:
404
428
            `rule` : str
405
429
                The match rule
406
 
        :Raises: `DBusException` on error.
 
430
        :Raises `DBusException`: on error.
 
431
        :Since: 0.80.0
407
432
        """
408
433
        self.call_async(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
409
434
                        BUS_DAEMON_IFACE, 'RemoveMatch', 's', (rule,),