]> git.meshlink.io Git - catta/commitdiff
update python programs to new DBUS API
authorLennart Poettering <lennart@poettering.net>
Sun, 25 Sep 2005 20:15:46 +0000 (20:15 +0000)
committerLennart Poettering <lennart@poettering.net>
Sun, 25 Sep 2005 20:15:46 +0000 (20:15 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@611 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-utils/avahi-bookmarks.in
avahi-utils/avahi-browse.in
avahi-utils/avahi-discover.in
avahi-utils/avahi-resolve-address.in
avahi-utils/avahi-resolve-host-name.in

index 49c4e3b9f29224704eae0ea5da3075d498b89c38..df36f49a254f2464f6bdedff18526b184dd399b2 100755 (executable)
@@ -46,6 +46,7 @@ urlproto = { "_http._tcp" : "http",  "_https._tcp" : "https", "_ftp._tcp" : "ftp
 port = 8080
 address = "127.0.0.1"
 use_host_names = False
+domain = "local"
 
 class AvahiBookmarks(resource.Resource):
     isLeaf = True
@@ -68,7 +69,9 @@ class AvahiBookmarks(resource.Resource):
 
     def browse_service_type(self, stype):
 
-        browser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype, "local")), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+        global domain
+
+        browser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
         browser.connect_to_signal('ItemNew', self.new_service)
         browser.connect_to_signal('ItemRemove', self.remove_service)
 
@@ -111,9 +114,9 @@ class AvahiBookmarks(resource.Resource):
         return t
 
 
-    def new_service(self, interface, protocol, name, type, domain):
+    def new_service(self, interface, protocol, name, type, domain, flags):
 
-        interface, protocol, name, type, domain, host, aprotocol, address, port, txt = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC)
+        interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, 0)
 
         if use_host_names:
             h = host
@@ -135,10 +138,11 @@ def usage(retval = 0):
     print "   -p --port PORT        Specify the port to use (default %u)" % port
     print "   -a --address ADDRESS  Specify the address to bind to (default %s)" % address
     print "   -H --host-names       Show all services, regardless of the type"
+    print "   -d --domain DOMAIN    Specify the domain to browse" 
     sys.exit(retval)
 
 try:
-    opts, args = getopt.getopt(sys.argv[1:], "hp:a:H", ["help", "port=", "address=", "host-names"])
+    opts, args = getopt.getopt(sys.argv[1:], "hp:a:Hd:", ["help", "port=", "address=", "host-names", "domain="])
 except getopt.GetoptError:
     usage(2)
 
@@ -154,6 +158,9 @@ for o, a in opts:
 
     if o in ("-H", "--host-names"):
         use_host_names = True
+
+    if o in ("-d", "--domain"):
+        domain = a
     
 site = server.Site(AvahiBookmarks())
 reactor.listenTCP(port, site, interface=address)
index 1acc165e634c30f68c13565f16c5464b319724ca..6ae00ba50e1eacfda0191a6a523f07b917307317 100755 (executable)
@@ -88,25 +88,25 @@ def lookup_service_type(stype):
     except KeyError:
         return "n/a"
 
-def service_resolved(interface, protocol, name, stype, domain, host, aprotocol, address, port, txt):
+def service_resolved(interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
     print "Service data for service '%s' of type '%s' (%s) in domain '%s' on %s.%i:" % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol)
     print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt))
 
 def print_error(err):
     print "Error:", str(err)
 
-def new_service(interface, protocol, name, stype, domain):
+def new_service(interface, protocol, name, stype, domain, flags):
     global server
     
     print "Found service '%s' of type '%s' (%s) in domain '%s' on %s.%i." % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol)
 
     # Asynchronous resolving
-    server.ResolveService(interface, protocol, name, stype, domain, avahi.PROTO_UNSPEC, reply_handler=service_resolved, error_handler=print_error)
+    server.ResolveService(interface, protocol, name, stype, domain, avahi.PROTO_UNSPEC, 0, reply_handler=service_resolved, error_handler=print_error)
 
-def remove_service(interface, protocol, name, stype, domain):
+def remove_service(interface, protocol, name, stype, domain, flags):
     print "Service '%s' of type '%s' (%s) in domain '%s' on %s.%i disappeared." % (name, stype, lookup_service_type(stype), domain, siocgifname(interface), protocol)
  
-def new_service_type(interface, protocol, stype, domain):
+def new_service_type(interface, protocol, stype, domain, flags):
     global server, service_browsers
 
     # Are we already browsing this domain for this type? 
@@ -115,7 +115,7 @@ def new_service_type(interface, protocol, stype, domain):
 
     print "Browsing for services of type '%s' (%s) in domain '%s' on %s.%i ..." % (stype, lookup_service_type(stype), domain, siocgifname(interface), protocol)
     
-    b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(interface, protocol, stype, domain)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+    b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(interface, protocol, stype, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
     b.connect_to_signal('ItemNew', new_service)
     b.connect_to_signal('ItemRemove', remove_service)
 
@@ -131,14 +131,14 @@ def browse_domain(interface, protocol, domain):
     if stype is None:
         print "Browsing domain '%s' on %s.%i ..." % (domain, siocgifname(interface), protocol)
 
-        b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceTypeBrowserNew(interface, protocol, domain)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
+        b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceTypeBrowserNew(interface, protocol, domain, 0)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
         b.connect_to_signal('ItemNew', new_service_type)
 
         service_type_browsers[(interface, protocol, domain)] = b
     else:
-        new_service_type(interface, protocol, stype, domain)
+        new_service_type(interface, protocol, stype, domain, 0)
 
-def new_domain(interface, protocol, domain):
+def new_domain(interface, protocol, domain, flags):
 
     # We browse for .local anyway...
     if domain != "local":
@@ -153,7 +153,7 @@ if domain is None:
     browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local")
 
     # Browse for other browsable domains
-    db = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
+    db = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE, 0)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
     db.connect_to_signal('ItemNew', new_domain)
 
 else:
index 04d133cdf439ff7f12ee0bfba73d0fa5b969b6fb..77ce72f07cc206dc8811b8d45e4c0218fd31f35f 100755 (executable)
@@ -52,7 +52,7 @@ class Main_window(SimpleGladeApp):
             self.info_label.set_markup("<i>No service currently selected.</i>")
             return
         #Asynchronous resolving
-        self.server.ResolveService( int(interface), int(protocol), name, stype, domain, avahi.PROTO_UNSPEC, reply_handler=self.service_resolved, error_handler=self.print_error)
+        self.server.ResolveService( int(interface), int(protocol), name, stype, domain, avahi.PROTO_UNSPEC, 0, reply_handler=self.service_resolved, error_handler=self.print_error)
 
 
     def protoname(self,protocol):
@@ -68,7 +68,7 @@ class Main_window(SimpleGladeApp):
         else:
             return self.server.GetNetworkInterfaceNameByIndex(interface)
                         
-    def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt):
+    def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
         print "Service data for service '%s' of type '%s' in domain '%s' on %i.%i:" % (name, stype, domain, interface, protocol)
 
         print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
@@ -93,7 +93,7 @@ class Main_window(SimpleGladeApp):
         except KeyError:
             return stype
             
-    def new_service(self, interface, protocol, name, stype, domain):
+    def new_service(self, interface, protocol, name, stype, domain, flags):
         print "Found service '%s' of type '%s' in domain '%s' on %i.%i." % (name, stype, domain, interface, protocol)
         if self.zc_ifaces.has_key((interface,protocol)) == False:
             self.zc_ifaces[(interface,protocol)] = self.insert_row(self.treemodel, None, str(self.siocgifname(interface))+" "+str(self.protoname(protocol)),None,interface,protocol,None,domain)
@@ -108,7 +108,7 @@ class Main_window(SimpleGladeApp):
         self.tree_view.expand_to_path(self.treemodel.get_path(treeiter))
 
 
-    def remove_service(self, interface, protocol, name, stype, domain):
+    def remove_service(self, interface, protocol, name, stype, domain, flags):
         print "Service '%s' of type '%s' in domain '%s' on %i.%i disappeared." % (name, stype, domain, interface, protocol)
         self.info_label.set_markup("")
         treeiter=self.services_browsed[(interface, protocol, name, stype, domain)]
@@ -132,7 +132,7 @@ class Main_window(SimpleGladeApp):
                     del self.zc_ifaces[(interface,protocol)]
 
  
-    def new_service_type(self, interface, protocol, stype, domain):
+    def new_service_type(self, interface, protocol, stype, domain, flags):
         global service_browsers
 
         # Are we already browsing this domain for this type? 
@@ -141,7 +141,7 @@ class Main_window(SimpleGladeApp):
         
         print "Browsing for services of type '%s' in domain '%s' on %i.%i ..." % (stype, domain, interface, protocol)
         
-        b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(interface, protocol, stype, domain)),  avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+        b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(interface, protocol, stype, domain, 0)),  avahi.DBUS_INTERFACE_SERVICE_BROWSER)
         b.connect_to_signal('ItemNew', self.new_service)
         b.connect_to_signal('ItemRemove', self.remove_service)
 
@@ -157,14 +157,14 @@ class Main_window(SimpleGladeApp):
         if self.stype is None:
             print "Browsing domain '%s' on %i.%i ..." % (domain, interface, protocol)
         
-            b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceTypeBrowserNew(interface, protocol, domain)),  avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
+            b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceTypeBrowserNew(interface, protocol, domain, 0)),  avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
             b.connect_to_signal('ItemNew', self.new_service_type)
 
             service_type_browsers[(interface, protocol, domain)] = b
         else:
             new_service_type(interface, protocol, stype, domain)
 
-    def new_domain(self,interface, protocol, domain):
+    def new_domain(self,interface, protocol, domain, flags):
         if self.zc_ifaces.has_key((interface,protocol)) == False:
             self.zc_ifaces[(interface,protocol)] = self.insert_row(self.treemodel, None, str(self.siocgifname(interface))+" "+str(self.protoname(protocol)),None,interface,protocol,None,domain)
         if self.zc_domains.has_key((interface,protocol,domain)) == False:
@@ -211,7 +211,7 @@ class Main_window(SimpleGladeApp):
             self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local")
                         
             # Browse for other browsable domains
-            db = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
+            db = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE, 0)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
             db.connect_to_signal('ItemNew', self.new_domain)
         else:
             # Just browse the domain the user wants us to browse
index 71c628765b3a7454b1fd651f9d77ed43229b842f..a645bbd0352c541e3b329832cc9c09670f7e9b6c 100755 (executable)
@@ -44,7 +44,7 @@ ret = 0
 
 for a in sys.argv[1:]:
     try:
-        r = server.ResolveAddress(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, a)
+        r = server.ResolveAddress(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, a, 0)
         print r[3], r[4]
     except dbus.DBusException, e:
         print "Resolving '%s' failed: %s" % (a, str(e))
index cc245266d469d2615113317b5bdb15e531ba5d63..3cc97b08d0ca97df4197199dbcc0ac68263d1f83 100755 (executable)
@@ -44,7 +44,7 @@ ret = 0
 
 for name in sys.argv[1:]:
     try:
-        r = server.ResolveHostName(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, name, avahi.PROTO_UNSPEC)
+        r = server.ResolveHostName(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, name, avahi.PROTO_UNSPEC, 0)
         print r[2], r[4]
     except dbus.DBusException, e:
         print "Resolving '%s' failed: %s" % (name, str(e))