Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--services/presence/activity.py14
-rw-r--r--services/presence/buddy.py16
-rw-r--r--services/presence/presenceservice.py16
-rw-r--r--services/presence/server_plugin.py31
4 files changed, 41 insertions, 36 deletions
diff --git a/services/presence/activity.py b/services/presence/activity.py
index c856f54..d955c71 100644
--- a/services/presence/activity.py
+++ b/services/presence/activity.py
@@ -16,7 +16,9 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import gobject
-import dbus, dbus.service
+import dbus
+import dbus.service
+from dbus.gobject_service import ExportedGObject
from sugar import util
import logging
@@ -25,10 +27,6 @@ from telepathy.interfaces import (CHANNEL_INTERFACE)
_ACTIVITY_PATH = "/org/laptop/Sugar/Presence/Activities/"
_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_NAME = "name"
_PROP_COLOR = "color"
@@ -38,7 +36,7 @@ _PROP_LOCAL = "local"
_PROP_JOINED = "joined"
_PROP_CUSTOM_PROPS = "custom-props"
-class Activity(DBusGObject):
+class Activity(ExportedGObject):
"""Represents a potentially shareable activity on the network.
"""
@@ -84,7 +82,6 @@ class Activity(DBusGObject):
self._object_id = object_id
self._object_path = _ACTIVITY_PATH + str(self._object_id)
- dbus.service.Object.__init__(self, bus_name, self._object_path)
self._buddies = []
self._joined = False
@@ -111,7 +108,8 @@ class Activity(DBusGObject):
if not util.validate_activity_id(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:
raise RuntimeError("local activities require color, type, and name")
diff --git a/services/presence/buddy.py b/services/presence/buddy.py
index fcc655b..f302b8c 100644
--- a/services/presence/buddy.py
+++ b/services/presence/buddy.py
@@ -18,7 +18,9 @@
import os
import gobject
-import dbus, dbus.service
+import dbus
+import dbus.service
+from dbus.gobject_service import ExportedGObject
from ConfigParser import ConfigParser, NoOptionError
from sugar import env, profile, util
@@ -35,10 +37,6 @@ class NotFoundError(dbus.DBusException):
dbus.DBusException.__init__(self)
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_KEY = "key"
_PROP_ICON = "icon"
@@ -50,7 +48,7 @@ _PROP_VALID = "valid"
# Will go away soon
_PROP_IP4_ADDRESS = "ip4-address"
-class Buddy(DBusGObject):
+class Buddy(ExportedGObject):
"""Person on the network (tracks properties and shared activites)
The Buddy is a collection of metadata describing a particular
@@ -111,7 +109,6 @@ class Buddy(DBusGObject):
self._bus_name = bus_name
self._object_id = 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._activity_sigids = {}
@@ -134,8 +131,9 @@ class Buddy(DBusGObject):
if key not in _ALLOWED_INIT_PROPS:
logging.debug("Invalid init property '%s'; ignoring..." % 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):
"""Retrieve current value for the given property specifier
diff --git a/services/presence/presenceservice.py b/services/presence/presenceservice.py
index 7f1df8f..bfda3d9 100644
--- a/services/presence/presenceservice.py
+++ b/services/presence/presenceservice.py
@@ -15,9 +15,14 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import gobject
-import dbus, dbus.service, dbus.glib
+import dbus
+import dbus.service
+from dbus.gobject_service import ExportedGObject
import logging
+# Note that this import has side effects!
+import dbus.glib
+
from telepathy.client import ManagerRegistry, Connection
from telepathy.interfaces import (CONN_MGR_INTERFACE, CONN_INTERFACE)
from telepathy.constants import (CONNECTION_STATUS_CONNECTING, CONNECTION_STATUS_CONNECTED,
@@ -40,10 +45,7 @@ class NotFoundError(dbus.DBusException):
dbus.DBusException.__init__(self, msg)
self._dbus_error_name = _PRESENCE_INTERFACE + '.NotFound'
-class DBusGObjectMetaclass(dbus.service.InterfaceType, gobject.GObjectMeta): pass
-class DBusGObject(dbus.service.Object, gobject.GObject): __metaclass__ = DBusGObjectMetaclass
-
-class PresenceService(DBusGObject):
+class PresenceService(ExportedGObject):
__gtype_name__ = "PresenceService"
__gsignals__ = {
@@ -59,8 +61,6 @@ class PresenceService(DBusGObject):
self._handles_buddies = {} # tp client -> (handle -> Buddy)
self._activities = {} # activity id -> Activity
- gobject.GObject.__init__(self)
-
bus = dbus.SessionBus()
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._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):
if success:
diff --git a/services/presence/server_plugin.py b/services/presence/server_plugin.py
index ef3b249..efb97fc 100644
--- a/services/presence/server_plugin.py
+++ b/services/presence/server_plugin.py
@@ -138,6 +138,7 @@ class ServerPlugin(gobject.GObject):
self._account = self._get_account_info()
self._conn = self._init_connection()
+ self._conn_status = CONNECTION_STATUS_DISCONNECTED
self._reconnect_id = 0
@@ -281,7 +282,7 @@ class ServerPlugin(gobject.GObject):
def _connected_cb(self):
"""Callback on successful connection to a server
"""
-
+
if self._account['register']:
# we successfully register this account
self._owner.set_registered(True)
@@ -309,8 +310,7 @@ class ServerPlugin(gobject.GObject):
if CONN_INTERFACE_BUDDY_INFO not in self._conn.get_valid_interfaces():
logging.debug('OLPC information not available')
- self.cleanup()
- return
+ return False
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('PropertiesChanged',
self._buddy_properties_changed_cb)
@@ -336,6 +336,7 @@ class ServerPlugin(gobject.GObject):
# Request presence for everyone on the channel
self._conn[CONN_INTERFACE_PRESENCE].GetPresence(subscribe_handles,
ignore_reply=True)
+ return True
def _set_self_avatar_cb(self, token):
self._icon_cache.set_avatar(hash, token)
@@ -444,6 +445,8 @@ class ServerPlugin(gobject.GObject):
def _set_self_olpc_properties(self):
"""Set color and key on our Telepathy server identity"""
+ if self._conn_status != CONNECTION_STATUS_CONNECTED:
+ return
props = {}
props['color'] = self._owner.props.color
props['key'] = dbus.ByteArray(self._owner.props.key)
@@ -508,19 +511,24 @@ class ServerPlugin(gobject.GObject):
reason -- integer code describing the reason...
"""
if state == CONNECTION_STATUS_CONNECTING:
+ self._conn_status = state
logging.debug("State: connecting...")
elif state == CONNECTION_STATUS_CONNECTED:
- logging.debug("State: connected")
- self._connected_cb()
- self.emit('status', state, int(reason))
+ if self._connected_cb():
+ logging.debug("State: connected")
+ self._conn_status = state
+ else:
+ self.cleanup()
+ logging.debug("State: was connected, but an error occurred")
elif state == CONNECTION_STATUS_DISCONNECTED:
+ self.cleanup()
logging.debug("State: disconnected (reason %r)" % reason)
- self.emit('status', state, int(reason))
- self._conn = None
if reason == CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
# FIXME: handle connection failure; retry later?
pass
+ self.emit('status', self._conn_status, int(reason))
+
def start(self):
"""Start up the Telepathy networking connections
@@ -565,9 +573,10 @@ class ServerPlugin(gobject.GObject):
def cleanup(self):
"""If we still have a connection, disconnect it"""
- if not self._conn:
- return
- self._conn[CONN_INTERFACE].Disconnect()
+ if self._conn:
+ self._conn[CONN_INTERFACE].Disconnect()
+ self._conn = None
+ self._conn_status = CONNECTION_STATUS_DISCONNECTED
def _contact_offline(self, handle):
"""Handle contact going offline (send message, update set)"""