00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <iomanip>
00034
00035 #include <gadget/gadgetConfig.h>
00036 #include <gadget/Type/DeviceInterface.h>
00037 #include <gadget/InputManager.h>
00038 #include <gadget/Type/Proxy.h>
00039
00040 namespace gadget
00041 {
00042
00043 BaseDeviceInterface::BaseDeviceInterface()
00044 : mProxyPtr(NULL)
00045 , mProxyName("UnInitialized")
00046 , mNameSet(false)
00047 {
00048
00049 BaseDeviceInterface::addDevInterface(this);
00050 }
00051
00052 BaseDeviceInterface::~BaseDeviceInterface()
00053 {
00054
00055 BaseDeviceInterface::removeDevInterface(this);
00056 }
00057
00058
00059 BaseDeviceInterface::BaseDeviceInterface(const BaseDeviceInterface& other)
00060 : mProxyPtr(other.mProxyPtr)
00061 , mProxyName(other.mProxyName)
00062 , mNameSet(other.mNameSet)
00063 {
00064
00065 BaseDeviceInterface::addDevInterface(this);
00066 }
00067
00068 void BaseDeviceInterface::init(const std::string& proxyName)
00069 {
00070 mProxyName = proxyName;
00071 mNameSet = true;
00072 refresh();
00073 }
00074
00075
00076
00077 void BaseDeviceInterface::refresh()
00078 {
00079 Proxy* prev_proxy_ptr = mProxyPtr;
00080
00081
00082 if ( ! mNameSet )
00083 {
00084 return;
00085 }
00086
00087 mProxyPtr = InputManager::instance()->getProxy(mProxyName);
00088
00089 if (NULL == mProxyPtr)
00090 {
00091 vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL)
00092 << "WARNING: DeviceInterface::refresh: could not find proxy: "
00093 << mProxyName.c_str() << std::endl << vprDEBUG_FLUSH;
00094 vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL)
00095 << " Make sure the proxy exists in the current configuration."
00096 << std::endl << vprDEBUG_FLUSH;
00097 vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL)
00098 << " referencing device interface will be stupefied to point at dummy device."
00099 << std::endl << vprDEBUG_FLUSH;
00100 }
00101
00102 else if((NULL != mProxyPtr) && (NULL == prev_proxy_ptr))
00103 {
00104 const int item_width(25+12);
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL)
00121 << "DeviceInterface found proxy: "
00122 << std::setiosflags(std::ios::right)
00123 << std::setfill(' ') << std::setw(item_width) << mProxyName
00124 << std::resetiosflags(std::ios::right) << " ";
00125 vprDEBUG_CONTnl(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL)
00126 << "[ " << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]";
00127 vprDEBUG_CONTnl(vprDBG_ALL,vprDBG_CONFIG_STATUS_LVL)
00128 << std::endl << vprDEBUG_FLUSH;
00129 }
00130 }
00131
00132 void BaseDeviceInterface::addDevInterface(BaseDeviceInterface* dev)
00133 {
00134 mAllocatedDevices.push_back(dev);
00135 }
00136
00137 void BaseDeviceInterface::removeDevInterface(BaseDeviceInterface* dev)
00138 {
00139
00140 std::vector<BaseDeviceInterface*>::iterator found_dev =
00141 std::find(mAllocatedDevices.begin(), mAllocatedDevices.end(), dev);
00142 vprASSERT(found_dev != mAllocatedDevices.end() &&
00143 "Tried to remove non-registered interface");
00144
00145 if ( mAllocatedDevices.end() != found_dev )
00146 {
00147 mAllocatedDevices.erase(found_dev);
00148 }
00149 }
00150
00151 void BaseDeviceInterface::refreshAllInterfaces()
00152 {
00153 for ( unsigned int i = 0; i < mAllocatedDevices.size(); ++i )
00154 {
00155 BaseDeviceInterface* dev = mAllocatedDevices[i];
00156 dev->refresh();
00157 }
00158 }
00159
00160 void BaseDeviceInterface::refreshAllDevices()
00161 {
00162 vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00163 << clrOutBOLD(clrYELLOW, "NOTICE:")
00164 << " gadget::BaseDeviceInterface::refreshAllDevices() has been replaced"
00165 << std::endl;
00166 vprDEBUG_NEXTnl(vprDBG_ALL, vprDBG_WARNING_LVL)
00167 << "by gadget::BaseDeviceInterface::refreshAllInterfaces()."
00168 << std::endl << vprDEBUG_FLUSH;
00169 refreshAllInterfaces();
00170 }
00171
00172 std::vector<BaseDeviceInterface*> BaseDeviceInterface::mAllocatedDevices;
00173
00174 }