The notifier should own the server not the listener!
This commit is contained in:
parent
6b78600646
commit
27b89c5b24
File diff suppressed because it is too large
Load Diff
@ -2,21 +2,13 @@ from Service import Service
|
|||||||
import network
|
import network
|
||||||
|
|
||||||
class NotificationListener:
|
class NotificationListener:
|
||||||
TYPE = "_olpc_model_notification._udp"
|
|
||||||
ADDRESS = "224.0.0.222"
|
|
||||||
PORT = 6300
|
|
||||||
|
|
||||||
def __init__(self, group, name):
|
def __init__(self, group, name):
|
||||||
server = network.GroupServer(NotificationListener.TYPE,
|
service = group.get_service(name, Notifier.TYPE)
|
||||||
NotificationListener.PORT,
|
server = network.GroupServer(service.get_address(),
|
||||||
|
service.get_port(),
|
||||||
self._recv_multicast)
|
self._recv_multicast)
|
||||||
server.start()
|
server.start()
|
||||||
|
|
||||||
service = Service(name, NotificationListener.TYPE,
|
|
||||||
NotificationListener.ADDRESS,
|
|
||||||
NotificationListener.PORT, True)
|
|
||||||
service.register(group)
|
|
||||||
|
|
||||||
self._listeners = {}
|
self._listeners = {}
|
||||||
|
|
||||||
def add_listener(self, listener):
|
def add_listener(self, listener):
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
import network
|
from sugar.p2p.NotificationListener import NotificationListener
|
||||||
|
from sugar.p2p import network
|
||||||
|
|
||||||
class Notifier:
|
class Notifier:
|
||||||
|
TYPE = "_olpc_model_notification._udp"
|
||||||
|
ADDRESS = "224.0.0.222"
|
||||||
|
PORT = 6300
|
||||||
|
|
||||||
def __init__(self, group, name):
|
def __init__(self, group, name):
|
||||||
service = group.get_service(name)
|
service = Service(name, NotificationListener.TYPE,
|
||||||
|
NotificationListener.ADDRESS,
|
||||||
|
NotificationListener.PORT, True)
|
||||||
|
service.register(group)
|
||||||
|
|
||||||
address = service.get_address()
|
address = service.get_address()
|
||||||
port = service.get_port()
|
port = service.get_port()
|
||||||
self._client = network.GroupClient(address, port)
|
self._client = network.GroupClient(address, port)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import socket
|
import socket
|
||||||
|
|
||||||
from sugar.p2p.Service import Service
|
from sugar.p2p.Service import Service
|
||||||
|
from sugar.p2p.Notifier import Notifier
|
||||||
from sugar.p2p.model.AbstractModel import AbstractModel
|
from sugar.p2p.model.AbstractModel import AbstractModel
|
||||||
from sugar.p2p import network
|
from sugar.p2p import network
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ class LocalModel(AbstractModel):
|
|||||||
self._values = {}
|
self._values = {}
|
||||||
|
|
||||||
self._setup_service()
|
self._setup_service()
|
||||||
|
self._notifier = Notifier(group, model_id)
|
||||||
|
|
||||||
def get_value(self, key):
|
def get_value(self, key):
|
||||||
return self._values[key]
|
return self._values[key]
|
||||||
@ -32,6 +34,7 @@ class LocalModel(AbstractModel):
|
|||||||
def set_value(self, key, value):
|
def set_value(self, key, value):
|
||||||
self._values[key] = value
|
self._values[key] = value
|
||||||
self._notify_model_change(key)
|
self._notify_model_change(key)
|
||||||
|
self._notifier.notify(key)
|
||||||
|
|
||||||
def _setup_service(self):
|
def _setup_service(self):
|
||||||
service = Service(self._model_id, LocalModel.SERVICE_TYPE, '',
|
service = Service(self._model_id, LocalModel.SERVICE_TYPE, '',
|
||||||
|
0
sugar/p2p/model/__init__.py
Normal file
0
sugar/p2p/model/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user