2015-04-19 22:52:45 +00:00
|
|
|
#ifndef CDEVICETOKEN
|
|
|
|
#define CDEVICETOKEN
|
|
|
|
|
|
|
|
#include <string>
|
2015-04-21 04:02:43 +00:00
|
|
|
#include "CDeviceBase.hpp"
|
|
|
|
#include "DeviceClasses.hpp"
|
|
|
|
|
|
|
|
#if __APPLE__
|
|
|
|
#include <IOKit/hid/IOHIDLib.h>
|
|
|
|
typedef IOHIDDeviceRef TDeviceHandle;
|
|
|
|
#elif _WIN32
|
|
|
|
#elif __linux__
|
|
|
|
#endif
|
2015-04-19 22:52:45 +00:00
|
|
|
|
|
|
|
class CDeviceBase;
|
|
|
|
|
|
|
|
class CDeviceToken
|
|
|
|
{
|
2015-04-21 04:02:43 +00:00
|
|
|
unsigned m_vendorId;
|
|
|
|
unsigned m_productId;
|
|
|
|
std::string m_vendorName;
|
|
|
|
std::string m_productName;
|
|
|
|
TDeviceHandle m_devHandle;
|
2015-04-19 22:52:45 +00:00
|
|
|
|
2015-04-21 04:02:43 +00:00
|
|
|
friend CDeviceBase;
|
|
|
|
CDeviceBase* m_connectedDev;
|
|
|
|
|
2015-04-19 22:52:45 +00:00
|
|
|
public:
|
2015-04-21 04:02:43 +00:00
|
|
|
inline CDeviceToken(unsigned vid, unsigned pid, const char* vname, const char* pname, TDeviceHandle handle)
|
|
|
|
: m_vendorId(vid), m_productId(pid), m_devHandle(handle), 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;}
|
|
|
|
inline TDeviceHandle getDeviceHandle() const {return m_devHandle;}
|
|
|
|
inline bool isDeviceOpen() const {return m_connectedDev;}
|
|
|
|
inline CDeviceBase* openAndGetDevice()
|
|
|
|
{
|
|
|
|
if (!m_connectedDev)
|
|
|
|
m_connectedDev = BooDeviceNew(this);
|
|
|
|
return m_connectedDev;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void _deviceClose()
|
|
|
|
{
|
|
|
|
if (m_connectedDev)
|
|
|
|
m_connectedDev->deviceDisconnected();
|
|
|
|
m_connectedDev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline CDeviceToken operator =(const CDeviceToken& other)
|
|
|
|
{return CDeviceToken(other);}
|
|
|
|
inline bool operator ==(const CDeviceToken& rhs) const
|
|
|
|
{return m_devHandle == rhs.m_devHandle;}
|
|
|
|
inline bool operator <(const CDeviceToken& rhs) const
|
|
|
|
{return m_devHandle < rhs.m_devHandle;}
|
2015-04-19 22:52:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CDEVICETOKEN
|