boo/include/inputdev/CDeviceToken.hpp

89 lines
2.4 KiB
C++
Raw Normal View History

2015-04-19 22:52:45 +00:00
#ifndef CDEVICETOKEN
#define CDEVICETOKEN
#include <string>
#include "CDeviceBase.hpp"
#include "SDeviceSignature.hpp"
2015-04-29 10:24:39 +00:00
namespace boo
{
2015-04-19 22:52:45 +00:00
class CDeviceToken
{
public:
enum TDeviceType
{
DEVTYPE_NONE = 0,
DEVTYPE_USB = 1,
DEVTYPE_BLUETOOTH = 2,
DEVTYPE_GENERICHID = 3
};
private:
TDeviceType m_devType;
unsigned m_vendorId;
unsigned m_productId;
std::string m_vendorName;
std::string m_productName;
2015-04-24 00:24:15 +00:00
std::string m_devPath;
2015-04-19 22:52:45 +00:00
2015-04-22 21:48:23 +00:00
friend class CDeviceBase;
CDeviceBase* m_connectedDev;
2015-04-22 21:48:23 +00:00
friend class CDeviceFinder;
inline void _deviceClose()
{
if (m_connectedDev)
m_connectedDev->_deviceDisconnected();
m_connectedDev = NULL;
}
2015-04-19 22:52:45 +00:00
public:
2015-04-22 21:48:23 +00:00
CDeviceToken(const CDeviceToken&) = delete;
CDeviceToken(const CDeviceToken&& other)
: m_devType(other.m_devType),
m_vendorId(other.m_vendorId),
m_productId(other.m_productId),
m_vendorName(other.m_vendorName),
m_productName(other.m_productName),
m_devPath(other.m_devPath),
m_connectedDev(other.m_connectedDev)
{}
inline CDeviceToken(enum TDeviceType devType, unsigned vid, unsigned pid, const char* vname, const char* pname, const char* path)
: m_devType(devType),
m_vendorId(vid),
m_productId(pid),
m_devPath(path),
m_connectedDev(NULL)
{
if (vname)
m_vendorName = vname;
if (pname)
m_productName = pname;
}
inline TDeviceType getDeviceType() const {return m_devType;}
inline unsigned getVendorId() const {return m_vendorId;}
inline unsigned getProductId() const {return m_productId;}
inline const std::string& getVendorName() const {return m_vendorName;}
inline const std::string& getProductName() const {return m_productName;}
2015-04-24 00:24:15 +00:00
inline const std::string& getDevicePath() const {return m_devPath;}
2015-05-03 06:40:20 +00:00
inline bool isDeviceOpen() const {return (m_connectedDev != NULL);}
inline CDeviceBase* openAndGetDevice()
{
if (!m_connectedDev)
m_connectedDev = SDeviceSignature::DeviceNew(*this);
return m_connectedDev;
}
inline bool operator ==(const CDeviceToken& rhs) const
2015-04-24 00:24:15 +00:00
{return m_devPath == rhs.m_devPath;}
inline bool operator <(const CDeviceToken& rhs) const
2015-04-24 00:24:15 +00:00
{return m_devPath < rhs.m_devPath;}
2015-04-19 22:52:45 +00:00
};
2015-04-29 10:24:39 +00:00
}
2015-04-19 22:52:45 +00:00
#endif // CDEVICETOKEN