示例#1
0
    def resolveService(self, event):
        serviceName, regtype, replyDomain = self.parent.hosts[self.parent.host_selector.GetSelection()]

        # finds the ip/port:
        sdRef2 = bonjour.AllocateDNSServiceRef()
        bonjour.pyDNSServiceResolve(sdRef2, 0, 0, serviceName, regtype, replyDomain, self.ResolveCallback, None)
        bonjour.DNSServiceProcessResult(sdRef2)
示例#2
0
 def _resolveCall(serviceRef):
     bonjour.pyDNSServiceResolve(
         serviceRef, flags, interfaceIndex,
         serviceName, self.type, replyDomain,
         self._resolveCallback,
         None
     )
     bonjour.DNSServiceProcessResult(serviceRef)
示例#3
0
        def __BrowseCallback(self,sdRef,flags,interfaceIndex,
                           errorCode,serviceName,regtype,
                           replyDomain,userdata):

            if flags & bonjour.kDNSServiceFlagsAdd:
                sdRef2 = bonjour.AllocateDNSServiceRef()
                ret = bonjour.pyDNSServiceResolve(sdRef2,
                                                  0,
                                                  0,
                                                  serviceName,
                                                  regtype,
                                                  replyDomain,
                                                  self.__ResolveCallback,
                                                  serviceName );

                bonjour.DNSServiceProcessResult(sdRef2)
                bonjour.DNSServiceRefDeallocate(sdRef2)

            elif flags == 0:
                self.lock.acquire()
                del self.serviceUrls[serviceName]
                self.lock.release()

                # Call callback (if registered) to signal delete
                if self.browseCallback:
                    self.browseCallback(self.DELETE,serviceName)
    def OnExpandItem(self,event):
    
        item = event.GetItem()
        if item == self.tree.GetRootItem():
            return
            
        
        data = self.tree.GetPyData(item)
        if not data:    
            return
        self.tree.DeleteChildren(item)
        name,regtype,replyDomain = data
        
        self.resolvingItem = item
        sdRef2 = bonjour.AllocateDNSServiceRef()
        ret = bonjour.pyDNSServiceResolve(sdRef2,
                                          0,
                                          0,
                                          name,
                                          regtype,
                                          replyDomain,
                                          ResolveCallback,
                                          None)

        bonjour.DNSServiceProcessResult(sdRef2)
示例#5
0
def _browse_callback(sdRef, flags, interfaceIndex,
			errorCode, serviceName, regtype,
			replyDomain, priv):
	if flags & bonjour.kDNSServiceFlagsAdd:
		args = priv.copy()

		args['name'] = serviceName
		service_ref = bonjour.AllocateDNSServiceRef()

		# FIXME (or better bonjour-py)
		# Bug in bonjour-py gives corrupt sdRef in callbacks
		# referencing sdRef results in a segfault!
		# The only way now is to pass a valid reference by means
		# of the user args. Badaboom!
		args['ref'] = service_ref
		retval = bonjour.pyDNSServiceResolve(service_ref, 0, 0,
							serviceName, regtype,
							replyDomain, _resolve_callback,
							args)
		fd = bonjour.DNSServiceRefSockFD(service_ref)
		source = gobject.io_add_watch(fd, gobject.IO_IN, _fd_callback, service_ref)
		_add_ref(service_ref, source)

	elif flags == 0:
		if priv['remover']:
			args = {'name': serviceName}
			priv['remover'](**args)
示例#6
0
    def startResolving(self):
        """Advertise the service with Bonjour.
        
        This method returns a deferred.  Upon success, the result
        is a dictionary of information about the service.  Upon failure,
        the result is a Failure object that knows the BonjourError code.
        """

        # Allocate a Bonjour Service Reference
        self.sdRef = bonjour.AllocateDNSServiceRef()

        # Initiate Registration of the service
        ret = bonjour.pyDNSServiceResolve(self.sdRef, self.flags,
                                          self.interfaceIndex, self.name,
                                          self.regtype, self.domain,
                                          self.callback, self.context)

        # Error check for immediate failure
        if ret != bonjour.kDNSServiceErr_NoError:
            raise BonjourResolveError(ret)

        # Get the file descriptor and integrate with twisted
        self.fd = bonjour.DNSServiceRefSockFD(self.sdRef)
        self.bonjourDesc = BonjourDescriptor(self.fd, self.sdRef)
        self.reactor.addReader(self.bonjourDesc)

        return None
def BrowseCallback(sdRef, flags, interfaceIndex, errorCode, serviceName,
                   regtype, replyDomain, userdata):
    if flags & bonjour.kDNSServiceFlagsAdd:
        sdRef2 = bonjour.AllocateDNSServiceRef()
        ret = bonjour.pyDNSServiceResolve(sdRef2, 0, 0, serviceName, regtype,
                                          replyDomain, ResolveCallback, None)

        bonjour.DNSServiceProcessResult(sdRef2)

    elif flags == 0:
        print "Service removed: ", serviceName, regtype
示例#8
0
def BrowseCallback(sdRef, flags, interfaceIndex, errorCode, serviceName,
                   regtype, replyDomain, userdata):
    if serviceName == servicename and flags & bonjour.kDNSServiceFlagsAdd:
        sys.stderr.write("Found service; resolving...\n")

        waitEvent.set()

        sdRef2 = bonjour.AllocateDNSServiceRef()
        ret = bonjour.pyDNSServiceResolve(sdRef2, 0, 0, serviceName, regtype,
                                          replyDomain, ResolveCallback, None)

        resolveEvent.clear()
        while not resolveEvent.isSet():
            bonjour.DNSServiceProcessResult(sdRef2)
	def BrowseCallback(self, sdRef,flags,interfaceIndex,
				 errorCode,serviceName,regtype,
				 replyDomain,
				 userdata):
		if flags & bonjour.kDNSServiceFlagsAdd:
			sdRef2 = bonjour.AllocateDNSServiceRef()
			ret = bonjour.pyDNSServiceResolve(sdRef2,
											0,
											0,
											serviceName,
											regtype,
											replyDomain,
											self.ResolveCallback,
											None );

			bonjour.DNSServiceProcessResult(sdRef2)
		elif flags == 0:
			self.ServiceGone(serviceName, regtype.split('.')[0][1:], None)
        def __BrowseCallback(self, sdRef, flags, interfaceIndex, errorCode,
                             serviceName, regtype, replyDomain, userdata):

            if flags & bonjour.kDNSServiceFlagsAdd:
                sdRef2 = bonjour.AllocateDNSServiceRef()
                ret = bonjour.pyDNSServiceResolve(sdRef2, 0, 0, serviceName,
                                                  regtype, replyDomain,
                                                  self.__ResolveCallback,
                                                  serviceName)

                bonjour.DNSServiceProcessResult(sdRef2)
                bonjour.DNSServiceRefDeallocate(sdRef2)

            elif flags == 0:
                self.lock.acquire()
                del self.serviceUrls[serviceName]
                self.lock.release()

                # Call callback (if registered) to signal delete
                if self.browseCallback:
                    self.browseCallback(self.DELETE, serviceName)
示例#11
0
    def __BrowseCallback(self,sdRef,flags,interfaceIndex,
                 errorCode,serviceName,regtype,
                 replyDomain,lookFor):
        """ Called when bonjour finds a service """
        if serviceName == lookFor and flags & bonjour.kDNSServiceFlagsAdd:
            sys.stderr.write( "Found service; resolving...\n")

            self.__waitEvent.set()
            
            sdRef2 = bonjour.AllocateDNSServiceRef()
            ret = bonjour.pyDNSServiceResolve(sdRef2,
                                              0,
                                              0,
                                              serviceName,
                                              regtype,
                                              replyDomain,
                                              self.__ResolveCallback,
                                              None );

            self.__resolveEvent.clear()
            while not self.__resolveEvent.isSet():
                bonjour.DNSServiceProcessResult(sdRef2)