Commit Graph

131 Commits

Author SHA1 Message Date
Tillmann Karras 1993eb436c Fix -Wignored-qualifiers warnings 2018-05-19 17:18:45 +01:00
spycrab 40bb9974f2 Reformat all the things! 2018-04-12 21:28:39 +02:00
Lioncash 75f5fcdfee Assert: Remove unused parameter from DEBUG_ASSERT
This brings the macro in line with the regular ASSERT macro, which only has one
macro parameter.
2018-03-16 13:01:11 -04:00
Lioncash 50a476c371 Assert: Uppercase assertion macros
Macros should be all upper-cased. This is also kind of a wart that's
been sticking out for quite a while now (we avoid prefixing
underscores).
2018-03-14 22:03:12 -04:00
Andrew Molloy f5839f854a Fix whitespace in and around WiimoteScannerDarwin::~WiimoteScannerDarwin() (linter). 2017-12-03 12:31:18 -05:00
Andrew Molloy 8354e89cf1 Break out of the loop waiting for the SearchBT to be done in WiimoteScannerDarwin::FindWiimotes() when the object is destroyed. Allows the application to quit correctly when Continuous Scanning is enabled on macOS. 2017-12-03 11:41:06 -05:00
Andrew Molloy d306397bbc -[deviceInquiryComplete:error:aborted:] comes in on the main thread in macOS 10.13, so instead of using CFRunLoopRun()/CFRunLoopStop(), just let the run loop do one pass. This is already in a loop waiting for done to be false. This also means -[deviceInquiryComplete:error:aborted:] should no longer call CFRunLoopStop(). Fixes connecting to Wiimotes in macOS 10.13+, should continue to work as before in 10.12 and below. 2017-12-03 10:32:07 -05:00
JosJuice b8c83dd5f3
Merge pull request #5973 from ligfx/renamefifoqueue
Rename Common::FifoQueue to Common::SPSCQueue
2017-11-19 13:51:22 +01:00
Michael M b58f8d19ab Rename Common::FifoQueue to Common::SPSCQueue
Since all queues are FIFO data structures, the name wasn't informative
as to why you'd use it over a normal queue. I originally thought it had
something to do with the hardware graphics FIFO.

This renames it using the common acronym SPSC, which stands for
single-producer single-consumer, and is most commonly used to talk about
lock-free data structures, both of which this is.
2017-08-23 17:00:52 -07:00
Léo Lam 52f26d462e WiimoteReal: Fix device handles not being closed
fail.

I have no idea how this didn't cause issues for more people.
2017-08-23 23:05:29 +02:00
JosJuice 09f3f9b41a Remove NonCopyable
The class NonCopyable is, like the name says, supposed to disallow
copying. But should it allow moving?

For a long time, NonCopyable used to not allow moving. (It declared
a deleted copy constructor and assigment operator without declaring
a move constructor and assignment operator, making the compiler
implicitly delete the move constructor and assignment operator.)
That's fine if the classes that inherit from NonCopyable don't need
to be movable or if writing the move constructor and assignment
operator by hand is fine, but that's not the case for all classes,
as I discovered when I was working on the DirectoryBlob PR.

Because of that, I decided to make NonCopyable movable in c7602cc,
allowing me to use NonCopyable in DirectoryBlob.h. That was however
an unfortunate decision, because some of the classes that inherit
from NonCopyable have incorrect behavior when moved by default-
generated move constructors and assignment operators, and do not
explicitly delete the move constructors and assignment operators,
relying on NonCopyable being non-movable.

So what can we do about this? There are four solutions that I can
think of:

1. Make NonCopyable non-movable and tell DirectoryBlob to suck it.

2. Keep allowing moving NonCopyable, and expect that classes that
   don't support moving will delete the move constructor and
   assignment operator manually. Not only is this inconsistent
   (having classes disallow copying one way and disallow moving
   another way), but deleting the move constructor and assignment
   operator manually is too easy to forget compared to how tricky
   the resulting problems are.

3. Have one "MovableNonCopyable" and one "NonMovableNonCopyable".
   It works, but it feels rather silly...

4. Don't have a NonCopyable class at all. Considering that deleting
   the copy constructor and assignment operator only takes two lines
   of code, I don't see much of a reason to keep NonCopyable. I
   suppose that there was more of a point in having NonCopyable back
   in the pre-C++11 days, when it wasn't possible to use "= delete".

I decided to go with the fourth one (like the commit title says).
The implementation of the commit is fairly straight-forward, though
I would like to point out that I skipped adding "= delete" lines
for classes whose only reason for being uncopyable is that they
contain uncopyable classes like File::IOFile and std::unique_ptr,
because the compiler makes such classes uncopyable automatically.
2017-08-22 16:40:34 +02:00
mimimi085181 576bf32ab2 Properly handle g_wiimotes_mutex again for reconnect on button press for real wiimotes
Sorry, i overlooked the mutex in PR  https://github.com/dolphin-emu/dolphin/pull/4949

This pr fixes issue 10434: https://bugs.dolphin-emu.org/issues/10434
2017-08-03 01:54:49 +02:00
mimimi085181 8b1e61b00a Change wiimote reconnect on button press code
This moves the reconnect logic into a single function, so the netplay code doesn't need to be written 2 times
2017-08-01 20:41:05 +02:00
Lioncash f6c21e002b General: Remove unnecessary semicolons 2017-07-30 16:39:53 -04:00
Léo Lam 1c33dfc787 Wiimote: Remove useless disconnections
ChangeWiimoteSource does not need to disconnect a Wiimote if it isn't
connected.
2017-07-23 15:52:15 +08:00
Léo Lam ee868e2362 Move the Wiimote connect code out of Host
I don't know who thought it would be a good idea to put the Wiimote
connect code as part of the Host interface, and have that called
from both the UI code and the core. And then hack around it by having
"force connect" events whenever Host_ConnectWiimote is called
from the core...
2017-07-23 15:47:32 +08:00
Léo Lam 90f8265497 Replace StringFromInt with std::to_string
Updated version of #47. Android should support to_string now that
we use a modern version of libc++ when building.
2017-07-05 13:49:33 +02:00
Tillmann Karras ad51311dbf Fix GCC warnings 2017-06-28 01:12:13 +01:00
Steven Newbury e9a696b160 Retry opening of wiimote channels on initial failure #5997
There seems to be a race condition between a peripheral device
connecting to the bluetooth controller and it being ready to use.
It's very short and it depends upon the controller, some appear to
connect synchronously and block until the device is ready, others
report the device upon discovery but do not allow communication straight
away. I don't know which is the correct behaviour, or whether it depends
on the peripheral, controller or both. Anyway, Dolphin waits for a
remote to appear and immediately attempts to open the communication
channels, this can fail because the device isn't ready yet, delay, try
again, and it works.

There are other (unlikely) chances the device is busy at random
moments after this initial race condition so it loops around try to
reconnect.

This was inspired by an earlier patch, see here:
https://bugs.dolphin-emu.org/issues/5997#note-20

I can confirm that it works perfectly for me on a bluetooth
controller where otherwise it's impossible to connect (Dell 380
Bluetooth 4.0).
2017-06-19 09:22:04 +01:00
Shawn Hoffman 1ada68aecd windows: fix handle leak when using continuous scan 2017-06-16 04:00:32 -07:00
Lioncash b676edd80c Core: include what you use
Eliminates a swath of indirectly included standard headers
2017-06-07 01:20:48 -04:00
Shawn Hoffman 2b0c600be5 windows: make IORead return number of valid bytes according to ReportID 2017-06-06 01:21:30 -07:00
Léo Lam f96ab66d31 Drop remnants of the plugin system 2017-05-19 19:13:16 +02:00
spycrab c3f435287e Clean up Wiimote* code (comments, casts, variable names) 2017-05-06 12:44:56 +02:00
spycrab 823dba47f5 Move shared Wiimote files into WiimoteCommon 2017-04-26 19:30:14 +02:00
Michael Maltese 4c5e283e75 WiimoteReal: init and destroy ScannerBackends in same thread
This fixes an error condition on macOS when HIDAPI calls
IOHIDManagerCreate and IOHIDManagerClose on different threads. The
error behavior is non-deterministic, but can cause EXC_BAD_ACCES and
kill the program.
2017-04-23 17:11:27 -07:00
Lioncash 552c0d8404 Common: Move byte swapping utilities into their own header
This moves all the byte swapping utilities into a header named Swap.h.

A dedicated header is much more preferable here due to the size of the
code itself. In general usage throughout the codebase, CommonFuncs.h was
generally only included for these functions anyway. These being in their
own header avoids dumping the lesser used utilities into scope. As well
as providing a localized area for more utilities related to byte
swapping in the future (should they be needed). This also makes it nicer
to identify which files depend on the byte swapping utilities in
particular.

Since this is a completely new header, moving the code uncovered a few
indirect includes, as well as making some other inclusions unnecessary.
2017-03-03 17:18:18 -05:00
Phil Christensen 2ed61b0ee1 C++ conformance fixes (MSVC /permissive-)
We (the Microsoft C++ team) use the dolphin project as part of our "Real world code" tests.
I noticed a few issues in windows specific code when building dolphin with the MSVC compiler
in its conformance mode (/permissive-).  For more information on /permissive- see our blog
https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/.

These changes are to address 3 different types of issues:

1) Use of qualified names in member declarations

    struct A {
        void A::f() { } // error C4596: illegal qualified name in member declaration
                        // remove redundant 'A::' to fix
    };

2) Binding a non-const reference to a temporary

    struct S{};
  
    // If arg is in 'in' parameter, then it should be made const.
    void func(S& arg){}
  
    int main() {
      //error C2664: 'void func(S &)': cannot convert argument 1 from 'S' to 'S &'
      //note: A non-const reference may only be bound to an lvalue
      func( S() );
   
      //Work around this by creating a local, and using it to call the function
      S s;
      func( s );
    }

3) Add missing #include <intrin.h>

Because of the workaround you are using in the code you will need to include
this.  This is because of changes in the libraries and not /permissive-
2017-02-15 20:37:04 -08:00
Michael Maltese 0bc40cacda No longer need to //clang-format off for Windows headers 2017-01-23 16:23:37 -08:00
Michael Maltese 713ec5ffd5 Add includes for building on Windows without PCH 2017-01-23 01:37:41 -08:00
Pringo 93bdab64fa Change "Wiimote" to "Wii Remote" in Logs 2016-11-03 17:58:28 -07:00
Léo Lam 4b47997cf8 Add ability to passthrough a Bluetooth adapter
This adds the ability to passthrough a whole Bluetooth adapter and skip
the majority of the Bluetooth emulation code. We use libusb to send HCI
commands, receive HCI events and transfer ACL data directly to the
first adapter that is found or to a specific adapter (if configured to)

This is possible because the Wii's Bluetooth module is actually just
a pretty standard Bluetooth adapter…

…except for two vendor-specific commands, for which replies are faked,
and also for the sync button. This adds a hotkey that works in the
exact same way as the sync button would on a Wii: it triggers an HCI
event, which emulated software interpret as a command to perform
a BT inquiry.

This commit also changes the UI code to expose passthrough mode
and WII_IPC_HLE to be a bit more thread safe (for the device map).
2016-10-03 23:06:23 +02:00
Léo Lam 2511bfdb8a WiimoteReal: Make the connected Wiimote check common
This moves the unordered_map used to store connected Wiimotes IDs to
WiimoteReal, and makes the ID insert/erase logic common so we don't
have to duplicate this code in scanner backends.
2016-10-03 11:43:05 +02:00
Léo Lam 222f7e6fc3 WiimoteReal: IOWin: Remove duplicate code
The Balance board detection logic is already implemented in a simpler
way in Wiimote::IsBalanceBoard() (since hidapi also needs it).

Therefore, IOWin now only needs to check if a device is a Wiimote.
2016-10-03 11:41:23 +02:00
Léo Lam 132ca8d02c WiimoteReal: hidapi: Add support for the Balance Board
A name change isn't enough for the DolphinBar; we have to actually
query the Wiimote to know if the Wiimote is a Balance Board.
2016-10-03 11:41:23 +02:00
Léo Lam d9a9e34994 WiimoteReal: Disconnect the Wiimote if IOWrite fails
This is intended to make reconnecting Wiimotes easier with a DolphinBar.
Unfortunately, this change isn't enough as it doesn't always catch
disconnections for Wiimotes connected with a DolphinBar.

But it's better than nothing and eventually a disconnection will be
detected when something tries to write to the Wiimote, instead of never.

There is no other solution as the DolphinBar always exposes 4 HIDs even
when the associated Wiimotes are not connected.

We could try to detect this using the fake input reports sent by the
DolphinBar, but this only works for the first HID (probably because of
a bug in the firmware?), so this method is not an option.
2016-10-03 11:41:23 +02:00
Léo Lam 53d553d2b0 WiimoteReal: Fix race between shutdown and FindWiimotes
If FindWiimotes() took more time than the UI shutting down, the scanner
would try connecting a Wiimote and sending an event to the UI code
long after it has shut down, which causes a segfault.

This fixes the race by ignoring any found Wiimotes during shutdown.

Normally this would have never happened, but it is possible with hidapi
since Wiimotes can be connected before Dolphin starts.
2016-10-03 11:41:23 +02:00
Léo Lam 843b030eda WiimoteReal: Add a hidapi IO implementation
Based on ca0c2efe7a. Credits go to flacs.
However, unlike the original commit, hidapi does not completely replace
the current implementations, so we can still connect Wiimotes with 1+2
(without pairing).

Also, it is only used on Linux and OS X for now. This removes the
advantage of having only one implementation but there is no other
choice: using hidapi on Windows is currently impossible because
hid_write() is implemented in a way that won't work with Wiimotes.

Additionally:
* We now check for the device name in addition to the PID/VID so we can
  support the Balance Board and maybe third-party Wiimotes too. This
  doesn't achieve anything with the DolphinBar but it does with hidraw.
* Added a check to not connect to the same device more than once.
2016-10-03 11:41:23 +02:00
shuffle2 8fcc3b04e0 Merge pull request #4227 from ligfx/clean_objc
Don't force compile everything as Objective-C++ on macOS
2016-10-02 19:42:04 -07:00
aldelaro5 f0aa9b3751 Reorganise a ton of logs level
Most of this commits changes performance decreasing logs from info to debug and also cleans up innacurate levels.
2016-10-01 15:50:28 -04:00
Michael Maltese cd19c9fa22 Don't force compile everything as Objective-C++ on macOS 2016-09-18 17:33:51 -07:00
Léo Lam dca22e08eb Use Common::Flag and Common::Event when possible
Replaces old and simple usages of std::atomic<bool> with Common::Flag
(which was introduced after the initial usage), so it's clear that
the variable is a flag and because Common::Flag is well tested.

This also replaces the ready logic in WiimoteReal with Common::Event
since it was basically just unnecessarily reimplementing Common::Event.
2016-08-10 16:08:15 +02:00
Léo Lam d2976086b6 WiimoteReal: Remove unsafe static_cast in IOLinux
Since we now support different scanner sources, g_wiimotes is not
guaranteed to only contain WiimoteLinux anymore.
This replaces the previous "already connected" check with one that
doesn't use g_wiimotes.
2016-07-27 14:20:26 +02:00
Léo Lam 9c02e327b7 WiimoteReal: Split WiimoteScannerDarwin
This moves out the HID code into a separate scanner.
2016-07-26 00:45:25 +02:00
Léo Lam 3305a923e1 WiimoteReal: Rename IONix to IOLinux
IONix.cpp really isn't for Unix, as the name would imply, but only
for Linux, so there is no reason to name it IONix.
2016-07-26 00:45:25 +02:00
Léo Lam 9455e2bca4 WiimoteReal: Change the scanner to support several backends
This makes WiimoteScanner support several scanner backends.

This adds a WiimoteScannerBackend base class, which scanner backends
derive from, and which allows backend-specific things to be moved out
of the common code.

Also removes IODummy which is not needed anymore.
2016-07-26 00:45:24 +02:00
Léo Lam 7c3a3ce46d Fix Wiimotes not reconnecting on button press
5.0-56 broke reconnecting a Wiimote on button press; this is because
data reporting was now always stopped for real Wii remotes on
disconnect, making it impossible to know a button was pressed in the
first place (to reconnect the Wiimote).

This semi-reverts to the previous behaviour, where data reporting is
never stopped.

(Also, control channels now go through WiimoteEmu, just like before,
to make sure some things are reset on disconnection.)

Hopefully fixes issue 9711.
2016-07-23 11:17:31 +02:00
Léo Lam 47859ad40c WiimoteReal: Call Update() less often
This moves back the WiimoteScanner:Update() call to where it originally
was, since according to a comment it is intended to be called only when
"when not looking for more Wiimotes", and calling it too often causes
the Bluetooth module to be loaded/unloaded a lot of times.
2016-07-12 16:50:41 +02:00
Léo Lam 80fc5e2814 WiimoteReal: Don't use a recursive mutex
This replaces a recursive mutex with a normal mutex.
2016-07-10 20:41:00 +02:00
Léo Lam c827fdd2b5 WiimoteReal: Don't block on refresh
This changes Refresh() to use the existing scanning thread to scan for
devices, instead of running the scan on the UI thread and blocking it.

Also makes the UI thread not block when Continuous Scanning is disabled
and removes duplicated code.

Should fix issue 8992.

Under the hood:
* The scanning thread is now always active, even when continuous
  scanning is disabled.
* The initialize code which waits for Wiimotes to be connected also
  uses the scanning thread instead of scanning on yet another thread.
* The scanning thread now always checks for disconnected devices, to
  avoid Dolphin thinking a Wiimote is still connected when it isn't. So
  we now check if we need new Wiimotes or a Balance Board at scan time.
2016-07-10 13:29:57 +02:00