Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorDan Williams <dcbw@localhost.localdomain>2006-07-23 04:56:40 (GMT)
committer Dan Williams <dcbw@localhost.localdomain>2006-07-23 04:56:40 (GMT)
commitb63e78a174d1db625edfd20ff6ae3fa6a412bde9 (patch)
tree56dc8cd06a95c4a72b19f4135c6c6d2d112ba570 /shell
parent1c35f8d92ca82525c82ede9b543fe603798ee817 (diff)
Make the PresenceService stuff start to work
Diffstat (limited to 'shell')
-rw-r--r--shell/Owner.py24
-rw-r--r--shell/PresenceService/PresenceService.py20
-rw-r--r--shell/PresenceService/Service.py34
-rw-r--r--shell/Session.py17
-rwxr-xr-xshell/Shell.py1
5 files changed, 52 insertions, 44 deletions
diff --git a/shell/Owner.py b/shell/Owner.py
index db9f7af..c279f51 100644
--- a/shell/Owner.py
+++ b/shell/Owner.py
@@ -4,6 +4,9 @@ import base64
from sugar import env
from sugar.p2p import Stream
+from sugar.presence import PresenceService
+
+PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
class ShellOwner(object):
"""Class representing the owner of this machine/instance. This class
@@ -27,21 +30,12 @@ class ShellOwner(object):
fd.close()
break
- # Our presence service
- port = random.randint(40000, 65000)
- properties = {}
-
-# self._service = Service.Service(nick, Buddy.PRESENCE_SERVICE_TYPE,
-# domain="", address=None, port=port, properties=properties)
-# print "Owner '%s' using port %d" % (nick, port)
-
-# self._icon_stream = Stream.Stream.new_from_service(self._service)
-# self._icon_stream.register_reader_handler(self._handle_buddy_icon_request, "get_buddy_icon")
-
- # Announce ourselves to the world
-# self._pservice = PresenceService.PresenceService.get_instance()
-# self._pservice.start()
-# self._pservice.register_service(self._service)
+ # Create and announce our presence
+ self._pservice = PresenceService.PresenceService()
+ self._service = self._pservice.registerService(nick, PRESENCE_SERVICE_TYPE)
+ print "Owner '%s' using port %d" % (nick, service.get_port())
+ self._icon_stream = Stream.Stream.new_from_service(self._service)
+ self._icon_stream.register_reader_handler(self._handle_buddy_icon_request, "get_buddy_icon")
def _handle_buddy_icon_request(self):
"""XMLRPC method, return the owner's icon encoded with base64."""
diff --git a/shell/PresenceService/PresenceService.py b/shell/PresenceService/PresenceService.py
index 92fa819..c111e89 100644
--- a/shell/PresenceService/PresenceService.py
+++ b/shell/PresenceService/PresenceService.py
@@ -175,6 +175,12 @@ class PresenceServiceDBusHelper(dbus.service.Object):
raise NotFoundError("Not found")
return owner.object_path()
+ @dbus.service.method(_PRESENCE_DBUS_INTERFACE,
+ in_signature="ssa{ss}sis", out_signature="o")
+ def registerService(self, name, stype, properties, address, port, domain):
+ service = self._parent.register_service(name, stype, properties, address,
+ port, domain)
+ return service.object_path()
class PresenceService(object):
def __init__(self):
@@ -202,8 +208,8 @@ class PresenceService(object):
self._registered_service_types = []
# Set up the dbus service we provide
- session_bus = dbus.SessionBus()
- self._bus_name = dbus.service.BusName(_PRESENCE_SERVICE, bus=session_bus)
+ self._session_bus = dbus.SessionBus()
+ self._bus_name = dbus.service.BusName(_PRESENCE_SERVICE, bus=self._session_bus)
self._dbus_helper = PresenceServiceDBusHelper(self, self._bus_name)
# Connect to Avahi for mDNS stuff
@@ -515,17 +521,19 @@ class PresenceService(object):
def _new_domain_cb_glue(self, interface, protocol, domain, flags=0):
gobject.idle_add(self._new_domain_cb, interface, protocol, domain, flags)
- def register_service(self, name, stype, properties, address, port, domain):
+ def register_service(self, name, stype, properties={}, address=None, port=None, domain=u"local"):
"""Register a new service, advertising it to other Buddies on the network."""
objid = self._get_next_object_id()
service = Service.Service(self._bus_name, objid, name=name,
stype=stype, domain=domain, address=address, port=port,
properties=properties)
+ key = (name, stype)
self._services[key] = service
if self.get_owner() and name != self.get_owner().get_nick_name():
raise RuntimeError("Tried to register a service that didn't have Owner nick as the service name!")
actid = service.get_activity_id()
+ rs_name = name
if actid:
rs_name = Service.compose_service_name(rs_name, actid)
rs_stype = service.get_type()
@@ -538,11 +546,12 @@ class PresenceService(object):
logging.debug("registered service name '%s' type '%s' on port %d with args %s" % (rs_name, rs_stype, rs_port, rs_props))
try:
- group = dbus.Interface(self._bus.get_object(avahi.DBUS_NAME, self._server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP)
+ obj = self._session_bus.get_object(avahi.DBUS_NAME, self._mdns_service.EntryGroupNew())
+ group = dbus.Interface(obj, avahi.DBUS_INTERFACE_ENTRY_GROUP)
# Add properties; ensure they are converted to ByteArray types
# because python sometimes can't figure that out
- info = []
+ info = [""]
for k, v in rs_props.items():
tmp_item = "%s=%s" % (k, v)
info.append(dbus.types.ByteArray(tmp_item))
@@ -564,6 +573,7 @@ class PresenceService(object):
pass
activity_stype = service.get_type()
self.register_service_type(activity_stype)
+ return service
def register_service_type(self, stype):
"""Requests that the Presence service look for and recognize
diff --git a/shell/PresenceService/Service.py b/shell/PresenceService/Service.py
index d9a504c..7c7aa54 100644
--- a/shell/PresenceService/Service.py
+++ b/shell/PresenceService/Service.py
@@ -3,6 +3,7 @@ import sys, os
sys.path.insert(0, os.path.abspath("../../"))
from sugar import util
import dbus, dbus.service
+import random
def _txt_to_dict(txt):
"""Convert an avahi-returned TXT record formatted
@@ -53,18 +54,6 @@ def _decompose_service_name(name):
return (None, name)
return (activity_id, name[:start - 2])
-def is_multicast_address(address):
- """Simple numerical check for whether an IP4 address
- is in the range for multicast addresses or not."""
- if not address:
- return False
- if address[3] != '.':
- return False
- first = int(float(address[:3]))
- if first >= 224 and first <= 239:
- return True
- return False
-
_ACTIVITY_ID_TAG = "ActivityID"
SERVICE_DBUS_INTERFACE = "org.laptop.Presence.Service"
@@ -86,7 +75,9 @@ class ServiceDBusHelper(dbus.service.Object):
pary['name'] = self._parent.get_name()
pary['type'] = self._parent.get_type()
pary['domain'] = self._parent.get_domain()
- pary['activityId'] = self._parent.get_activity_id()
+ actid = self._parent.get_activity_id()
+ if actid:
+ pary['activityId'] = actid
port = self._parent.get_port()
if port:
pary['port'] = self._parent.get_port()
@@ -190,11 +181,6 @@ class Service(object):
def get_full_name(self):
return self._full_name
- def is_multicast_service(self):
- """Return True if the service's address is a multicast address,
- False if it is not."""
- return is_multicast_address(self._address)
-
def get_one_property(self, key):
"""Return one property of the service, or None
if the property was not found. Cannot distinguish
@@ -222,12 +208,14 @@ class Service(object):
# Set key/value pairs on internal property list
for key, value in props.items():
+ if len(key) == 0:
+ continue
tmp_key = key
tmp_val = value
- if type(tmp_key) == type(u""):
- tmp_key = tmp_key.encode()
- if type(tmp_val) == type(u""):
- tmp_val = tmp_val.encode()
+ if type(tmp_key) != type(u""):
+ tmp_key = unicode(tmp_key)
+ if type(tmp_val) != type(u""):
+ tmp_val = unicode(tmp_val)
self._properties[tmp_key] = tmp_val
def get_type(self):
@@ -242,6 +230,8 @@ class Service(object):
return self._port
def set_port(self, port):
+ if port == -1:
+ port = random.randint(4000, 65000)
if type(port) != type(1) or (port <= 1024 and port > 65536):
raise ValueError("must specify a valid port number between 1024 and 65536.")
self._port = port
diff --git a/shell/Session.py b/shell/Session.py
index 87ea3db..d44889d 100644
--- a/shell/Session.py
+++ b/shell/Session.py
@@ -1,6 +1,7 @@
import os
import gtk
import gobject
+import time
from Shell import Shell
from Process import Process
@@ -44,6 +45,17 @@ class MatchboxProcess(Process):
def get_name(self):
return 'Matchbox'
+class PresenceServiceProcess(Process):
+ def __init__(self):
+ Process.__init__(self, "python shell/PresenceService/PresenceService.py",)
+
+ def get_name(self):
+ return "PresenceService"
+
+ def start(self):
+ Process.start(self, True)
+ time.sleep(3)
+
class Session:
"""Takes care of running the shell and all the sugar processes"""
@@ -57,7 +69,10 @@ class Session:
process = MatchboxProcess()
process.start()
-
+
+ process = PresenceServiceProcess()
+ process.start()
+
shell = Shell()
shell.start()
diff --git a/shell/Shell.py b/shell/Shell.py
index 2dc411c..6866cc4 100755
--- a/shell/Shell.py
+++ b/shell/Shell.py
@@ -56,7 +56,6 @@ class Shell:
bus_name = dbus.service.BusName('com.redhat.Sugar.Shell', bus=session_bus)
ShellDbusService(self, bus_name)
- self._ps = PresenceService.PresenceService()
self._owner = ShellOwner()
self._registry = ActivityRegistry()