Refactor IPC-message sending

This commit is contained in:
fokinv 2016-04-25 13:54:06 +02:00 committed by Attila Dusnoki
parent ecf4c942da
commit c8672ed0af
7 changed files with 326 additions and 493 deletions

View file

@ -5,78 +5,71 @@ use bluetooth_scanfilter::RequestDeviceoptions;
use ipc_channel::ipc::IpcSender;
#[derive(Deserialize, Serialize)]
pub enum BluetoothMethodMsg {
RequestDevice(RequestDeviceoptions, IpcSender<BluetoothObjectMsg>),
GATTServerConnect(String, IpcSender<BluetoothObjectMsg>),
GATTServerDisconnect(String, IpcSender<BluetoothObjectMsg>),
GetPrimaryService(String, String, IpcSender<BluetoothObjectMsg>),
GetPrimaryServices(String, Option<String>, IpcSender<BluetoothObjectMsg>),
GetCharacteristic(String, String, IpcSender<BluetoothObjectMsg>),
GetCharacteristics(String, Option<String>, IpcSender<BluetoothObjectMsg>),
GetDescriptor(String, String, IpcSender<BluetoothObjectMsg>),
GetDescriptors(String, Option<String>, IpcSender<BluetoothObjectMsg>),
ReadValue(String, IpcSender<BluetoothObjectMsg>),
WriteValue(String, Vec<u8>, IpcSender<BluetoothObjectMsg>),
Exit,
pub struct BluetoothDeviceMsg {
// Bluetooth Device properties
pub id: String,
pub name: Option<String>,
pub device_class: Option<u32>,
pub vendor_id_source: Option<String>,
pub vendor_id: Option<u32>,
pub product_id: Option<u32>,
pub product_version: Option<u32>,
// Advertisiong Data properties
pub appearance: Option<u16>,
pub tx_power: Option<i8>,
pub rssi: Option<i8>,
}
#[derive(Deserialize, Serialize)]
pub enum BluetoothObjectMsg {
BluetoothDevice {
// Bluetooth Device properties
id: String,
name: Option<String>,
device_class: Option<u32>,
vendor_id_source: Option<String>,
vendor_id: Option<u32>,
product_id: Option<u32>,
product_version: Option<u32>,
// Advertisiong Data properties
appearance: Option<u16>,
tx_power: Option<i8>,
rssi: Option<i8>
},
BluetoothServer {
connected: bool
},
BluetoothService {
uuid: String,
is_primary: bool,
instance_id: String
},
BluetoothServices {
services_vec: Vec<BluetoothObjectMsg>
},
BluetoothCharacteristic {
// Characteristic
uuid: String,
instance_id: String,
// Characteristic properties
broadcast: bool,
read: bool,
write_without_response: bool,
write: bool,
notify: bool,
indicate: bool,
authenticated_signed_writes: bool,
reliable_write: bool,
writable_auxiliaries: bool
},
BluetoothCharacteristics {
characteristics_vec: Vec<BluetoothObjectMsg>
},
BluetoothDescriptor {
uuid: String,
instance_id: String
},
BluetoothDescriptors {
descriptors_vec: Vec<BluetoothObjectMsg>,
},
BluetoothReadValue {
value: Vec<u8>
},
BluetoothWriteValue,
Error {
error: String
},
pub struct BluetoothServiceMsg {
pub uuid: String,
pub is_primary: bool,
pub instance_id: String,
}
#[derive(Deserialize, Serialize)]
pub struct BluetoothCharacteristicMsg {
// Characteristic
pub uuid: String,
pub instance_id: String,
// Characteristic properties
pub broadcast: bool,
pub read: bool,
pub write_without_response: bool,
pub write: bool,
pub notify: bool,
pub indicate: bool,
pub authenticated_signed_writes: bool,
pub reliable_write: bool,
pub writable_auxiliaries: bool,
}
#[derive(Deserialize, Serialize)]
pub struct BluetoothDescriptorMsg {
pub uuid: String,
pub instance_id: String,
}
pub type BluetoothServicesMsg = Vec<BluetoothServiceMsg>;
pub type BluetoothCharacteristicsMsg = Vec<BluetoothCharacteristicMsg>;
pub type BluetoothDescriptorsMsg = Vec<BluetoothDescriptorMsg>;
pub type BluetoothResult<T> = Result<T, String>;
#[derive(Deserialize, Serialize)]
pub enum BluetoothMethodMsg {
RequestDevice(RequestDeviceoptions, IpcSender<BluetoothResult<BluetoothDeviceMsg>>),
GATTServerConnect(String, IpcSender<BluetoothResult<bool>>),
GATTServerDisconnect(String, IpcSender<BluetoothResult<bool>>),
GetPrimaryService(String, String, IpcSender<BluetoothResult<BluetoothServiceMsg>>),
GetPrimaryServices(String, Option<String>, IpcSender<BluetoothResult<BluetoothServicesMsg>>),
GetCharacteristic(String, String, IpcSender<BluetoothResult<BluetoothCharacteristicMsg>>),
GetCharacteristics(String, Option<String>, IpcSender<BluetoothResult<BluetoothCharacteristicsMsg>>),
GetDescriptor(String, String, IpcSender<BluetoothResult<BluetoothDescriptorMsg>>),
GetDescriptors(String, Option<String>, IpcSender<BluetoothResult<BluetoothDescriptorsMsg>>),
ReadValue(String, IpcSender<BluetoothResult<Vec<u8>>>),
WriteValue(String, Vec<u8>, IpcSender<BluetoothResult<bool>>),
Exit,
}