Documentation
¶
Overview ¶
This is a rfkill client library for golang, works only on linux.
For implementation details see: https://github.com/torvalds/linux/blob/master/include/uapi/linux/rfkill.h
Index ¶
Constants ¶
View Source
const ( // OpAdd a device is added. OpAdd = iota // OpDel a device is deleted. OpDel // OpChange a device's state is changed. OpChange // OpChangeAll userspace changes in all devices. OpChangeAll )
View Source
const ( // TypeAll toggles all switches, useless in this library. TypeAll = iota // TypeWLAN switch is on a 802.11 wireless network device. TypeWLAN // TypeBluetooth switch is on a bluetooth device. TypeBluetooth // TypeUWB switch is on a ultra wideband device. TypeUWB // TypeWiMAX switch is on a WiMAX device. TypeWiMAX // TypeWWAN switch is on a wireless WAN device. TypeWWAN // TypeGPS switch is on a GPS device. TypeGPS // TypeFM switch is on a FM radio device. TypeFM // TypeNFC switch is on an NFC device. TypeNFC )
Variables ¶
View Source
var ErrClosed = errors.New("rfkill: closed")
ErrClosed denotes closed watcher.
Functions ¶
func BlockByIdx ¶
BlockByIdx soft blocks or unblocks a device by the given idx.
func Each ¶
Each iterates over all registered devices yielding them as OpAdd events. If fn returns an error the function immediately propagates it.
Example how to unblock all devices:
if err := rfkill.Each(func(ev rfkill.Event) error {
return rfkill.BlockByIdx(ev.Idx, false)
}); err != nil {
return err
}
Types ¶
type Event ¶
type Event struct {
// Idx is device index.
Idx uint32
// Type of the event.
Type Type
// Op operation code.
Op Op
// Soft state.
Soft uint8
// Hard state.
Hard uint8
}
Event is a rfkill event read from /dev/rfkill.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher is a event watching instance.
func Watch ¶
Watch monitors the rfkill events.
If ops is not empty it acts as a filter, otherwise it delivers everything.
Example:
w, err := rfkill.Watch()
if err != nil {
return err
}
defer w.Close()
for ev := range w.C() {
fmt.Printf("idx=%d type=%s soft=%t hard=%t",
ev.Idx, ev.Type, ev.Soft != 0, ev.Hard != 0)
}
if err = w.Err(); err != nil {
return err
}
Click to show internal directories.
Click to hide internal directories.