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

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

	UID                    *dbusPropertyUserUID
	GID                    *dbusPropertyUserGID
	Name                   *dbusPropertyUserName
	Timestamp              *dbusPropertyUserTimestamp
	TimestampMonotonic     *dbusPropertyUserTimestampMonotonic
	RuntimePath            *dbusPropertyUserRuntimePath
	Service                *dbusPropertyUserService
	Slice                  *dbusPropertyUserSlice
	Display                *dbusPropertyUserDisplay
	State                  *dbusPropertyUserState
	Sessions               *dbusPropertyUserSessions
	IdleHint               *dbusPropertyUserIdleHint
	IdleSinceHint          *dbusPropertyUserIdleSinceHint
	IdleSinceHintMonotonic *dbusPropertyUserIdleSinceHintMonotonic
	Linger                 *dbusPropertyUserLinger
}

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

	obj.UID.Reset()
	obj.GID.Reset()
	obj.Name.Reset()
	obj.Timestamp.Reset()
	obj.TimestampMonotonic.Reset()
	obj.RuntimePath.Reset()
	obj.Service.Reset()
	obj.Slice.Reset()
	obj.Display.Reset()
	obj.State.Reset()
	obj.Sessions.Reset()
	obj.IdleHint.Reset()
	obj.IdleSinceHint.Reset()
	obj.IdleSinceHintMonotonic.Reset()
	obj.Linger.Reset()
}

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

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

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

func (this *dbusPropertyUserUID) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.UID is not writable")
}

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

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

func (this *dbusPropertyUserGID) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.GID is not writable")
}

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

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

func (this *dbusPropertyUserName) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.Name is not writable")
}

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

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

func (this *dbusPropertyUserTimestamp) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.Timestamp is not writable")
}

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

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

func (this *dbusPropertyUserTimestampMonotonic) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.TimestampMonotonic is not writable")
}

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

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

func (this *dbusPropertyUserRuntimePath) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.RuntimePath is not writable")
}

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

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

func (this *dbusPropertyUserService) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.Service is not writable")
}

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

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

func (this *dbusPropertyUserSlice) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.Slice is not writable")
}

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

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

func (this *dbusPropertyUserDisplay) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.Display is not writable")
}

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

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

func (this *dbusPropertyUserState) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.State is not writable")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyUserLinger) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.login1.User.Linger is not writable")
}

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

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

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

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

	obj.UID = &dbusPropertyUserUID{&property.BaseObserver{}, core}
	obj.GID = &dbusPropertyUserGID{&property.BaseObserver{}, core}
	obj.Name = &dbusPropertyUserName{&property.BaseObserver{}, core}
	obj.Timestamp = &dbusPropertyUserTimestamp{&property.BaseObserver{}, core}
	obj.TimestampMonotonic = &dbusPropertyUserTimestampMonotonic{&property.BaseObserver{}, core}
	obj.RuntimePath = &dbusPropertyUserRuntimePath{&property.BaseObserver{}, core}
	obj.Service = &dbusPropertyUserService{&property.BaseObserver{}, core}
	obj.Slice = &dbusPropertyUserSlice{&property.BaseObserver{}, core}
	obj.Display = &dbusPropertyUserDisplay{&property.BaseObserver{}, core}
	obj.State = &dbusPropertyUserState{&property.BaseObserver{}, core}
	obj.Sessions = &dbusPropertyUserSessions{&property.BaseObserver{}, core}
	obj.IdleHint = &dbusPropertyUserIdleHint{&property.BaseObserver{}, core}
	obj.IdleSinceHint = &dbusPropertyUserIdleSinceHint{&property.BaseObserver{}, core}
	obj.IdleSinceHintMonotonic = &dbusPropertyUserIdleSinceHintMonotonic{&property.BaseObserver{}, core}
	obj.Linger = &dbusPropertyUserLinger{&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.User',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.User" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "UID" {
						obj.UID.Notify()

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

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

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

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

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

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

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

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

					} else if key == "State" {
						obj.State.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 key == "Linger" {
						obj.Linger.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.login1.User.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 == "UID" {
						obj.UID.Notify()

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

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

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

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

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

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

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

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

					} else if key == "State" {
						obj.State.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 key == "Linger" {
						obj.Linger.Notify()
					}
				}
			}
		}
	}()

	runtime.SetFinalizer(obj, func(_obj *User) { DestroyUser(_obj) })
	return obj, nil
}
