コード例 #1
0
ファイル: avahi.go プロジェクト: kleopatra999/cups-connector
func (z *zeroconf) removePrinter(name string) error {
	z.spMutex.Lock()
	defer z.spMutex.Unlock()

	r, exists := z.printers[name]
	if !exists {
		return fmt.Errorf("printer %s cannot be updated for Avahi publishing; it was never added", name)
	}

	if z.state == C.AVAHI_CLIENT_S_RUNNING && r.group != nil {
		C.avahi_threaded_poll_lock(z.threadedPoll)
		defer C.avahi_threaded_poll_unlock(z.threadedPoll)

		var errstr *C.char
		C.removeAvahiGroup(z.threadedPoll, r.group, &errstr)
		if errstr != nil {
			err := errors.New(C.GoString(errstr))
			C.free(unsafe.Pointer(errstr))
			return err
		}
	}

	C.free(unsafe.Pointer(r.name))

	delete(z.printers, name)
	return nil
}
コード例 #2
0
ファイル: avahi.go プロジェクト: t-yuki/cups-connector
func (z *zeroconf) updatePrinterTXT(name, ty, url, id string, online bool) error {
	z.spMutex.Lock()
	defer z.spMutex.Unlock()

	r, exists := z.printers[name]
	if !exists {
		return fmt.Errorf("printer %s cannot be updated for Avahi publishing; it was never added", name)
	}

	r.ty = ty
	r.url = url
	r.id = id
	r.online = online

	if z.state == C.AVAHI_CLIENT_S_RUNNING && r.group != nil {
		txt := prepareTXT(ty, url, id, online)
		defer C.avahi_string_list_free(txt)

		C.avahi_threaded_poll_lock(z.threadedPoll)
		defer C.avahi_threaded_poll_unlock(z.threadedPoll)

		if errstr := C.updateAvahiGroup(z.threadedPoll, r.group, r.name, txt); errstr != nil {
			err := fmt.Errorf("Failed to update Avahi group: %s", C.GoString(errstr))
			return err
		}
	}

	z.printers[name] = r
	return nil
}
コード例 #3
0
ファイル: avahi.go プロジェクト: t-yuki/cups-connector
func (z *zeroconf) addPrinter(name string, port uint16, ty, url, id string, online bool) error {
	r := record{
		name:   C.CString(name),
		port:   port,
		ty:     ty,
		url:    url,
		id:     id,
		online: online,
	}

	z.spMutex.Lock()
	defer z.spMutex.Unlock()

	if _, exists := z.printers[name]; exists {
		return fmt.Errorf("printer %s was already added to Avahi publishing", name)
	}
	if z.state == C.AVAHI_CLIENT_S_RUNNING {
		txt := prepareTXT(ty, url, id, online)
		defer C.avahi_string_list_free(txt)

		C.avahi_threaded_poll_lock(z.threadedPoll)
		defer C.avahi_threaded_poll_unlock(z.threadedPoll)

		if errstr := C.addAvahiGroup(z.threadedPoll, z.client, &r.group, r.name, C.ushort(r.port), txt); errstr != nil {
			err := fmt.Errorf("Failed to add Avahi group: %s", C.GoString(errstr))
			return err
		}
	}

	z.printers[name] = r
	return nil
}
コード例 #4
0
ファイル: avahi.go プロジェクト: kleopatra999/cups-connector
func (z *zeroconf) addPrinter(name string, port uint16, ty, url, id string, online bool) error {
	r := record{
		name:   C.CString(name),
		port:   port,
		ty:     ty,
		url:    url,
		id:     id,
		online: online,
	}

	z.spMutex.Lock()
	defer z.spMutex.Unlock()

	if _, exists := z.printers[name]; exists {
		return fmt.Errorf("printer %s was already added to Avahi publishing", name)
	}
	if z.state == C.AVAHI_CLIENT_S_RUNNING {
		tyC := C.CString(ty)
		defer C.free(unsafe.Pointer(tyC))
		urlC := C.CString(url)
		defer C.free(unsafe.Pointer(urlC))
		idC := C.CString(id)
		defer C.free(unsafe.Pointer(idC))
		var onlineC *C.char
		if online {
			onlineC = C.CString("online")
		} else {
			onlineC = C.CString("offline")
		}
		defer C.free(unsafe.Pointer(onlineC))

		C.avahi_threaded_poll_lock(z.threadedPoll)
		defer C.avahi_threaded_poll_unlock(z.threadedPoll)

		var errstr *C.char
		C.addAvahiGroup(z.threadedPoll, z.client, &r.group, r.name, C.ushort(port),
			tyC, urlC, idC, onlineC, &errstr)
		if errstr != nil {
			err := errors.New(C.GoString(errstr))
			C.free(unsafe.Pointer(errstr))
			return err
		}
	}

	z.printers[name] = r
	return nil
}
コード例 #5
0
ファイル: avahi.go プロジェクト: kleopatra999/cups-connector
func (z *zeroconf) updatePrinterTXT(name, ty, url, id string, online bool) error {
	z.spMutex.Lock()
	defer z.spMutex.Unlock()

	r, exists := z.printers[name]
	if !exists {
		return fmt.Errorf("printer %s cannot be updated for Avahi publishing; it was never added", name)
	}

	r.ty = ty
	r.url = url
	r.id = id
	r.online = online

	if z.state == C.AVAHI_CLIENT_S_RUNNING && r.group != nil {
		tyC := C.CString(ty)
		defer C.free(unsafe.Pointer(tyC))
		urlC := C.CString(url)
		defer C.free(unsafe.Pointer(urlC))
		idC := C.CString(id)
		defer C.free(unsafe.Pointer(idC))
		var onlineC *C.char
		if online {
			onlineC = C.CString("online")
		} else {
			onlineC = C.CString("offline")
		}
		defer C.free(unsafe.Pointer(onlineC))

		C.avahi_threaded_poll_lock(z.threadedPoll)
		defer C.avahi_threaded_poll_unlock(z.threadedPoll)

		var errstr *C.char
		C.updateAvahiGroup(z.threadedPoll, r.group, r.name, tyC, urlC, idC, onlineC, &errstr)
		if errstr != nil {
			err := errors.New(C.GoString(errstr))
			C.free(unsafe.Pointer(errstr))
			return err
		}
	}

	z.printers[name] = r
	return nil
}