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

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

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

	HasChanged      *dbusPropertyDisplayHasChanged
	HasCustomConfig *dbusPropertyDisplayHasCustomConfig
	DisplayMode     *dbusPropertyDisplayDisplayMode
	ScreenWidth     *dbusPropertyDisplayScreenWidth
	ScreenHeight    *dbusPropertyDisplayScreenHeight
	Primary         *dbusPropertyDisplayPrimary
	PrimaryRect     *dbusPropertyDisplayPrimaryRect
	Monitors        *dbusPropertyDisplayMonitors
	Brightness      *dbusPropertyDisplayBrightness
	TouchMap        *dbusPropertyDisplayTouchMap
}

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

	obj.HasChanged.Reset()
	obj.HasCustomConfig.Reset()
	obj.DisplayMode.Reset()
	obj.ScreenWidth.Reset()
	obj.ScreenHeight.Reset()
	obj.Primary.Reset()
	obj.PrimaryRect.Reset()
	obj.Monitors.Reset()
	obj.Brightness.Reset()
	obj.TouchMap.Reset()
}

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

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

func (obj *Display) ChangeBrightness(arg0 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Display.ChangeBrightness", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

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

func (obj *Display) ListOutputsCommonModes() (arg0 [][]interface{}, _err error) {
	_err = obj.core.Call("com.deepin.daemon.Display.ListOutputsCommonModes", 0).Store(&arg0)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyDisplayHasChanged) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.HasChanged is not writable")
}

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

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

func (this *dbusPropertyDisplayHasCustomConfig) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.HasCustomConfig is not writable")
}

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

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

func (this *dbusPropertyDisplayDisplayMode) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.DisplayMode is not writable")
}

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

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

func (this *dbusPropertyDisplayScreenWidth) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.ScreenWidth is not writable")
}

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

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

func (this *dbusPropertyDisplayScreenHeight) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.ScreenHeight is not writable")
}

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

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

func (this *dbusPropertyDisplayPrimary) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.Primary is not writable")
}

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

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

func (this *dbusPropertyDisplayPrimaryRect) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.PrimaryRect is not writable")
}

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

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

func (this *dbusPropertyDisplayMonitors) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.Monitors is not writable")
}

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

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

func (this *dbusPropertyDisplayBrightness) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.Brightness is not writable")
}

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

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

func (this *dbusPropertyDisplayTouchMap) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Display.TouchMap is not writable")
}

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

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

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

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

	obj.HasChanged = &dbusPropertyDisplayHasChanged{&property.BaseObserver{}, core}
	obj.HasCustomConfig = &dbusPropertyDisplayHasCustomConfig{&property.BaseObserver{}, core}
	obj.DisplayMode = &dbusPropertyDisplayDisplayMode{&property.BaseObserver{}, core}
	obj.ScreenWidth = &dbusPropertyDisplayScreenWidth{&property.BaseObserver{}, core}
	obj.ScreenHeight = &dbusPropertyDisplayScreenHeight{&property.BaseObserver{}, core}
	obj.Primary = &dbusPropertyDisplayPrimary{&property.BaseObserver{}, core}
	obj.PrimaryRect = &dbusPropertyDisplayPrimaryRect{&property.BaseObserver{}, core}
	obj.Monitors = &dbusPropertyDisplayMonitors{&property.BaseObserver{}, core}
	obj.Brightness = &dbusPropertyDisplayBrightness{&property.BaseObserver{}, core}
	obj.TouchMap = &dbusPropertyDisplayTouchMap{&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.Display',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.Display" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "HasChanged" {
						obj.HasChanged.Notify()

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

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

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

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

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

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

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

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

					} else if key == "TouchMap" {
						obj.TouchMap.Notify()
					}
				}
			} else if v.Name == "com.deepin.daemon.Display.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 == "HasChanged" {
						obj.HasChanged.Notify()

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Display) { DestroyDisplay(_obj) })
	return obj, nil
}
