More work on notification
This commit is contained in:
parent
d2a0bd4d65
commit
2fdedc751e
@ -223,14 +223,14 @@ class GroupChat(Chat):
|
||||
self._group.join()
|
||||
|
||||
name = self._group.get_owner().get_service_name()
|
||||
service = Service(name, CHAT_SERVICE_TYPE, '', CHAT_SERVICE_PORT)
|
||||
service = Service(name, CHAT_SERVICE_TYPE, CHAT_SERVICE_PORT)
|
||||
self._buddy_reader = StreamReader(self._group, service)
|
||||
self._buddy_reader.set_listener(self._buddy_recv_message)
|
||||
service.register(self._group)
|
||||
|
||||
service = Service(name, GROUP_CHAT_SERVICE_TYPE,
|
||||
GROUP_CHAT_SERVICE_ADDRESS,
|
||||
GROUP_CHAT_SERVICE_PORT, True)
|
||||
GROUP_CHAT_SERVICE_PORT,
|
||||
GROUP_CHAT_SERVICE_ADDRESS)
|
||||
self._group.add_service(service)
|
||||
|
||||
self._buddy_reader = StreamReader(self._group, service)
|
||||
|
@ -26,7 +26,7 @@ class Owner(Buddy):
|
||||
nick = "n00b"
|
||||
|
||||
service = Service(nick, PRESENCE_SERVICE_TYPE,
|
||||
'', PRESENCE_SERVICE_PORT)
|
||||
PRESENCE_SERVICE_PORT)
|
||||
|
||||
Buddy.__init__(self, service, nick)
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import avahi
|
||||
|
||||
from Buddy import Buddy
|
||||
from Buddy import Owner
|
||||
from Buddy import PRESENCE_SERVICE_TYPE
|
||||
@ -103,7 +105,13 @@ class LocalGroup(Group):
|
||||
|
||||
def _on_service_resolved(self, interface, protocol, name, stype, domain,
|
||||
host, aprotocol, address, port, txt, flags):
|
||||
service = Service(name, stype, address, port)
|
||||
multicast = None
|
||||
for prop in avahi.txt_array_to_string_array(txt):
|
||||
(key, value) = prop.split('=')
|
||||
if key == 'multicast':
|
||||
multicast = value
|
||||
|
||||
service = Service(name, stype, port, multicast)
|
||||
if stype == PRESENCE_SERVICE_TYPE:
|
||||
self._add_buddy(Buddy(service, name))
|
||||
elif stype.startswith("_olpc"):
|
||||
|
@ -1,12 +1,9 @@
|
||||
from Service import Service
|
||||
from sugar.p2p.Notifier import Notifier
|
||||
import network
|
||||
|
||||
class NotificationListener:
|
||||
def __init__(self, group, name):
|
||||
service = group.get_service(name, Notifier.TYPE)
|
||||
print service.get_address()
|
||||
print service.get_port()
|
||||
server = network.GroupServer(service.get_address(),
|
||||
service.get_port(),
|
||||
self._recv_multicast)
|
||||
@ -18,6 +15,5 @@ class NotificationListener:
|
||||
self._listeners.add(listener)
|
||||
|
||||
def _recv_multicast(self, msg):
|
||||
print 'Got message ' + msg
|
||||
for listener in self._listeners:
|
||||
listener(msg)
|
||||
|
@ -7,11 +7,10 @@ class Notifier:
|
||||
PORT = 6300
|
||||
|
||||
def __init__(self, group, name):
|
||||
service = Service(name, Notifier.TYPE, Notifier.ADDRESS,
|
||||
Notifier.PORT, True)
|
||||
service = Service(name, Notifier.TYPE, Notifier.PORT, Notifier.ADDRESS)
|
||||
service.register(group)
|
||||
|
||||
address = service.get_address()
|
||||
address = service.get_multicast_group()
|
||||
port = service.get_port()
|
||||
self._client = network.GroupClient(address, port)
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
import presence
|
||||
|
||||
class Service(object):
|
||||
def __init__(self, name, stype, address, port, multicast=False):
|
||||
def __init__(self, name, stype, port, mgroup=None):
|
||||
self._name = name
|
||||
self._stype = stype
|
||||
self._address = str(address)
|
||||
self._port = int(port)
|
||||
self._multicast = multicast
|
||||
self._mgroup = mgroup
|
||||
|
||||
def get_name(self):
|
||||
return self._name
|
||||
@ -23,10 +22,16 @@ class Service(object):
|
||||
def set_port(self, port):
|
||||
self._port = port
|
||||
|
||||
def get_multicast_group(self):
|
||||
return self._mgroup
|
||||
|
||||
def is_multicast(self):
|
||||
return self._multicast
|
||||
return self._mgroup != None
|
||||
|
||||
def register(self, group):
|
||||
pannounce = presence.PresenceAnnounce()
|
||||
pannounce.register_service(self._address, self._name,
|
||||
self._port, self._stype)
|
||||
if self._mgroup:
|
||||
pannounce.register_service(self._name, self._port, self._stype,
|
||||
multicast = self._mgroup)
|
||||
else:
|
||||
pannounce.register_service(self._name, self._port, self._stype)
|
||||
|
@ -37,7 +37,7 @@ class LocalModel(AbstractModel):
|
||||
self._notifier.notify(key)
|
||||
|
||||
def _setup_service(self):
|
||||
service = Service(self._model_id, LocalModel.SERVICE_TYPE, '',
|
||||
service = Service(self._model_id, LocalModel.SERVICE_TYPE,
|
||||
LocalModel.SERVICE_PORT)
|
||||
self._setup_server(service)
|
||||
service.register(self._group)
|
||||
|
@ -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._hostname = None
|
||||
|
||||
def register_service(self, rs_address, rs_name, rs_port, rs_service, **kwargs):
|
||||
def register_service(self, 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)
|
||||
if rs_name is None:
|
||||
if self._hostname is None:
|
||||
|
Loading…
Reference in New Issue
Block a user