Skip to content

Commit

Permalink
[stdstring] get rid of CStdString in peripherals
Browse files Browse the repository at this point in the history
  • Loading branch information
notspiff authored and Montellese committed Jan 7, 2015
1 parent c87eada commit a337745
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 177 deletions.
49 changes: 25 additions & 24 deletions xbmc/peripherals/PeripheralTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
*
*/

#include <algorithm>
#include <map>
#include <string>
#include <stdio.h>
#ifdef TARGET_WINDOWS
#include "PlatformDefs.h"
#endif
#include "utils/StdString.h"
#include "utils/StringUtils.h"

class CSetting;
Expand Down Expand Up @@ -83,9 +84,9 @@ namespace PERIPHERALS
std::vector<PeripheralID> m_PeripheralID;
PeripheralBusType m_busType;
PeripheralType m_class;
CStdString m_strDeviceName;
std::string m_strDeviceName;
PeripheralType m_mappedTo;
std::map<CStdString, PeripheralDeviceSetting> m_settings;
std::map<std::string, PeripheralDeviceSetting> m_settings;
};

class PeripheralTypeTranslator
Expand Down Expand Up @@ -116,26 +117,26 @@ namespace PERIPHERALS
}
};

static PeripheralType GetTypeFromString(const CStdString &strType)
static PeripheralType GetTypeFromString(const std::string &strType)
{
CStdString strTypeLowerCase(strType);
std::string strTypeLowerCase(strType);
StringUtils::ToLower(strTypeLowerCase);

if (strTypeLowerCase.Equals("bluetooth"))
if (strTypeLowerCase == "bluetooth")
return PERIPHERAL_BLUETOOTH;
else if (strTypeLowerCase.Equals("cec"))
else if (strTypeLowerCase == "cec")
return PERIPHERAL_CEC;
else if (strTypeLowerCase.Equals("disk"))
else if (strTypeLowerCase == "disk")
return PERIPHERAL_DISK;
else if (strTypeLowerCase.Equals("hid"))
else if (strTypeLowerCase == "hid")
return PERIPHERAL_HID;
else if (strTypeLowerCase.Equals("nic"))
else if (strTypeLowerCase == "nic")
return PERIPHERAL_NIC;
else if (strTypeLowerCase.Equals("nyxboard"))
else if (strTypeLowerCase == "nyxboard")
return PERIPHERAL_NYXBOARD;
else if (strTypeLowerCase.Equals("tuner"))
else if (strTypeLowerCase == "tuner")
return PERIPHERAL_TUNER;
else if (strTypeLowerCase.Equals("imon"))
else if (strTypeLowerCase == "imon")
return PERIPHERAL_IMON;

return PERIPHERAL_UNKNOWN;
Expand All @@ -158,18 +159,18 @@ namespace PERIPHERALS
}
};

static PeripheralBusType GetBusTypeFromString(const CStdString &strType)
static PeripheralBusType GetBusTypeFromString(const std::string &strType)
{
CStdString strTypeLowerCase(strType);
std::string strTypeLowerCase(strType);
StringUtils::ToLower(strTypeLowerCase);

if (strTypeLowerCase.Equals("usb"))
if (strTypeLowerCase == "usb")
return PERIPHERAL_BUS_USB;
else if (strTypeLowerCase.Equals("pci"))
else if (strTypeLowerCase == "pci")
return PERIPHERAL_BUS_PCI;
else if (strTypeLowerCase.Equals("rpi"))
else if (strTypeLowerCase == "rpi")
return PERIPHERAL_BUS_RPI;
else if (strTypeLowerCase.Equals("cec"))
else if (strTypeLowerCase == "cec")
return PERIPHERAL_BUS_CEC;

return PERIPHERAL_BUS_UNKNOWN;
Expand All @@ -182,7 +183,7 @@ namespace PERIPHERALS
return iVal;
};

static void FormatHexString(int iVal, CStdString &strHexString)
static void FormatHexString(int iVal, std::string &strHexString)
{
if (iVal < 0)
iVal = 0;
Expand Down Expand Up @@ -220,7 +221,7 @@ namespace PERIPHERALS
m_iProductId == right.m_iProductId &&
m_type == right.m_type &&
m_busType == right.m_busType &&
m_strLocation.Equals(right.m_strLocation);
StringUtils::EqualsNoCase(m_strLocation, right.m_strLocation);
}

bool operator !=(const PeripheralScanResult& right) const
Expand All @@ -229,19 +230,19 @@ namespace PERIPHERALS
}

PeripheralType m_type;
CStdString m_strLocation;
std::string m_strLocation;
int m_iVendorId;
int m_iProductId;
PeripheralType m_mappedType;
CStdString m_strDeviceName;
std::string m_strDeviceName;
PeripheralBusType m_busType;
PeripheralBusType m_mappedBusType;
unsigned int m_iSequence; // when more than one adapter of the same type is found
};

struct PeripheralScanResults
{
bool GetDeviceOnLocation(const CStdString& strLocation, PeripheralScanResult* result) const
bool GetDeviceOnLocation(const std::string& strLocation, PeripheralScanResult* result) const
{
for (std::vector<PeripheralScanResult>::const_iterator it = m_results.begin(); it != m_results.end(); it++)
{
Expand Down
54 changes: 28 additions & 26 deletions xbmc/peripherals/Peripherals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void CPeripherals::Clear(void)
/* delete mappings */
for (unsigned int iMappingPtr = 0; iMappingPtr < m_mappings.size(); iMappingPtr++)
{
map<CStdString, PeripheralDeviceSetting> settings = m_mappings.at(iMappingPtr).m_settings;
for (map<CStdString, PeripheralDeviceSetting>::iterator itr = settings.begin(); itr != settings.end(); ++itr)
map<std::string, PeripheralDeviceSetting> settings = m_mappings.at(iMappingPtr).m_settings;
for (map<std::string, PeripheralDeviceSetting>::iterator itr = settings.begin(); itr != settings.end(); ++itr)
delete itr->second.m_setting;
m_mappings.at(iMappingPtr).m_settings.clear();
}
Expand Down Expand Up @@ -159,7 +159,7 @@ CPeripheralBus *CPeripherals::GetBusByType(const PeripheralBusType type) const
return bus;
}

CPeripheral *CPeripherals::GetPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType /* = PERIPHERAL_BUS_UNKNOWN */) const
CPeripheral *CPeripherals::GetPeripheralAtLocation(const std::string &strLocation, PeripheralBusType busType /* = PERIPHERAL_BUS_UNKNOWN */) const
{
CSingleLock lock(m_critSection);
CPeripheral *peripheral(NULL);
Expand All @@ -177,12 +177,12 @@ CPeripheral *CPeripherals::GetPeripheralAtLocation(const CStdString &strLocation
return peripheral;
}

bool CPeripherals::HasPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType /* = PERIPHERAL_BUS_UNKNOWN */) const
bool CPeripherals::HasPeripheralAtLocation(const std::string &strLocation, PeripheralBusType busType /* = PERIPHERAL_BUS_UNKNOWN */) const
{
return (GetPeripheralAtLocation(strLocation, busType) != NULL);
}

CPeripheralBus *CPeripherals::GetBusWithDevice(const CStdString &strLocation) const
CPeripheralBus *CPeripherals::GetBusWithDevice(const std::string &strLocation) const
{
CSingleLock lock(m_critSection);
for (unsigned int iBusPtr = 0; iBusPtr < m_busses.size(); iBusPtr++)
Expand Down Expand Up @@ -366,7 +366,7 @@ bool CPeripherals::GetMappingForDevice(const CPeripheralBus &bus, PeripheralScan

if (bProductMatch && bBusMatch && bClassMatch)
{
CStdString strVendorId, strProductId;
std::string strVendorId, strProductId;
PeripheralTypeTranslator::FormatHexString(result.m_iVendorId, strVendorId);
PeripheralTypeTranslator::FormatHexString(result.m_iProductId, strProductId);
CLog::Log(LOGDEBUG, "%s - device (%s:%s) mapped to %s (type = %s)", __FUNCTION__, strVendorId.c_str(), strProductId.c_str(), mapping.m_strDeviceName.c_str(), PeripheralTypeTranslator::TypeToString(mapping.m_mappedTo));
Expand Down Expand Up @@ -403,12 +403,13 @@ void CPeripherals::GetSettingsFromMapping(CPeripheral &peripheral) const

if (bBusMatch && bProductMatch && bClassMatch)
{
for (map<CStdString, PeripheralDeviceSetting>::const_iterator itr = mapping->m_settings.begin(); itr != mapping->m_settings.end(); ++itr)
for (map<std::string, PeripheralDeviceSetting>::const_iterator itr = mapping->m_settings.begin(); itr != mapping->m_settings.end(); ++itr)
peripheral.AddSetting((*itr).first, (*itr).second.m_setting, (*itr).second.m_order);
}
}
}

#define SS(x) ((x) ? x : "")
bool CPeripherals::LoadMappings(void)
{
CXBMCTinyXML xmlDoc;
Expand All @@ -419,7 +420,7 @@ bool CPeripherals::LoadMappings(void)
}

TiXmlElement *pRootElement = xmlDoc.RootElement();
if (strcmpi(pRootElement->Value(), "peripherals") != 0)
if (!pRootElement || strcmpi(pRootElement->Value(), "peripherals") != 0)
{
CLog::Log(LOGERROR, "%s - peripherals.xml does not contain <peripherals>", __FUNCTION__);
return false;
Expand Down Expand Up @@ -464,47 +465,47 @@ bool CPeripherals::LoadMappings(void)
return true;
}

void CPeripherals::GetSettingsFromMappingsFile(TiXmlElement *xmlNode, map<CStdString, PeripheralDeviceSetting> &settings)
void CPeripherals::GetSettingsFromMappingsFile(TiXmlElement *xmlNode, map<std::string, PeripheralDeviceSetting> &settings)
{
TiXmlElement *currentNode = xmlNode->FirstChildElement("setting");
int iMaxOrder = 0;

while (currentNode)
{
CSetting *setting = NULL;
CStdString strKey = XMLUtils::GetAttribute(currentNode, "key");
std::string strKey = XMLUtils::GetAttribute(currentNode, "key");
if (strKey.empty())
continue;

CStdString strSettingsType = XMLUtils::GetAttribute(currentNode, "type");
std::string strSettingsType = XMLUtils::GetAttribute(currentNode, "type");
int iLabelId = currentNode->Attribute("label") ? atoi(currentNode->Attribute("label")) : -1;
const std::string config = XMLUtils::GetAttribute(currentNode, "configurable");
bool bConfigurable = (config.empty() || (config != "no" && config != "false" && config != "0"));
if (strSettingsType.Equals("bool"))
if (strSettingsType == "bool")
{
const std::string value = XMLUtils::GetAttribute(currentNode, "value");
bool bValue = (value != "no" && value != "false" && value != "0");
setting = new CSettingBool(strKey, iLabelId, bValue);
}
else if (strSettingsType.Equals("int"))
else if (strSettingsType == "int")
{
int iValue = currentNode->Attribute("value") ? atoi(currentNode->Attribute("value")) : 0;
int iMin = currentNode->Attribute("min") ? atoi(currentNode->Attribute("min")) : 0;
int iStep = currentNode->Attribute("step") ? atoi(currentNode->Attribute("step")) : 1;
int iMax = currentNode->Attribute("max") ? atoi(currentNode->Attribute("max")) : 255;
setting = new CSettingInt(strKey, iLabelId, iValue, iMin, iStep, iMax);
}
else if (strSettingsType.Equals("float"))
else if (strSettingsType == "float")
{
float fValue = currentNode->Attribute("value") ? (float) atof(currentNode->Attribute("value")) : 0;
float fMin = currentNode->Attribute("min") ? (float) atof(currentNode->Attribute("min")) : 0;
float fStep = currentNode->Attribute("step") ? (float) atof(currentNode->Attribute("step")) : 0;
float fMax = currentNode->Attribute("max") ? (float) atof(currentNode->Attribute("max")) : 0;
setting = new CSettingNumber(strKey, iLabelId, fValue, fMin, fStep, fMax);
}
else if (strSettingsType.Equals("enum"))
else if (StringUtils::EqualsNoCase(strSettingsType, "enum"))
{
CStdString strEnums = XMLUtils::GetAttribute(currentNode, "lvalues");
std::string strEnums = XMLUtils::GetAttribute(currentNode, "lvalues");
if (!strEnums.empty())
{
vector< pair<int,int> > enums;
Expand All @@ -518,7 +519,7 @@ void CPeripherals::GetSettingsFromMappingsFile(TiXmlElement *xmlNode, map<CStdSt
}
else
{
CStdString strValue = XMLUtils::GetAttribute(currentNode, "value");
std::string strValue = XMLUtils::GetAttribute(currentNode, "value");
setting = new CSettingString(strKey, iLabelId, strValue);
}

Expand Down Expand Up @@ -547,41 +548,42 @@ void CPeripherals::GetSettingsFromMappingsFile(TiXmlElement *xmlNode, map<CStdSt
}

/* add the settings without an order attribute or an invalid order attribute set at the end */
for (map<CStdString, PeripheralDeviceSetting>::iterator it = settings.begin(); it != settings.end(); ++it)
for (map<std::string, PeripheralDeviceSetting>::iterator it = settings.begin(); it != settings.end(); ++it)
{
if (it->second.m_order == 0)
it->second.m_order = ++iMaxOrder;
}
}

void CPeripherals::GetDirectory(const CStdString &strPath, CFileItemList &items) const
void CPeripherals::GetDirectory(const std::string &strPath, CFileItemList &items) const
{
if (!StringUtils::StartsWithNoCase(strPath, "peripherals://"))
return;

CStdString strPathCut = strPath.substr(14);
CStdString strBus = strPathCut.substr(0, strPathCut.find('/'));
std::string strPathCut = strPath.substr(14);
std::string strBus = strPathCut.substr(0, strPathCut.find('/'));

CSingleLock lock(m_critSection);
for (unsigned int iBusPtr = 0; iBusPtr < m_busses.size(); iBusPtr++)
{
if (strBus.Equals("all") || strBus.Equals(PeripheralTypeTranslator::BusTypeToString(m_busses.at(iBusPtr)->Type())))
if (StringUtils::EqualsNoCase(strBus, "all") ||
StringUtils::EqualsNoCase(strBus, PeripheralTypeTranslator::BusTypeToString(m_busses.at(iBusPtr)->Type())))
m_busses.at(iBusPtr)->GetDirectory(strPath, items);
}
}

CPeripheral *CPeripherals::GetByPath(const CStdString &strPath) const
CPeripheral *CPeripherals::GetByPath(const std::string &strPath) const
{
if (!StringUtils::StartsWithNoCase(strPath, "peripherals://"))
return NULL;

CStdString strPathCut = strPath.substr(14);
CStdString strBus = strPathCut.substr(0, strPathCut.find('/'));
std::string strPathCut = strPath.substr(14);
std::string strBus = strPathCut.substr(0, strPathCut.find('/'));

CSingleLock lock(m_critSection);
for (unsigned int iBusPtr = 0; iBusPtr < m_busses.size(); iBusPtr++)
{
if (strBus.Equals(PeripheralTypeTranslator::BusTypeToString(m_busses.at(iBusPtr)->Type())))
if (StringUtils::EqualsNoCase(strBus, PeripheralTypeTranslator::BusTypeToString(m_busses.at(iBusPtr)->Type())))
return m_busses.at(iBusPtr)->GetByPath(strPath);
}

Expand Down
12 changes: 6 additions & 6 deletions xbmc/peripherals/Peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ namespace PERIPHERALS
* @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
* @return The peripheral or NULL if it wasn't found.
*/
virtual CPeripheral *GetPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
virtual CPeripheral *GetPeripheralAtLocation(const std::string &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;

/*!
* @brief Check whether a peripheral is present at the given location.
* @param strLocation The location.
* @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
* @return True when a peripheral was found, false otherwise.
*/
virtual bool HasPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
virtual bool HasPeripheralAtLocation(const std::string &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;

/*!
* @brief Get the bus that holds the device with the given location.
* @param strLocation The location.
* @return The bus or NULL if no device was found.
*/
virtual CPeripheralBus *GetBusWithDevice(const CStdString &strLocation) const;
virtual CPeripheralBus *GetBusWithDevice(const std::string &strLocation) const;

/*!
* @brief Get all peripheral instances that have the given feature.
Expand Down Expand Up @@ -142,14 +142,14 @@ namespace PERIPHERALS
* @param strPath The path to the directory to get the items from.
* @param items The item list.
*/
virtual void GetDirectory(const CStdString &strPath, CFileItemList &items) const;
virtual void GetDirectory(const std::string &strPath, CFileItemList &items) const;

/*!
* @brief Get the instance of a peripheral given it's path.
* @param strPath The path to the peripheral.
* @return The peripheral or NULL if it wasn't found.
*/
virtual CPeripheral *GetByPath(const CStdString &strPath) const;
virtual CPeripheral *GetByPath(const std::string &strPath) const;

/*!
* @brief Try to let one of the peripherals handle an action.
Expand Down Expand Up @@ -214,7 +214,7 @@ namespace PERIPHERALS
CPeripherals(void);
bool LoadMappings(void);
bool GetMappingForDevice(const CPeripheralBus &bus, PeripheralScanResult& result) const;
static void GetSettingsFromMappingsFile(TiXmlElement *xmlNode, std::map<CStdString, PeripheralDeviceSetting> &m_settings);
static void GetSettingsFromMappingsFile(TiXmlElement *xmlNode, std::map<std::string, PeripheralDeviceSetting> &m_settings);

bool m_bInitialised;
bool m_bIsStarted;
Expand Down
Loading

0 comments on commit a337745

Please sign in to comment.