Use ExportedGObject from dbus-python rather than reimplementing it
This commit is contained in:
parent
a86293dcb4
commit
2216f5095d
services/presence
@ -16,7 +16,9 @@
|
|||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
import dbus, dbus.service
|
import dbus
|
||||||
|
import dbus.service
|
||||||
|
from dbus.gobject_service import ExportedGObject
|
||||||
from sugar import util
|
from sugar import util
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -25,10 +27,6 @@ from telepathy.interfaces import (CHANNEL_INTERFACE)
|
|||||||
_ACTIVITY_PATH = "/org/laptop/Sugar/Presence/Activities/"
|
_ACTIVITY_PATH = "/org/laptop/Sugar/Presence/Activities/"
|
||||||
_ACTIVITY_INTERFACE = "org.laptop.Sugar.Presence.Activity"
|
_ACTIVITY_INTERFACE = "org.laptop.Sugar.Presence.Activity"
|
||||||
|
|
||||||
class DBusGObjectMetaclass(dbus.service.InterfaceType, gobject.GObjectMeta): pass
|
|
||||||
class DBusGObject(dbus.service.Object, gobject.GObject): __metaclass__ = DBusGObjectMetaclass
|
|
||||||
|
|
||||||
|
|
||||||
_PROP_ID = "id"
|
_PROP_ID = "id"
|
||||||
_PROP_NAME = "name"
|
_PROP_NAME = "name"
|
||||||
_PROP_COLOR = "color"
|
_PROP_COLOR = "color"
|
||||||
@ -38,7 +36,7 @@ _PROP_LOCAL = "local"
|
|||||||
_PROP_JOINED = "joined"
|
_PROP_JOINED = "joined"
|
||||||
_PROP_CUSTOM_PROPS = "custom-props"
|
_PROP_CUSTOM_PROPS = "custom-props"
|
||||||
|
|
||||||
class Activity(DBusGObject):
|
class Activity(ExportedGObject):
|
||||||
"""Represents a potentially shareable activity on the network.
|
"""Represents a potentially shareable activity on the network.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -84,7 +82,6 @@ class Activity(DBusGObject):
|
|||||||
|
|
||||||
self._object_id = object_id
|
self._object_id = object_id
|
||||||
self._object_path = _ACTIVITY_PATH + str(self._object_id)
|
self._object_path = _ACTIVITY_PATH + str(self._object_id)
|
||||||
dbus.service.Object.__init__(self, bus_name, self._object_path)
|
|
||||||
|
|
||||||
self._buddies = []
|
self._buddies = []
|
||||||
self._joined = False
|
self._joined = False
|
||||||
@ -111,7 +108,8 @@ class Activity(DBusGObject):
|
|||||||
if not util.validate_activity_id(kwargs[_PROP_ID]):
|
if not util.validate_activity_id(kwargs[_PROP_ID]):
|
||||||
raise ValueError("Invalid activity id '%s'" % kwargs[_PROP_ID])
|
raise ValueError("Invalid activity id '%s'" % kwargs[_PROP_ID])
|
||||||
|
|
||||||
gobject.GObject.__init__(self, **kwargs)
|
ExportedGObject.__init__(self, bus_name, self._object_path,
|
||||||
|
gobject_properties=kwargs)
|
||||||
if self.props.local and not self.props.valid:
|
if self.props.local and not self.props.valid:
|
||||||
raise RuntimeError("local activities require color, type, and name")
|
raise RuntimeError("local activities require color, type, and name")
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import gobject
|
import gobject
|
||||||
import dbus, dbus.service
|
import dbus
|
||||||
|
import dbus.service
|
||||||
|
from dbus.gobject_service import ExportedGObject
|
||||||
from ConfigParser import ConfigParser, NoOptionError
|
from ConfigParser import ConfigParser, NoOptionError
|
||||||
|
|
||||||
from sugar import env, profile, util
|
from sugar import env, profile, util
|
||||||
@ -35,10 +37,6 @@ class NotFoundError(dbus.DBusException):
|
|||||||
dbus.DBusException.__init__(self)
|
dbus.DBusException.__init__(self)
|
||||||
self._dbus_error_name = _PRESENCE_INTERFACE + '.NotFound'
|
self._dbus_error_name = _PRESENCE_INTERFACE + '.NotFound'
|
||||||
|
|
||||||
class DBusGObjectMetaclass(dbus.service.InterfaceType, gobject.GObjectMeta): pass
|
|
||||||
class DBusGObject(dbus.service.Object, gobject.GObject): __metaclass__ = DBusGObjectMetaclass
|
|
||||||
|
|
||||||
|
|
||||||
_PROP_NICK = "nick"
|
_PROP_NICK = "nick"
|
||||||
_PROP_KEY = "key"
|
_PROP_KEY = "key"
|
||||||
_PROP_ICON = "icon"
|
_PROP_ICON = "icon"
|
||||||
@ -50,7 +48,7 @@ _PROP_VALID = "valid"
|
|||||||
# Will go away soon
|
# Will go away soon
|
||||||
_PROP_IP4_ADDRESS = "ip4-address"
|
_PROP_IP4_ADDRESS = "ip4-address"
|
||||||
|
|
||||||
class Buddy(DBusGObject):
|
class Buddy(ExportedGObject):
|
||||||
"""Person on the network (tracks properties and shared activites)
|
"""Person on the network (tracks properties and shared activites)
|
||||||
|
|
||||||
The Buddy is a collection of metadata describing a particular
|
The Buddy is a collection of metadata describing a particular
|
||||||
@ -111,7 +109,6 @@ class Buddy(DBusGObject):
|
|||||||
self._bus_name = bus_name
|
self._bus_name = bus_name
|
||||||
self._object_id = object_id
|
self._object_id = object_id
|
||||||
self._object_path = _BUDDY_PATH + str(self._object_id)
|
self._object_path = _BUDDY_PATH + str(self._object_id)
|
||||||
dbus.service.Object.__init__(self, self._bus_name, self._object_path)
|
|
||||||
|
|
||||||
self._activities = {} # Activity ID -> Activity
|
self._activities = {} # Activity ID -> Activity
|
||||||
self._activity_sigids = {}
|
self._activity_sigids = {}
|
||||||
@ -135,7 +132,8 @@ class Buddy(DBusGObject):
|
|||||||
logging.debug("Invalid init property '%s'; ignoring..." % key)
|
logging.debug("Invalid init property '%s'; ignoring..." % key)
|
||||||
del kwargs[key]
|
del kwargs[key]
|
||||||
|
|
||||||
gobject.GObject.__init__(self, **kwargs)
|
ExportedGObject.__init__(self, bus_name, self._object_path,
|
||||||
|
gobject_properties=kwargs)
|
||||||
|
|
||||||
def do_get_property(self, pspec):
|
def do_get_property(self, pspec):
|
||||||
"""Retrieve current value for the given property specifier
|
"""Retrieve current value for the given property specifier
|
||||||
|
@ -15,9 +15,14 @@
|
|||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
import dbus, dbus.service, dbus.glib
|
import dbus
|
||||||
|
import dbus.service
|
||||||
|
from dbus.gobject_service import ExportedGObject
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
# Note that this import has side effects!
|
||||||
|
import dbus.glib
|
||||||
|
|
||||||
from telepathy.client import ManagerRegistry, Connection
|
from telepathy.client import ManagerRegistry, Connection
|
||||||
from telepathy.interfaces import (CONN_MGR_INTERFACE, CONN_INTERFACE)
|
from telepathy.interfaces import (CONN_MGR_INTERFACE, CONN_INTERFACE)
|
||||||
from telepathy.constants import (CONNECTION_STATUS_CONNECTING, CONNECTION_STATUS_CONNECTED,
|
from telepathy.constants import (CONNECTION_STATUS_CONNECTING, CONNECTION_STATUS_CONNECTED,
|
||||||
@ -40,10 +45,7 @@ class NotFoundError(dbus.DBusException):
|
|||||||
dbus.DBusException.__init__(self, msg)
|
dbus.DBusException.__init__(self, msg)
|
||||||
self._dbus_error_name = _PRESENCE_INTERFACE + '.NotFound'
|
self._dbus_error_name = _PRESENCE_INTERFACE + '.NotFound'
|
||||||
|
|
||||||
class DBusGObjectMetaclass(dbus.service.InterfaceType, gobject.GObjectMeta): pass
|
class PresenceService(ExportedGObject):
|
||||||
class DBusGObject(dbus.service.Object, gobject.GObject): __metaclass__ = DBusGObjectMetaclass
|
|
||||||
|
|
||||||
class PresenceService(DBusGObject):
|
|
||||||
__gtype_name__ = "PresenceService"
|
__gtype_name__ = "PresenceService"
|
||||||
|
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
@ -59,8 +61,6 @@ class PresenceService(DBusGObject):
|
|||||||
self._handles_buddies = {} # tp client -> (handle -> Buddy)
|
self._handles_buddies = {} # tp client -> (handle -> Buddy)
|
||||||
self._activities = {} # activity id -> Activity
|
self._activities = {} # activity id -> Activity
|
||||||
|
|
||||||
gobject.GObject.__init__(self)
|
|
||||||
|
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
self._bus_name = dbus.service.BusName(_PRESENCE_SERVICE, bus=bus)
|
self._bus_name = dbus.service.BusName(_PRESENCE_SERVICE, bus=bus)
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ class PresenceService(DBusGObject):
|
|||||||
self._ll_plugin = LinkLocalPlugin(self._registry, self._owner)
|
self._ll_plugin = LinkLocalPlugin(self._registry, self._owner)
|
||||||
self._handles_buddies[self._ll_plugin] = {}
|
self._handles_buddies[self._ll_plugin] = {}
|
||||||
|
|
||||||
dbus.service.Object.__init__(self, self._bus_name, _PRESENCE_PATH)
|
ExportedGObject.__init__(self, self._bus_name, _PRESENCE_PATH)
|
||||||
|
|
||||||
def _activity_shared_cb(self, tp, activity, success, exc, async_cb, async_err_cb):
|
def _activity_shared_cb(self, tp, activity, success, exc, async_cb, async_err_cb):
|
||||||
if success:
|
if success:
|
||||||
|
Loading…
Reference in New Issue
Block a user