boo/include/inputdev/CDeviceToken.hpp

64 lines
1.7 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
{
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(CDeviceToken&&) = default;
2015-04-24 00:24:15 +00:00
inline CDeviceToken(unsigned vid, unsigned pid, const char* vname, const char* pname, const char* path)
: m_vendorId(vid), m_productId(pid), m_devPath(path), m_connectedDev(NULL)
{
if (vname)
m_vendorName = vname;
if (pname)
m_productName = pname;
}
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;}
inline bool isDeviceOpen() const {return m_connectedDev;}
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