utilities.py
Go to the documentation of this file.
1 '''
2 Created on 01/08/2011
3 
4 Utility functions
5 
6 @author: Daniel Stonier
7 '''
8 
9 def service_to_str(service):
10  '''
11  String representation of zeroconf announcement
12  '''
13  #print service
14  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" % (
15  service.name,
16  service_name(service.type),
17  service.type,
18  service.domain,
19  service.hostname,
20  service.address,
21  service.port,
22  service.hardware_interface,
23  service.protocol,
24  service.description,
25  service.is_local,
26  service.our_own,
27  service.wide_area,
28  service.multicast
29  )
30 
31 def same_service(service_one, service_two):
32  '''
33  Sometimes you'll see the same service on multiple interfaces - this will often happen on localhost
34  where the service will be getting advertised on whatever network devices you currently have
35  running (e.g. eth0 and wlan1).
36 
37  In these cases, we assume they're equal. In fact, the important properties uniquely
38  identifying the service for us (remembering that we're discovering on a particular domain and
39  service_type) are:
40 
41  service_name, port, domain
42 
43  '''
44  if ( service_one.name == service_two.name ) and ( service_one.port == service_two.port ) and ( service_one.domain == service_two.domain ):
45  return True
46  else:
47  return False
48 
49 def service_name(service_type):
50  '''
51  This emulates what python-avahi's ServiceTypeDatabase class does in
52  conjuction with /usr/share/service-types and /usr/lib/avahi/service-types.db.
53 
54  We could just roll out further .db's which would then get
55  it to print nice englishified versions of the service types for any
56  zeroconf browser, however we're really only interested in making it functional
57  internally (ros-internally) for now. So just hacking it in code for now.
58  '''
59  if service_type == '_ros-master._tcp':
60  return "Ros Master"
61  if service_type == '_concert-master._tcp':
62  return "Concert Master"
63  if service_type == '_app-manager._tcp':
64  return "App Manager"
65 
66  if service_type == '_ros-master._udp':
67  return "Ros Master (UDP)"
68  if service_type == '_concert-master._udp':
69  return "Concert Master (UDP)"
70  if service_type == '_app-manager._udp':
71  return "App Manager (UDP)"
72 
73  # or else...
74  return service_type
def service_to_str(service)
Definition: utilities.py:9
def service_name(service_type)
Definition: utilities.py:49
def same_service(service_one, service_two)
Definition: utilities.py:31


zeroconf_avahi
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 15:49:04