Expose owner details through the Shell's DBus service

For security, we need the PresenceService to listen for changes to the
owner's attributes, like changed color, nickname, icon, and current activity,
rather than having D-Bus API in the PS itself that any process could call.

So, the shell provides signals when these attributes change, which the PS
listens to and pushes out over the network accordingly.
This commit is contained in:
Dan Williams 2007-03-08 22:17:33 -05:00
parent 5210231e8f
commit 8dc201bc5f
2 changed files with 67 additions and 9 deletions

View File

@ -14,6 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import gobject
import os
import random
import base64
@ -30,11 +31,24 @@ from model.Invites import Invites
PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
class ShellOwner(object):
class ShellOwner(gobject.GObject):
__gtype_name__ = "ShellOwner"
__gsignals__ = {
'nick-changed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_STRING])),
'color-changed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'icon-changed' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
"""Class representing the owner of this machine/instance. This class
runs in the shell and serves up the buddy icon and other stuff. It's the
server portion of the Owner, paired with the client portion in Buddy.py."""
def __init__(self):
gobject.GObject.__init__(self)
self._nick = profile.get_nick_name()
user_dir = env.get_profile_path()
@ -45,12 +59,14 @@ class ShellOwner(object):
continue
fd = open(os.path.join(user_dir, fname), "r")
self._icon = fd.read()
if self._icon:
# Get the icon's hash
import md5, binascii
digest = md5.new(self._icon).digest()
self._icon_hash = util.printable_hash(digest)
fd.close()
if not self._icon:
raise RuntimeError("No buddy icon exists")
# Get the icon's hash
import md5, binascii
digest = md5.new(self._icon).digest()
self._icon_hash = util.printable_hash(digest)
break
self._pservice = PresenceService.get_instance()
@ -60,6 +76,7 @@ class ShellOwner(object):
self._last_activity_update = time.time()
self._pending_activity_update_timer = None
self._pending_activity_update = None
self._current_activity = None
def get_invites(self):
return self._invites
@ -94,6 +111,7 @@ class ShellOwner(object):
self._last_activity_update = time.time()
self._pending_activity_update_timer = None
if self._pending_activity_update:
self.emit('current-activity-changed', self._pending_activity_update)
logging.debug("*** Updating current activity to %s" % self._pending_activity_update)
self._service.set_published_value('curact', dbus.String(self._pending_activity_update))
return False

View File

@ -4,18 +4,58 @@ from sugar.activity import bundleregistry
_DBUS_SERVICE = "org.laptop.Shell"
_DBUS_INTERFACE = "org.laptop.Shell"
_DBUS_OWNER_INTERFACE = "org.laptop.Shell.Owner"
_DBUS_PATH = "/org/laptop/Shell"
class ShellService(dbus.service.Object):
def __init__(self, shellModel):
self._shellModel = shellModel
def __init__(self, shell_model):
self._shell_model = shell_model
self._owner = self._shell_model.get_owner()
self._owner.connect('nick-changed', self._owner_nick_changed_cb)
self._owner.connect('icon-changed', self._owner_icon_changed_cb)
self._owner.connect('color-changed', self._owner_color_changed_cb)
self._home_model = self._shell_model.get_home()
self._home_model.connect('active-activity-changed', self._cur_activity_changed_cb)
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(_DBUS_SERVICE, bus=bus)
dbus.service.Object.__init__(self, bus_name, _DBUS_PATH)
@dbus.service.method(_DBUS_INTERFACE, in_signature="s", out_signature="b")
def add_bundle(self, bundle_path):
registry = bundleregistry.get_registry()
return registry.add_bundle(bundle_path)
@dbus.service.signal(_DBUS_OWNER_INTERFACE, signature="s")
def ColorChanged(self, color):
pass
def _owner_color_changed_cb(self, new_color):
self.ColorChanged(new_color.to_string())
@dbus.service.signal(_DBUS_OWNER_INTERFACE, signature="s")
def NickChanged(self, nick):
pass
def _owner_nick_changed_cb(self, new_nick):
self.NickChanged(new_nick)
@dbus.service.signal(_DBUS_OWNER_INTERFACE, signature="ay")
def IconChanged(self, icon_data):
pass
def _owner_icon_changed_cb(self, new_icon):
self.IconChanged(dbus.ByteArray(new_icon))
@dbus.service.signal(_DBUS_OWNER_INTERFACE, signature="s")
def CurrentActivityChanged(self, activity_id):
pass
def _cur_activity_changed_cb(self, owner, new_activity):
new_id = ""
if new_activity:
new_id = new_activity.get_id()
self.CurrentActivityChanged(new_id)