bluetooth-mitm: remove unnecessary Initialize/Finalize functions

This commit is contained in:
ndeadly 2021-02-21 19:35:19 +01:00
parent ff9d6fe44b
commit 04a4d1fcd8
7 changed files with 45 additions and 49 deletions

View file

@ -38,6 +38,10 @@ namespace ams::bluetooth::ble {
return g_init_event.TryWait();
}
void SignalInitialized(void) {
g_init_event.Signal();
}
void WaitInitialized(void) {
g_init_event.Wait();
}
@ -54,17 +58,6 @@ namespace ams::bluetooth::ble {
return &g_system_event_user_fwd;
}
Result Initialize(Handle event_handle) {
g_system_event.AttachReadableHandle(event_handle, false, os::EventClearMode_ManualClear);
g_init_event.Signal();
return ams::ResultSuccess();
}
void Finalize(void) {
;
}
Result GetEventInfo(bluetooth::BleEventType *type, void *buffer, size_t size) {
std::scoped_lock lk(g_event_data_lock);

View file

@ -21,15 +21,13 @@
namespace ams::bluetooth::ble {
bool IsInitialized(void);
void SignalInitialized(void);
void WaitInitialized(void);
os::SystemEvent *GetSystemEvent(void);
os::SystemEvent *GetForwardEvent(void);
os::SystemEvent *GetUserForwardEvent(void);
Result Initialize(Handle event_handle);
void Finalize(void);
Result GetEventInfo(bluetooth::BleEventType *type, void *buffer, size_t size);
void HandleEvent(void);

View file

@ -41,6 +41,10 @@ namespace ams::bluetooth::core {
return g_init_event.TryWait();
}
void SignalInitialized(void) {
g_init_event.Signal();
}
void WaitInitialized(void) {
g_init_event.Wait();
}
@ -65,17 +69,6 @@ namespace ams::bluetooth::core {
return &g_system_event_user_fwd;
}
Result Initialize(Handle event_handle) {
g_system_event.AttachReadableHandle(event_handle, false, os::EventClearMode_ManualClear);
g_init_event.Signal();
return ams::ResultSuccess();
}
void Finalize(void) {
;
}
Result GetEventInfo(bluetooth::EventType *type, void *buffer, size_t size) {
std::scoped_lock lk(g_event_info_lock);

View file

@ -21,6 +21,7 @@
namespace ams::bluetooth::core {
bool IsInitialized(void);
void SignalInitialized(void);
void WaitInitialized(void);
void SignalEnabled(void);
void WaitEnabled(void);
@ -29,9 +30,6 @@ namespace ams::bluetooth::core {
os::SystemEvent *GetForwardEvent(void);
os::SystemEvent *GetUserForwardEvent(void);
Result Initialize(Handle event_handle);
void Finalize(void);
Result GetEventInfo(bluetooth::EventType *type, void *buffer, size_t size);
void HandleEvent(void);

View file

@ -40,6 +40,10 @@ namespace ams::bluetooth::hid {
return g_init_event.TryWait();
}
void SignalInitialized(void) {
g_init_event.Signal();
}
void WaitInitialized(void) {
g_init_event.Wait();
}
@ -56,17 +60,6 @@ namespace ams::bluetooth::hid {
return &g_system_event_user_fwd;
}
Result Initialize(Handle event_handle) {
g_system_event.AttachReadableHandle(event_handle, false, os::EventClearMode_ManualClear);
g_init_event.Signal();
return ams::ResultSuccess();
}
void Finalize(void) {
;
}
Result GetEventInfo(bluetooth::HidEventType *type, void *buffer, size_t size) {
std::scoped_lock lk(g_event_info_lock);

View file

@ -21,15 +21,13 @@
namespace ams::bluetooth::hid {
bool IsInitialized(void);
void SignalInitialized(void);
void WaitInitialized(void);
os::SystemEvent *GetSystemEvent(void);
os::SystemEvent *GetForwardEvent(void);
os::SystemEvent *GetUserForwardEvent(void);
Result Initialize(Handle event_handle);
void Finalize(void);
Result GetEventInfo(bluetooth::HidEventType *type, void *buffer, size_t size);
void HandleEvent(void);

View file

@ -28,12 +28,21 @@ namespace ams::mitm::bluetooth {
Result BtdrvMitmService::InitializeBluetooth(sf::OutCopyHandle out_handle) {
if (!ams::bluetooth::core::IsInitialized()) {
// Forward to the real function to obtain the system event handle
Handle handle = INVALID_HANDLE;
R_TRY(btdrvInitializeBluetoothFwd(this->forward_service.get(), &handle));
R_TRY(ams::bluetooth::core::Initialize(handle));
R_TRY(ams::bluetooth::hid::report::InitializeReportBuffer());
out_handle.SetValue(ams::bluetooth::core::GetForwardEvent()->GetReadableHandle());
// Attach the real system event handle to our own event
ams::bluetooth::core::GetSystemEvent()->AttachReadableHandle(handle, false, os::EventClearMode_ManualClear);
// Return our forwarder event handle to the caller instead
out_handle.SetValue(ams::bluetooth::core::GetForwardEvent()->GetReadableHandle());
// Initialise the hid report circular buffer
R_TRY(ams::bluetooth::hid::report::InitializeReportBuffer());
// Signal that the interface is initialised
ams::bluetooth::core::SignalInitialized();
} else {
out_handle.SetValue(ams::bluetooth::core::GetUserForwardEvent()->GetReadableHandle());
}
@ -73,11 +82,18 @@ namespace ams::mitm::bluetooth {
Result BtdrvMitmService::InitializeHid(sf::OutCopyHandle out_handle, u16 version) {
if (!ams::bluetooth::hid::IsInitialized()) {
// Forward to the real function to obtain the system event handle
Handle handle = INVALID_HANDLE;
R_TRY(btdrvInitializeHidFwd(this->forward_service.get(), &handle, version));
R_TRY(ams::bluetooth::hid::Initialize(handle));
out_handle.SetValue(ams::bluetooth::hid::GetForwardEvent()->GetReadableHandle());
// Attach the real system event handle to our own event
ams::bluetooth::hid::GetSystemEvent()->AttachReadableHandle(handle, false, os::EventClearMode_ManualClear);
// Return our forwarder event handle to the caller instead
out_handle.SetValue(ams::bluetooth::hid::GetForwardEvent()->GetReadableHandle());
// Signal that the interface is initialised
ams::bluetooth::hid::SignalInitialized();
}
else {
out_handle.SetValue(ams::bluetooth::hid::GetUserForwardEvent()->GetReadableHandle());
@ -201,11 +217,18 @@ namespace ams::mitm::bluetooth {
Result BtdrvMitmService::InitializeBle(sf::OutCopyHandle out_handle) {
if (!ams::bluetooth::ble::IsInitialized()) {
// Forward to the real function to obtain the system event handle
Handle handle = INVALID_HANDLE;
R_TRY(btdrvInitializeBleFwd(this->forward_service.get(), &handle));
R_TRY(ams::bluetooth::ble::Initialize(handle));
out_handle.SetValue(ams::bluetooth::ble::GetForwardEvent()->GetReadableHandle());
// Attach the real system event handle to our own event
ams::bluetooth::ble::GetSystemEvent()->AttachReadableHandle(handle, false, os::EventClearMode_ManualClear);
// Return our forwarder event handle to the caller instead
out_handle.SetValue(ams::bluetooth::ble::GetForwardEvent()->GetReadableHandle());
// Signal that the interface is initialised
ams::bluetooth::ble::SignalInitialized();
}
else {
out_handle.SetValue(ams::bluetooth::ble::GetUserForwardEvent()->GetReadableHandle());