sugar-toolkit-gtk3/sugar/p2p/model/RemoteModel.py

30 lines
906 B
Python
Raw Normal View History

2006-05-15 20:48:08 +02:00
import xmlrpclib
2006-06-18 04:06:40 +02:00
import logging
2006-05-15 20:48:08 +02:00
from sugar.p2p.NotificationListener import NotificationListener
from sugar.p2p.model.AbstractModel import AbstractModel
class RemoteModel(AbstractModel):
def __init__(self, service, notification_service):
2006-05-15 20:48:08 +02:00
AbstractModel.__init__(self)
self._service = service
self._notification_service = notification_service
2006-05-15 20:48:08 +02:00
addr = "http://%s:%d" % (service.get_address(), service.get_port())
2006-06-18 04:06:40 +02:00
logging.debug('Setup remote model ' + addr)
2006-05-15 20:48:08 +02:00
self._client = xmlrpclib.ServerProxy(addr)
self._setup_notification_listener()
def get_value(self, key):
return self._client.get_value(key)
def set_value(self, key, value):
self._client.set_value(key, value)
def _setup_notification_listener(self):
name = self._service.get_name()
self._notification = NotificationListener(self._notification_service)
2006-05-15 20:48:08 +02:00
self._notification.add_listener(self._notify_model_change)