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

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

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

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

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='ActiveSessionChanged'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='SessionAdded'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='SessionRemoved'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='DeviceAdded'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='DeviceRemoved'")

}

func (obj *Seat) GetId() (sid dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Seat.GetId", 0).Store(&sid)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) GetSessions() (sessions []dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Seat.GetSessions", 0).Store(&sessions)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) GetDevices() (devices [][]interface{}, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Seat.GetDevices", 0).Store(&devices)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) GetActiveSession() (ssid dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Seat.GetActiveSession", 0).Store(&ssid)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) CanActivateSessions() (can_activate bool, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Seat.CanActivateSessions", 0).Store(&can_activate)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) ActivateSession(ssid dbus.ObjectPath) (_err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Seat.ActivateSession", 0, ssid).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Seat) ConnectActiveSessionChanged(callback func(ssid dbus.ObjectPath)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ConsoleKit.Seat.ActiveSessionChanged" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*dbus.ObjectPath)(nil)).Elem() {
				continue
			}

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

func (obj *Seat) ConnectSessionAdded(callback func(ssid dbus.ObjectPath)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ConsoleKit.Seat.SessionAdded" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*dbus.ObjectPath)(nil)).Elem() {
				continue
			}

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

func (obj *Seat) ConnectSessionRemoved(callback func(ssid dbus.ObjectPath)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ConsoleKit.Seat.SessionRemoved" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*dbus.ObjectPath)(nil)).Elem() {
				continue
			}

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

func (obj *Seat) ConnectDeviceAdded(callback func(device []interface{})) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ConsoleKit.Seat.DeviceAdded" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*[]interface{})(nil)).Elem() {
				continue
			}

			callback(v.Body[0].([]interface{}))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

func (obj *Seat) ConnectDeviceRemoved(callback func(device []interface{})) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ConsoleKit.Seat.DeviceRemoved" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*[]interface{})(nil)).Elem() {
				continue
			}

			callback(v.Body[0].([]interface{}))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

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

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

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

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='ActiveSessionChanged'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='SessionAdded'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='SessionRemoved'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='DeviceAdded'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Seat',sender='" + obj.DestName + "',member='DeviceRemoved'")

	runtime.SetFinalizer(obj, func(_obj *Seat) { DestroySeat(_obj) })
	return obj, nil
}
