Documentation ¶
Overview ¶
Copyright 2018 Jonathan Pentecost
Copyright 2020 darkhz ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func DecodeVariantMap(variants map[string]dbus.Variant, data interface{}, checkProps ...string) error
- func GetAdapterID(adapterPath string) string
- func GetDeviceType(class uint32) string
- func ServiceExists(uuidList []string, svclass uint32) bool
- func ServiceType(serviceUUID string) string
- type Adapter
- type AudioProfile
- type Bluez
- func (b *Bluez) CallAdapter(adapter, method string, flags dbus.Flags, args ...interface{}) *dbus.Call
- func (b *Bluez) CallDevice(devicePath, method string, flags dbus.Flags, args ...interface{}) *dbus.Call
- func (b *Bluez) CallMediaPlayer(command string) error
- func (b *Bluez) CancelPairing(devicePath string) error
- func (b *Bluez) Close()
- func (b *Bluez) Conn() *dbus.Conn
- func (b *Bluez) Connect(devicePath string) error
- func (b *Bluez) ConvertAndStoreObjects(objects map[dbus.ObjectPath]map[string]map[string]dbus.Variant) error
- func (b *Bluez) ConvertToAdapter(path string, values map[string]dbus.Variant, adapters *[]Adapter) error
- func (b *Bluez) ConvertToDevice(path string, values map[string]dbus.Variant, devices *[]Device) error
- func (b *Bluez) Disconnect(devicePath string) error
- func (b *Bluez) FastForward() error
- func (b *Bluez) GetAdapterProperties(adapterPath string) (map[string]dbus.Variant, error)
- func (b *Bluez) GetAdapters() []Adapter
- func (b *Bluez) GetBatteryPercentage(devicePath string) (byte, error)
- func (b *Bluez) GetCurrentAdapter() Adapter
- func (b *Bluez) GetCurrentAdapterID() string
- func (b *Bluez) GetCurrentPlayer() dbus.ObjectPath
- func (b *Bluez) GetDevice(devicePath string) Device
- func (b *Bluez) GetDeviceProperties(devicePath string) (map[string]dbus.Variant, error)
- func (b *Bluez) GetDevices() []Device
- func (b *Bluez) GetMediaControlProperties(devicePath string) (map[string]dbus.Variant, error)
- func (b *Bluez) GetMediaPlayerProperties() (map[string]dbus.Variant, error)
- func (b *Bluez) GetMediaPlayerProperty(property string) (interface{}, error)
- func (b *Bluez) GetMediaProperties(values ...map[string]dbus.Variant) (MediaProperties, error)
- func (b *Bluez) InitMediaPlayer(devicePath string) error
- func (b *Bluez) ManagedObjects() (map[dbus.ObjectPath]map[string]map[string]dbus.Variant, error)
- func (b *Bluez) Next() error
- func (b *Bluez) Pair(devicePath string) error
- func (b *Bluez) ParseSignalData(signal *dbus.Signal) interface{}
- func (b *Bluez) Pause() error
- func (b *Bluez) Play() error
- func (b *Bluez) Power(adapterPath string, enable bool) error
- func (b *Bluez) Previous() error
- func (b *Bluez) RefreshStore() error
- func (b *Bluez) RemoveDevice(devicePath string) error
- func (b *Bluez) Rewind() error
- func (b *Bluez) SetAdapterProperty(adapterPath, key string, value interface{}) error
- func (b *Bluez) SetCurrentAdapter(adapter ...Adapter) error
- func (b *Bluez) SetCurrentPlayer(playerPath dbus.ObjectPath)
- func (b *Bluez) SetDeviceProperty(devicePath, key string, value interface{}) error
- func (b *Bluez) StartDiscovery(adapter string) error
- func (b *Bluez) Stop() error
- func (b *Bluez) StopDiscovery(adapter string) error
- func (b *Bluez) TogglePlayPause() error
- func (b *Bluez) WatchSignal() chan *dbus.Signal
- type Device
- type MediaProperties
- type Obex
- func (o *Obex) CallClient(method string, args ...interface{}) *dbus.Call
- func (o *Obex) CallClientAsync(ctx context.Context, method string, args ...interface{}) *dbus.Call
- func (o *Obex) CallObjectPush(sessionPath dbus.ObjectPath, method string, args ...interface{}) *dbus.Call
- func (o *Obex) CallTransfer(transferPath dbus.ObjectPath, method string, args ...interface{}) *dbus.Call
- func (o *Obex) CancelTransfer(transferPath dbus.ObjectPath) error
- func (o *Obex) Close()
- func (o *Obex) Conn() *dbus.Conn
- func (o *Obex) CreateSession(ctx context.Context, address string) (dbus.ObjectPath, error)
- func (o *Obex) GetSessionProperties(sessionPath dbus.ObjectPath, sprop ...map[string]dbus.Variant) (ObexSessionProperties, error)
- func (o *Obex) GetTransferProperties(props map[string]dbus.Variant) (ObexTransferProperties, error)
- func (o *Obex) ManagedObjects() (map[dbus.ObjectPath]map[string]map[string]dbus.Variant, error)
- func (o *Obex) ParseSignalData(signal *dbus.Signal) interface{}
- func (o *Obex) ReceiveFile(sessionPath, transferPath dbus.ObjectPath) (string, string, ObexTransferProperties, error)
- func (o *Obex) RemoveSession(sessionPath dbus.ObjectPath) error
- func (o *Obex) ResumeTransfer(transferPath dbus.ObjectPath) error
- func (o *Obex) SendFile(sessionPath dbus.ObjectPath, path string) (dbus.ObjectPath, ObexTransferProperties, error)
- func (o *Obex) SuspendTransfer(transferPath dbus.ObjectPath) error
- func (o *Obex) WatchSignal() chan *dbus.Signal
- type ObexProperties
- type ObexSessionProperties
- type ObexTransferProperties
- type Resolver
- type StoreObject
- type TrackProperties
Constants ¶
const ( SDP_SERVER_SVCLASS_ID = 0x1000 BROWSE_GRP_DESC_SVCLASS_ID = 0x1001 PUBLIC_BROWSE_GROUP = 0x1002 SERIAL_PORT_SVCLASS_ID = 0x1101 LAN_ACCESS_SVCLASS_ID = 0x1102 DIALUP_NET_SVCLASS_ID = 0x1103 IRMC_SYNC_SVCLASS_ID = 0x1104 OBEX_OBJPUSH_SVCLASS_ID = 0x1105 OBEX_FILETRANS_SVCLASS_ID = 0x1106 IRMC_SYNC_CMD_SVCLASS_ID = 0x1107 HEADSET_SVCLASS_ID = 0x1108 CORDLESS_TELEPHONY_SVCLASS_ID = 0x1109 AUDIO_SOURCE_SVCLASS_ID = 0x110a AUDIO_SINK_SVCLASS_ID = 0x110b AV_REMOTE_TARGET_SVCLASS_ID = 0x110c ADVANCED_AUDIO_SVCLASS_ID = 0x110d AV_REMOTE_SVCLASS_ID = 0x110e AV_REMOTE_CONTROLLER_SVCLASS_ID = 0x110f INTERCOM_SVCLASS_ID = 0x1110 FAX_SVCLASS_ID = 0x1111 HEADSET_AGW_SVCLASS_ID = 0x1112 WAP_SVCLASS_ID = 0x1113 WAP_CLIENT_SVCLASS_ID = 0x1114 PANU_SVCLASS_ID = 0x1115 NAP_SVCLASS_ID = 0x1116 GN_SVCLASS_ID = 0x1117 DIRECT_PRINTING_SVCLASS_ID = 0x1118 REFERENCE_PRINTING_SVCLASS_ID = 0x1119 IMAGING_SVCLASS_ID = 0x111a IMAGING_RESPONDER_SVCLASS_ID = 0x111b IMAGING_ARCHIVE_SVCLASS_ID = 0x111c IMAGING_REFOBJS_SVCLASS_ID = 0x111d HANDSFREE_SVCLASS_ID = 0x111e HANDSFREE_AGW_SVCLASS_ID = 0x111f DIRECT_PRT_REFOBJS_SVCLASS_ID = 0x1120 REFLECTED_UI_SVCLASS_ID = 0x1121 BASIC_PRINTING_SVCLASS_ID = 0x1122 PRINTING_STATUS_SVCLASS_ID = 0x1123 HID_SVCLASS_ID = 0x1124 HCR_SVCLASS_ID = 0x1125 HCR_PRINT_SVCLASS_ID = 0x1126 HCR_SCAN_SVCLASS_ID = 0x1127 CIP_SVCLASS_ID = 0x1128 VIDEO_CONF_GW_SVCLASS_ID = 0x1129 UDI_MT_SVCLASS_ID = 0x112a UDI_TA_SVCLASS_ID = 0x112b AV_SVCLASS_ID = 0x112c SAP_SVCLASS_ID = 0x112d PBAP_PCE_SVCLASS_ID = 0x112e PBAP_PSE_SVCLASS_ID = 0x112f PBAP_SVCLASS_ID = 0x1130 MAP_MSE_SVCLASS_ID = 0x1132 MAP_MCE_SVCLASS_ID = 0x1133 MAP_SVCLASS_ID = 0x1134 GNSS_SVCLASS_ID = 0x1135 GNSS_SERVER_SVCLASS_ID = 0x1136 MPS_SC_SVCLASS_ID = 0x113A MPS_SVCLASS_ID = 0x113B PNP_INFO_SVCLASS_ID = 0x1200 GENERIC_NETWORKING_SVCLASS_ID = 0x1201 GENERIC_FILETRANS_SVCLASS_ID = 0x1202 GENERIC_AUDIO_SVCLASS_ID = 0x1203 GENERIC_TELEPHONY_SVCLASS_ID = 0x1204 UPNP_SVCLASS_ID = 0x1205 UPNP_IP_SVCLASS_ID = 0x1206 UPNP_PAN_SVCLASS_ID = 0x1300 UPNP_LAP_SVCLASS_ID = 0x1301 UPNP_L2CAP_SVCLASS_ID = 0x1302 VIDEO_SOURCE_SVCLASS_ID = 0x1303 VIDEO_SINK_SVCLASS_ID = 0x1304 VIDEO_DISTRIBUTION_SVCLASS_ID = 0x1305 HDP_SVCLASS_ID = 0x1400 HDP_SOURCE_SVCLASS_ID = 0x1401 HDP_SINK_SVCLASS_ID = 0x1402 GENERIC_ACCESS_SVCLASS_ID = 0x1800 GENERIC_ATTRIB_SVCLASS_ID = 0x1801 APPLE_AGENT_SVCLASS_ID = 0x2112 )
Service Class identifiers. Adapted from: https://github.com/bluez/bluez/blob/master/lib/sdp.h#L64
Variables ¶
var Services = map[uint32]string{}/* 866 elements not displayed */
Services stores a service UUID and its corresponding description. Adapted from: https://github.com/bluez/bluez/blob/master/src/shared/util.c#L195
Functions ¶
func DecodeVariantMap ¶ added in v0.1.9
func DecodeVariantMap( variants map[string]dbus.Variant, data interface{}, checkProps ...string, ) error
DecodeVariantMap decodes a map of variants into the provided data.
func GetAdapterID ¶
GetAdapterID gets the adapter ID from the adapter path.
func GetDeviceType ¶ added in v0.0.3
GetDeviceType parses the device class and returns its type.
func ServiceExists ¶ added in v0.0.8
ServiceExists checks if the service class ID exists in the UUID list.
func ServiceType ¶ added in v0.0.8
ServiceType returns a service description of the service UUID. Adapted from: https://github.com/bluez/bluez/blob/master/src/shared/util.c#L1189
Types ¶
type Adapter ¶
type Adapter struct { Path string Name string Alias string Address string Discoverable bool Pairable bool Powered bool Discovering bool Lock *semaphore.Weighted }
Adapter holds the bluetooth device adapter installed for a system.
type AudioProfile ¶ added in v0.0.9
AudioProfile stores the audio profile information.
func ListAudioProfiles ¶ added in v0.0.9
func ListAudioProfiles(deviceAddress string) ([]AudioProfile, error)
ListAudioProfiles lists audio profiles of a sound card.
func (AudioProfile) SetAudioProfile ¶ added in v0.0.9
func (a AudioProfile) SetAudioProfile() error
SetAudioProfile sets an audio profile for a sound card.
type Bluez ¶
type Bluez struct { CurrentAdapter Adapter AdapterLock sync.Mutex Store map[string]StoreObject StoreLock sync.Mutex CurrentPlayer dbus.ObjectPath PlayerLock sync.Mutex // contains filtered or unexported fields }
Bluez represents an overview of the bluetooth adapters and devices installed and configured on a system. A connection to `bluez` dbus is also used to interact with the bluetooth server on a system.
func (*Bluez) CallAdapter ¶
func (b *Bluez) CallAdapter(adapter, method string, flags dbus.Flags, args ...interface{}) *dbus.Call
CallAdapter is used to interact with the bluez Adapter dbus interface. https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt
func (*Bluez) CallDevice ¶
func (b *Bluez) CallDevice(devicePath, method string, flags dbus.Flags, args ...interface{}) *dbus.Call
CallDevice is used to interact with the bluez Device dbus interface. https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/device-api.txt
func (*Bluez) CallMediaPlayer ¶ added in v0.0.9
CallMediaPlayer is used to interact with the bluez MediaPlayer interface.
func (*Bluez) CancelPairing ¶
CancelPairing will cancel a pairing attempt.
func (*Bluez) Conn ¶
func (b *Bluez) Conn() *dbus.Conn
Conn returns the current SystemBus connection.
func (*Bluez) Connect ¶
Connect will attempt to connect an already paired bluetooth device to an adapter.
func (*Bluez) ConvertAndStoreObjects ¶ added in v0.1.9
func (*Bluez) ConvertToAdapter ¶ added in v0.1.9
func (b *Bluez) ConvertToAdapter(path string, values map[string]dbus.Variant, adapters *[]Adapter) error
ConvertToAdapters converts a map of dbus objects to a common Adapter structure.
func (*Bluez) ConvertToDevice ¶ added in v0.1.9
func (b *Bluez) ConvertToDevice(path string, values map[string]dbus.Variant, devices *[]Device) error
ConvertToDevices converts a map of dbus objects to a common Device structure.
func (*Bluez) Disconnect ¶
Disconnect will remove the bluetooth device from the adapter.
func (*Bluez) FastForward ¶ added in v0.0.9
FastForward forward-skips the currently playing track.
func (*Bluez) GetAdapterProperties ¶
GetAdapterProperties gathers all the properties for a bluetooth adapter.
func (*Bluez) GetAdapters ¶
GetAdapters gets the stored adapters.
func (*Bluez) GetBatteryPercentage ¶ added in v0.1.0
GetBatteryPercentage gets the battery percentage of a device.
func (*Bluez) GetCurrentAdapter ¶
GetCurrentAdapter gets the current adapter.
func (*Bluez) GetCurrentAdapterID ¶
GetCurrentAdapterID gets the adapter ID from the current adapter's path.
func (*Bluez) GetCurrentPlayer ¶ added in v0.0.9
func (b *Bluez) GetCurrentPlayer() dbus.ObjectPath
GetCurrentPlayer gets the currently running player's path.
func (*Bluez) GetDeviceProperties ¶
GetDeviceProperties gathers all the properties for a bluetooth device.
func (*Bluez) GetDevices ¶
GetDevices gets the stored devices.
func (*Bluez) GetMediaControlProperties ¶ added in v0.0.9
GetMediaControlProperties gets the media control properties.
func (*Bluez) GetMediaPlayerProperties ¶ added in v0.0.9
GetMediaPlayerProperties gets the media player properties.
func (*Bluez) GetMediaPlayerProperty ¶ added in v0.0.9
GetMediaPlayerProperty gets the specified media player property.
func (*Bluez) GetMediaProperties ¶ added in v0.0.9
func (b *Bluez) GetMediaProperties(values ...map[string]dbus.Variant) (MediaProperties, error)
GetMediaProperties gets the media properties of the currently playing track.
func (*Bluez) InitMediaPlayer ¶ added in v0.0.9
InitMediaPlayer initializes the media player.
func (*Bluez) ManagedObjects ¶
ManagedObjects gets all bluetooth devices and adapters that are currently managed by bluez.
func (*Bluez) ParseSignalData ¶
func (b *Bluez) ParseSignalData(signal *dbus.Signal) interface{}
ParseSignalData parses bluez DBus signal data.
func (*Bluez) RefreshStore ¶
RefreshStore will query system for known bluetooth adapters and devices and will store them on the Bluez structure.
func (*Bluez) RemoveDevice ¶
RemoveDevice will permantently remove the bluetooth device from the adapter. Once a device is removed, it can only be added again by being paired.
func (*Bluez) SetAdapterProperty ¶
SetAdapterProperty can be used to set certain properties for a bluetooth adapter.
func (*Bluez) SetCurrentAdapter ¶
SetCurrentAdapter sets the current adapter.
func (*Bluez) SetCurrentPlayer ¶ added in v0.0.9
func (b *Bluez) SetCurrentPlayer(playerPath dbus.ObjectPath)
SetCurrentPlayer sets the player path.
func (*Bluez) SetDeviceProperty ¶
SetDeviceProperty can be used to set certain properties for a bluetooth device.
func (*Bluez) StartDiscovery ¶
StartDiscovery will put the adapter into "discovering" mode, which means the bluetooth device will be able to discover other bluetooth devices that are in pairing mode.
func (*Bluez) StopDiscovery ¶
StopDiscovery will stop the "discovering" mode, which means the bluetooth device will no longer be able to discover other bluetooth devices that are in pairing mode.
func (*Bluez) TogglePlayPause ¶ added in v0.0.9
TogglePlayPause toggles the play/pause states.
func (*Bluez) WatchSignal ¶
func (b *Bluez) WatchSignal() chan *dbus.Signal
WatchSignal will register to receive events form the bluez dbus interface. Any events received are passed along to the returned channel for the caller to use.
type Device ¶
type Device struct { Path string Name string Type string Alias string Address string AddressType string Adapter string Modalias string UUIDs []string Paired bool Connected bool Trusted bool Blocked bool Bonded bool LegacyPairing bool RSSI int16 Class uint32 Percentage int }
Device holds bluetooth device information.
func (Device) HaveService ¶ added in v0.0.8
HaveService checks if the device has the specified service.
type MediaProperties ¶ added in v0.0.9
type MediaProperties struct { Status string Position uint32 Track TrackProperties }
MediaProperties holds the media player information.
type Obex ¶ added in v0.0.5
type Obex struct { Store map[dbus.ObjectPath]ObexProperties StoreLock sync.Mutex // contains filtered or unexported fields }
Obex represents an OBEX connection. It also stores information about the currently running transfers.
func (*Obex) CallClient ¶ added in v0.0.5
CallClient calls the Client1 interface with the provided method.
func (*Obex) CallClientAsync ¶ added in v0.1.7
CallClientAsync calls the Client1 interface asynchronously with the provided method.
func (*Obex) CallObjectPush ¶ added in v0.0.5
func (o *Obex) CallObjectPush(sessionPath dbus.ObjectPath, method string, args ...interface{}) *dbus.Call
CallObjectPush calls the ObjectPush1 interface with the provided method.
func (*Obex) CallTransfer ¶ added in v0.0.5
func (o *Obex) CallTransfer(transferPath dbus.ObjectPath, method string, args ...interface{}) *dbus.Call
CallTransfer calls the Transfer1 interface with the provided method.
func (*Obex) CancelTransfer ¶ added in v0.0.5
CancelTransfer cancels the transfer.
func (*Obex) Conn ¶ added in v0.0.5
func (o *Obex) Conn() *dbus.Conn
Conn returns the current SessionBus connection.
func (*Obex) CreateSession ¶ added in v0.0.5
CreateSession creates a new OBEX transfer session.
func (*Obex) GetSessionProperties ¶ added in v0.0.5
func (o *Obex) GetSessionProperties(sessionPath dbus.ObjectPath, sprop ...map[string]dbus.Variant) (ObexSessionProperties, error)
GetSessionProperties converts a map of OBEX session properties to ObexSessionProperties.
func (*Obex) GetTransferProperties ¶ added in v0.0.5
func (o *Obex) GetTransferProperties(props map[string]dbus.Variant) (ObexTransferProperties, error)
GetTransferProperties converts a map of transfer properties to ObexTransferProperties.
func (*Obex) ManagedObjects ¶ added in v0.0.5
ManagedObjects gets the currently managed objects from the OBEX DBus.
func (*Obex) ParseSignalData ¶ added in v0.0.5
func (o *Obex) ParseSignalData(signal *dbus.Signal) interface{}
ParseSignalData parses OBEX DBus signal data.
func (*Obex) ReceiveFile ¶ added in v0.0.5
func (o *Obex) ReceiveFile(sessionPath, transferPath dbus.ObjectPath) (string, string, ObexTransferProperties, error)
ReceiveFile returns a path where the OBEX daemon (obexd) will receive the file, along with the transfer properties.
func (*Obex) RemoveSession ¶ added in v0.0.5
RemoveSession removes the OBEX transfer session and cancels any pending transfers.
func (*Obex) ResumeTransfer ¶ added in v0.0.5
ResumeTransfer resumes the transfer.
func (*Obex) SendFile ¶ added in v0.0.5
func (o *Obex) SendFile(sessionPath dbus.ObjectPath, path string) (dbus.ObjectPath, ObexTransferProperties, error)
SendFile sends a file to the target device.
func (*Obex) SuspendTransfer ¶ added in v0.0.5
SuspendTransfer suspends the transfer.
func (*Obex) WatchSignal ¶ added in v0.0.5
func (o *Obex) WatchSignal() chan *dbus.Signal
WatchSignal will register a signal and watch for events from the OBEX DBus interface.
type ObexProperties ¶ added in v0.0.5
type ObexProperties struct { SessionPath dbus.ObjectPath SessionProperties ObexSessionProperties TransferPath dbus.ObjectPath TransferProperties ObexTransferProperties }
ObexProperties stores the session and transfer paths of an OBEX transfer, along with their properties.
type ObexSessionProperties ¶ added in v0.0.5
ObexSessionProperties describes the session properties of an OBEX transfer.
type ObexTransferProperties ¶ added in v0.0.5
type ObexTransferProperties struct { Name string Type string Status string Filename string Size uint64 Transferred uint64 Session string }
ObexTransferProperties describes the transfer properties of an OBEX transfer.
type Resolver ¶ added in v0.1.9
type Resolver struct {
// contains filtered or unexported fields
}
Resolver holds an encoder and decoder.
type StoreObject ¶
StoreObject holds an Adapter and the Devices that belong to it. Each device is stored into Devices with the device adapter path (held by (Device).Adapter) as the identifier.