Skip to content

Commit

Permalink
Switch public Device & System properties from wstrings to UTF-8 in an…
Browse files Browse the repository at this point in the history
…ticipation of possible multi-platform developments in the future
  • Loading branch information
noorus committed Nov 15, 2014
1 parent ce95e3d commit ea55c65
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 118 deletions.
14 changes: 7 additions & 7 deletions include/nil.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Nil {
DeviceID mID; //!< Unique identifier, only valid per session
Status mStatus; //!< Current status
Status mSavedStatus; //!< Status backup when updating
String mName; //!< Device name
utf8String mName; //!< Device name
Type mType; //!< Device type
System* mSystem; //!< My owner
DeviceInstance* mInstance; //!< My instance, if created
Expand All @@ -76,7 +76,7 @@ namespace Nil {
virtual const Handler getHandler() const = 0; //!< Get my handler
virtual const Type getType() const; //!< Get my type
virtual const Status getStatus() const; //!< Get my status
virtual const String& getName() const; //!< Get my name
virtual const utf8String& getName() const; //!< Get my name
virtual System* getSystem(); //!< Get my owning system
virtual const bool isDisconnectFlagged() const; //!< Am I flagged for disconnection?
};
Expand All @@ -103,9 +103,9 @@ namespace Nil {
friend class System;
private:
HANDLE mRawHandle; //!< The internal raw input device handle
String mRawPath; //!< The full input device raw path
wideString mRawPath; //!< The full input device raw path

RawInputDevice( System* system, DeviceID id, HANDLE rawHandle, String& rawPath );
RawInputDevice( System* system, DeviceID id, HANDLE rawHandle, wideString& rawPath );
public:
virtual ~RawInputDevice();
virtual const Handler getHandler() const;
Expand All @@ -115,7 +115,7 @@ namespace Nil {
virtual const HANDLE getRawHandle() const;

//! Get the RawInput device path.
virtual const String& getRawPath() const;
virtual const wideString& getRawPath() const;

//! Get the RawInput device information structure.
virtual const RID_DEVICE_INFO* getRawInfo() const;
Expand Down Expand Up @@ -622,9 +622,9 @@ namespace Nil {
void mapKeyboard( HANDLE handle, RawInputKeyboard* keyboard );
void unmapKeyboard( HANDLE handle );
//! \b Internal My PnP plug callback.
virtual void onPnPPlug( const GUID& deviceClass, const String& devicePath );
virtual void onPnPPlug( const GUID& deviceClass, const wideString& devicePath );
//! \b Internal My PnP unplug callback.
virtual void onPnPUnplug( const GUID& deviceClass, const String& devicePath );
virtual void onPnPUnplug( const GUID& deviceClass, const wideString& devicePath );
//! \b Internal My Raw arrival callback.
virtual void onRawArrival( HANDLE handle );
//! \b Internal My Raw mouse input callback.
Expand Down
16 changes: 8 additions & 8 deletions include/nilException.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Nil {
{
public:
uint32_t code;
String description;
wideString description;
};

//! \class Exception
Expand All @@ -30,28 +30,28 @@ namespace Nil {
Exception();

Type mType; //!< Exception type
String mDescription; //!< Exception description
String mSource; //!< Exception source
mutable String mFullDescription; //!< Full, extended description
wideString mDescription; //!< Exception description
wideString mSource; //!< Exception source
mutable wideString mFullDescription; //!< Full, extended description
mutable utf8String mUTF8Description; //!< Full, extended description in UTF-8
variant<WinAPIError> mAdditional; //!< \b Internal Additional exception data

//! \b Internal Handle additional exception data for WinAPI/DI exceptions.
void handleAdditional( HRESULT hr = 0 );
public:
//! Generic constructor.
Exception( const String& description, Type type = Generic );
Exception( const wideString& description, Type type = Generic );

//! Constructor with source.
Exception( const String& description, const String& source,
Exception( const wideString& description, const wideString& source,
Type type = Generic );

//! Constructor with source and a WinAPI/DirectInput error code.
Exception( const String& description, const String& source,
Exception( const wideString& description, const wideString& source,
HRESULT hr, Type type = Generic );

//! Get the full, extended description of the exception.
virtual const String& getFullDescription() const;
virtual const wideString& getFullDescription() const;

//! Get the std::exception compatible exception description.
virtual const char* what() const throw();
Expand Down
24 changes: 12 additions & 12 deletions include/nilHID.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ namespace Nil {
class HIDRecord
{
private:
String mPath; //!< Raw device path
wideString mPath; //!< Raw device path
uint16_t mVendorID; //!< USB Vendor ID for this device
uint16_t mProductID; //!< USB Product ID for this device
uint32_t mIdentifier; //!< Combined HID identifier
HIDP_CAPS mCapabilities; //!< HID API capabilities
String mName; //!< Device name
String mManufacturer; //!< Device manufacturer
String mSerialNumber; //!< Device serial number
utf8String mName; //!< Device name
utf8String mManufacturer; //!< Device manufacturer
utf8String mSerialNumber; //!< Device serial number
bool mIsXInput; //!< Am I an XInput device?
bool mIsRDP; //!< Am I a Remote Desktop device?

Expand All @@ -42,7 +42,7 @@ namespace Nil {
//! Constructor.
//! \param path Full system path to the device.
//! \param handle Device handle.
HIDRecord( const String& path, HANDLE handle );
HIDRecord( const wideString& path, HANDLE handle );

//! Am I a Remote Desktop device?
bool isRDP() const;
Expand All @@ -57,18 +57,18 @@ namespace Nil {
bool isLogitech() const;

//! Get full device path.
const String& getPath() const;
const wideString& getPath() const;

//! Get device name.
const String& getName() const;
const utf8String& getName() const;

//! Get manufacturer name.
//! Can be empty.
const String& getManufacturer() const;
const utf8String& getManufacturer() const;

//! Get serial number.
//! Can be empty.
const String& getSerialNumber() const;
const utf8String& getSerialNumber() const;

//! Get USB usage page ID.
uint16_t getUsagePage() const;
Expand Down Expand Up @@ -97,14 +97,14 @@ namespace Nil {
HIDRecordList mRecords; //!< Records container

//! \b Internal My PnP plug callback.
virtual void onPnPPlug( const GUID& deviceClass, const String& devicePath );
virtual void onPnPPlug( const GUID& deviceClass, const wideString& devicePath );

//! \b Internal My PnP unplug callback.
virtual void onPnPUnplug( const GUID& deviceClass, const String& devicePath );
virtual void onPnPUnplug( const GUID& deviceClass, const wideString& devicePath );

//! \b Internal Process an existing device.
void processDevice( SP_DEVICE_INTERFACE_DATA& interfaceData,
SP_DEVINFO_DATA& deviceData, const String& devicePath );
SP_DEVINFO_DATA& deviceData, const wideString& devicePath );

//! \b Internal Initialization stuff
void initialize();
Expand Down
8 changes: 4 additions & 4 deletions include/nilPnP.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ namespace Nil {
public:
//! Plug-n-Play device plug event.
virtual void onPnPPlug( const GUID& deviceClass,
const String& devicePath ) = 0;
const wideString& devicePath ) = 0;

//! Plug-n-Play device unplug event.
virtual void onPnPUnplug( const GUID& deviceClass,
const String& devicePath ) = 0;
const wideString& devicePath ) = 0;
};

//! A list of Plug-and-Play event listeners.
Expand Down Expand Up @@ -86,11 +86,11 @@ namespace Nil {

//! \b Internal Handle interface arrival.
void handleInterfaceArrival( const GUID& deviceClass,
const String& devicePath );
const wideString& devicePath );

//! \b Internal Handle interface removal.
void handleInterfaceRemoval( const GUID& deviceClass,
const String& devicePath );
const wideString& devicePath );

//! \b Internal Handle raw device arrival.
void handleRawArrival( HANDLE handle );
Expand Down
2 changes: 1 addition & 1 deletion include/nilTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Nil {
# define NIL_REAL_MINUSONE -1.0f //!< Real number minus one constant.

typedef std::string utf8String; //!< UTF-8 string type.
typedef std::wstring String; //!< Wide string type.
typedef std::wstring wideString; //!< Wide string type.

enum Cooperation: int {
Cooperation_Foreground,
Expand Down
8 changes: 4 additions & 4 deletions include/nilUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ namespace Nil {
//! 32-bit Fowler/Noll/Vo-1a hash function.
extern uint32_t fnv_32a_buf( void* buf, size_t len, uint32_t hashval );
//! Cleanup a device name.
extern inline String cleanupName( String name ) throw();
extern inline utf8String cleanupName( utf8String name ) throw();
//! UTF-8 to wide string conversion.
extern inline String utf8ToWide( const utf8String& in ) throw();
extern inline wideString utf8ToWide( const utf8String& in ) throw();
//! Wide string to UTF-8 conversion.
extern inline utf8String wideToUtf8( const String& in ) throw();
extern inline utf8String wideToUtf8( const wideString& in ) throw();
//! Auto-generate a name for a nameless device.
String generateName( Device::Type deviceType, int index ) throw();
utf8String generateName( Device::Type deviceType, int index ) throw();
}

//! @}
Expand Down
2 changes: 1 addition & 1 deletion src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace Nil {
return mSavedStatus;
}

const String& Device::getName() const
const utf8String& Device::getName() const
{
return mName;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DirectInputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Nil {
mInstanceID( instance->guidInstance )
{
// Only replace auto-generated name if fetched one isn't empty
String tmpName = Util::cleanupName( instance->tszInstanceName );
utf8String tmpName = Util::cleanupName( Util::wideToUtf8( instance->tszInstanceName ) );
if ( !tmpName.empty() )
mName = tmpName;
}
Expand Down
4 changes: 2 additions & 2 deletions src/EventMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ namespace Nil {
}

void EventMonitor::handleInterfaceArrival( const GUID& deviceClass,
const String& devicePath )
const wideString& devicePath )
{
for ( auto listener : mPnPListeners )
listener->onPnPPlug( deviceClass, devicePath );
}

void EventMonitor::handleInterfaceRemoval( const GUID& deviceClass,
const String& devicePath )
const wideString& devicePath )
{
for ( auto listener : mPnPListeners )
listener->onPnPUnplug( deviceClass, devicePath );
Expand Down
8 changes: 4 additions & 4 deletions src/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ namespace Nil {
// Stub
}

Exception::Exception( const String& description, Type type ):
Exception::Exception( const wideString& description, Type type ):
mDescription( description ), mType( type )
{
handleAdditional();
}

Exception::Exception( const String& description, const String& source, Type type ):
Exception::Exception( const wideString& description, const wideString& source, Type type ):
mDescription( description ), mSource( source ), mType( type )
{
handleAdditional();
}

Exception::Exception( const String& description, const String& source, HRESULT hr, Type type ):
Exception::Exception( const wideString& description, const wideString& source, HRESULT hr, Type type ):
mDescription( description ), mSource( source ), mType( type )
{
handleAdditional( hr );
Expand Down Expand Up @@ -108,7 +108,7 @@ namespace Nil {
}
}

const String& Exception::getFullDescription() const
const wideString& Exception::getFullDescription() const
{
if ( mFullDescription.empty() )
{
Expand Down
6 changes: 3 additions & 3 deletions src/HIDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Nil {
return mRecords;
}

void HIDManager::onPnPPlug( const GUID& deviceClass, const String& devicePath )
void HIDManager::onPnPPlug( const GUID& deviceClass, const wideString& devicePath )
{
if ( deviceClass != g_HIDInterfaceGUID )
return;
Expand All @@ -32,7 +32,7 @@ namespace Nil {
}
}

void HIDManager::onPnPUnplug( const GUID& deviceClass, const String& devicePath )
void HIDManager::onPnPUnplug( const GUID& deviceClass, const wideString& devicePath )
{
if ( deviceClass != g_HIDInterfaceGUID )
return;
Expand All @@ -47,7 +47,7 @@ namespace Nil {
}

void HIDManager::processDevice( SP_DEVICE_INTERFACE_DATA& interfaceData,
SP_DEVINFO_DATA& deviceData, const String& devicePath )
SP_DEVINFO_DATA& deviceData, const wideString& devicePath )
{
if ( interfaceData.InterfaceClassGuid != g_HIDInterfaceGUID )
return;
Expand Down
16 changes: 8 additions & 8 deletions src/HIDRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Nil {

HIDRecord::HIDRecord( const String& path, HANDLE handle ):
HIDRecord::HIDRecord( const wideString& path, HANDLE handle ):
mPath( path ), mIsXInput( false ), mIsRDP( false )
{
HIDD_ATTRIBUTES attributes = { sizeof( HIDD_ATTRIBUTES ) };
Expand All @@ -25,11 +25,11 @@ namespace Nil {

wchar_t buffer[256];
if ( HidD_GetProductString( handle, &buffer, 256 ) )
mName = Util::cleanupName( buffer );
mName = Util::cleanupName( Util::wideToUtf8( buffer ) );
if ( HidD_GetManufacturerString( handle, &buffer, 256 ) )
mManufacturer = Util::cleanupName( buffer );
mManufacturer = Util::cleanupName( Util::wideToUtf8( buffer ) );
if ( HidD_GetSerialNumberString( handle, &buffer, 256 ) )
mSerialNumber = buffer;
mSerialNumber = Util::wideToUtf8( buffer );

identify();
}
Expand Down Expand Up @@ -81,22 +81,22 @@ namespace Nil {
return mCapabilities.Usage;
}

const String& HIDRecord::getPath() const
const wideString& HIDRecord::getPath() const
{
return mPath;
}

const String& HIDRecord::getManufacturer() const
const utf8String& HIDRecord::getManufacturer() const
{
return mManufacturer;
}

const String& HIDRecord::getName() const
const utf8String& HIDRecord::getName() const
{
return mName;
}

const String& HIDRecord::getSerialNumber() const
const utf8String& HIDRecord::getSerialNumber() const
{
return mSerialNumber;
}
Expand Down
6 changes: 3 additions & 3 deletions src/RawInputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Nil {
// RawInputDevice class

RawInputDevice::RawInputDevice( System* system, DeviceID id,
HANDLE rawHandle, String& rawPath ):
HANDLE rawHandle, wideString& rawPath ):
RawInputDeviceInfo( rawHandle ),
Device( system, id, rawInfoResolveType() ),
mRawHandle( rawHandle ), mRawPath( rawPath )
Expand All @@ -59,7 +59,7 @@ namespace Nil {
if ( HidD_GetProductString( deviceHandle, &buffer, 256 ) )
{
// Only replace auto-generated name if fetched one isn't empty
String tmpName = Util::cleanupName( buffer );
utf8String tmpName = Util::cleanupName( Util::wideToUtf8( buffer ) );
if ( !tmpName.empty() )
mName = tmpName;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace Nil {
return mRawHandle;
}

const String& RawInputDevice::getRawPath() const
const wideString& RawInputDevice::getRawPath() const
{
return mRawPath;
}
Expand Down
Loading

0 comments on commit ea55c65

Please sign in to comment.