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

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

	ActivationState         *dbusPropertyModemModemCdmaActivationState
	Meid                    *dbusPropertyModemModemCdmaMeid
	Esn                     *dbusPropertyModemModemCdmaEsn
	Sid                     *dbusPropertyModemModemCdmaSid
	Nid                     *dbusPropertyModemModemCdmaNid
	Cdma1xRegistrationState *dbusPropertyModemModemCdmaCdma1xRegistrationState
	EvdoRegistrationState   *dbusPropertyModemModemCdmaEvdoRegistrationState
}

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

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ModemManager1.Modem.ModemCdma',sender='" + obj.DestName + "',member='ActivationStateChanged'")

	obj.ActivationState.Reset()
	obj.Meid.Reset()
	obj.Esn.Reset()
	obj.Sid.Reset()
	obj.Nid.Reset()
	obj.Cdma1xRegistrationState.Reset()
	obj.EvdoRegistrationState.Reset()
}

func (obj *ModemModemCdma) Activate(carrier_code string) (_err error) {
	_err = obj.core.Call("org.freedesktop.ModemManager1.Modem.ModemCdma.Activate", 0, carrier_code).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *ModemModemCdma) ActivateManual(properties map[string]dbus.Variant) (_err error) {
	_err = obj.core.Call("org.freedesktop.ModemManager1.Modem.ModemCdma.ActivateManual", 0, properties).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *ModemModemCdma) ConnectActivationStateChanged(callback func(activation_state uint32, activation_error uint32, status_changes map[string]dbus.Variant)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ModemManager1.Modem.ModemCdma.ActivationStateChanged" || 3 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*uint32)(nil)).Elem() {
				continue
			}
			if reflect.TypeOf(v.Body[1]) != reflect.TypeOf((*uint32)(nil)).Elem() {
				continue
			}
			if reflect.TypeOf(v.Body[2]) != reflect.TypeOf((*map[string]dbus.Variant)(nil)).Elem() {
				continue
			}

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

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

func (this *dbusPropertyModemModemCdmaActivationState) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.ModemCdma.ActivationState is not writable")
}

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

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

func (this *dbusPropertyModemModemCdmaMeid) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.ModemCdma.Meid is not writable")
}

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

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

func (this *dbusPropertyModemModemCdmaEsn) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.ModemCdma.Esn is not writable")
}

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

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

func (this *dbusPropertyModemModemCdmaSid) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.ModemCdma.Sid is not writable")
}

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

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

func (this *dbusPropertyModemModemCdmaNid) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.ModemCdma.Nid is not writable")
}

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

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

func (this *dbusPropertyModemModemCdmaCdma1xRegistrationState) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.ModemCdma.Cdma1xRegistrationState is not writable")
}

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

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

func (this *dbusPropertyModemModemCdmaEvdoRegistrationState) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.ModemCdma.EvdoRegistrationState is not writable")
}

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

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

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

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

	obj.ActivationState = &dbusPropertyModemModemCdmaActivationState{&property.BaseObserver{}, core}
	obj.Meid = &dbusPropertyModemModemCdmaMeid{&property.BaseObserver{}, core}
	obj.Esn = &dbusPropertyModemModemCdmaEsn{&property.BaseObserver{}, core}
	obj.Sid = &dbusPropertyModemModemCdmaSid{&property.BaseObserver{}, core}
	obj.Nid = &dbusPropertyModemModemCdmaNid{&property.BaseObserver{}, core}
	obj.Cdma1xRegistrationState = &dbusPropertyModemModemCdmaCdma1xRegistrationState{&property.BaseObserver{}, core}
	obj.EvdoRegistrationState = &dbusPropertyModemModemCdmaEvdoRegistrationState{&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.ModemCdma',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.ModemCdma" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "ActivationState" {
						obj.ActivationState.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ModemManager1.Modem.ModemCdma',sender='" + obj.DestName + "',member='ActivationStateChanged'")

	runtime.SetFinalizer(obj, func(_obj *ModemModemCdma) { DestroyModemModemCdma(_obj) })
	return obj, nil
}
