Esempio n. 1
0
func (i *InterfaceKit) setOnChangeHandler(c chan InterfaceKitChange, t onChangeType) (*C.handler, error) {
	h, err := createHandler(func(h *C.handler) C.int {
		return C.setOnChangeHandler(i.ifkHandle, h, C.onChangeType(t))
	})
	if err != nil {
		return nil, err
	}

	go func() {
		for {
			r := C.onChangeAwait(h)

			change := InterfaceKitChange{}
			change.Index = int(r.index)
			change.Value = int(r.value)

			C.onChangeResultFree(r)

			select {
			case c <- change:
			default:
			}
		}
	}()

	return h, nil
}
Esempio n. 2
0
func (i *InterfaceKit) unsetOnChangeHandler(t onChangeType, h **C.handler) {
	C.unsetOnChangeHandler(i.ifkHandle, C.onChangeType(t))
	C.handlerFree(*h)
	*h = nil
}