1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
# Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
"LightBlue - a simple bluetooth library."
# Docstrings for attributes in this module.
_docstrings = {
"finddevices":
"""
Performs a device discovery and returns the found devices as a list of
(address, name, class-of-device) tuples. Raises BluetoothError if an error
occurs.
Arguments:
- getnames=True: True if device names should be retrieved during
discovery. If false, None will be returned instead of the device
name.
- length=10: the number of seconds to spend discovering devices
(this argument has no effect on Python for Series 60)
Do not invoke a new discovery before a previous discovery has finished.
Also, to minimise interference with other wireless and bluetooth traffic,
and to conserve battery power on the local device, discoveries should not
be invoked too frequently (an interval of at least 20 seconds is
recommended).
""",
"findservices":
"""
Performs a service discovery and returns the found services as a list of
(device-address, service-port, service-name) tuples. Raises BluetoothError
if an error occurs.
Arguments:
- addr=None: a device address, to search only for services on a
specific device
- name=None: a service name string, to search only for a service with a
specific name
- servicetype=None: can be RFCOMM or OBEX to search only for RFCOMM or
OBEX-type services. (OBEX services are not returned from an RFCOMM
search)
If more than one criteria is specified, this returns services that match
all criteria.
Currently the Python for Series 60 implementation will only find RFCOMM and
OBEX services.
""",
"finddevicename":
"""
Returns the name of the device with the given bluetooth address.
finddevicename(gethostaddr()) returns the local device name.
Arguments:
- address: the address of the device to look up
- usecache=True: if True, the device name will be fetched from a local
cache if possible. If False, or if the device name is not in the
cache, the remote device will be contacted to request its name.
Raise BluetoothError if the name cannot be retrieved.
""",
"gethostaddr":
"""
Returns the address of the local bluetooth device.
Raise BluetoothError if the local device is not available.
""",
"gethostclass":
"""
Returns the class of device of the local bluetooth device.
These values indicate the device's major services and the type of the
device (e.g. mobile phone, laptop, etc.). If you google for
"assigned numbers bluetooth baseband" you might find some documents
that discuss how to extract this information from the class of device.
Raise BluetoothError if the local device is not available.
""",
"socket":
"""
socket(proto=RFCOMM) -> socket object
Returns a new socket object.
Arguments:
- proto=RFCOMM: the type of socket to be created - either L2CAP or
RFCOMM.
Note that L2CAP sockets are not available on Python For Series 60, and
only L2CAP client sockets are supported on Mac OS X and Linux (i.e. you can
connect() the socket but not bind(), accept(), etc.).
""",
"advertise":
"""
Starts advertising a service with the given name, using the given server
socket. Raises BluetoothError if the service cannot be advertised.
Arguments:
- name: name of the service to be advertised
- sock: the socket object that will serve this service. The socket must
be already bound to a channel. If a RFCOMM service is being
advertised, the socket should also be listening.
- servicetype: the type of service to advertise - either RFCOMM or
OBEX. (L2CAP services are not currently supported.)
(If the servicetype is RFCOMM, the service will be advertised with the
Serial Port Profile; if the servicetype is OBEX, the service will be
advertised with the OBEX Object Push Profile.)
""",
"stopadvertise":
"""
Stops advertising the service on the given socket. Raises BluetoothError if
no service is advertised on the socket.
This will error if the given socket is already closed.
""",
"selectdevice":
"""
Displays a GUI which allows the end user to select a device from a list of
discovered devices.
Returns the selected device as an (address, name, class-of-device) tuple.
Returns None if the selection was cancelled.
(On Python For Series 60, the device selection will fail if there are any
open bluetooth connections.)
""",
"selectservice":
"""
Displays a GUI which allows the end user to select a service from a list of
discovered devices and their services.
Returns the selected service as a (device-address, service-port, service-
name) tuple. Returns None if the selection was cancelled.
(On Python For Series 60, the device selection will fail if there are any
open bluetooth connections.)
Currently the Python for Series 60 implementation will only find RFCOMM and
OBEX services.
"""
}
# import implementation modules
from ._lightblue import *
from ._lightbluecommon import *
from . import obex # plus submodule
# set docstrings
from . import _lightblue
localattrs = locals()
for attr in _lightblue.__all__:
try:
localattrs[attr].__doc__ = _docstrings[attr]
except KeyError:
pass
del attr, localattrs
|