1 // FGDeviceConfigurationMap.cxx -- a map to access xml device configuration
3 // Written by Torsten Dreyer, started August 2009
4 // Based on work from David Megginson, started May 2001.
6 // Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
7 // Copyright (C) 2001 David Megginson, david@megginson.com
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include "FGDeviceConfigurationMap.hxx"
30 #include <simgear/props/props_io.hxx>
31 #include <Main/globals.hxx>
33 FGDeviceConfigurationMap::FGDeviceConfigurationMap( const char * relative_path, SGPropertyNode_ptr aBase, const char * aChildname ) :
37 SGPath path(globals->get_fg_root());
38 path.append( relative_path );
41 scan_dir( path, &index);
43 vector<SGPropertyNode_ptr> childNodes = base->getChildren(childname);
44 for (int k = (int)childNodes.size() - 1; k >= 0; k--) {
45 SGPropertyNode *n = childNodes[k];
46 vector<SGPropertyNode_ptr> names = n->getChildren("name");
47 if (names.size() ) // && (n->getChildren("axis").size() || n->getChildren("button").size()))
48 for (unsigned int j = 0; j < names.size(); j++)
49 (*this)[names[j]->getStringValue()] = n;
53 FGDeviceConfigurationMap::~FGDeviceConfigurationMap()
55 base->removeChildren( childname );
58 void FGDeviceConfigurationMap::scan_dir( SGPath & path, int *index)
60 ulDir *dir = ulOpenDir(path.c_str());
63 while ((dent = ulReadDir(dir)) != 0) {
64 if (dent->d_name[0] == '.')
68 p.append(dent->d_name);
73 } else if (path.extension() == "xml") {
74 SG_LOG(SG_INPUT, SG_DEBUG, "Reading joystick file " << path.str());
75 SGPropertyNode_ptr n = base->getChild(childname, (*index)++, true);
76 readProperties(path.str(), n);
77 n->setStringValue("source", path.c_str());