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

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

	RepeatEnabled  *dbusPropertyKeyboardRepeatEnabled
	CapslockToggle *dbusPropertyKeyboardCapslockToggle
	CursorBlink    *dbusPropertyKeyboardCursorBlink
	RepeatInterval *dbusPropertyKeyboardRepeatInterval
	RepeatDelay    *dbusPropertyKeyboardRepeatDelay
	CurrentLayout  *dbusPropertyKeyboardCurrentLayout
	UserLayoutList *dbusPropertyKeyboardUserLayoutList
	UserOptionList *dbusPropertyKeyboardUserOptionList
}

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

	obj.RepeatEnabled.Reset()
	obj.CapslockToggle.Reset()
	obj.CursorBlink.Reset()
	obj.RepeatInterval.Reset()
	obj.RepeatDelay.Reset()
	obj.CurrentLayout.Reset()
	obj.UserLayoutList.Reset()
	obj.UserOptionList.Reset()
}

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

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

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

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

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

func (obj *Keyboard) GetLayoutDesc(arg0 string) (arg1 string, _err error) {
	_err = obj.core.Call("com.deepin.daemon.InputDevice.Keyboard.GetLayoutDesc", 0, arg0).Store(&arg1)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Keyboard) LayoutList() (arg0 map[string]string, _err error) {
	_err = obj.core.Call("com.deepin.daemon.InputDevice.Keyboard.LayoutList", 0).Store(&arg0)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyKeyboardUserLayoutList) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.InputDevice.Keyboard.UserLayoutList is not writable")
}

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

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

func (this *dbusPropertyKeyboardUserOptionList) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.InputDevice.Keyboard.UserOptionList is not writable")
}

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

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

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

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

	obj.RepeatEnabled = &dbusPropertyKeyboardRepeatEnabled{&property.BaseObserver{}, core}
	obj.CapslockToggle = &dbusPropertyKeyboardCapslockToggle{&property.BaseObserver{}, core}
	obj.CursorBlink = &dbusPropertyKeyboardCursorBlink{&property.BaseObserver{}, core}
	obj.RepeatInterval = &dbusPropertyKeyboardRepeatInterval{&property.BaseObserver{}, core}
	obj.RepeatDelay = &dbusPropertyKeyboardRepeatDelay{&property.BaseObserver{}, core}
	obj.CurrentLayout = &dbusPropertyKeyboardCurrentLayout{&property.BaseObserver{}, core}
	obj.UserLayoutList = &dbusPropertyKeyboardUserLayoutList{&property.BaseObserver{}, core}
	obj.UserOptionList = &dbusPropertyKeyboardUserOptionList{&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.Keyboard',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.Keyboard" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "RepeatEnabled" {
						obj.RepeatEnabled.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Keyboard) { DestroyKeyboard(_obj) })
	return obj, nil
}
