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

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

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

	Interface  *dbusPropertyBearerInterface
	Connected  *dbusPropertyBearerConnected
	Suspended  *dbusPropertyBearerSuspended
	Ip4Config  *dbusPropertyBearerIp4Config
	Ip6Config  *dbusPropertyBearerIp6Config
	IpTimeout  *dbusPropertyBearerIpTimeout
	Properties *dbusPropertyBearerProperties
}

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

	obj.Interface.Reset()
	obj.Connected.Reset()
	obj.Suspended.Reset()
	obj.Ip4Config.Reset()
	obj.Ip6Config.Reset()
	obj.IpTimeout.Reset()
	obj.Properties.Reset()
}

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

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

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

func (this *dbusPropertyBearerInterface) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Bearer.Interface is not writable")
}

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

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

func (this *dbusPropertyBearerConnected) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Bearer.Connected is not writable")
}

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

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

func (this *dbusPropertyBearerSuspended) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Bearer.Suspended is not writable")
}

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

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

func (this *dbusPropertyBearerIp4Config) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Bearer.Ip4Config is not writable")
}

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

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

func (this *dbusPropertyBearerIp6Config) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Bearer.Ip6Config is not writable")
}

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

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

func (this *dbusPropertyBearerIpTimeout) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Bearer.IpTimeout is not writable")
}

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

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

func (this *dbusPropertyBearerProperties) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Bearer.Properties is not writable")
}

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

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

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

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

	obj.Interface = &dbusPropertyBearerInterface{&property.BaseObserver{}, core}
	obj.Connected = &dbusPropertyBearerConnected{&property.BaseObserver{}, core}
	obj.Suspended = &dbusPropertyBearerSuspended{&property.BaseObserver{}, core}
	obj.Ip4Config = &dbusPropertyBearerIp4Config{&property.BaseObserver{}, core}
	obj.Ip6Config = &dbusPropertyBearerIp6Config{&property.BaseObserver{}, core}
	obj.IpTimeout = &dbusPropertyBearerIpTimeout{&property.BaseObserver{}, core}
	obj.Properties = &dbusPropertyBearerProperties{&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.ModemManager1.Bearer',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.ModemManager1.Bearer" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Interface" {
						obj.Interface.Notify()

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

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

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

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

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

					} else if key == "Properties" {
						obj.Properties.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.ModemManager1.Bearer.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 == "Interface" {
						obj.Interface.Notify()

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Bearer) { DestroyBearer(_obj) })
	return obj, nil
}
