-
-
Notifications
You must be signed in to change notification settings - Fork 1
Architecture
Latisha. edited this page Dec 27, 2024
·
1 revision
LibDC-Swift is organized into three main layers:
Core Swift components providing high-level APIs:
graph TB
A[BLEManager] --> B[CoreBluetoothManager]
C[DiveLogRetriever] --> D[DiveDataViewModel]
E[GenericParser] --> F[DiveData Models]
G[DeviceConfiguration] --> H[Device Management]
Key Components:
-
BLEManager
: Bluetooth operations and device management -
DiveLogRetriever
: Coordinate dive log downloads -
GenericParser
: Parse dive data into Swift models -
DeviceConfiguration
: Handle device setup and identification
Objective-C/C bridge connecting Swift and libdivecomputer:
graph LR
A[BLEBridge.m] --> B[configuredc.c]
B --> C[libdivecomputer]
D[Swift] --> A
Components:
-
BLEBridge
: Objective-C interface for BLE operations -
configuredc
: C implementation of device protocols - Bridge headers for Swift/C interop
Native C library integration:
graph TB
A[libdivecomputer] --> B[Device Communication]
A --> C[Data Parsing]
A --> D[Protocol Handling]
sequenceDiagram
participant App
participant BLEManager
participant Bridge
participant Device
App->>BLEManager: startScanning()
BLEManager->>Device: Discover
Device-->>BLEManager: Found
App->>BLEManager: connect()
BLEManager->>Bridge: openBLEDevice()
Bridge->>Device: Establish Connection
Device-->>App: Connected
sequenceDiagram
participant App
participant DiveLogRetriever
participant Parser
participant Device
App->>DiveLogRetriever: retrieveDiveLogs()
DiveLogRetriever->>Device: Request Logs
Device-->>DiveLogRetriever: Raw Data
DiveLogRetriever->>Parser: Parse Data
Parser-->>App: DiveData Models
classDiagram
class CoreBluetoothManager {
+shared: CoreBluetoothManager
+startScanning()
+stopScanning()
+connect()
}
class DiveLogRetriever {
+retrieveDiveLogs()
-handleCallback()
-processData()
}
class GenericParser {
+parseDiveData()
-parseProfile()
-parseEvents()
}
class DiveData {
+number: Int
+datetime: Date
+profile: [DiveProfilePoint]
}
CoreBluetoothManager --> DiveLogRetriever
DiveLogRetriever --> GenericParser
GenericParser --> DiveData
- libdivecomputer: Core dive computer communication
- CoreBluetooth: iOS/macOS Bluetooth functionality
- Swift Standard Library: Foundation, Combine
graph TD
A[LibDCSwift] --> B[LibDCBridge]
B --> C[Clibdivecomputer]
A --> D[CoreBluetooth]
A --> E[Combine]
- Proper memory management between Swift and C
- Manual memory management in C layer
- ARC in Swift layer
- Bridge cleanup and deallocation
// Example of proper resource management
class DeviceHandler {
private var devicePtr: UnsafeMutablePointer<device_data_t>?
deinit {
if let ptr = devicePtr {
ptr.deallocate()
}
}
}
graph TD
A[C Error] --> B[Bridge Layer]
B --> C[Swift Error]
C --> D[User Interface]
- Device Communication Errors
- Parse Errors
- BLE Connection Errors
- Resource Errors
- BLE operations on dedicated queue
- Parse operations on background queue
- UI updates on main queue
- Thread-safe data structures
struct DeviceConfig {
let family: DeviceFamily
let model: UInt32
let capabilities: DeviceCapabilities
}
- Logging levels
- Timeout values
- Retry policies
- Buffer sizes
- Efficient buffer management
- Proper resource cleanup
- Lazy loading where appropriate
- Batch processing of dive data
- Incremental updates using fingerprints
- Optimized parsing algorithms