MissionControl/btdrv-mitm/source/bluetooth/bluetooth_circularbuffer.hpp

71 lines
1.9 KiB
C++

#pragma once
#include <stratosphere.hpp>
#include <switch.h>
#define BLUETOOTH_CIRCBUFFER_SIZE 10000
namespace ams::bluetooth {
enum CircularBufferType {
CircularBufferType_Other,
CircularBufferType_HidReport,
CircularBufferType_Bluetooth,
CircularBufferType_Ble,
CircularBufferType_BleCore,
CircularBufferType_BleHid,
};
struct CircularBufferPacketHeader{
u8 type;
os::Tick timestamp;
u64 size;
};
struct CircularBufferPacket{
CircularBufferPacketHeader header;
BluetoothHidReportData data;
};
class CircularBuffer {
public:
CircularBuffer(void);
void Initialize(const char *name); // 10.0.0+, previously took event argument
void Finalize(void);
bool IsInitialized(void);
u64 GetWriteableSize(void);
void SetWriteCompleteEvent(os::EventType *event);
u64 Write(u8 type, void *data, size_t size);
void DiscardOldPackets(u8 type, u32 ageLimit);
CircularBufferPacket *Read(void);
u64 Free(void);
private:
void _setReadOffset(u32 offset);
void _setWriteOffset(u32 offset);
u32 _getWriteOffset(void);
u32 _getReadOffset(void);
u64 _write(u8 type, void *data, size_t size);
void _updateUtilization(void);
CircularBufferPacket *_read(void);
os::SdkMutex mutex;
os::EventType *event;
u8 data[BLUETOOTH_CIRCBUFFER_SIZE];
u32 writeOffset;
u32 readOffset;
s64 size;
char name[16];
u8 _unk1;
bool isInitialized;
u8 _unk2[6];
public:
CircularBufferType type;
bool _unk3;
//u8 _unk3[4];
};
}