| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#include <iomanip> |
|---|
| 28 |
|
|---|
| 29 |
#include <gadget/gadgetConfig.h> |
|---|
| 30 |
#include <gadget/Type/DeviceInterface.h> |
|---|
| 31 |
#include <gadget/InputManager.h> |
|---|
| 32 |
#include <gadget/Type/Proxy.h> |
|---|
| 33 |
|
|---|
| 34 |
namespace gadget |
|---|
| 35 |
{ |
|---|
| 36 |
|
|---|
| 37 |
BaseDeviceInterface::BaseDeviceInterface() |
|---|
| 38 |
: mProxyPtr(NULL) |
|---|
| 39 |
, mProxyName("UnInitialized") |
|---|
| 40 |
, mNameSet(false) |
|---|
| 41 |
{ |
|---|
| 42 |
|
|---|
| 43 |
BaseDeviceInterface::addDevInterface(this); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
BaseDeviceInterface::~BaseDeviceInterface() |
|---|
| 47 |
{ |
|---|
| 48 |
|
|---|
| 49 |
BaseDeviceInterface::removeDevInterface(this); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
BaseDeviceInterface::BaseDeviceInterface(const BaseDeviceInterface& other) |
|---|
| 54 |
: mProxyPtr(other.mProxyPtr) |
|---|
| 55 |
, mProxyName(other.mProxyName) |
|---|
| 56 |
, mNameSet(other.mNameSet) |
|---|
| 57 |
{ |
|---|
| 58 |
|
|---|
| 59 |
BaseDeviceInterface::addDevInterface(this); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
void BaseDeviceInterface::init(const std::string& proxyName) |
|---|
| 63 |
{ |
|---|
| 64 |
mProxyName = proxyName; |
|---|
| 65 |
mNameSet = true; |
|---|
| 66 |
refresh(); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
void BaseDeviceInterface::refresh() |
|---|
| 72 |
{ |
|---|
| 73 |
Proxy* prev_proxy_ptr = mProxyPtr; |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
if ( ! mNameSet ) |
|---|
| 77 |
{ |
|---|
| 78 |
return; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
mProxyPtr = InputManager::instance()->getProxy(mProxyName); |
|---|
| 82 |
|
|---|
| 83 |
if (NULL == mProxyPtr) |
|---|
| 84 |
{ |
|---|
| 85 |
vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL) |
|---|
| 86 |
<< "WARNING: DeviceInterface::refresh: could not find proxy: " |
|---|
| 87 |
<< mProxyName.c_str() << std::endl << vprDEBUG_FLUSH; |
|---|
| 88 |
vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL) |
|---|
| 89 |
<< " Make sure the proxy exists in the current configuration." |
|---|
| 90 |
<< std::endl << vprDEBUG_FLUSH; |
|---|
| 91 |
vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL) |
|---|
| 92 |
<< " referencing device interface will be stupefied to point at dummy device." |
|---|
| 93 |
<< std::endl << vprDEBUG_FLUSH; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
else if((NULL != mProxyPtr) && (NULL == prev_proxy_ptr)) |
|---|
| 97 |
{ |
|---|
| 98 |
const int item_width(25+12); |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL) |
|---|
| 115 |
<< "DeviceInterface found proxy: " |
|---|
| 116 |
<< std::setiosflags(std::ios::right) |
|---|
| 117 |
<< std::setfill(' ') << std::setw(item_width) << mProxyName |
|---|
| 118 |
<< std::resetiosflags(std::ios::right) << " "; |
|---|
| 119 |
vprDEBUG_CONTnl(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL) |
|---|
| 120 |
<< "[ " << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]"; |
|---|
| 121 |
vprDEBUG_CONTnl(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL) |
|---|
| 122 |
<< std::endl << vprDEBUG_FLUSH; |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
void BaseDeviceInterface::addDevInterface(BaseDeviceInterface* dev) |
|---|
| 127 |
{ |
|---|
| 128 |
mAllocatedDevices.push_back(dev); |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
void BaseDeviceInterface::removeDevInterface(BaseDeviceInterface* dev) |
|---|
| 132 |
{ |
|---|
| 133 |
|
|---|
| 134 |
std::vector<BaseDeviceInterface*>::iterator found_dev = |
|---|
| 135 |
std::find(mAllocatedDevices.begin(), mAllocatedDevices.end(), dev); |
|---|
| 136 |
vprASSERT(found_dev != mAllocatedDevices.end() && |
|---|
| 137 |
"Tried to remove non-registered interface"); |
|---|
| 138 |
|
|---|
| 139 |
if ( mAllocatedDevices.end() != found_dev ) |
|---|
| 140 |
{ |
|---|
| 141 |
mAllocatedDevices.erase(found_dev); |
|---|
| 142 |
} |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
void BaseDeviceInterface::refreshAllInterfaces() |
|---|
| 146 |
{ |
|---|
| 147 |
for ( unsigned int i = 0; i < mAllocatedDevices.size(); ++i ) |
|---|
| 148 |
{ |
|---|
| 149 |
BaseDeviceInterface* dev = mAllocatedDevices[i]; |
|---|
| 150 |
dev->refresh(); |
|---|
| 151 |
} |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
std::vector<BaseDeviceInterface*> BaseDeviceInterface::mAllocatedDevices; |
|---|
| 155 |
|
|---|
| 156 |
} |
|---|
| 157 |
|
|---|