Merge branch 'linux-wiimote-crash-fix'

This commit is contained in:
Jordan Woyak 2013-01-10 16:55:03 -06:00
commit 240ea0f116
6 changed files with 50 additions and 23 deletions

View File

@ -36,6 +36,11 @@ void Wiimote::RealDisconnect()
return;
}
bool Wiimote::IsOpen() const
{
return IsConnected();
}
int Wiimote::IORead(unsigned char* buf)
{
return 0;

View File

@ -136,10 +136,10 @@ int FindWiimotes(Wiimote** wm, int max_wiimotes)
// Connect to a wiimote with a known address.
bool Wiimote::Connect()
{
struct sockaddr_l2 addr;
if (IsConnected()) return false;
if (IsConnected())
return false;
sockaddr_l2 addr;
addr.l2_family = AF_BLUETOOTH;
addr.l2_bdaddr = bdaddr;
addr.l2_cid = 0;
@ -195,6 +195,13 @@ void Wiimote::RealDisconnect()
if (m_wiimote_thread.joinable())
m_wiimote_thread.join();
Close();
}
void Wiimote::Close()
{
if (IsOpen())
{
Host_ConnectWiimote(index, false);
close(out_sock);
@ -203,20 +210,21 @@ void Wiimote::RealDisconnect()
out_sock = -1;
in_sock = -1;
}
}
bool Wiimote::IsOpen() const
{
return out_sock != -1 && in_sock != -1;
}
int Wiimote::IORead(unsigned char *buf)
{
struct timeval tv;
fd_set fds;
int r;
if (!IsConnected())
return 0;
// Block select for 1/2000th of a second
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = WIIMOTE_DEFAULT_TIMEOUT * 1000;
fd_set fds;
FD_ZERO(&fds);
FD_SET(in_sock, &fds);
@ -230,7 +238,7 @@ int Wiimote::IORead(unsigned char *buf)
return 0;
// Read the pending message into the buffer
r = read(in_sock, buf, MAX_PAYLOAD);
int r = read(in_sock, buf, MAX_PAYLOAD);
if (r == -1)
{
// Error reading data
@ -241,17 +249,17 @@ int Wiimote::IORead(unsigned char *buf)
// This can happen if the bluetooth dongle is disconnected
ERROR_LOG(WIIMOTE, "Bluetooth appears to be disconnected. "
"Wiimote %i will be disconnected.", index + 1);
RealDisconnect();
Close();
}
return 0;
}
if (!r)
else if (!r)
{
// Disconnect
RealDisconnect();
return 0;
Close();
}
return r;
}

View File

@ -294,6 +294,11 @@ void Wiimote::RealDisconnect()
ResetEvent(&hid_overlap);
}
bool Wiimote::IsOpen() const
{
return IsConnected();
}
int Wiimote::IORead(unsigned char* buf)
{
DWORD b, r;

View File

@ -227,6 +227,11 @@ void Wiimote::RealDisconnect()
ichan = NULL;
}
bool Wiimote::IsOpen() const
{
return IsConnected();
}
int Wiimote::IORead(unsigned char *buf)
{
int bytes;

View File

@ -240,7 +240,7 @@ void Wiimote::Disconnect()
DisableDataReporting();
}
bool Wiimote::IsConnected()
bool Wiimote::IsConnected() const
{
return m_connected;
}
@ -312,7 +312,7 @@ void Wiimote::ThreadFunc()
Rumble();
// main loop
while (IsConnected())
while (IsOpen())
{
#ifdef __APPLE__
while (Write()) {}

View File

@ -53,7 +53,8 @@ public:
bool Read();
bool Write();
bool Connect();
bool IsConnected();
bool IsConnected() const;
bool IsOpen() const;
void Disconnect();
void DisableDataReporting();
void Rumble();
@ -72,6 +73,9 @@ public:
bdaddr_t bdaddr; // Bluetooth address
int out_sock; // Output socket
int in_sock; // Input socket
void Close();
#elif defined(_WIN32)
char devicepath[255]; // Unique wiimote reference
//ULONGLONG btaddr; // Bluetooth address