Get rid of GetUsbPointer for emulated Bluetooth

It held a raw pointer to a IOS::HLE::Device::BluetoothEmu that is not
guaranteed to exist (and of course, nothing checked that it wasn't
nullptr), but what is more, it's totally unnecessary because we have
IOS::HLE::GetDeviceByName().

Since we cannot always inform the host that Wii remotes are
disconnected from ES, that is now done in BluetoothEmu's destructor.
This commit is contained in:
Léo Lam 2017-01-28 22:57:43 +01:00
parent 5fd5eeb82a
commit fd49a1b2d5
8 changed files with 43 additions and 51 deletions

View File

@ -528,9 +528,11 @@ void EmuThread()
Wiimote::LoadConfig(); Wiimote::LoadConfig();
// Activate Wiimotes which don't have source set to "None" // Activate Wiimotes which don't have source set to "None"
const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
IOS::HLE::GetDeviceByName("/dev/usb/oh1/57e/305"));
for (unsigned int i = 0; i != MAX_BBMOTES; ++i) for (unsigned int i = 0; i != MAX_BBMOTES; ++i)
if (g_wiimote_sources[i]) if (g_wiimote_sources[i] && bt)
IOS::HLE::GetUsbPointer()->AccessWiiMote(i | 0x100)->Activate(true); bt->AccessWiiMote(i | 0x100)->Activate(true);
} }
AudioCommon::InitSoundStream(); AudioCommon::InitSoundStream();

View File

@ -1201,29 +1201,30 @@ IPCCommandResult ES::LaunchBC(const IOCtlVRequest& request)
void ES::ResetAfterLaunch(const u64 ios_to_load) const void ES::ResetAfterLaunch(const u64 ios_to_load) const
{ {
auto bt = std::static_pointer_cast<BluetoothEmu>(GetDeviceByName("/dev/usb/oh1/57e/305"));
bool* wiiMoteConnected = new bool[MAX_BBMOTES]; bool* wiiMoteConnected = new bool[MAX_BBMOTES];
if (!SConfig::GetInstance().m_bt_passthrough_enabled) if (!SConfig::GetInstance().m_bt_passthrough_enabled && bt)
{ {
BluetoothEmu* s_Usb = GetUsbPointer();
for (unsigned int i = 0; i < MAX_BBMOTES; i++) for (unsigned int i = 0; i < MAX_BBMOTES; i++)
wiiMoteConnected[i] = s_Usb->m_WiiMotes[i].IsConnected(); wiiMoteConnected[i] = bt->m_WiiMotes[i].IsConnected();
} }
Reload(ios_to_load); Reload(ios_to_load);
if (!SConfig::GetInstance().m_bt_passthrough_enabled) // Get the new Bluetooth device. Note that it is not guaranteed to exist.
bt = std::static_pointer_cast<BluetoothEmu>(GetDeviceByName("/dev/usb/oh1/57e/305"));
if (!SConfig::GetInstance().m_bt_passthrough_enabled && bt)
{ {
BluetoothEmu* s_Usb = GetUsbPointer();
for (unsigned int i = 0; i < MAX_BBMOTES; i++) for (unsigned int i = 0; i < MAX_BBMOTES; i++)
{ {
if (wiiMoteConnected[i]) if (wiiMoteConnected[i])
{ {
s_Usb->m_WiiMotes[i].Activate(false); bt->m_WiiMotes[i].Activate(false);
s_Usb->m_WiiMotes[i].Activate(true); bt->m_WiiMotes[i].Activate(true);
} }
else else
{ {
s_Usb->m_WiiMotes[i].Activate(false); bt->m_WiiMotes[i].Activate(false);
} }
} }
} }

View File

@ -50,7 +50,6 @@ BluetoothEmu::BluetoothEmu(u32 device_id, const std::string& device_name)
// Activate only first Wii Remote by default // Activate only first Wii Remote by default
_conf_pads BT_DINF; _conf_pads BT_DINF;
SetUsbPointer(this);
if (!sysconf.GetArrayData("BT.DINF", (u8*)&BT_DINF, sizeof(_conf_pads))) if (!sysconf.GetArrayData("BT.DINF", (u8*)&BT_DINF, sizeof(_conf_pads)))
{ {
PanicAlertT("Trying to read from invalid SYSCONF\nWii Remote Bluetooth IDs are not available"); PanicAlertT("Trying to read from invalid SYSCONF\nWii Remote Bluetooth IDs are not available");
@ -103,8 +102,8 @@ BluetoothEmu::BluetoothEmu(u32 device_id, const std::string& device_name)
BluetoothEmu::~BluetoothEmu() BluetoothEmu::~BluetoothEmu()
{ {
Host_SetWiiMoteConnectionState(0);
m_WiiMotes.clear(); m_WiiMotes.clear();
SetUsbPointer(nullptr);
} }
template <typename T> template <typename T>

View File

@ -25,18 +25,6 @@ namespace IOS
{ {
namespace HLE namespace HLE
{ {
static Device::BluetoothEmu* s_Usb = nullptr;
Device::BluetoothEmu* GetUsbPointer()
{
return s_Usb;
}
void SetUsbPointer(Device::BluetoothEmu* ptr)
{
s_Usb = ptr;
}
WiimoteDevice::WiimoteDevice(Device::BluetoothEmu* host, int number, bdaddr_t bd, bool ready) WiimoteDevice::WiimoteDevice(Device::BluetoothEmu* host, int number, bdaddr_t bd, bool ready)
: m_BD(bd), : m_BD(bd),
m_Name(number == WIIMOTE_BALANCE_BOARD ? "Nintendo RVL-WBC-01" : "Nintendo RVL-CNT-01"), m_Name(number == WIIMOTE_BALANCE_BOARD ? "Nintendo RVL-WBC-01" : "Nintendo RVL-CNT-01"),
@ -943,6 +931,9 @@ void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _
DEBUG_LOG(WIIMOTE, " Data: %s", ArrayToString(pData, _Size, 50).c_str()); DEBUG_LOG(WIIMOTE, " Data: %s", ArrayToString(pData, _Size, 50).c_str());
DEBUG_LOG(WIIMOTE, " Channel: %x", _channelID); DEBUG_LOG(WIIMOTE, " Channel: %x", _channelID);
IOS::HLE::s_Usb->m_WiiMotes[_number].ReceiveL2capData(_channelID, _pData, _Size); const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
IOS::HLE::GetDeviceByName("/dev/usb/oh1/57e/305"));
if (bt)
bt->m_WiiMotes[_number].ReceiveL2capData(_channelID, _pData, _Size);
} }
} }

View File

@ -23,9 +23,6 @@ namespace Device
class BluetoothEmu; class BluetoothEmu;
} }
Device::BluetoothEmu* GetUsbPointer();
void SetUsbPointer(Device::BluetoothEmu* ptr);
class CBigEndianBuffer class CBigEndianBuffer
{ {
public: public:

View File

@ -521,11 +521,13 @@ void ChangeWiiPads(bool instantly)
if (instantly && (s_controllers >> 4) == controllers) if (instantly && (s_controllers >> 4) == controllers)
return; return;
const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
IOS::HLE::GetDeviceByName("/dev/usb/oh1/57e/305"));
for (int i = 0; i < MAX_WIIMOTES; ++i) for (int i = 0; i < MAX_WIIMOTES; ++i)
{ {
g_wiimote_sources[i] = IsUsingWiimote(i) ? WIIMOTE_SRC_EMU : WIIMOTE_SRC_NONE; g_wiimote_sources[i] = IsUsingWiimote(i) ? WIIMOTE_SRC_EMU : WIIMOTE_SRC_NONE;
if (!SConfig::GetInstance().m_bt_passthrough_enabled) if (!SConfig::GetInstance().m_bt_passthrough_enabled && bt)
IOS::HLE::GetUsbPointer()->AccessWiiMote(i | 0x100)->Activate(IsUsingWiimote(i)); bt->AccessWiiMote(i | 0x100)->Activate(IsUsingWiimote(i));
} }
} }

View File

@ -1245,7 +1245,10 @@ void CFrame::ConnectWiimote(int wm_idx, bool connect)
!SConfig::GetInstance().m_bt_passthrough_enabled) !SConfig::GetInstance().m_bt_passthrough_enabled)
{ {
bool was_unpaused = Core::PauseAndLock(true); bool was_unpaused = Core::PauseAndLock(true);
IOS::HLE::GetUsbPointer()->AccessWiiMote(wm_idx | 0x100)->Activate(connect); const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
IOS::HLE::GetDeviceByName("/dev/usb/oh1/57e/305"));
if (bt)
bt->AccessWiiMote(wm_idx | 0x100)->Activate(connect);
const char* message = connect ? "Wii Remote %i connected" : "Wii Remote %i disconnected"; const char* message = connect ? "Wii Remote %i connected" : "Wii Remote %i disconnected";
Core::DisplayMessage(StringFromFormat(message, wm_idx + 1), 3000); Core::DisplayMessage(StringFromFormat(message, wm_idx + 1), 3000);
Host_UpdateMainFrame(); Host_UpdateMainFrame();
@ -1258,10 +1261,11 @@ void CFrame::OnConnectWiimote(wxCommandEvent& event)
if (SConfig::GetInstance().m_bt_passthrough_enabled) if (SConfig::GetInstance().m_bt_passthrough_enabled)
return; return;
bool was_unpaused = Core::PauseAndLock(true); bool was_unpaused = Core::PauseAndLock(true);
ConnectWiimote(event.GetId() - IDM_CONNECT_WIIMOTE1, const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
!IOS::HLE::GetUsbPointer() IOS::HLE::GetDeviceByName("/dev/usb/oh1/57e/305"));
->AccessWiiMote((event.GetId() - IDM_CONNECT_WIIMOTE1) | 0x100) const bool is_connected =
->IsConnected()); bt && bt->AccessWiiMote((event.GetId() - IDM_CONNECT_WIIMOTE1) | 0x100)->IsConnected();
ConnectWiimote(event.GetId() - IDM_CONNECT_WIIMOTE1, !is_connected);
Core::PauseAndLock(false, was_unpaused); Core::PauseAndLock(false, was_unpaused);
} }
@ -1416,8 +1420,9 @@ void CFrame::UpdateGUI()
// Tools // Tools
GetMenuBar()->FindItem(IDM_CHEATS)->Enable(SConfig::GetInstance().bEnableCheats); GetMenuBar()->FindItem(IDM_CHEATS)->Enable(SConfig::GetInstance().bEnableCheats);
bool ShouldEnableWiimotes = const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
Running && SConfig::GetInstance().bWii && !SConfig::GetInstance().m_bt_passthrough_enabled; IOS::HLE::GetDeviceByName("/dev/usb/oh1/57e/305"));
bool ShouldEnableWiimotes = Running && bt && !SConfig::GetInstance().m_bt_passthrough_enabled;
GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Enable(ShouldEnableWiimotes); GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Enable(ShouldEnableWiimotes);
GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Enable(ShouldEnableWiimotes); GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Enable(ShouldEnableWiimotes);
GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Enable(ShouldEnableWiimotes); GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Enable(ShouldEnableWiimotes);
@ -1426,21 +1431,13 @@ void CFrame::UpdateGUI()
if (ShouldEnableWiimotes) if (ShouldEnableWiimotes)
{ {
bool was_unpaused = Core::PauseAndLock(true); bool was_unpaused = Core::PauseAndLock(true);
GetMenuBar() GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Check(bt->AccessWiiMote(0x0100)->IsConnected());
->FindItem(IDM_CONNECT_WIIMOTE1) GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Check(bt->AccessWiiMote(0x0101)->IsConnected());
->Check(IOS::HLE::GetUsbPointer()->AccessWiiMote(0x0100)->IsConnected()); GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Check(bt->AccessWiiMote(0x0102)->IsConnected());
GetMenuBar() GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Check(bt->AccessWiiMote(0x0103)->IsConnected());
->FindItem(IDM_CONNECT_WIIMOTE2)
->Check(IOS::HLE::GetUsbPointer()->AccessWiiMote(0x0101)->IsConnected());
GetMenuBar()
->FindItem(IDM_CONNECT_WIIMOTE3)
->Check(IOS::HLE::GetUsbPointer()->AccessWiiMote(0x0102)->IsConnected());
GetMenuBar()
->FindItem(IDM_CONNECT_WIIMOTE4)
->Check(IOS::HLE::GetUsbPointer()->AccessWiiMote(0x0103)->IsConnected());
GetMenuBar() GetMenuBar()
->FindItem(IDM_CONNECT_BALANCEBOARD) ->FindItem(IDM_CONNECT_BALANCEBOARD)
->Check(IOS::HLE::GetUsbPointer()->AccessWiiMote(0x0104)->IsConnected()); ->Check(bt->AccessWiiMote(0x0104)->IsConnected());
Core::PauseAndLock(false, was_unpaused); Core::PauseAndLock(false, was_unpaused);
} }

View File

@ -143,7 +143,10 @@ void Host_ConnectWiimote(int wm_idx, bool connect)
{ {
Core::QueueHostJob([=] { Core::QueueHostJob([=] {
bool was_unpaused = Core::PauseAndLock(true); bool was_unpaused = Core::PauseAndLock(true);
IOS::HLE::GetUsbPointer()->AccessWiiMote(wm_idx | 0x100)->Activate(connect); const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
IOS::HLE::GetDeviceByName("/dev/usb/oh1/57e/305"));
if (bt)
bt->AccessWiiMote(wm_idx | 0x100)->Activate(connect);
Host_UpdateMainFrame(); Host_UpdateMainFrame();
Core::PauseAndLock(false, was_unpaused); Core::PauseAndLock(false, was_unpaused);
}); });