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

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

	LeftHanded        *dbusPropertyWacomLeftHanded
	CursorMode        *dbusPropertyWacomCursorMode
	KeyUpAction       *dbusPropertyWacomKeyUpAction
	KeyDownAction     *dbusPropertyWacomKeyDownAction
	DoubleDelta       *dbusPropertyWacomDoubleDelta
	PressureSensitive *dbusPropertyWacomPressureSensitive
	ActionInfos       *dbusPropertyWacomActionInfos
	DeviceList        *dbusPropertyWacomDeviceList
	Exist             *dbusPropertyWacomExist
}

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

	obj.LeftHanded.Reset()
	obj.CursorMode.Reset()
	obj.KeyUpAction.Reset()
	obj.KeyDownAction.Reset()
	obj.DoubleDelta.Reset()
	obj.PressureSensitive.Reset()
	obj.ActionInfos.Reset()
	obj.DeviceList.Reset()
	obj.Exist.Reset()
}

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

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

func (this *dbusPropertyWacomLeftHanded) 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.Wacom", "LeftHanded", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property LeftHanded of com.deepin.daemon.InputDevice.Wacom is an bool but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyWacomLeftHanded) Set(v bool) {
	this.SetValue(v)
}

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

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

func (this *dbusPropertyWacomCursorMode) 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.Wacom", "CursorMode", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property CursorMode of com.deepin.daemon.InputDevice.Wacom is an bool but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyWacomCursorMode) Set(v bool) {
	this.SetValue(v)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyWacomActionInfos) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.InputDevice.Wacom.ActionInfos is not writable")
}

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

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

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

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

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

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

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

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

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

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

	obj.LeftHanded = &dbusPropertyWacomLeftHanded{&property.BaseObserver{}, core}
	obj.CursorMode = &dbusPropertyWacomCursorMode{&property.BaseObserver{}, core}
	obj.KeyUpAction = &dbusPropertyWacomKeyUpAction{&property.BaseObserver{}, core}
	obj.KeyDownAction = &dbusPropertyWacomKeyDownAction{&property.BaseObserver{}, core}
	obj.DoubleDelta = &dbusPropertyWacomDoubleDelta{&property.BaseObserver{}, core}
	obj.PressureSensitive = &dbusPropertyWacomPressureSensitive{&property.BaseObserver{}, core}
	obj.ActionInfos = &dbusPropertyWacomActionInfos{&property.BaseObserver{}, core}
	obj.DeviceList = &dbusPropertyWacomDeviceList{&property.BaseObserver{}, core}
	obj.Exist = &dbusPropertyWacomExist{&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.Wacom',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.Wacom" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "LeftHanded" {
						obj.LeftHanded.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Wacom) { DestroyWacom(_obj) })
	return obj, nil
}
