X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInput%2FFGDeviceConfigurationMap.cxx;h=d62a32f9e88bd243976fc91fa94e56bc0bdc36cb;hb=5151f7f5e0ba7c7e6688bdfbc4cea365196e1ed3;hp=b27d6816cf96f4210b0147d138eb9617eb13f4e8;hpb=6e7ac46751fc10fd03d1637a63a1ca5beade657d;p=flightgear.git diff --git a/src/Input/FGDeviceConfigurationMap.cxx b/src/Input/FGDeviceConfigurationMap.cxx index b27d6816c..d62a32f9e 100644 --- a/src/Input/FGDeviceConfigurationMap.cxx +++ b/src/Input/FGDeviceConfigurationMap.cxx @@ -40,8 +40,17 @@ using simgear::PropertyList; using std::string; -FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path) +FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path, + SGPropertyNode* nodePath, + const std::string& nodeName) { + // scan for over-ride configurations, loaded via joysticks.xml, etc + BOOST_FOREACH(SGPropertyNode_ptr preloaded, nodePath->getChildren(nodeName)) { + BOOST_FOREACH(SGPropertyNode* nameProp, preloaded->getChildren("name")) { + overrideDict[nameProp->getStringValue()] = preloaded; + } // of names iteration + } // of defined overrides iteration + scan_dir( SGPath(globals->get_fg_home(), relative_path)); scan_dir( SGPath(globals->get_fg_root(), relative_path)); } @@ -53,6 +62,12 @@ FGDeviceConfigurationMap::~FGDeviceConfigurationMap() SGPropertyNode_ptr FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name) { + NameNodeMap::iterator j = overrideDict.find(name); + if (j != overrideDict.end()) { + return j->second; + } + +// no override, check out list of config files NamePathMap::iterator it = namePathMap.find(name); if (it == namePathMap.end()) { return SGPropertyNode_ptr(); @@ -62,7 +77,7 @@ FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name) try { readProperties(it->second.str(), result); result->setStringValue("source", it->second.c_str()); - } catch (sg_exception& e) { + } catch (sg_exception&) { SG_LOG(SG_INPUT, SG_WARN, "parse failure reading:" << it->second); return NULL; } @@ -71,6 +86,11 @@ FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name) bool FGDeviceConfigurationMap::hasConfiguration(const std::string& name) const { + NameNodeMap::const_iterator j = overrideDict.find(name); + if (j != overrideDict.end()) { + return true; + } + return namePathMap.find(name) != namePathMap.end(); } @@ -79,10 +99,12 @@ void FGDeviceConfigurationMap::scan_dir(const SGPath & path) if (!path.exists()) return; + flightgear::NavDataCache* cache = flightgear::NavDataCache::instance(); + flightgear::NavDataCache::Transaction txn(cache); + simgear::Dir dir(path); simgear::PathList children = dir.children(simgear::Dir::TYPE_FILE | simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT); - flightgear::NavDataCache* cache = flightgear::NavDataCache::instance(); BOOST_FOREACH(SGPath path, children) { if (path.isDir()) { @@ -95,6 +117,8 @@ void FGDeviceConfigurationMap::scan_dir(const SGPath & path) } // of cached file stamp is valid } // of child is a file with '.xml' extension } // of directory children iteration + + txn.commit(); } void FGDeviceConfigurationMap::readCachedData(const SGPath& path) @@ -118,7 +142,7 @@ void FGDeviceConfigurationMap::refreshCacheForFile(const SGPath& path) SGPropertyNode_ptr n(new SGPropertyNode); try { readProperties(path.str(), n); - } catch (sg_exception& e) { + } catch (sg_exception&) { SG_LOG(SG_INPUT, SG_WARN, "parse failure reading:" << path); return; }