Skip to content

Commit

Permalink
Changed Device to DeviceEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
noorus committed Jan 12, 2014
1 parent 514dc14 commit 7dc20eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
14 changes: 7 additions & 7 deletions include/nil.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ namespace nil {
virtual const char* what() const throw();
};

//! \class Device
//! Input device instance.
class Device {
//! \class DeviceEntry
//! Input device information entry.
class DeviceEntry {
friend class System;
public:
enum Type {
Expand All @@ -97,16 +97,16 @@ namespace nil {
} mXInput;
void setState( State state );
void makeXInput( int index );
Device( Type type, GUID productID, GUID deviceID );
~Device();
DeviceEntry( Type type, GUID productID, GUID deviceID );
~DeviceEntry();
public:
const Type getType();
const State getState();
const GUID getProductID();
const GUID getDeviceID();
};

typedef list<Device*> DeviceList;
typedef list<DeviceEntry*> DeviceEntryList;

//! \class PnPListener
//! Plug-n-Play event listener.
Expand Down Expand Up @@ -145,7 +145,7 @@ namespace nil {
HINSTANCE mInstance; //!< Host application instance handle
HWND mWindow; //!< Host application window handle
PnPMonitor* mMonitor; //!< Our Plug-n-Play event monitor
DeviceList mDevices; //!< List of current devices
DeviceEntryList mEntries; //!< List of possible devices
bool mInitializedCOM; //!< Are we responsible for freeing COM?
void refreshDevices();
void identifyXInputDevices();
Expand Down
20 changes: 10 additions & 10 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

namespace nil {

Device::Device( Type type, GUID productID, GUID deviceID ):
DeviceEntry::DeviceEntry( Type type, GUID productID, GUID deviceID ):
mType( type ), mProductID( productID ), mDeviceID( deviceID ),
mState( State_Disconnected )
{
wprintf_s( L"Device:\r\n ProductID: %s\r\n DeviceID: %s\r\n",
wprintf_s( L"DeviceEntry:\r\n ProductID: %s\r\n DeviceID: %s\r\n",
guidToStr( mProductID ).c_str(),
guidToStr( mDeviceID ).c_str() );
}

void Device::setState( State state )
void DeviceEntry::setState( State state )
{
mState = state;
}

void Device::makeXInput( int index )
void DeviceEntry::makeXInput( int index )
{
mType = Device_XInput;
mXInput.deviceID = index;
Expand All @@ -26,29 +26,29 @@ namespace nil {
mXInput.deviceID );
}

const Device::Type Device::getType()
const DeviceEntry::Type DeviceEntry::getType()
{
return mType;
}

const Device::State Device::getState()
const DeviceEntry::State DeviceEntry::getState()
{
return mState;
}

const GUID Device::getProductID()
const GUID DeviceEntry::getProductID()
{
return mProductID;
}

const GUID Device::getDeviceID()
const GUID DeviceEntry::getDeviceID()
{
return mDeviceID;
}

Device::~Device()
DeviceEntry::~DeviceEntry()
{
wprintf_s( L"~Device:\r\n ProductID: %s\r\n DeviceID: %s\r\n",
wprintf_s( L"~DeviceEntry:\r\n ProductID: %s\r\n DeviceID: %s\r\n",
guidToStr( mProductID ).c_str(),
guidToStr( mDeviceID ).c_str() );
}
Expand Down
22 changes: 11 additions & 11 deletions src/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace nil {

void System::refreshDevices()
{
mDevices.clear();
mEntries.clear();

HRESULT hr = mDirectInput->EnumDevices( DI8DEVCLASS_ALL,
diEnumCallback, this, DIEDFL_ATTACHEDONLY );
Expand Down Expand Up @@ -129,14 +129,14 @@ namespace nil {
|| deviceType == DI8DEVTYPE_FLIGHT
|| deviceType == DI8DEVTYPE_1STPERSON )
{
Device* device = new Device(
Device::Device_DirectInput,
DeviceEntry* device = new DeviceEntry(
DeviceEntry::Device_DirectInput,
instance->guidProduct,
instance->guidInstance );

device->setState( Device::State_Current );
device->setState( DeviceEntry::State_Current );

system->mDevices.push_back( device );
system->mEntries.push_back( device );
}

return DIENUM_CONTINUE;
Expand Down Expand Up @@ -203,13 +203,13 @@ namespace nil {

unsigned long identifier = MAKELONG( vid, pid );

for ( Device* device : mDevices )
for ( DeviceEntry* entry : mEntries )
{
if ( device->getType() == Device::Device_XInput )
if ( entry->getType() == DeviceEntry::Device_XInput )
continue;
if ( device->getProductID().Data1 == identifier )
if ( entry->getProductID().Data1 == identifier )
{
device->makeXInput( xinputIndex );
entry->makeXInput( xinputIndex );
xinputIndex++;
}
}
Expand All @@ -232,8 +232,8 @@ namespace nil {

System::~System()
{
for ( Device* device : mDevices )
delete device;
for ( DeviceEntry* entry : mEntries )
delete entry;

SAFE_DELETE( mMonitor );
SAFE_RELEASE( mDirectInput );
Expand Down

0 comments on commit 7dc20eb

Please sign in to comment.