Major refactor for better modularity

This commit is contained in:
Jack Andersen
2015-08-18 09:40:26 -10:00
parent 3007714b5a
commit e56b8539bf
62 changed files with 275 additions and 791 deletions

View File

@@ -8,20 +8,20 @@
namespace boo
{
class CDeviceBase
class DeviceBase
{
friend class CDeviceToken;
friend class CHIDDeviceIOKit;
friend class CHIDDeviceUdev;
friend class CHIDDeviceWinUSB;
friend class DeviceToken;
friend class HIDDeviceIOKit;
friend class HIDDeviceUdev;
friend class HIDDeviceWinUSB;
class CDeviceToken* m_token;
class DeviceToken* m_token;
class IHIDDevice* m_hidDev;
void _deviceDisconnected();
public:
CDeviceBase(CDeviceToken* token);
virtual ~CDeviceBase();
DeviceBase(DeviceToken* token);
virtual ~DeviceBase();
void closeDevice();
virtual void deviceDisconnected()=0;
virtual void deviceError(const char* error) {fprintf(stderr, "%s\n", error);}

View File

@@ -19,20 +19,20 @@
namespace boo
{
static class CDeviceFinder* skDevFinder = NULL;
static class DeviceFinder* skDevFinder = NULL;
class CDeviceFinder
class DeviceFinder
{
public:
friend class CHIDListenerIOKit;
friend class CHIDListenerUdev;
friend class CHIDListenerWinUSB;
static inline CDeviceFinder* instance() {return skDevFinder;}
friend class HIDListenerIOKit;
friend class HIDListenerUdev;
friend class HIDListenerWinUSB;
static inline DeviceFinder* instance() {return skDevFinder;}
private:
/* Types this finder is interested in (immutable) */
SDeviceSignature::TDeviceSignatureSet m_types;
DeviceSignature::TDeviceSignatureSet m_types;
/* Platform-specific USB event registration
* (for auto-scanning, NULL if not registered) */
@@ -51,9 +51,9 @@ private:
return true;
return false;
}
inline bool _insertToken(CDeviceToken&& token)
inline bool _insertToken(DeviceToken&& token)
{
if (SDeviceSignature::DeviceMatchToken(token, m_types)) {
if (DeviceSignature::DeviceMatchToken(token, m_types)) {
m_tokensLock.lock();
TInsertedDeviceToken inseredTok =
m_tokens.insert(std::make_pair(token.getDevicePath(), std::move(token)));
@@ -68,8 +68,8 @@ private:
auto preCheck = m_tokens.find(path);
if (preCheck != m_tokens.end())
{
CDeviceToken& tok = preCheck->second;
CDeviceBase* dev = tok.m_connectedDev;
DeviceToken& tok = preCheck->second;
DeviceBase* dev = tok.m_connectedDev;
tok._deviceClose();
deviceDisconnected(tok, dev);
m_tokensLock.lock();
@@ -82,9 +82,9 @@ public:
class CDeviceTokensHandle
{
CDeviceFinder& m_finder;
DeviceFinder& m_finder;
public:
inline CDeviceTokensHandle(CDeviceFinder& finder) : m_finder(finder)
inline CDeviceTokensHandle(DeviceFinder& finder) : m_finder(finder)
{m_finder.m_tokensLock.lock();}
inline ~CDeviceTokensHandle() {m_finder.m_tokensLock.unlock();}
inline TDeviceTokens::iterator begin() {return m_finder.m_tokens.begin();}
@@ -92,7 +92,7 @@ public:
};
/* Application must specify its interested device-types */
CDeviceFinder(std::unordered_set<std::type_index> types)
DeviceFinder(std::unordered_set<std::type_index> types)
: m_listener(NULL)
{
if (skDevFinder)
@@ -103,7 +103,7 @@ public:
skDevFinder = this;
for (const std::type_index& typeIdx : types)
{
const SDeviceSignature* sigIter = BOO_DEVICE_SIGS;
const DeviceSignature* sigIter = BOO_DEVICE_SIGS;
while (sigIter->m_name)
{
if (sigIter->m_typeIdx == typeIdx)
@@ -112,7 +112,7 @@ public:
}
}
}
~CDeviceFinder()
~DeviceFinder()
{
if (m_listener)
m_listener->stopScanning();
@@ -121,7 +121,7 @@ public:
}
/* Get interested device-type mask */
inline const SDeviceSignature::TDeviceSignatureSet& getTypes() const {return m_types;}
inline const DeviceSignature::TDeviceSignatureSet& getTypes() const {return m_types;}
/* Iterable set of tokens */
inline CDeviceTokensHandle getTokens() {return CDeviceTokensHandle(*this);}
@@ -154,8 +154,8 @@ public:
return false;
}
virtual void deviceConnected(CDeviceToken&) {}
virtual void deviceDisconnected(CDeviceToken&, CDeviceBase*) {}
virtual void deviceConnected(DeviceToken&) {}
virtual void deviceDisconnected(DeviceToken&, DeviceBase*) {}
#if _WIN32
/* Windows-specific WM_DEVICECHANGED handler */

View File

@@ -8,29 +8,29 @@
namespace boo
{
class CDeviceToken;
class CDeviceBase;
class DeviceToken;
class DeviceBase;
struct SDeviceSignature
struct DeviceSignature
{
typedef std::vector<const SDeviceSignature*> TDeviceSignatureSet;
typedef std::function<CDeviceBase*(CDeviceToken*)> TFactoryLambda;
typedef std::vector<const DeviceSignature*> TDeviceSignatureSet;
typedef std::function<DeviceBase*(DeviceToken*)> TFactoryLambda;
const char* m_name;
std::type_index m_typeIdx;
unsigned m_vid, m_pid;
TFactoryLambda m_factory;
SDeviceSignature() : m_name(NULL), m_typeIdx(typeid(SDeviceSignature)) {} /* Sentinel constructor */
SDeviceSignature(const char* name, std::type_index&& typeIdx, unsigned vid, unsigned pid, TFactoryLambda&& factory)
DeviceSignature() : m_name(NULL), m_typeIdx(typeid(DeviceSignature)) {} /* Sentinel constructor */
DeviceSignature(const char* name, std::type_index&& typeIdx, unsigned vid, unsigned pid, TFactoryLambda&& factory)
: m_name(name), m_typeIdx(typeIdx), m_vid(vid), m_pid(pid), m_factory(factory) {}
static bool DeviceMatchToken(const CDeviceToken& token, const TDeviceSignatureSet& sigSet);
static CDeviceBase* DeviceNew(CDeviceToken& token);
static bool DeviceMatchToken(const DeviceToken& token, const TDeviceSignatureSet& sigSet);
static DeviceBase* DeviceNew(DeviceToken& token);
};
#define DEVICE_SIG(name, vid, pid) \
SDeviceSignature(#name, typeid(name), vid, pid, [](CDeviceToken* tok) -> CDeviceBase* {return new name(tok);})
#define DEVICE_SIG_SENTINEL() SDeviceSignature()
DeviceSignature(#name, typeid(name), vid, pid, [](DeviceToken* tok) -> DeviceBase* {return new name(tok);})
#define DEVICE_SIG_SENTINEL() DeviceSignature()
extern const SDeviceSignature BOO_DEVICE_SIGS[];
extern const DeviceSignature BOO_DEVICE_SIGS[];
}

View File

@@ -8,7 +8,7 @@
namespace boo
{
class CDeviceToken
class DeviceToken
{
public:
enum TDeviceType
@@ -27,10 +27,10 @@ private:
std::string m_productName;
std::string m_devPath;
friend class CDeviceBase;
CDeviceBase* m_connectedDev;
friend class DeviceBase;
DeviceBase* m_connectedDev;
friend class CDeviceFinder;
friend class DeviceFinder;
inline void _deviceClose()
{
if (m_connectedDev)
@@ -40,8 +40,8 @@ private:
public:
CDeviceToken(const CDeviceToken&) = delete;
CDeviceToken(const CDeviceToken&& other)
DeviceToken(const DeviceToken&) = delete;
DeviceToken(const DeviceToken&& other)
: m_devType(other.m_devType),
m_vendorId(other.m_vendorId),
m_productId(other.m_productId),
@@ -50,7 +50,7 @@ public:
m_devPath(other.m_devPath),
m_connectedDev(other.m_connectedDev)
{}
inline CDeviceToken(enum TDeviceType devType, unsigned vid, unsigned pid, const char* vname, const char* pname, const char* path)
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),
@@ -70,16 +70,16 @@ public:
inline const std::string& getProductName() const {return m_productName;}
inline const std::string& getDevicePath() const {return m_devPath;}
inline bool isDeviceOpen() const {return (m_connectedDev != NULL);}
inline CDeviceBase* openAndGetDevice()
inline DeviceBase* openAndGetDevice()
{
if (!m_connectedDev)
m_connectedDev = SDeviceSignature::DeviceNew(*this);
m_connectedDev = DeviceSignature::DeviceNew(*this);
return m_connectedDev;
}
inline bool operator ==(const CDeviceToken& rhs) const
inline bool operator ==(const DeviceToken& rhs) const
{return m_devPath == rhs.m_devPath;}
inline bool operator <(const CDeviceToken& rhs) const
inline bool operator <(const DeviceToken& rhs) const
{return m_devPath < rhs.m_devPath;}
};

View File

@@ -30,7 +30,7 @@ enum EDolphinControllerButtons
DOL_UP = 1<<15
};
struct SDolphinControllerState
struct DolphinControllerState
{
uint8_t m_leftStick[2];
uint8_t m_rightStick[2];
@@ -43,10 +43,10 @@ struct IDolphinSmashAdapterCallback
virtual void controllerConnected(unsigned idx, EDolphinControllerType type) {(void)idx;(void)type;}
virtual void controllerDisconnected(unsigned idx, EDolphinControllerType type) {(void)idx;(void)type;}
virtual void controllerUpdate(unsigned idx, EDolphinControllerType type,
const SDolphinControllerState& state) {(void)idx;(void)type;(void)state;}
const DolphinControllerState& state) {(void)idx;(void)type;(void)state;}
};
class CDolphinSmashAdapter final : public CDeviceBase
class DolphinSmashAdapter final : public DeviceBase
{
IDolphinSmashAdapterCallback* m_callback;
uint8_t m_knownControllers;
@@ -57,8 +57,8 @@ class CDolphinSmashAdapter final : public CDeviceBase
void transferCycle();
void finalCycle();
public:
CDolphinSmashAdapter(CDeviceToken* token);
~CDolphinSmashAdapter();
DolphinSmashAdapter(DeviceToken* token);
~DolphinSmashAdapter();
inline void setCallback(IDolphinSmashAdapterCallback* cb)
{m_callback = cb; m_knownControllers = 0;}

View File

@@ -6,11 +6,11 @@
namespace boo
{
class CGenericPad final : public CDeviceBase
class GenericPad final : public DeviceBase
{
public:
CGenericPad(CDeviceToken* token);
~CGenericPad();
GenericPad(DeviceToken* token);
~GenericPad();
void deviceDisconnected();
};

View File

@@ -8,9 +8,9 @@
namespace boo
{
typedef std::unordered_map<std::string, CDeviceToken> TDeviceTokens;
typedef std::unordered_map<std::string, DeviceToken> TDeviceTokens;
typedef std::pair<TDeviceTokens::iterator, bool> TInsertedDeviceToken;
class CDeviceFinder;
class DeviceFinder;
class IHIDListener
{
@@ -33,7 +33,7 @@ public:
};
/* Platform-specific constructor */
IHIDListener* IHIDListenerNew(CDeviceFinder& finder);
IHIDListener* IHIDListenerNew(DeviceFinder& finder);
}