2006-10-15 01:08:44 +02:00
|
|
|
# Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
|
2006-06-18 04:06:40 +02:00
|
|
|
import logging
|
|
|
|
|
2006-05-15 21:36:17 +02:00
|
|
|
from sugar.p2p.Notifier import Notifier
|
2006-06-18 04:06:40 +02:00
|
|
|
from sugar.p2p import network
|
2006-05-15 20:48:08 +02:00
|
|
|
|
|
|
|
class NotificationListener:
|
2006-06-16 20:20:09 +02:00
|
|
|
def __init__(self, service):
|
2006-06-18 04:06:40 +02:00
|
|
|
logging.debug('Start notification listener. Service %s, address %s, port %s' % (service.get_type(), service.get_address(), service.get_port()))
|
2006-06-16 20:20:09 +02:00
|
|
|
server = network.GroupServer(service.get_address(),
|
2006-05-15 21:03:05 +02:00
|
|
|
service.get_port(),
|
2006-05-15 20:48:08 +02:00
|
|
|
self._recv_multicast)
|
|
|
|
server.start()
|
|
|
|
|
2006-05-15 23:16:55 +02:00
|
|
|
self._listeners = []
|
2006-05-15 20:48:08 +02:00
|
|
|
|
|
|
|
def add_listener(self, listener):
|
2006-05-15 23:16:55 +02:00
|
|
|
self._listeners.append(listener)
|
2006-05-15 20:48:08 +02:00
|
|
|
|
|
|
|
def _recv_multicast(self, msg):
|
|
|
|
for listener in self._listeners:
|
|
|
|
listener(msg)
|