Fixed Mac OS X build
authorSam Lantinga <slouken@libsdl.org>
Wed, 15 Aug 2018 19:53:24 -0700
changeset 12110c52772e46ee2
parent 12109 00411ca61edb
child 12111 6c1ae9f1effb
Fixed Mac OS X build
src/joystick/hidapi/SDL_hidapijoystick.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Wed Aug 15 19:53:22 2018 -0700
     1.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Wed Aug 15 19:53:24 2018 -0700
     1.3 @@ -103,7 +103,7 @@
     1.4      Uint32 m_unLastDetect;
     1.5  
     1.6  #if defined(__WIN32__)
     1.7 -	SDL_threadID m_nThreadID;
     1.8 +    SDL_threadID m_nThreadID;
     1.9      WNDCLASSEXA m_wndClass;
    1.10      HWND m_hwndMsg;
    1.11      HDEVNOTIFY m_hNotify;
    1.12 @@ -158,7 +158,7 @@
    1.13          switch (wParam) {
    1.14          case DBT_DEVICEARRIVAL:
    1.15              if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
    1.16 -				SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
    1.17 +                SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
    1.18              }
    1.19              break;
    1.20          }
    1.21 @@ -171,10 +171,11 @@
    1.22  
    1.23  
    1.24  #if defined(__MACOSX__)
    1.25 -static void CallbackIOServiceFUNC(void *context, io_iterator_t portIterator)
    1.26 +static void CallbackIOServiceFunc(void *context, io_iterator_t portIterator)
    1.27  {
    1.28      /* Must drain the iterator, or we won't receive new notifications */
    1.29 -    while ((io_object_t entry = IOIteratorNext(portIterator)) != NULL) {
    1.30 +    io_object_t entry;
    1.31 +    while ((entry = IOIteratorNext(portIterator)) != 0) {
    1.32          IOObjectRelease(entry);
    1.33          *(SDL_bool*)context = SDL_TRUE;
    1.34      }
    1.35 @@ -200,21 +201,21 @@
    1.36      RegisterClassExA(&SDL_HIDAPI_discovery.m_wndClass);
    1.37      SDL_HIDAPI_discovery.m_hwndMsg = CreateWindowExA(0, "ControllerDetect", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
    1.38  
    1.39 -	{
    1.40 -		DEV_BROADCAST_DEVICEINTERFACE_A devBroadcast;
    1.41 -		SDL_memset( &devBroadcast, 0x0, sizeof( devBroadcast ) );
    1.42 +    {
    1.43 +        DEV_BROADCAST_DEVICEINTERFACE_A devBroadcast;
    1.44 +        SDL_memset( &devBroadcast, 0x0, sizeof( devBroadcast ) );
    1.45  
    1.46 -		devBroadcast.dbcc_size = sizeof( devBroadcast );
    1.47 -		devBroadcast.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    1.48 -		devBroadcast.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
    1.49 +        devBroadcast.dbcc_size = sizeof( devBroadcast );
    1.50 +        devBroadcast.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    1.51 +        devBroadcast.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
    1.52  
    1.53 -		/* DEVICE_NOTIFY_ALL_INTERFACE_CLASSES is important, makes GUID_DEVINTERFACE_USB_DEVICE ignored,
    1.54 -		 * but that seems to be necessary to get a notice after each individual usb input device actually
    1.55 -		 * installs, rather than just as the composite device is seen.
    1.56 -		 */
    1.57 -		SDL_HIDAPI_discovery.m_hNotify = RegisterDeviceNotification( SDL_HIDAPI_discovery.m_hwndMsg, &devBroadcast, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES );
    1.58 -		SDL_HIDAPI_discovery.m_bCanGetNotifications = ( SDL_HIDAPI_discovery.m_hNotify != 0 );
    1.59 -	}
    1.60 +        /* DEVICE_NOTIFY_ALL_INTERFACE_CLASSES is important, makes GUID_DEVINTERFACE_USB_DEVICE ignored,
    1.61 +         * but that seems to be necessary to get a notice after each individual usb input device actually
    1.62 +         * installs, rather than just as the composite device is seen.
    1.63 +         */
    1.64 +        SDL_HIDAPI_discovery.m_hNotify = RegisterDeviceNotification( SDL_HIDAPI_discovery.m_hwndMsg, &devBroadcast, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES );
    1.65 +        SDL_HIDAPI_discovery.m_bCanGetNotifications = ( SDL_HIDAPI_discovery.m_hNotify != 0 );
    1.66 +    }
    1.67  #endif /* __WIN32__ */
    1.68  
    1.69  #if defined(__MACOSX__)
    1.70 @@ -225,9 +226,10 @@
    1.71  
    1.72              /* Note: IOServiceAddMatchingNotification consumes the reference to matchingDict */
    1.73              io_iterator_t portIterator = 0;
    1.74 +            io_object_t entry;
    1.75              if (IOServiceAddMatchingNotification(SDL_HIDAPI_discovery.m_notificationPort, kIOMatchedNotification, matchingDict, CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator) == 0) {
    1.76                  /* Must drain the existing iterator, or we won't receive new notifications */
    1.77 -                while (io_object_t entry = IOIteratorNext(portIterator)) {
    1.78 +                while ((entry = IOIteratorNext(portIterator)) != 0) {
    1.79                      IOObjectRelease(entry);
    1.80                  }
    1.81              } else {
    1.82 @@ -240,9 +242,10 @@
    1.83  
    1.84              /* Note: IOServiceAddMatchingNotification consumes the reference to matchingDict */
    1.85              io_iterator_t portIterator = 0;
    1.86 +            io_object_t entry;
    1.87              if (IOServiceAddMatchingNotification(SDL_HIDAPI_discovery.m_notificationPort, kIOMatchedNotification, matchingDict, CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator) == 0) {
    1.88                  /* Must drain the existing iterator, or we won't receive new notifications */
    1.89 -                while (io_object_t entry = IOIteratorNext(portIterator)) {
    1.90 +                while ((entry = IOIteratorNext(portIterator)) != 0) {
    1.91                      IOObjectRelease(entry);
    1.92                  }
    1.93              } else {
    1.94 @@ -803,6 +806,8 @@
    1.95  {
    1.96      int i;
    1.97  
    1.98 +    HIDAPI_ShutdownDiscovery();
    1.99 +
   1.100      while (SDL_HIDAPI_devices) {
   1.101          HIDAPI_DelDevice(SDL_HIDAPI_devices, SDL_FALSE);
   1.102      }