-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServerCallback.cs
More file actions
78 lines (67 loc) · 4.83 KB
/
Copy pathServerCallback.cs
File metadata and controls
78 lines (67 loc) · 4.83 KB
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
using System;
using System.Reactive.Subjects;
using Android.Bluetooth;
using ReactiveBluetooth.Core.Exceptions;
namespace ReactiveBluetooth.Android.Peripheral.GattServer
{
public class ServerCallback : BluetoothGattServerCallback, IServerCallback
{
public ServerCallback()
{
CharacteristicReadRequestSubject = new Subject<Tuple<BluetoothDevice, int, int, BluetoothGattCharacteristic>>();
CharacteristicWriteRequestSubject = new Subject<Tuple<BluetoothDevice, int, BluetoothGattCharacteristic, bool, bool, int, byte[]>>();
ConnectionStateChangedSubject = new Subject<Tuple<BluetoothDevice, ProfileState, ProfileState>>();
DescriptorReadRequestSubject = new Subject<Tuple<BluetoothDevice, int, int, BluetoothGattDescriptor>>();
DescriptorWriteRequestSubject = new Subject<Tuple<BluetoothDevice, int, BluetoothGattDescriptor, bool, bool, int, byte[]>>();
ExecuteWriteSubject = new Subject<Tuple<BluetoothDevice, int, bool>>();
MtuChangedSubject = new Subject<Tuple<BluetoothDevice, int>>();
NotificationSentSubject = new Subject<Tuple<BluetoothDevice, GattStatus>>();
ServiceAddedSubject = new Subject<Tuple<ProfileState, BluetoothGattService>>();
}
public Subject<Tuple<BluetoothDevice, int, int, BluetoothGattCharacteristic>> CharacteristicReadRequestSubject { get; }
public Subject<Tuple<BluetoothDevice, int, BluetoothGattCharacteristic, bool, bool, int, byte[]>> CharacteristicWriteRequestSubject { get; }
public Subject<Tuple<BluetoothDevice, ProfileState, ProfileState>> ConnectionStateChangedSubject { get; }
public Subject<Tuple<BluetoothDevice, int, int, BluetoothGattDescriptor>> DescriptorReadRequestSubject { get; }
public Subject<Tuple<BluetoothDevice, int, BluetoothGattDescriptor, bool, bool, int, byte[]>> DescriptorWriteRequestSubject { get; }
public Subject<Tuple<BluetoothDevice, int, bool>> ExecuteWriteSubject { get; }
public Subject<Tuple<BluetoothDevice, int>> MtuChangedSubject { get; }
public Subject<Tuple<BluetoothDevice, GattStatus>> NotificationSentSubject { get; }
public Subject<Tuple<ProfileState, BluetoothGattService>> ServiceAddedSubject { get; }
public override void OnCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic)
{
CharacteristicReadRequestSubject?.OnNext(new Tuple<BluetoothDevice, int, int , BluetoothGattCharacteristic>(device, requestId, offset, characteristic));
}
public override void OnCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, bool preparedWrite, bool responseNeeded, int offset, byte[] value)
{
CharacteristicWriteRequestSubject?.OnNext(new Tuple<BluetoothDevice, int, BluetoothGattCharacteristic, bool, bool, int, byte[]>(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value));
}
public override void OnConnectionStateChange(BluetoothDevice device, ProfileState status, ProfileState newState)
{
ConnectionStateChangedSubject?.OnNext(new Tuple<BluetoothDevice, ProfileState, ProfileState>(device, status, newState));
}
public override void OnDescriptorReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattDescriptor descriptor)
{
DescriptorReadRequestSubject?.OnNext(new Tuple<BluetoothDevice, int, int, BluetoothGattDescriptor>(device, requestId, offset, descriptor));
}
public override void OnDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, bool preparedWrite, bool responseNeeded, int offset, byte[] value)
{
DescriptorWriteRequestSubject?.OnNext(new Tuple<BluetoothDevice, int, BluetoothGattDescriptor, bool, bool, int, byte[]>(device, requestId, descriptor, preparedWrite, responseNeeded, offset, value));
}
public override void OnExecuteWrite(BluetoothDevice device, int requestId, bool execute)
{
ExecuteWriteSubject?.OnNext(new Tuple<BluetoothDevice, int, bool>(device, requestId, execute));
}
public override void OnMtuChanged(BluetoothDevice device, int mtu)
{
MtuChangedSubject?.OnNext(new Tuple<BluetoothDevice, int>(device, mtu));
}
public override void OnNotificationSent(BluetoothDevice device, GattStatus status)
{
NotificationSentSubject?.OnNext(new Tuple<BluetoothDevice, GattStatus>(device, status));
}
public override void OnServiceAdded(ProfileState status, BluetoothGattService service)
{
ServiceAddedSubject?.OnNext(new Tuple<ProfileState, BluetoothGattService>(status, service));
}
}
}