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

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

	Imei                 *dbusPropertyModemModem3gppImei
	RegistrationState    *dbusPropertyModemModem3gppRegistrationState
	OperatorCode         *dbusPropertyModemModem3gppOperatorCode
	OperatorName         *dbusPropertyModemModem3gppOperatorName
	EnabledFacilityLocks *dbusPropertyModemModem3gppEnabledFacilityLocks
	SubscriptionState    *dbusPropertyModemModem3gppSubscriptionState
}

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

	obj.Imei.Reset()
	obj.RegistrationState.Reset()
	obj.OperatorCode.Reset()
	obj.OperatorName.Reset()
	obj.EnabledFacilityLocks.Reset()
	obj.SubscriptionState.Reset()
}

func (obj *ModemModem3gpp) Register(operator_id string) (_err error) {
	_err = obj.core.Call("org.freedesktop.ModemManager1.Modem.Modem3gpp.Register", 0, operator_id).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *ModemModem3gpp) Scan() (results []map[string]dbus.Variant, _err error) {
	_err = obj.core.Call("org.freedesktop.ModemManager1.Modem.Modem3gpp.Scan", 0).Store(&results)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertyModemModem3gppImei) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Modem3gpp.Imei is not writable")
}

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

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

func (this *dbusPropertyModemModem3gppRegistrationState) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Modem3gpp.RegistrationState is not writable")
}

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

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

func (this *dbusPropertyModemModem3gppOperatorCode) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Modem3gpp.OperatorCode is not writable")
}

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

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

func (this *dbusPropertyModemModem3gppOperatorName) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Modem3gpp.OperatorName is not writable")
}

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

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

func (this *dbusPropertyModemModem3gppEnabledFacilityLocks) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Modem3gpp.EnabledFacilityLocks is not writable")
}

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

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

func (this *dbusPropertyModemModem3gppSubscriptionState) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Modem3gpp.SubscriptionState is not writable")
}

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

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

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

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

	obj.Imei = &dbusPropertyModemModem3gppImei{&property.BaseObserver{}, core}
	obj.RegistrationState = &dbusPropertyModemModem3gppRegistrationState{&property.BaseObserver{}, core}
	obj.OperatorCode = &dbusPropertyModemModem3gppOperatorCode{&property.BaseObserver{}, core}
	obj.OperatorName = &dbusPropertyModemModem3gppOperatorName{&property.BaseObserver{}, core}
	obj.EnabledFacilityLocks = &dbusPropertyModemModem3gppEnabledFacilityLocks{&property.BaseObserver{}, core}
	obj.SubscriptionState = &dbusPropertyModemModem3gppSubscriptionState{&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.Modem.Modem3gpp',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.Modem.Modem3gpp" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Imei" {
						obj.Imei.Notify()

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

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

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

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

					} else if key == "SubscriptionState" {
						obj.SubscriptionState.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.ModemManager1.Modem.Modem3gpp.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 == "Imei" {
						obj.Imei.Notify()

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *ModemModem3gpp) { DestroyModemModem3gpp(_obj) })
	return obj, nil
}
