~ubuntu-branches/ubuntu/quantal/zeitgeist/quantal

« back to all changes in this revision

Viewing changes to _zeitgeist/engine/remote.py

  • Committer: Bazaar Package Importer
  • Author(s): Siegfried-Angel Gevatter Pujals
  • Date: 2011-03-20 16:11:48 UTC
  • mfrom: (1.2.4 upstream)
  • mto: (6.2.2 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20110320161148-e8e9anja20zouslv
Tags: upstream-0.7.1
Import upstream version 0.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
# Copyright © 2009-2010 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
6
6
# Copyright © 2009 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>
7
7
# Copyright © 2010 Seif Lotfy <seif@lotfy.com>
 
8
# Copyright © 2011 Markus Korn <thekorn@gmx.de>
8
9
#
9
10
# This program is free software: you can redistribute it and/or modify
10
11
# it under the terms of the GNU Lesser General Public License as published by
23
24
import dbus.service
24
25
import logging
25
26
 
 
27
from xml.etree import ElementTree
 
28
 
26
29
from zeitgeist.datamodel import TimeRange, StorageState, ResultType, NULL_EVENT
27
30
from _zeitgeist.engine.datamodel import Event, Subject
28
31
from _zeitgeist.engine import get_engine
30
33
from _zeitgeist.engine import constants
31
34
from _zeitgeist.singleton import SingletonApplication
32
35
 
 
36
class DBUSProperty(property):
 
37
        
 
38
        def __init__(self, fget=None, fset=None, in_signature=None, out_signature=None):
 
39
                assert not (fget and not out_signature), "fget needs a dbus signature"
 
40
                assert not (fset and not in_signature), "fset needs a dbus signature"
 
41
                assert (fget and not fset) or (fset and fget), \
 
42
                        "dbus properties needs to be either readonly or readwritable"
 
43
                self.in_signature = in_signature
 
44
                self.out_signature = out_signature
 
45
                super(DBUSProperty, self).__init__(fget, fset)
 
46
 
 
47
 
33
48
class RemoteInterface(SingletonApplication):
34
49
        """
35
50
        Primary interface to the Zeitgeist engine. Used to update and query
42
57
        :const:`org.gnome.zeitgeist.Engine`.
43
58
        """
44
59
        _dbus_properties = {
45
 
                "version": property(lambda self: (0, 7, 0)),
46
 
                "extensions": property(lambda self: list(self._engine.extensions.iter_names())),
 
60
                "version": DBUSProperty(lambda self: (0, 7, 1), out_signature="iii"),
 
61
                "extensions": DBUSProperty(
 
62
                        lambda self: list(self._engine.extensions.iter_names()),
 
63
                        out_signature="as"),
47
64
        }
48
65
        
49
66
        # Initialization
357
374
        @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
358
375
                                                 in_signature="ss", out_signature="v")
359
376
        def Get(self, interface_name, property_name):
 
377
                if interface_name != constants.DBUS_INTERFACE:
 
378
                        raise ValueError(
 
379
                                "'%s' doesn't know anything about the '%s' interface" \
 
380
                                %(constants.DBUS_INTERFACE, interface_name)
 
381
                        )
360
382
                try:
361
383
                        return self._dbus_properties[property_name].fget(self)
362
384
                except KeyError, e:
365
387
        @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
366
388
                                                 in_signature="ssv", out_signature="")
367
389
        def Set(self, interface_name, property_name, value):
 
390
                if interface_name != constants.DBUS_INTERFACE:
 
391
                        raise ValueError(
 
392
                                "'%s' doesn't know anything about the '%s' interface" \
 
393
                                %(constants.DBUS_INTERFACE, interface_name)
 
394
                        )
368
395
                try:
369
396
                        prop = self._dbus_properties[property_name].fset(self, value)
370
397
                except (KeyError, TypeError), e:
373
400
        @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
374
401
                                                 in_signature="s", out_signature="a{sv}")
375
402
        def GetAll(self, interface_name):
 
403
                if interface_name != constants.DBUS_INTERFACE:
 
404
                        raise ValueError(
 
405
                                "'%s' doesn't know anything about the '%s' interface" \
 
406
                                %(constants.DBUS_INTERFACE, interface_name)
 
407
                        )
376
408
                return dict((k, v.fget(self)) for (k,v) in self._dbus_properties.items())
 
409
                
 
410
        # Instrospection Interface
 
411
        
 
412
        @dbus.service.method(dbus.INTROSPECTABLE_IFACE, in_signature="", out_signature="s",
 
413
                                                 path_keyword="object_path", connection_keyword="connection")
 
414
        def Introspect(self, object_path, connection):
 
415
                data = dbus.service.Object.Introspect(self, object_path, connection)
 
416
                xml = ElementTree.fromstring(data)
 
417
                for iface in xml.findall("interface"):
 
418
                        if iface.attrib["name"] != constants.DBUS_INTERFACE:
 
419
                                continue
 
420
                        for prop_name, prop_func in self._dbus_properties.iteritems():
 
421
                                prop = {"name": prop_name}
 
422
                                if prop_func.fset is not None:
 
423
                                        prop["access"] = "readwrite"
 
424
                                else:
 
425
                                        prop["access"] = "read"
 
426
                                prop["type"] = prop_func.out_signature
 
427
                                iface.append(ElementTree.Element("property", prop))
 
428
                return ElementTree.tostring(xml, encoding="UTF-8")
377
429
        
378
430
        # Notifications interface
379
431