Index: controlies/Server.py
===================================================================
--- controlies/Server.py	(revision 90)
+++ controlies/Server.py	(revision 91)
@@ -18,11 +18,12 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 # GNU General Public License for more details.
 # You should have received a copy of the GNU General Public License
-# along with ControlAula. If not, see <http://www.gnu.org/licenses/>.
+# along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
-from twisted.internet import reactor
+from Utils.avahiClient import avahiClient
+
 from twisted.web import static, server
 from twisted.web.server import Session
 from twisted.python.components import registerAdapter
@@ -29,7 +30,9 @@
 import MainLoop
 from zope.interface import Interface, Attribute, implements
 from Plugins.LdapConnection import LdapConnection, ILdapConnection
+import os.path
 
+
 registerAdapter(LdapConnection, Session, ILdapConnection)
 
 # Start up the web service.     
@@ -38,7 +41,40 @@
 #Root.PageDir='/home/chisco/Proyectos/controlies/www'
 site = server.Site(Root)
 
-#my_server = static.File('/home/chisco/workspace/adminies/www/')
+fileName = '/tmp/controlIES.ltpsSevers'
 
+if os.path.isfile(fileName):
+	os.remove(fileName)
+	
+f = open(fileName, 'w')
+
+
+def _add_location(self, name, address, port):
+	f = open(fileName, 'r+')
+	f.write(name)
+	f.close()
+	print "add"
+
+	
+def _remove_location(self, name, address, port):	
+	print "remove"
+	#remove ipv6 entries:
+	if address.find(":") == -1:
+		print "removed:" + name,address,port
+
+
+
+try:	
+	_monitor = avahiClient()	
+	_monitor.add_callback('new-service', _add_location)
+	_monitor.add_callback('remove-service', _remove_location)
+	_monitor.start()
+	
+except Exception, ex:
+	error_msg = "Couldn't initialize Avahi monitor: %s" % str(ex)
+	#raise InitializeFailure(self.name, error_msg)
+
+from twisted.internet import reactor
+
 reactor.listenTCP(7778,site)
 reactor.run()
Index: controlies/Utils/avahiClient.py
===================================================================
--- controlies/Utils/avahiClient.py	(revision 90)
+++ controlies/Utils/avahiClient.py	(revision 91)
@@ -1,56 +1,99 @@
-import dbus, gobject, avahi
-from dbus import DBusException
-from dbus.mainloop.glib import DBusGMainLoop
-import threading
+##############################################################################
+# -*- coding: utf-8 -*-
+# Project:		ControlIES
+# Module:    	avahiClient.py
+# Purpose:		Avahi client to detect ltsp servers
+# Language:		Python 2.5
+# Date:			27-Feb-2011.
+# Ver:			27-Feb-2011.
+# Author:		José Luis Redrejo Rodriguez
+# Copyright:    2011 - José Luis Redrejo Rodriguez <jredrejo @no-spam@ debian.org>
+# Modified by:  Manuel Mora Gordillo <manuito @no-spam@ gmail.com>
+#
+# ControlIES is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# ControlIES 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 General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
 
-class avahiClient(threading.Thread):  
+try:
+    import dbus
+    if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
+		import dbus.glib		
+except ImportError:
+    dbus = None
 
-	names = []
+if dbus:
+    try:
+        import avahi
+    except ImportError:
+        avahi = None
+else:
+    avahi = None
 
-	def __init__(self):  
-		threading.Thread.__init__(self)  
+from twisted.internet import defer, threads
+from twisted.internet import glib2reactor
+glib2reactor.install()
 
-	def run(self):
+class avahiClient():
 
-		loop = DBusGMainLoop()
-		bus = dbus.SystemBus(mainloop=loop)
+    def __init__(self):
+		self._callbacks = {'new-service':  [], 'remove-service': [] }
+		# initialize dbus stuff needed for discovery
+								   
+		self.bus = dbus.SystemBus()
+		
+		avahi_bus = self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER)
+		self.server = dbus.Interface(avahi_bus, avahi.DBUS_INTERFACE_SERVER)
+		
+		stype = '_workstation._tcp'
+		domain = 'local'
+		self._plugged = {}
 
-		self.server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, '/'), 'org.freedesktop.Avahi.Server')
+		avahi_browser = self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype, domain, dbus.UInt32(0))
+		obj = self.bus.get_object(avahi.DBUS_NAME, avahi_browser)
+		self.browser = dbus.Interface(obj, avahi.DBUS_INTERFACE_SERVICE_BROWSER)
 
-		sbrowser = dbus.Interface(bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "_workstation._tcp", 'local', dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
-		sbrowser.connect_to_signal("ItemNew", self.myhandler)
+    def start(self):
+		self.browser.connect_to_signal('ItemNew', self.new_service)
+		self.browser.connect_to_signal('ItemRemove', self.remove_service)
+		
+    def stop(self):
+        self.bus.close()
 
-		self.loop = gobject.MainLoop()
-		self.loop.run()
+    def new_service(self, interface, protocol, name, type, domain, flags):
+		
+		def resolve_service_reply(*service):
+			address, port = service[-4:-2]
+			name = unicode(service[2])
+			for cb in self._callbacks['new-service']:
+				self._plugged[name] = (address,port)				
+				cb(self,name, address, port)
+				
+		def resolve_service_error(exception):
+			self.warning('could not resolve daap service %s %s: %s' %
+				(name, domain, exception))
 
+		self.server.ResolveService(interface, protocol, name, type, domain,
+				avahi.PROTO_UNSPEC, dbus.UInt32(0),
+				reply_handler=resolve_service_reply,
+				error_handler=resolve_service_error)
 
-	def service_resolved(self,*args):
-		#print args
-		print 'service resolved'
-		print 'name:', args[2]
-		print 'address:', args[7]
-		print 'port:', args[8]
-		#print args
-		self.names.append(args[2])
+    def remove_service(self, interface, protocol, name, type, domain,server):
+        address, port = self._plugged[name]
+        for cb in self._callbacks['remove-service']:
+            cb(self,name, address, port)
 
-		#self.loop.quit()
 
+    def add_callback(self, sig_name, callback):
+        self._callbacks[sig_name].append(callback)
 
-	def print_error(self,*args):
-		print 'error_handler'
-		print args[0]
-
-	def myhandler(self,interface, protocol, name, stype, domain, flags):
-		#print "Found service '%s' type '%s' domain '%s' " % (name, stype, domain)
-
-		if flags & avahi.LOOKUP_RESULT_LOCAL:
-				#print "que es esto"
-				pass
-
-		self.server.ResolveService(interface, protocol, name, stype, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), reply_handler=self.service_resolved, error_handler=self.print_error)
-		
-	def getList(self):
-		return self.names
-
-	def kill(self):
-		self.loop.quit()
+    def remove_callback(self, sig_name, callback):
+        self._callback[sig_name].remove(callback)
Index: controlies/Plugins/Hosts.py
===================================================================
--- controlies/Plugins/Hosts.py	(revision 90)
+++ controlies/Plugins/Hosts.py	(revision 91)
@@ -20,7 +20,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 # GNU General Public License for more details.
 # You should have received a copy of the GNU General Public License
-# along with ControlAula. If not, see <http://www.gnu.org/licenses/>.
+# along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
