Ejemplo n.º 1
0
//-------------------------------------------------------------------//
JoyStickInfoList LinuxJoyStick::_scanJoys()
{
	JoyStickInfoList joys;

	//Search through all of the event devices.. and identify which ones are joysticks
	//xxx move this to InputManager, as it can also scan all other events
	for(int i = 0; i < OIS_MAX_DEVICES; ++i )
	{
		std::stringstream s;
		s << "/dev/input/event" << i;

		int fd = open( s.str().c_str(), O_RDONLY |O_NONBLOCK );
	
		try
		{
			JoyStickInfo js;
			if( EventUtils::isJoyStick(fd, js) )
				joys.push_back(js);
			else
				close(fd);
		}
		catch(...)
		{
			close(fd);
			break;
		}
	}

	return joys;
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------//
JoyStickInfoList LinuxJoyStick::_scanJoys()
{
    JoyStickInfoList joys;

    //Search through all of the event devices.. and identify which ones are joysticks
    //xxx move this to InputManager, as it can also scan all other events
    for(int i = 0; i < 64; ++i )
    {
        stringstream s;
        s << "/dev/input/event" << i;
        int fd = open( s.str().c_str(), O_RDWR |O_NONBLOCK );
        if(fd == -1)
            continue;

        #ifdef OIS_LINUX_JOY_DEBUG
          cout << "Opening " << s.str() << "..." << endl;
        #endif
        try
        {
            JoyStickInfo js;
            if( EventUtils::isJoyStick(fd, js) )
            {
                joys.push_back(js);
                #ifdef OIS_LINUX_JOY_DEBUG
                  cout << "=> Joystick added to list." << endl;
                #endif
            }
            else
            {
                #ifdef OIS_LINUX_JOY_DEBUG
                  cout << "=> Not a joystick." << endl;
                #endif
                close(fd);
            }
        }
        catch(...)
        {
            #ifdef OIS_LINUX_JOY_DEBUG
              cout << "Exception caught!!" << endl;
            #endif
            close(fd);
        }
    }

    return joys;
}
Ejemplo n.º 3
0
//--------------------------------------------------------------------------------------------------//
void Win32JoyStick::CheckXInputDevices(JoyStickInfoList &joys)
{
    IWbemLocator*           pIWbemLocator  = NULL;
    IEnumWbemClassObject*   pEnumDevices   = NULL;
    IWbemClassObject*       pDevices[20]   = {0};
    IWbemServices*          pIWbemServices = NULL;
    BSTR                    bstrNamespace  = NULL;
    BSTR                    bstrDeviceID   = NULL;
    BSTR                    bstrClassName  = NULL;
    DWORD                   uReturned      = 0;
    bool                    bIsXinputDevice= false;
	DWORD                   iDevice        = 0;
	int                     xDevice        = 0;
    VARIANT                 var;
    HRESULT                 hr;

	if(joys.size() == 0)
		return;

    // CoInit if needed
    hr = CoInitialize(NULL);
    bool bCleanupCOM = SUCCEEDED(hr);

    // Create WMI
    hr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IWbemLocator), (LPVOID*)&pIWbemLocator);
    if( FAILED(hr) || pIWbemLocator == NULL )
        goto LCleanup;

    bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );
	if( bstrNamespace == NULL )
		goto LCleanup;

    bstrClassName = SysAllocString( L"Win32_PNPEntity" );
	if( bstrClassName == NULL )
		goto LCleanup;

    bstrDeviceID  = SysAllocString( L"DeviceID" );
	if( bstrDeviceID == NULL )
		goto LCleanup;
    
    // Connect to WMI 
    hr = pIWbemLocator->ConnectServer( bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices );
    if( FAILED(hr) || pIWbemServices == NULL )
        goto LCleanup;

    // Switch security level to IMPERSONATE. 
    CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );                    

    hr = pIWbemServices->CreateInstanceEnum( bstrClassName, 0, NULL, &pEnumDevices ); 
    if( FAILED(hr) || pEnumDevices == NULL )
        goto LCleanup;

    // Loop over all devices
    for( ;; )
    {
        // Get 20 at a time
        hr = pEnumDevices->Next(5000, 20, pDevices, &uReturned);
        if( FAILED(hr) )
            goto LCleanup;

        if( uReturned == 0 )
            break;

        for(iDevice = 0; iDevice < uReturned; iDevice++)
        {
            // For each device, get its device ID
            hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL);
            if(SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL)
            {
                // Check if the device ID contains "IG_".  If it does, then it's an XInput device - This information can not be found from DirectInput 
                if(wcsstr(var.bstrVal, L"IG_"))
                {
                    // If it does, then get the VID/PID from var.bstrVal
                    DWORD dwPid = 0, dwVid = 0;
                    WCHAR* strVid = wcsstr( var.bstrVal, L"VID_" );
                    if(strVid && swscanf_s( strVid, L"VID_%4X", &dwVid ) != 1)
						dwVid = 0;

                    WCHAR* strPid = wcsstr( var.bstrVal, L"PID_" );
                    if(strPid && swscanf_s( strPid, L"PID_%4X", &dwPid ) != 1)
                        dwPid = 0;

                    // Compare the VID/PID to the DInput device
                    DWORD dwVidPid = MAKELONG(dwVid, dwPid);
					for(JoyStickInfoList::iterator i = joys.begin(); i != joys.end(); ++i)
					{
						if(dwVidPid == i->productGuid.Data1)
						{
							i->isXInput = true;
							i->xInputDev = xDevice;
						}
					}

					if(joys.size() == 0)
						goto LCleanup;
                }
            }

            SAFE_RELEASE(pDevices[iDevice]);
        }
    }

LCleanup:
    if(bstrNamespace)
        SysFreeString(bstrNamespace);

    if(bstrDeviceID)
        SysFreeString(bstrDeviceID);

    if(bstrClassName)
        SysFreeString(bstrClassName);

    for(iDevice=0; iDevice < 20; iDevice++)
        SAFE_RELEASE(pDevices[iDevice]);

    SAFE_RELEASE(pEnumDevices);
    SAFE_RELEASE(pIWbemLocator);
    SAFE_RELEASE(pIWbemServices);

    if(bCleanupCOM)
        CoUninitialize();
}
Ejemplo n.º 4
0
//-------------------------------------------------------------------//
void LinuxJoyStick::_clearJoys(JoyStickInfoList &joys)
{
    for(JoyStickInfoList::iterator i = joys.begin(); i != joys.end(); ++i)
        close(i->joyFileD);
    joys.clear();
}