mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-08 21:17:50 +00:00
better event handling
This commit is contained in:
@@ -8,10 +8,12 @@ class CDeviceBase
|
||||
{
|
||||
CDeviceToken* m_token;
|
||||
IHIDDevice* m_hidDev;
|
||||
friend CDeviceToken;
|
||||
void _deviceDisconnected();
|
||||
public:
|
||||
inline CDeviceBase(CDeviceToken* token, IHIDDevice* hidDev)
|
||||
: m_token(token), m_hidDev(hidDev) {}
|
||||
void _deviceDisconnected();
|
||||
void closeDevice();
|
||||
virtual void deviceDisconnected()=0;
|
||||
};
|
||||
|
||||
|
||||
@@ -44,8 +44,9 @@ private:
|
||||
{
|
||||
if (BooDeviceMatchToken(token, m_types)) {
|
||||
m_tokensLock.lock();
|
||||
m_tokens.insert(std::make_pair(token.getDeviceHandle(), token));
|
||||
TInsertedDeviceToken inseredTok = m_tokens.insert(std::make_pair(token.getDeviceHandle(), std::move(token)));
|
||||
m_tokensLock.unlock();
|
||||
deviceConnected(inseredTok.first->second);
|
||||
}
|
||||
}
|
||||
inline void _removeToken(TDeviceHandle handle)
|
||||
@@ -55,6 +56,7 @@ private:
|
||||
{
|
||||
CDeviceToken& tok = preCheck->second;
|
||||
tok._deviceClose();
|
||||
deviceDisconnected(tok);
|
||||
m_tokensLock.lock();
|
||||
m_tokens.erase(preCheck);
|
||||
m_tokensLock.unlock();
|
||||
@@ -75,14 +77,12 @@ public:
|
||||
};
|
||||
|
||||
/* Application must specify its interested device-types */
|
||||
CDeviceFinder(EDeviceMask types, bool autoScan=true)
|
||||
CDeviceFinder(EDeviceMask types)
|
||||
: m_types(types), m_listener(NULL)
|
||||
{
|
||||
if (skDevFinder)
|
||||
throw std::runtime_error("only one instance of CDeviceFinder may be constructed");
|
||||
skDevFinder = this;
|
||||
if (autoScan)
|
||||
startScanning();
|
||||
}
|
||||
~CDeviceFinder()
|
||||
{
|
||||
@@ -126,6 +126,9 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void deviceConnected(CDeviceToken&) {}
|
||||
virtual void deviceDisconnected(CDeviceToken&) {}
|
||||
|
||||
};
|
||||
|
||||
#endif // CDEVICEFINDER_HPP
|
||||
|
||||
@@ -12,8 +12,6 @@ typedef IOHIDDeviceRef TDeviceHandle;
|
||||
#elif __linux__
|
||||
#endif
|
||||
|
||||
class CDeviceBase;
|
||||
|
||||
class CDeviceToken
|
||||
{
|
||||
unsigned m_vendorId;
|
||||
@@ -22,10 +20,21 @@ class CDeviceToken
|
||||
std::string m_productName;
|
||||
TDeviceHandle m_devHandle;
|
||||
|
||||
friend CDeviceBase;
|
||||
friend class CDeviceBase;
|
||||
CDeviceBase* m_connectedDev;
|
||||
|
||||
friend class CDeviceFinder;
|
||||
inline void _deviceClose()
|
||||
{
|
||||
printf("CLOSE %p\n", this);
|
||||
if (m_connectedDev)
|
||||
m_connectedDev->_deviceDisconnected();
|
||||
m_connectedDev = NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
CDeviceToken(const CDeviceToken&) = delete;
|
||||
CDeviceToken(CDeviceToken&&) = default;
|
||||
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)
|
||||
{
|
||||
@@ -43,20 +52,12 @@ public:
|
||||
inline bool isDeviceOpen() const {return m_connectedDev;}
|
||||
inline CDeviceBase* openAndGetDevice()
|
||||
{
|
||||
printf("OPEN %p\n", this);
|
||||
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
|
||||
|
||||
@@ -7,11 +7,7 @@ class CDolphinSmashAdapter final : public CDeviceBase
|
||||
{
|
||||
void deviceDisconnected();
|
||||
public:
|
||||
CDolphinSmashAdapter(CDeviceToken* token, IHIDDevice* hidDev)
|
||||
: CDeviceBase(token, hidDev)
|
||||
{
|
||||
|
||||
}
|
||||
CDolphinSmashAdapter(CDeviceToken* token, IHIDDevice* hidDev);
|
||||
};
|
||||
|
||||
#endif // CDOLPHINSMASHADAPTER_HPP
|
||||
|
||||
Reference in New Issue
Block a user