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

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

	Name        *dbusPropertyMonitorName
	Enabled     *dbusPropertyMonitorEnabled
	Connected   *dbusPropertyMonitorConnected
	X           *dbusPropertyMonitorX
	Y           *dbusPropertyMonitorY
	Width       *dbusPropertyMonitorWidth
	Height      *dbusPropertyMonitorHeight
	Rotation    *dbusPropertyMonitorRotation
	Reflect     *dbusPropertyMonitorReflect
	RefreshRate *dbusPropertyMonitorRefreshRate
	Rotations   *dbusPropertyMonitorRotations
	Reflects    *dbusPropertyMonitorReflects
	BestMode    *dbusPropertyMonitorBestMode
	CurrentMode *dbusPropertyMonitorCurrentMode
	Modes       *dbusPropertyMonitorModes
}

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

	obj.Name.Reset()
	obj.Enabled.Reset()
	obj.Connected.Reset()
	obj.X.Reset()
	obj.Y.Reset()
	obj.Width.Reset()
	obj.Height.Reset()
	obj.Rotation.Reset()
	obj.Reflect.Reset()
	obj.RefreshRate.Reset()
	obj.Rotations.Reset()
	obj.Reflects.Reset()
	obj.BestMode.Reset()
	obj.CurrentMode.Reset()
	obj.Modes.Reset()
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	obj.Name = &dbusPropertyMonitorName{&property.BaseObserver{}, core}
	obj.Enabled = &dbusPropertyMonitorEnabled{&property.BaseObserver{}, core}
	obj.Connected = &dbusPropertyMonitorConnected{&property.BaseObserver{}, core}
	obj.X = &dbusPropertyMonitorX{&property.BaseObserver{}, core}
	obj.Y = &dbusPropertyMonitorY{&property.BaseObserver{}, core}
	obj.Width = &dbusPropertyMonitorWidth{&property.BaseObserver{}, core}
	obj.Height = &dbusPropertyMonitorHeight{&property.BaseObserver{}, core}
	obj.Rotation = &dbusPropertyMonitorRotation{&property.BaseObserver{}, core}
	obj.Reflect = &dbusPropertyMonitorReflect{&property.BaseObserver{}, core}
	obj.RefreshRate = &dbusPropertyMonitorRefreshRate{&property.BaseObserver{}, core}
	obj.Rotations = &dbusPropertyMonitorRotations{&property.BaseObserver{}, core}
	obj.Reflects = &dbusPropertyMonitorReflects{&property.BaseObserver{}, core}
	obj.BestMode = &dbusPropertyMonitorBestMode{&property.BaseObserver{}, core}
	obj.CurrentMode = &dbusPropertyMonitorCurrentMode{&property.BaseObserver{}, core}
	obj.Modes = &dbusPropertyMonitorModes{&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.Monitor',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.Monitor" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Name" {
						obj.Name.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Monitor) { DestroyMonitor(_obj) })
	return obj, nil
}
