/*This file is automatically generated by pkg.deepin.io/dbus-generator. Don't edit it*/
package fprint

import "pkg.deepin.io/lib/dbus"
import "pkg.deepin.io/lib/dbus/property"
import "reflect"
import "sync"
import "runtime"
import "fmt"
import "errors"

/*prevent compile error*/
var _ = fmt.Println
var _ = runtime.SetFinalizer
var _ = sync.NewCond
var _ = reflect.TypeOf
var _ = property.BaseObserver{}

type Device struct {
	Path     dbus.ObjectPath
	DestName string
	core     *dbus.Object

	signals       map[<-chan *dbus.Signal]struct{}
	signalsLocker sync.Mutex

	scan_type         *dbusPropertyDevicescan_type
	num_enroll_stages *dbusPropertyDevicenum_enroll_stages
	name              *dbusPropertyDevicename
}

func (obj *Device) _createSignalChan() <-chan *dbus.Signal {
	obj.signalsLocker.Lock()
	ch := getBus().Signal()
	obj.signals[ch] = struct{}{}
	obj.signalsLocker.Unlock()
	return ch
}
func (obj *Device) _deleteSignalChan(ch <-chan *dbus.Signal) {
	obj.signalsLocker.Lock()
	delete(obj.signals, ch)
	getBus().DetachSignal(ch)
	obj.signalsLocker.Unlock()
}
func DestroyDevice(obj *Device) {
	obj.signalsLocker.Lock()
	defer obj.signalsLocker.Unlock()
	if obj.signals == nil {
		return
	}
	for ch, _ := range obj.signals {
		getBus().DetachSignal(ch)
	}
	obj.signals = nil

	runtime.SetFinalizer(obj, nil)

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.DBus.Properties',sender='" + obj.DestName + "',member='PropertiesChanged'")
	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='net.reactivated.Fprint.Device',sender='" + obj.DestName + "',member='PropertiesChanged'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='net.reactivated.Fprint.Device',sender='" + obj.DestName + "',member='EnrollStatus'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='net.reactivated.Fprint.Device',sender='" + obj.DestName + "',member='VerifyStatus'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='net.reactivated.Fprint.Device',sender='" + obj.DestName + "',member='VerifyFingerSelected'")

	obj.scan_type.Reset()
	obj.num_enroll_stages.Reset()
	obj.name.Reset()
}

func (obj *Device) EnrollStop() (_err error) {
	_err = obj.core.Call("net.reactivated.Fprint.Device.EnrollStop", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Device) EnrollStart(finger_name string) (_err error) {
	_err = obj.core.Call("net.reactivated.Fprint.Device.EnrollStart", 0, finger_name).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Device) VerifyStop() (_err error) {
	_err = obj.core.Call("net.reactivated.Fprint.Device.VerifyStop", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Device) VerifyStart(finger_name string) (_err error) {
	_err = obj.core.Call("net.reactivated.Fprint.Device.VerifyStart", 0, finger_name).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Device) Release() (_err error) {
	_err = obj.core.Call("net.reactivated.Fprint.Device.Release", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Device) Claim(username string) (_err error) {
	_err = obj.core.Call("net.reactivated.Fprint.Device.Claim", 0, username).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Device) DeleteEnrolledFingers(username string) (_err error) {
	_err = obj.core.Call("net.reactivated.Fprint.Device.DeleteEnrolledFingers", 0, username).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Device) ListEnrolledFingers(username string) (enrolled_fingers []string, _err error) {
	_err = obj.core.Call("net.reactivated.Fprint.Device.ListEnrolledFingers", 0, username).Store(&enrolled_fingers)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Device) ConnectEnrollStatus(callback func(arg0 string, arg1 bool)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "net.reactivated.Fprint.Device.EnrollStatus" || 2 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}
			if reflect.TypeOf(v.Body[1]) != reflect.TypeOf((*bool)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(string), v.Body[1].(bool))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

func (obj *Device) ConnectVerifyStatus(callback func(arg0 string, arg1 bool)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "net.reactivated.Fprint.Device.VerifyStatus" || 2 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}
			if reflect.TypeOf(v.Body[1]) != reflect.TypeOf((*bool)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(string), v.Body[1].(bool))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

func (obj *Device) ConnectVerifyFingerSelected(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "net.reactivated.Fprint.Device.VerifyFingerSelected" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(string))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

type dbusPropertyDevicescan_type struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDevicescan_type) SetValue(notwritable interface{}) {
	fmt.Println("net.reactivated.Fprint.Device.scan_type is not writable")
}

func (this *dbusPropertyDevicescan_type) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyDevicescan_type) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "net.reactivated.Fprint.Device", "scan_type").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyDevicescan_type) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyDevicenum_enroll_stages struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDevicenum_enroll_stages) SetValue(notwritable interface{}) {
	fmt.Println("net.reactivated.Fprint.Device.num_enroll_stages is not writable")
}

func (this *dbusPropertyDevicenum_enroll_stages) Get() int32 {
	v, _ := this.GetValue()
	return v.(int32)
}
func (this *dbusPropertyDevicenum_enroll_stages) GetValue() (interface{} /*int32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "net.reactivated.Fprint.Device", "num_enroll_stages").Store(&r)
	if err == nil && r.Signature().String() == "i" {
		return r.Value().(int32), nil
	}
	return *new(int32), err
}
func (this *dbusPropertyDevicenum_enroll_stages) GetType() reflect.Type {
	return reflect.TypeOf((*int32)(nil)).Elem()
}

type dbusPropertyDevicename struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDevicename) SetValue(notwritable interface{}) {
	fmt.Println("net.reactivated.Fprint.Device.name is not writable")
}

func (this *dbusPropertyDevicename) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyDevicename) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "net.reactivated.Fprint.Device", "name").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyDevicename) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

func NewDevice(destName string, path dbus.ObjectPath) (*Device, error) {
	if !path.IsValid() {
		return nil, errors.New("The path of '" + string(path) + "' is invalid.")
	}

	core := getBus().Object(destName, path)

	obj := &Device{Path: path, DestName: destName, core: core, signals: make(map[<-chan *dbus.Signal]struct{})}

	obj.scan_type = &dbusPropertyDevicescan_type{&property.BaseObserver{}, core}
	obj.num_enroll_stages = &dbusPropertyDevicenum_enroll_stages{&property.BaseObserver{}, core}
	obj.name = &dbusPropertyDevicename{&property.BaseObserver{}, core}

	dbusAddMatch("type='signal',path='" + string(path) + "',interface='org.freedesktop.DBus.Properties',sender='" + destName + "',member='PropertiesChanged'")
	dbusAddMatch("type='signal',path='" + string(path) + "',interface='net.reactivated.Fprint.Device',sender='" + destName + "',member='PropertiesChanged'")
	sigChan := obj._createSignalChan()
	go func() {
		typeString := reflect.TypeOf("")
		typeKeyValues := reflect.TypeOf(map[string]dbus.Variant{})
		typeArrayValues := reflect.TypeOf([]string{})
		for v := range sigChan {
			if v.Name == "org.freedesktop.DBus.Properties.PropertiesChanged" &&
				len(v.Body) == 3 &&
				reflect.TypeOf(v.Body[0]) == typeString &&
				reflect.TypeOf(v.Body[1]) == typeKeyValues &&
				reflect.TypeOf(v.Body[2]) == typeArrayValues &&
				v.Body[0].(string) == "net.reactivated.Fprint.Device" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "scan_type" {
						obj.scan_type.Notify()

					} else if key == "num_enroll_stages" {
						obj.num_enroll_stages.Notify()

					} else if key == "name" {
						obj.name.Notify()
					}
				}
			} else if v.Name == "net.reactivated.Fprint.Device.PropertiesChanged" && len(v.Body) == 1 && reflect.TypeOf(v.Body[0]) == typeKeyValues {
				for key, _ := range v.Body[0].(map[string]dbus.Variant) {
					if false {
					} else if key == "scan_type" {
						obj.scan_type.Notify()

					} else if key == "num_enroll_stages" {
						obj.num_enroll_stages.Notify()

					} else if key == "name" {
						obj.name.Notify()
					}
				}
			}
		}
	}()

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='net.reactivated.Fprint.Device',sender='" + obj.DestName + "',member='EnrollStatus'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='net.reactivated.Fprint.Device',sender='" + obj.DestName + "',member='VerifyStatus'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='net.reactivated.Fprint.Device',sender='" + obj.DestName + "',member='VerifyFingerSelected'")

	runtime.SetFinalizer(obj, func(_obj *Device) { DestroyDevice(_obj) })
	return obj, nil
}
