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

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

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

	ConnectionPath           *dbusPropertyConnectionSessionConnectionPath
	Uuid                     *dbusPropertyConnectionSessionUuid
	Type                     *dbusPropertyConnectionSessionType
	AllowDelete              *dbusPropertyConnectionSessionAllowDelete
	AvailableVirtualSections *dbusPropertyConnectionSessionAvailableVirtualSections
	AvailableSections        *dbusPropertyConnectionSessionAvailableSections
	AvailableKeys            *dbusPropertyConnectionSessionAvailableKeys
	Errors                   *dbusPropertyConnectionSessionErrors
}

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

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.ConnectionSession',sender='" + obj.DestName + "',member='ConnectionDataChanged'")

	obj.ConnectionPath.Reset()
	obj.Uuid.Reset()
	obj.Type.Reset()
	obj.AllowDelete.Reset()
	obj.AvailableVirtualSections.Reset()
	obj.AvailableSections.Reset()
	obj.AvailableKeys.Reset()
	obj.Errors.Reset()
}

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

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

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

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

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

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

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

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

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

func (obj *ConnectionSession) ConnectConnectionDataChanged(callback func()) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.ConnectionSession.ConnectionDataChanged" || 0 != len(v.Body) {
				continue
			}

			callback()
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

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

func (this *dbusPropertyConnectionSessionConnectionPath) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.ConnectionSession.ConnectionPath is not writable")
}

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

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

func (this *dbusPropertyConnectionSessionUuid) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.ConnectionSession.Uuid is not writable")
}

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

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

func (this *dbusPropertyConnectionSessionType) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.ConnectionSession.Type is not writable")
}

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

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

func (this *dbusPropertyConnectionSessionAllowDelete) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.ConnectionSession.AllowDelete is not writable")
}

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

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

func (this *dbusPropertyConnectionSessionAvailableVirtualSections) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.ConnectionSession.AvailableVirtualSections is not writable")
}

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

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

func (this *dbusPropertyConnectionSessionAvailableSections) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.ConnectionSession.AvailableSections is not writable")
}

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

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

func (this *dbusPropertyConnectionSessionAvailableKeys) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.ConnectionSession.AvailableKeys is not writable")
}

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

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

func (this *dbusPropertyConnectionSessionErrors) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.ConnectionSession.Errors is not writable")
}

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

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

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

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

	obj.ConnectionPath = &dbusPropertyConnectionSessionConnectionPath{&property.BaseObserver{}, core}
	obj.Uuid = &dbusPropertyConnectionSessionUuid{&property.BaseObserver{}, core}
	obj.Type = &dbusPropertyConnectionSessionType{&property.BaseObserver{}, core}
	obj.AllowDelete = &dbusPropertyConnectionSessionAllowDelete{&property.BaseObserver{}, core}
	obj.AvailableVirtualSections = &dbusPropertyConnectionSessionAvailableVirtualSections{&property.BaseObserver{}, core}
	obj.AvailableSections = &dbusPropertyConnectionSessionAvailableSections{&property.BaseObserver{}, core}
	obj.AvailableKeys = &dbusPropertyConnectionSessionAvailableKeys{&property.BaseObserver{}, core}
	obj.Errors = &dbusPropertyConnectionSessionErrors{&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.ConnectionSession',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.ConnectionSession" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "ConnectionPath" {
						obj.ConnectionPath.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.ConnectionSession',sender='" + obj.DestName + "',member='ConnectionDataChanged'")

	runtime.SetFinalizer(obj, func(_obj *ConnectionSession) { DestroyConnectionSession(_obj) })
	return obj, nil
}
