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

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 Mouse struct {
	Path     dbus.ObjectPath
	DestName string
	core     *dbus.Object

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

	LeftHanded         *dbusPropertyMouseLeftHanded
	DisableTpad        *dbusPropertyMouseDisableTpad
	NaturalScroll      *dbusPropertyMouseNaturalScroll
	MotionAcceleration *dbusPropertyMouseMotionAcceleration
	MotionThreshold    *dbusPropertyMouseMotionThreshold
	DoubleClick        *dbusPropertyMouseDoubleClick
	DragThreshold      *dbusPropertyMouseDragThreshold
	DeviceList         *dbusPropertyMouseDeviceList
	Exist              *dbusPropertyMouseExist
}

func (obj *Mouse) _createSignalChan() <-chan *dbus.Signal {
	obj.signalsLocker.Lock()
	ch := getBus().Signal()
	obj.signals[ch] = struct{}{}
	obj.signalsLocker.Unlock()
	return ch
}
func (obj *Mouse) _deleteSignalChan(ch <-chan *dbus.Signal) {
	obj.signalsLocker.Lock()
	delete(obj.signals, ch)
	getBus().DetachSignal(ch)
	obj.signalsLocker.Unlock()
}
func DestroyMouse(obj *Mouse) {
	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='com.deepin.daemon.InputDevice.Mouse',sender='" + obj.DestName + "',member='PropertiesChanged'")

	obj.LeftHanded.Reset()
	obj.DisableTpad.Reset()
	obj.NaturalScroll.Reset()
	obj.MotionAcceleration.Reset()
	obj.MotionThreshold.Reset()
	obj.DoubleClick.Reset()
	obj.DragThreshold.Reset()
	obj.DeviceList.Reset()
	obj.Exist.Reset()
}

func (obj *Mouse) Reset() (_err error) {
	_err = obj.core.Call("com.deepin.daemon.InputDevice.Mouse.Reset", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertyMouseLeftHanded) SetValue(v interface{} /*bool*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*bool)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.InputDevice.Mouse", "LeftHanded", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property LeftHanded of com.deepin.daemon.InputDevice.Mouse is an bool but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyMouseLeftHanded) Set(v bool) {
	this.SetValue(v)
}

func (this *dbusPropertyMouseLeftHanded) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyMouseLeftHanded) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "LeftHanded").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyMouseLeftHanded) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

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

func (this *dbusPropertyMouseDisableTpad) SetValue(v interface{} /*bool*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*bool)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.InputDevice.Mouse", "DisableTpad", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property DisableTpad of com.deepin.daemon.InputDevice.Mouse is an bool but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyMouseDisableTpad) Set(v bool) {
	this.SetValue(v)
}

func (this *dbusPropertyMouseDisableTpad) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyMouseDisableTpad) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "DisableTpad").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyMouseDisableTpad) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

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

func (this *dbusPropertyMouseNaturalScroll) SetValue(v interface{} /*bool*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*bool)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.InputDevice.Mouse", "NaturalScroll", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property NaturalScroll of com.deepin.daemon.InputDevice.Mouse is an bool but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyMouseNaturalScroll) Set(v bool) {
	this.SetValue(v)
}

func (this *dbusPropertyMouseNaturalScroll) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyMouseNaturalScroll) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "NaturalScroll").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyMouseNaturalScroll) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

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

func (this *dbusPropertyMouseMotionAcceleration) SetValue(v interface{} /*float64*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*float64)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.InputDevice.Mouse", "MotionAcceleration", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property MotionAcceleration of com.deepin.daemon.InputDevice.Mouse is an float64 but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyMouseMotionAcceleration) Set(v float64) {
	this.SetValue(v)
}

func (this *dbusPropertyMouseMotionAcceleration) Get() float64 {
	v, _ := this.GetValue()
	return v.(float64)
}
func (this *dbusPropertyMouseMotionAcceleration) GetValue() (interface{} /*float64*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "MotionAcceleration").Store(&r)
	if err == nil && r.Signature().String() == "d" {
		return r.Value().(float64), nil
	}
	return *new(float64), err
}
func (this *dbusPropertyMouseMotionAcceleration) GetType() reflect.Type {
	return reflect.TypeOf((*float64)(nil)).Elem()
}

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

func (this *dbusPropertyMouseMotionThreshold) SetValue(v interface{} /*float64*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*float64)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.InputDevice.Mouse", "MotionThreshold", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property MotionThreshold of com.deepin.daemon.InputDevice.Mouse is an float64 but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyMouseMotionThreshold) Set(v float64) {
	this.SetValue(v)
}

func (this *dbusPropertyMouseMotionThreshold) Get() float64 {
	v, _ := this.GetValue()
	return v.(float64)
}
func (this *dbusPropertyMouseMotionThreshold) GetValue() (interface{} /*float64*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "MotionThreshold").Store(&r)
	if err == nil && r.Signature().String() == "d" {
		return r.Value().(float64), nil
	}
	return *new(float64), err
}
func (this *dbusPropertyMouseMotionThreshold) GetType() reflect.Type {
	return reflect.TypeOf((*float64)(nil)).Elem()
}

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

func (this *dbusPropertyMouseDoubleClick) SetValue(v interface{} /*int32*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*int32)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.InputDevice.Mouse", "DoubleClick", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property DoubleClick of com.deepin.daemon.InputDevice.Mouse is an int32 but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyMouseDoubleClick) Set(v int32) {
	this.SetValue(v)
}

func (this *dbusPropertyMouseDoubleClick) Get() int32 {
	v, _ := this.GetValue()
	return v.(int32)
}
func (this *dbusPropertyMouseDoubleClick) GetValue() (interface{} /*int32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "DoubleClick").Store(&r)
	if err == nil && r.Signature().String() == "i" {
		return r.Value().(int32), nil
	}
	return *new(int32), err
}
func (this *dbusPropertyMouseDoubleClick) GetType() reflect.Type {
	return reflect.TypeOf((*int32)(nil)).Elem()
}

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

func (this *dbusPropertyMouseDragThreshold) SetValue(v interface{} /*int32*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*int32)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.InputDevice.Mouse", "DragThreshold", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property DragThreshold of com.deepin.daemon.InputDevice.Mouse is an int32 but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyMouseDragThreshold) Set(v int32) {
	this.SetValue(v)
}

func (this *dbusPropertyMouseDragThreshold) Get() int32 {
	v, _ := this.GetValue()
	return v.(int32)
}
func (this *dbusPropertyMouseDragThreshold) GetValue() (interface{} /*int32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "DragThreshold").Store(&r)
	if err == nil && r.Signature().String() == "i" {
		return r.Value().(int32), nil
	}
	return *new(int32), err
}
func (this *dbusPropertyMouseDragThreshold) GetType() reflect.Type {
	return reflect.TypeOf((*int32)(nil)).Elem()
}

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

func (this *dbusPropertyMouseDeviceList) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.InputDevice.Mouse.DeviceList is not writable")
}

func (this *dbusPropertyMouseDeviceList) Get() [][]interface{} {
	v, _ := this.GetValue()
	return v.([][]interface{})
}
func (this *dbusPropertyMouseDeviceList) GetValue() (interface{} /*[][]interface {}*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "DeviceList").Store(&r)
	if err == nil && r.Signature().String() == "a(sib)" {
		return r.Value().([][]interface{}), nil
	}
	return *new([][]interface{}), err
}
func (this *dbusPropertyMouseDeviceList) GetType() reflect.Type {
	return reflect.TypeOf((*[][]interface{})(nil)).Elem()
}

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

func (this *dbusPropertyMouseExist) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.InputDevice.Mouse.Exist is not writable")
}

func (this *dbusPropertyMouseExist) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyMouseExist) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.InputDevice.Mouse", "Exist").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyMouseExist) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

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

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

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

	obj.LeftHanded = &dbusPropertyMouseLeftHanded{&property.BaseObserver{}, core}
	obj.DisableTpad = &dbusPropertyMouseDisableTpad{&property.BaseObserver{}, core}
	obj.NaturalScroll = &dbusPropertyMouseNaturalScroll{&property.BaseObserver{}, core}
	obj.MotionAcceleration = &dbusPropertyMouseMotionAcceleration{&property.BaseObserver{}, core}
	obj.MotionThreshold = &dbusPropertyMouseMotionThreshold{&property.BaseObserver{}, core}
	obj.DoubleClick = &dbusPropertyMouseDoubleClick{&property.BaseObserver{}, core}
	obj.DragThreshold = &dbusPropertyMouseDragThreshold{&property.BaseObserver{}, core}
	obj.DeviceList = &dbusPropertyMouseDeviceList{&property.BaseObserver{}, core}
	obj.Exist = &dbusPropertyMouseExist{&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='com.deepin.daemon.InputDevice.Mouse',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) == "com.deepin.daemon.InputDevice.Mouse" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "LeftHanded" {
						obj.LeftHanded.Notify()

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

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

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

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

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

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

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

					} else if key == "Exist" {
						obj.Exist.Notify()
					}
				}
			} else if v.Name == "com.deepin.daemon.InputDevice.Mouse.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 == "LeftHanded" {
						obj.LeftHanded.Notify()

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Mouse) { DestroyMouse(_obj) })
	return obj, nil
}
