boo/include/inputdev/DeviceToken.hpp

89 lines
2.3 KiB
C++
Raw Normal View History

2015-04-19 22:52:45 +00:00
#ifndef CDEVICETOKEN
#define CDEVICETOKEN
#include <string>
2015-08-18 18:00:24 +00:00
#include "DeviceBase.hpp"
#include "DeviceSignature.hpp"
2015-04-29 10:24:39 +00:00
namespace boo
{
2015-08-18 19:40:26 +00:00
class DeviceToken
2015-04-19 22:52:45 +00:00
{
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-08-18 19:40:26 +00:00
friend class DeviceBase;
DeviceBase* m_connectedDev;
2015-04-22 21:48:23 +00:00
2015-08-18 19:40:26 +00:00
friend class DeviceFinder;
2015-04-22 21:48:23 +00:00
inline void _deviceClose()
{
if (m_connectedDev)
m_connectedDev->_deviceDisconnected();
m_connectedDev = NULL;
}
2015-04-19 22:52:45 +00:00
public:
2015-08-18 19:40:26 +00:00
DeviceToken(const DeviceToken&) = delete;
DeviceToken(const DeviceToken&& 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)
{}
2015-08-18 19:40:26 +00:00
inline DeviceToken(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);}
2015-08-18 19:40:26 +00:00
inline DeviceBase* openAndGetDevice()
{
if (!m_connectedDev)
2015-08-18 19:40:26 +00:00
m_connectedDev = DeviceSignature::DeviceNew(*this);
return m_connectedDev;
}
2015-08-18 19:40:26 +00:00
inline bool operator ==(const DeviceToken& rhs) const
2015-04-24 00:24:15 +00:00
{return m_devPath == rhs.m_devPath;}
2015-08-18 19:40:26 +00:00
inline bool operator <(const DeviceToken& 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