Relay RuView REST calls (/api/v1/*) to the sensing-server.
(subpath)
| 235 | # same adapter. |
| 236 | # ============================================================================ |
| 237 | |
| 238 | _ble_server = None |
| 239 | _ble_lock = threading.Lock() |
| 240 | # One start/stop at a time. _ble_lock only guards the reference (the status |
| 241 | # route takes it and must stay quick); this one is held across a whole start |
| 242 | # or stop, so two requests never build or tear down a peripheral together. |
| 243 | _ble_op_lock = threading.RLock() |
| 244 | _ble_link_hub = None |
| 245 | |
| 246 | |
| 247 | def _ble_link(): |
| 248 | """The Bluetooth link hub (ble_link.py): answers the app's small requests |
| 249 | over BLE through these same Flask routes. One per process.""" |
| 250 | global _ble_link_hub |
| 251 | if _ble_link_hub is None: |
| 252 | import ble_link |
| 253 | _ble_link_hub = ble_link.LinkHub( |
| 254 | app, get_config=lambda: shared_data.config, logger=logger, |
| 255 | save_config=shared_data.save_config) |
| 256 | return _ble_link_hub |
| 257 | |
| 258 | |
| 259 | def _start_ble(): |
| 260 | """Start the peripheral if config enables it. Never raises.""" |
| 261 | with _ble_op_lock: |
| 262 | return _start_ble_locked() |
| 263 | |
| 264 | |
| 265 | def _start_ble_locked(): |
| 266 | global _ble_server |
| 267 | try: |
| 268 | if not shared_data.config.get('ble_enabled', False): |
| 269 | return False |
| 270 | import ble_peripheral |
| 271 | # Retire any previous peripheral BEFORE building a new one. Overwriting |
| 272 | # the reference used to drop a still-registered server on the floor — |
| 273 | # its GLib thread and, worse, its BlueZ registration of the fixed path |
| 274 | # /one/gode/ragnar/ble survived, so the new server's |
| 275 | # RegisterApplication came back org.bluez.Error.AlreadyExists. |
| 276 | old = None |
| 277 | with _ble_lock: |
| 278 | if _ble_server is not None: |