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

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

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

	Id                     *dbusPropertySeatId
	ActiveSession          *dbusPropertySeatActiveSession
	CanMultiSession        *dbusPropertySeatCanMultiSession
	CanTTY                 *dbusPropertySeatCanTTY
	CanGraphical           *dbusPropertySeatCanGraphical
	Sessions               *dbusPropertySeatSessions
	IdleHint               *dbusPropertySeatIdleHint
	IdleSinceHint          *dbusPropertySeatIdleSinceHint
	IdleSinceHintMonotonic *dbusPropertySeatIdleSinceHintMonotonic
}

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

	obj.Id.Reset()
	obj.ActiveSession.Reset()
	obj.CanMultiSession.Reset()
	obj.CanTTY.Reset()
	obj.CanGraphical.Reset()
	obj.Sessions.Reset()
	obj.IdleHint.Reset()
	obj.IdleSinceHint.Reset()
	obj.IdleSinceHintMonotonic.Reset()
}

func (obj *Seat) Terminate() (_err error) {
	_err = obj.core.Call("org.freedesktop.login1.Seat.Terminate", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) ActivateSession(arg0 string) (_err error) {
	_err = obj.core.Call("org.freedesktop.login1.Seat.ActivateSession", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) SwitchTo(arg0 uint32) (_err error) {
	_err = obj.core.Call("org.freedesktop.login1.Seat.SwitchTo", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) SwitchToNext() (_err error) {
	_err = obj.core.Call("org.freedesktop.login1.Seat.SwitchToNext", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) SwitchToPrevious() (_err error) {
	_err = obj.core.Call("org.freedesktop.login1.Seat.SwitchToPrevious", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertySeatId) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.Id is not writable")
}

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

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

func (this *dbusPropertySeatActiveSession) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.ActiveSession is not writable")
}

func (this *dbusPropertySeatActiveSession) Get() []interface{} {
	v, _ := this.GetValue()
	return v.([]interface{})
}
func (this *dbusPropertySeatActiveSession) GetValue() (interface{} /*[]interface {}*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.login1.Seat", "ActiveSession").Store(&r)
	if err == nil && r.Signature().String() == "(so)" {
		return r.Value().([]interface{}), nil
	}
	return *new([]interface{}), err
}
func (this *dbusPropertySeatActiveSession) GetType() reflect.Type {
	return reflect.TypeOf((*[]interface{})(nil)).Elem()
}

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

func (this *dbusPropertySeatCanMultiSession) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.CanMultiSession is not writable")
}

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

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

func (this *dbusPropertySeatCanTTY) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.CanTTY is not writable")
}

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

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

func (this *dbusPropertySeatCanGraphical) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.CanGraphical is not writable")
}

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

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

func (this *dbusPropertySeatSessions) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.Sessions is not writable")
}

func (this *dbusPropertySeatSessions) Get() [][]interface{} {
	v, _ := this.GetValue()
	return v.([][]interface{})
}
func (this *dbusPropertySeatSessions) GetValue() (interface{} /*[][]interface {}*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.login1.Seat", "Sessions").Store(&r)
	if err == nil && r.Signature().String() == "a(so)" {
		return r.Value().([][]interface{}), nil
	}
	return *new([][]interface{}), err
}
func (this *dbusPropertySeatSessions) GetType() reflect.Type {
	return reflect.TypeOf((*[][]interface{})(nil)).Elem()
}

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

func (this *dbusPropertySeatIdleHint) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.IdleHint is not writable")
}

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

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

func (this *dbusPropertySeatIdleSinceHint) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.IdleSinceHint is not writable")
}

func (this *dbusPropertySeatIdleSinceHint) Get() uint64 {
	v, _ := this.GetValue()
	return v.(uint64)
}
func (this *dbusPropertySeatIdleSinceHint) GetValue() (interface{} /*uint64*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.login1.Seat", "IdleSinceHint").Store(&r)
	if err == nil && r.Signature().String() == "t" {
		return r.Value().(uint64), nil
	}
	return *new(uint64), err
}
func (this *dbusPropertySeatIdleSinceHint) GetType() reflect.Type {
	return reflect.TypeOf((*uint64)(nil)).Elem()
}

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

func (this *dbusPropertySeatIdleSinceHintMonotonic) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.Seat.IdleSinceHintMonotonic is not writable")
}

func (this *dbusPropertySeatIdleSinceHintMonotonic) Get() uint64 {
	v, _ := this.GetValue()
	return v.(uint64)
}
func (this *dbusPropertySeatIdleSinceHintMonotonic) GetValue() (interface{} /*uint64*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.login1.Seat", "IdleSinceHintMonotonic").Store(&r)
	if err == nil && r.Signature().String() == "t" {
		return r.Value().(uint64), nil
	}
	return *new(uint64), err
}
func (this *dbusPropertySeatIdleSinceHintMonotonic) GetType() reflect.Type {
	return reflect.TypeOf((*uint64)(nil)).Elem()
}

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

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

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

	obj.Id = &dbusPropertySeatId{&property.BaseObserver{}, core}
	obj.ActiveSession = &dbusPropertySeatActiveSession{&property.BaseObserver{}, core}
	obj.CanMultiSession = &dbusPropertySeatCanMultiSession{&property.BaseObserver{}, core}
	obj.CanTTY = &dbusPropertySeatCanTTY{&property.BaseObserver{}, core}
	obj.CanGraphical = &dbusPropertySeatCanGraphical{&property.BaseObserver{}, core}
	obj.Sessions = &dbusPropertySeatSessions{&property.BaseObserver{}, core}
	obj.IdleHint = &dbusPropertySeatIdleHint{&property.BaseObserver{}, core}
	obj.IdleSinceHint = &dbusPropertySeatIdleSinceHint{&property.BaseObserver{}, core}
	obj.IdleSinceHintMonotonic = &dbusPropertySeatIdleSinceHintMonotonic{&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='org.freedesktop.login1.Seat',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) == "org.freedesktop.login1.Seat" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Id" {
						obj.Id.Notify()

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

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

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

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

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

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

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

					} else if key == "IdleSinceHintMonotonic" {
						obj.IdleSinceHintMonotonic.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.login1.Seat.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 == "Id" {
						obj.Id.Notify()

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Seat) { DestroySeat(_obj) })
	return obj, nil
}
