More fixes...

This commit is contained in:
Marco Pesenti Gritti 2006-05-15 15:36:17 -04:00
parent 7300b8e429
commit d2a0bd4d65
6 changed files with 10 additions and 5 deletions

View File

@ -1,9 +1,12 @@
from Service import Service from Service import Service
from sugar.p2p.Notifier import Notifier
import network import network
class NotificationListener: class NotificationListener:
def __init__(self, group, name): def __init__(self, group, name):
service = group.get_service(name, Notifier.TYPE) service = group.get_service(name, Notifier.TYPE)
print service.get_address()
print service.get_port()
server = network.GroupServer(service.get_address(), server = network.GroupServer(service.get_address(),
service.get_port(), service.get_port(),
self._recv_multicast) self._recv_multicast)
@ -15,5 +18,6 @@ class NotificationListener:
self._listeners.add(listener) self._listeners.add(listener)
def _recv_multicast(self, msg): def _recv_multicast(self, msg):
print 'Got message ' + msg
for listener in self._listeners: for listener in self._listeners:
listener(msg) listener(msg)

View File

@ -1,4 +1,3 @@
from sugar.p2p.NotificationListener import NotificationListener
from sugar.p2p import network from sugar.p2p import network
from sugar.p2p.Service import Service from sugar.p2p.Service import Service

View File

@ -28,4 +28,5 @@ class Service(object):
def register(self, group): def register(self, group):
pannounce = presence.PresenceAnnounce() pannounce = presence.PresenceAnnounce()
pannounce.register_service(self._name, self._port, self._stype) pannounce.register_service(self._address, self._name,
self._port, self._stype)

View File

@ -4,10 +4,11 @@ from sugar.p2p.NotificationListener import NotificationListener
from sugar.p2p.model.AbstractModel import AbstractModel from sugar.p2p.model.AbstractModel import AbstractModel
class RemoteModel(AbstractModel): class RemoteModel(AbstractModel):
def __init__(self, service): def __init__(self, group, service):
AbstractModel.__init__(self) AbstractModel.__init__(self)
self._service = service self._service = service
self._group = group
addr = "http://%s:%d" % (service.get_address(), service.get_port()) addr = "http://%s:%d" % (service.get_address(), service.get_port())
self._client = xmlrpclib.ServerProxy(addr) self._client = xmlrpclib.ServerProxy(addr)

View File

@ -17,6 +17,6 @@ class Store:
else: else:
service = self._group.get_service(model_id, LocalModel.SERVICE_TYPE) service = self._group.get_service(model_id, LocalModel.SERVICE_TYPE)
if service: if service:
return RemoteModel(service) return RemoteModel(self._group, service)
else: else:
return None return None

View File

@ -77,7 +77,7 @@ class PresenceAnnounce(object):
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER) self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
self._hostname = None self._hostname = None
def register_service(self, rs_name, rs_port, rs_service, **kwargs): def register_service(self, rs_address, rs_name, rs_port, rs_service, **kwargs):
g = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP) g = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP)
if rs_name is None: if rs_name is None:
if self._hostname is None: if self._hostname is None: