boo/include/inputdev/CDeviceToken.hpp

67 lines
1.8 KiB
C++

#ifndef CDEVICETOKEN
#define CDEVICETOKEN
#include <string>
#include "CDeviceBase.hpp"
#include "DeviceClasses.hpp"
#if __APPLE__
#include <IOKit/hid/IOHIDLib.h>
typedef IOHIDDeviceRef TDeviceHandle;
#elif _WIN32
#elif __linux__
#endif
class CDeviceBase;
class CDeviceToken
{
unsigned m_vendorId;
unsigned m_productId;
std::string m_vendorName;
std::string m_productName;
TDeviceHandle m_devHandle;
friend CDeviceBase;
CDeviceBase* m_connectedDev;
public:
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;}
};
#endif // CDEVICETOKEN