Do not expose the service names from Activity.

This create quite a bit of duplication, but I have to start somewhere cleaning this mess :/
This commit is contained in:
Marco Pesenti Gritti 2007-02-21 17:28:49 +01:00
parent c05b179675
commit f5b13b716e
5 changed files with 45 additions and 36 deletions

View File

@ -15,14 +15,18 @@
# 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 time import time
import gobject
import logging import logging
import gobject
import dbus
from sugar.graphics.iconcolor import IconColor from sugar.graphics.iconcolor import IconColor
from sugar.presence import PresenceService from sugar.presence import PresenceService
from sugar.activity import Activity
from sugar import profile from sugar import profile
_ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
class HomeActivity(gobject.GObject): class HomeActivity(gobject.GObject):
__gsignals__ = { __gsignals__ = {
'launch-timeout': (gobject.SIGNAL_RUN_FIRST, 'launch-timeout': (gobject.SIGNAL_RUN_FIRST,
@ -69,7 +73,10 @@ class HomeActivity(gobject.GObject):
self._window = window self._window = window
self._xid = window.get_xid() self._xid = window.get_xid()
self._service = Activity.get_service(window.get_xid())
bus = dbus.SessionBus()
self._service = bus.get_object(_ACTIVITY_SERVICE_NAME + '%d' % self._xid,
_ACTIVITY_SERVICE_PATH + "/%s" % self._xid)
# verify id and type details # verify id and type details
act_id = self._service.get_id() act_id = self._service.get_id()
@ -79,6 +86,9 @@ class HomeActivity(gobject.GObject):
if act_type != self._type: if act_type != self._type:
raise RuntimeError("Activity's real type (%s) didn't match expected (%s)." % (act_type, self._type)) raise RuntimeError("Activity's real type (%s) didn't match expected (%s)." % (act_type, self._type))
def get_service(self):
return self._service
def get_title(self): def get_title(self):
if not self._launched: if not self._launched:
raise RuntimeError("Activity is still launching.") raise RuntimeError("Activity is still launching.")

View File

@ -18,10 +18,14 @@ import logging
import gobject import gobject
import wnck import wnck
import dbus
from model.homeactivity import HomeActivity from model.homeactivity import HomeActivity
from sugar.activity import Activity from sugar.activity import Activity
_ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
class HomeModel(gobject.GObject): class HomeModel(gobject.GObject):
__gsignals__ = { __gsignals__ = {
@ -114,7 +118,10 @@ class HomeModel(gobject.GObject):
self.emit('active-activity-changed', self._current_activity) self.emit('active-activity-changed', self._current_activity)
def _add_activity(self, window): def _add_activity(self, window):
act_service = Activity.get_service(window.get_xid()) bus = dbus.SessionBus()
xid = window.get_xid()
act_service = bus.get_object(_ACTIVITY_SERVICE_NAME + '%d' % xid,
_ACTIVITY_SERVICE_PATH + "/%s" % xid)
act_id = act_service.get_id() act_id = act_service.get_id()
activity = None activity = None
@ -128,7 +135,7 @@ class HomeModel(gobject.GObject):
if not bundle: if not bundle:
raise RuntimeError("No bundle for activity type '%s'." % act_type) raise RuntimeError("No bundle for activity type '%s'." % act_type)
return return
activity = HomeActivity(bundle, act_id) activity = HomeActivity(act_service, bundle)
self._activities[act_id] = activity self._activities[act_id] = activity
activity.set_window(window) activity.set_window(window)

View File

@ -17,7 +17,6 @@
import gtk import gtk
import dbus import dbus
from sugar.activity import Activity
from sugar.p2p import Stream from sugar.p2p import Stream
from sugar.p2p import network from sugar.p2p import network
from sugar.chat import ActivityChat from sugar.chat import ActivityChat
@ -42,7 +41,7 @@ class ActivityHost:
self._model = model self._model = model
self._id = model.get_id() self._id = model.get_id()
self._window = model.get_window() self._window = model.get_window()
self._activity = Activity.get_service(self.get_xid()) self._activity = model.get_service()
self._gdk_window = gtk.gdk.window_foreign_new(self.get_xid()) self._gdk_window = gtk.gdk.window_foreign_new(self.get_xid())
try: try:

View File

@ -30,21 +30,9 @@ from sugar import activity
from sugar import env from sugar import env
import sugar.util import sugar.util
ACTIVITY_SERVICE_NAME = "org.laptop.Activity" _ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
ACTIVITY_SERVICE_PATH = "/org/laptop/Activity" _ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
ACTIVITY_INTERFACE = "org.laptop.Activity" _ACTIVITY_INTERFACE = "org.laptop.Activity"
def get_service_name(xid):
return ACTIVITY_SERVICE_NAME + '%d' % xid
def get_object_path(xid):
return ACTIVITY_SERVICE_PATH + "/%s" % xid
def get_service(xid):
bus = dbus.SessionBus()
proxy_obj = bus.get_object(get_service_name(xid), get_object_path(xid))
return dbus.Interface(proxy_obj, ACTIVITY_INTERFACE)
class ActivityDbusService(dbus.service.Object): class ActivityDbusService(dbus.service.Object):
"""Base dbus service object that each Activity uses to export dbus methods. """Base dbus service object that each Activity uses to export dbus methods.
@ -53,46 +41,48 @@ class ActivityDbusService(dbus.service.Object):
tightly control what stuff passes through the dbus python bindings.""" tightly control what stuff passes through the dbus python bindings."""
def __init__(self, activity): def __init__(self, activity):
xid = activity.window.xid service_name = _ACTIVITY_SERVICE_NAME + '%d' % activity.window.xid
object_path = _ACTIVITY_SERVICE_PATH + "/%s" % activity.window.xid
bus = dbus.SessionBus() bus = dbus.SessionBus()
bus_name = dbus.service.BusName(get_service_name(xid), bus=bus) bus_name = dbus.service.BusName(service_name, bus=bus)
dbus.service.Object.__init__(self, bus_name, get_object_path(xid)) dbus.service.Object.__init__(self, bus_name, object_path)
self._activity = activity self._activity = activity
self._pservice = PresenceService.get_instance() self._pservice = PresenceService.get_instance()
@dbus.service.method(ACTIVITY_INTERFACE) @dbus.service.method(_ACTIVITY_INTERFACE)
def start(self, activity_id): def start(self, activity_id):
"""Start the activity in unshared mode.""" """Start the activity in unshared mode."""
self._activity.start(activity_id) self._activity.start(activity_id)
@dbus.service.method(ACTIVITY_INTERFACE) @dbus.service.method(_ACTIVITY_INTERFACE)
def join(self, activity_ps_path): def join(self, activity_ps_path):
"""Join the activity specified by its presence service path.""" """Join the activity specified by its presence service path."""
activity_ps = self._pservice.get(activity_ps_path) activity_ps = self._pservice.get(activity_ps_path)
return self._activity.join(activity_ps) return self._activity.join(activity_ps)
@dbus.service.method(ACTIVITY_INTERFACE) @dbus.service.method(_ACTIVITY_INTERFACE)
def share(self): def share(self):
"""Called by the shell to request the activity to share itself on the network.""" """Called by the shell to request the activity to share itself on the network."""
self._activity.share() self._activity.share()
@dbus.service.method(ACTIVITY_INTERFACE) @dbus.service.method(_ACTIVITY_INTERFACE)
def get_id(self): def get_id(self):
"""Get the activity identifier""" """Get the activity identifier"""
return self._activity.get_id() return self._activity.get_id()
@dbus.service.method(ACTIVITY_INTERFACE) @dbus.service.method(_ACTIVITY_INTERFACE)
def get_type(self): def get_type(self):
"""Get the activity type""" """Get the activity type"""
return self._activity.get_type() return self._activity.get_type()
@dbus.service.method(ACTIVITY_INTERFACE) @dbus.service.method(_ACTIVITY_INTERFACE)
def get_shared(self): def get_shared(self):
"""Returns True if the activity is shared on the mesh.""" """Returns True if the activity is shared on the mesh."""
return self._activity.get_shared() return self._activity.get_shared()
@dbus.service.method(ACTIVITY_INTERFACE, @dbus.service.method(_ACTIVITY_INTERFACE,
in_signature="sas", out_signature="b") in_signature="sas", out_signature="b")
def execute(self, command, args): def execute(self, command, args):
return self._activity.execute(command, args) return self._activity.execute(command, args)

View File

@ -25,10 +25,13 @@ import gobject
import gtk import gtk
from sugar.presence.PresenceService import PresenceService from sugar.presence.PresenceService import PresenceService
from sugar.activity import Activity
from sugar.activity.bundle import Bundle from sugar.activity.bundle import Bundle
from sugar import logger from sugar import logger
_ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
_ACTIVITY_INTERFACE = "org.laptop.Activity"
def get_path(activity_name): def get_path(activity_name):
"""Returns the activity path""" """Returns the activity path"""
return '/' + activity_name.replace('.', '/') return '/' + activity_name.replace('.', '/')
@ -101,9 +104,9 @@ class ActivityCreationHandler(gobject.GObject):
def _reply_handler(self, xid): def _reply_handler(self, xid):
bus = dbus.SessionBus() bus = dbus.SessionBus()
proxy_obj = bus.get_object(Activity.get_service_name(xid), proxy_obj = bus.get_object(_ACTIVITY_SERVICE_NAME + '%d' % xid,
Activity.get_object_path(xid)) _ACTIVITY_SERVICE_PATH + "/%s" % xid)
activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE) activity = dbus.Interface(proxy_obj, _ACTIVITY_INTERFACE)
self.emit('success', activity) self.emit('success', activity)
def _error_handler(self, err): def _error_handler(self, err):