utilities.py
Go to the documentation of this file.
00001 '''
00002 Created on 01/08/2011
00003 
00004 Utility functions
00005 
00006 @author: Daniel Stonier
00007 '''
00008 
00009 def service_to_str(service):
00010     ''' 
00011       String representation of zeroconf announcement 
00012     '''
00013     #print service
00014     return "\tname: %s\n\ttype: %s [%s]\n\tdomain: %s\n\thostname: %s\n\taddress: %s\n\tport: %d\n\tinterface: %d\n\tprotocol: %d\n\tdescription: %s\n\tis_local:%d\n\tour_own: %d\n\twide_area: %d\n\tmulticast: %d" % (
00015         service.name, 
00016         service_name(service.type),
00017         service.type,
00018         service.domain,
00019         service.hostname, 
00020         service.address, 
00021         service.port,
00022         service.hardware_interface,
00023         service.protocol,
00024         service.description,
00025         service.is_local,
00026         service.our_own,
00027         service.wide_area,
00028         service.multicast
00029         )
00030 
00031 def same_service(service_one, service_two):
00032     '''
00033       Sometimes you'll see the same service on multiple interfaces - this will often happen on localhost
00034       where the service will be getting advertised on whatever network devices you currently have
00035       running (e.g. eth0 and wlan1).
00036       
00037       In these cases, we assume they're equal. In fact, the important properties uniquely
00038       identifying the service for us (remembering that we're discovering on a particular domain and
00039       service_type) are:
00040       
00041         service_name, port, domain
00042       
00043     '''
00044     if ( service_one.name == service_two.name ) and ( service_one.port == service_two.port ) and ( service_one.domain == service_two.domain ):
00045         return True
00046     else:
00047         return False
00048         
00049 def service_name(service_type):
00050     '''
00051         This emulates what python-avahi's ServiceTypeDatabase class does in 
00052         conjuction with /usr/share/service-types and /usr/lib/avahi/service-types.db.
00053         
00054         We could just roll out further .db's which would then get 
00055         it to print nice englishified versions of the service types for any
00056         zeroconf browser, however we're really only interested in making it functional
00057         internally (ros-internally) for now. So just hacking it in code for now.
00058     '''
00059     if service_type == '_ros-master._tcp':
00060         return "Ros Master"
00061     if service_type == '_concert-master._tcp':
00062         return "Concert Master"
00063     if service_type == '_app-manager._tcp':
00064         return "App Manager"
00065 
00066     if service_type == '_ros-master._udp':
00067         return "Ros Master (UDP)"
00068     if service_type == '_concert-master._udp':
00069         return "Concert Master (UDP)"
00070     if service_type == '_app-manager._udp':
00071         return "App Manager (UDP)"
00072     
00073     # or else...
00074     return service_type


zeroconf_avahi
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 20:53:01