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

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

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

	Addresses   *dbusPropertyIP4ConfigAddresses
	AddressData *dbusPropertyIP4ConfigAddressData
	Gateway     *dbusPropertyIP4ConfigGateway
	Routes      *dbusPropertyIP4ConfigRoutes
	RouteData   *dbusPropertyIP4ConfigRouteData
	Nameservers *dbusPropertyIP4ConfigNameservers
	Domains     *dbusPropertyIP4ConfigDomains
	Searches    *dbusPropertyIP4ConfigSearches
	DnsOptions  *dbusPropertyIP4ConfigDnsOptions
	DnsPriority *dbusPropertyIP4ConfigDnsPriority
	WinsServers *dbusPropertyIP4ConfigWinsServers
}

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

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.NetworkManager.IP4Config',sender='" + obj.DestName + "',member='PropertiesChanged'")

	obj.Addresses.Reset()
	obj.AddressData.Reset()
	obj.Gateway.Reset()
	obj.Routes.Reset()
	obj.RouteData.Reset()
	obj.Nameservers.Reset()
	obj.Domains.Reset()
	obj.Searches.Reset()
	obj.DnsOptions.Reset()
	obj.DnsPriority.Reset()
	obj.WinsServers.Reset()
}

func (obj *IP4Config) ConnectPropertiesChanged(callback func(properties map[string]dbus.Variant)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.NetworkManager.IP4Config.PropertiesChanged" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*map[string]dbus.Variant)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(map[string]dbus.Variant))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

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

func (this *dbusPropertyIP4ConfigAddresses) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.Addresses is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigAddressData) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.AddressData is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigGateway) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.Gateway is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigRoutes) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.Routes is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigRouteData) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.RouteData is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigNameservers) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.Nameservers is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigDomains) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.Domains is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigSearches) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.Searches is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigDnsOptions) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.DnsOptions is not writable")
}

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

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

func (this *dbusPropertyIP4ConfigDnsPriority) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.DnsPriority is not writable")
}

func (this *dbusPropertyIP4ConfigDnsPriority) Get() int32 {
	v, _ := this.GetValue()
	return v.(int32)
}
func (this *dbusPropertyIP4ConfigDnsPriority) GetValue() (interface{} /*int32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.IP4Config", "DnsPriority").Store(&r)
	if err == nil && r.Signature().String() == "i" {
		return r.Value().(int32), nil
	}
	return *new(int32), err
}
func (this *dbusPropertyIP4ConfigDnsPriority) GetType() reflect.Type {
	return reflect.TypeOf((*int32)(nil)).Elem()
}

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

func (this *dbusPropertyIP4ConfigWinsServers) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.IP4Config.WinsServers is not writable")
}

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

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

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

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

	obj.Addresses = &dbusPropertyIP4ConfigAddresses{&property.BaseObserver{}, core}
	obj.AddressData = &dbusPropertyIP4ConfigAddressData{&property.BaseObserver{}, core}
	obj.Gateway = &dbusPropertyIP4ConfigGateway{&property.BaseObserver{}, core}
	obj.Routes = &dbusPropertyIP4ConfigRoutes{&property.BaseObserver{}, core}
	obj.RouteData = &dbusPropertyIP4ConfigRouteData{&property.BaseObserver{}, core}
	obj.Nameservers = &dbusPropertyIP4ConfigNameservers{&property.BaseObserver{}, core}
	obj.Domains = &dbusPropertyIP4ConfigDomains{&property.BaseObserver{}, core}
	obj.Searches = &dbusPropertyIP4ConfigSearches{&property.BaseObserver{}, core}
	obj.DnsOptions = &dbusPropertyIP4ConfigDnsOptions{&property.BaseObserver{}, core}
	obj.DnsPriority = &dbusPropertyIP4ConfigDnsPriority{&property.BaseObserver{}, core}
	obj.WinsServers = &dbusPropertyIP4ConfigWinsServers{&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.NetworkManager.IP4Config',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.NetworkManager.IP4Config" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Addresses" {
						obj.Addresses.Notify()

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

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

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

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

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

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

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

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

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

					} else if key == "WinsServers" {
						obj.WinsServers.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.NetworkManager.IP4Config.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 == "Addresses" {
						obj.Addresses.Notify()

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

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

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

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

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

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

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

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

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

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

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.NetworkManager.IP4Config',sender='" + obj.DestName + "',member='PropertiesChanged'")

	runtime.SetFinalizer(obj, func(_obj *IP4Config) { DestroyIP4Config(_obj) })
	return obj, nil
}
