private void ValidateStatus(NativeMethods.BTSTATUS status) { switch (status) { case NativeMethods.BTSTATUS.BTSTATUS_SUCCESS: break; case NativeMethods.BTSTATUS.BTSTATUS_FAIL: throw new BluesoleilFailException(); case NativeMethods.BTSTATUS.BTSTATUS_BT_NOT_READY: throw new BluesoleilNotReadyException(); case NativeMethods.BTSTATUS.BTSTATUS_BT_BUSY: throw new BluesoleilBluetoothBusyException(); case NativeMethods.BTSTATUS.BTSTATUS_SYSTEM_ERROR: throw new BluesoleilSystemException(); case NativeMethods.BTSTATUS.BTSTATUS_CONNECTION_NOT_EXIST: throw new BluesoleilNonExistingConnectionException(); default: throw new BluesoleilException(status.ToString()); } }
public void DisconnectService(BluetoothConnection connection) { int connectionHandle = connection.ConnectionHandle; NativeMethods.BTSTATUS status = NativeMethods.BT_DisconnectService(connectionHandle); ValidateStatus(status); lookupConnections.Remove(connectionHandle); connections.Remove(connection); OnConnectionClosed(new BluetoothConnectionEventArgs(connection)); }
public BluetoothService[] BrowseServices(BluetoothDevice device) { ValidateThread(); NativeMethods.GENERAL_SERVICE_INFO[] serviceInfos; NativeMethods.BTSTATUS status = NativeMethods.BT_BrowseServices(device.DeviceInfo, true, out serviceInfos); ValidateStatus(status); BluetoothService[] services = new BluetoothService[serviceInfos.Length]; for (int i = 0; i < serviceInfos.Length; i++) { services[i] = new BluetoothService(this, device, serviceInfos[i]); } return(services); }
public BluetoothConnection ConnectService(BluetoothService service) { ValidateThread(); int connectionHandle = 0; NativeMethods.BTSTATUS status = NativeMethods.BT_ConnectService(service.Device.DeviceInfo, service.ServiceInfo, ref connectionHandle); ValidateStatus(status); BluetoothConnection connection = new BluetoothConnection(this, service, connectionHandle); lookupConnections.Add(connectionHandle, connection); connections.Add(connection); OnConnectionOpened(new BluetoothConnectionEventArgs(connection)); return(connection); }
public BluetoothDevice[] InquireDevices(TimeSpan timeOut) { ValidateThread(); ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state) { Thread.Sleep(timeOut); NativeMethods.BT_CancelInquiry(); })); NativeMethods.BLUETOOTH_DEVICE_INFO[] deviceInfos; NativeMethods.BTSTATUS status = NativeMethods.BT_InquireDevices(NativeMethods.INQUIRY.INQUIRY_GENERAL_REFRESH, 0, out deviceInfos); ValidateStatus(status); BluetoothDevice[] devices = new BluetoothDevice[deviceInfos.Length]; for (int i = 0; i < devices.Length; i++) { devices[i] = CreateBluetoothDevice(deviceInfos[i]); } return(devices); }
public void StopBluetooth() { NativeMethods.BTSTATUS status = NativeMethods.BT_StartBluetooth(); ValidateStatus(status); OnBluetoothStopped(EventArgs.Empty); }