20 #include <QDomElement> 23 #include <QTextStream> 65 std::map<std::string,std::string>::const_iterator n;
67 n = paramMap.find(name);
68 if (n != paramMap.end())
81 std::map<std::string,std::string>::const_iterator n;
83 n = paramMap.find(name);
84 if (n != paramMap.end())
95 std::string value =
"";
96 std::map<std::string,std::string>::const_iterator n;
98 n = paramMap.find(name);
99 if (n != paramMap.end())
107 std::ostringstream s;
109 paramMap[name] = s.str();
114 std::ostringstream s;
116 paramMap[name] = s.str();
121 paramMap[name] = value;
127 std::map<std::string,State>::const_iterator n;
129 n = stateMap.find(
const_cast<std::string &
>(name));
130 if (n != stateMap.end())
138 stateMap[name] = value;
143 QDomElement e = doc.createElement(
"OBJECT");
144 e.setAttribute(
"id",QString::number(
id));
146 for (std::map<std::string,std::string>::const_iterator i = paramMap.begin(); i != paramMap.end(); ++i)
148 QDomElement e1 = doc.createElement(
"PARAM");
149 e1.setAttribute(
"name",QString::fromStdString(i->first));
152 QDomText t = doc.createTextNode(QString::fromStdString(i->second));
156 for (std::map<std::string,State>::const_iterator i = stateMap.begin(); i!= stateMap.end(); ++i)
158 QDomElement e1 = i->second.xml(doc);
159 e1.setAttribute(
"name",QString::fromStdString(i->first));
171 if (e1.tagName().toUpper() !=
"OBJECT")
173 ERROR_MSG(
"Settings::Object::State::xml : invalid element\n");
176 id = e1.attribute(
"id",
"0").toULong();
179 for(QDomElement e2 = e1.firstChild().toElement(); !e2.isNull(); e2 = e2.nextSibling().toElement())
181 if(e2.tagName().toUpper() ==
"PARAM" && e2.attribute(
"name") != QString::null)
182 paramMap[e2.attribute(
"name").toStdString()] = e2.text().toStdString();
183 else if(e2.tagName().toUpper() ==
"OBJECT" && e2.attribute(
"name") != QString::null)
184 stateMap[e2.attribute(
"name").toStdString()].xml(e2);
216 std::map<Object::ID,Object *>::const_iterator i = objectMap.find(
id);
217 if (i != objectMap.end())
226 for (std::list<Object *>::iterator i = objectList.begin(),end = objectList.end(); i != end; ++i)
232 QFile file(QString::fromStdString(filename));
233 if (!file.open(QIODevice::ReadOnly))
235 ERROR_MSG(
"Settings::Manager::load : failed to open %s for reading\n", filename.c_str());
241 int errorLine, errorColumn;
243 if (!doc.setContent(&file,
false,&errorMsg,&errorLine,&errorColumn))
245 ERROR_MSG(
"Settings::Manager::load : %s:%d:%d: %s\n", filename.c_str(), errorLine, errorColumn, errorMsg.toStdString().c_str());
249 QDomElement e1 = doc.documentElement();
251 if (e1.tagName() !=
"RTXI" || e1.attribute(
"class") !=
"settings")
253 ERROR_MSG(
"Settings::Manager::load : invalid document element\n");
268 std::list<defer_t> deferList;
269 for (QDomElement e2 = e1.firstChild().toElement(); !e2.isNull(); e2 = e2.nextSibling().toElement())
271 if (e2.tagName() !=
"OBJECT" || e2.attribute(
"component") == QString::null)
continue;
275 if (e2.attribute(
"component") ==
"plugin")
279 defer_t defer = { plugin, s };
280 deferList.push_back(defer);
285 else if (e2.attribute(
"component") ==
"rt")
287 period = strtoll(s.
loadString(
"Period").c_str(),0,10);
292 else if (e2.attribute(
"component") ==
"io")
295 deferList.push_back(defer);
298 for (std::list<defer_t>::iterator i = deferList.begin(),end = deferList.end(); i != end; ++i)
299 i->object->deferred(i->s);
306 userprefs.setPath(QSettings::NativeFormat, QSettings::SystemScope,
"/usr/local/share/rtxi/");
308 int oldestsetting = userprefs.value(
"/recentSettingsList/start").toInt();
309 int num_settings = userprefs.value(
"/recentSettingsList/num").toInt();
311 userprefs.beginGroup(
"/recentSettingsList");
312 QStringList entries = userprefs.childKeys();
313 userprefs.endGroup();
314 int numRecentFiles = entries.size();
316 bool doesnotexist =
true;
318 for (
int i = 0; i < numRecentFiles; ++i)
320 listsetting = userprefs.value(
"/recentSettingsList/" + entries[i]).toString();
321 if (QString::fromStdString(filename) == listsetting)
322 doesnotexist =
false;
325 if (filename ==
"/usr/local/share/rtxi/rtxi.conf")
326 doesnotexist =
false;
330 if (num_settings == 10)
332 userprefs.setValue(
"/recentSettingsList/" + QString::number(oldestsetting), QVariant(QString::fromStdString(filename)));
334 if (oldestsetting == 10)
336 userprefs.setValue(
"/recentSettingsList/start", oldestsetting);
340 userprefs.setValue(
"/recentSettingsList/" + QString::number(num_settings++), QVariant(QString::fromStdString(filename)));
341 userprefs.setValue(
"/recentSettingsList/num", num_settings);
350 QDomDocument *doc =
reinterpret_cast<QDomDocument *
>(param);
351 QDomElement e = plugin->
save().
xml(*doc);
353 e.setAttribute(
"component",
"plugin");
354 e.setAttribute(
"library",QString::fromStdString(plugin->
getLibrary()));
355 doc->documentElement().appendChild(e);
363 doc.appendChild(doc.createElement(
"RTXI"));
364 doc.documentElement().setAttribute(
"class",
"settings");
365 doc.documentElement().setAttribute(
"version",QString(
VERSION));
375 e.setAttribute(
"component",
"rt");
376 doc.documentElement().appendChild(e);
382 e.setAttribute(
"component",
"io");
383 doc.documentElement().appendChild(e);
390 QFile file(QString::fromStdString(filename));
391 if (!file.open(QIODevice::WriteOnly))
393 ERROR_MSG(
"Settings::Manager::save : failed to open %s for writing\n",filename.c_str());
397 QTextStream stream(&file);
402 userprefs.setPath (QSettings::NativeFormat, QSettings::SystemScope,
"/usr/local/share/rtxi/");
404 int oldestsetting = userprefs.value(
"/recentSettingsList/start").toInt();
405 int num_settings = userprefs.value(
"/recentSettingsList/num").toInt();
407 userprefs.beginGroup(
"/recentSettingsList");
408 QStringList entries = userprefs.childKeys();
409 userprefs.endGroup();
410 int numRecentFiles = entries.size();
412 bool doesnotexist =
true;
414 for (
int i = 0; i < numRecentFiles; ++i)
416 listsetting = userprefs.value(
"/recentSettingsList/" + entries[i]).toString();
417 if (QString::fromStdString(filename) == listsetting)
418 doesnotexist =
false;
421 if (filename ==
"/usr/local/share/rtxi/rtxi.conf")
422 doesnotexist =
false;
426 if (num_settings == 10)
428 userprefs.setValue(
"/recentSettingsList/" + QString::number(oldestsetting), QVariant(QString::fromStdString(filename)));
430 if (oldestsetting == 11)
432 userprefs.setValue(
"/recentSettingsList/start", oldestsetting);
436 userprefs.setValue(
"/recentSettingsList/" + QString::number(num_settings++), QVariant(QString::fromStdString(filename)));
437 userprefs.setValue(
"/recentSettingsList/num", num_settings);
450 if (objectMap.find(
id) == objectMap.end())
452 objectMap[id] = object;
465 while (objectMap.find(currentID) != objectMap.end() && currentID !=
Object::INVALID) ++currentID;
476 ERROR_MSG(
"Settings::Manager::acquireID : maximum number of settings objects loaded.\n");
481 object->id = currentID;
482 objectMap[currentID++] = object;
492 objectMap.erase(object->id);
493 if (object->id < currentID) currentID =
object->id;
502 ERROR_MSG(
"Settings::Manager::insertObject : invalid object\n");
509 std::list<Object *>::iterator i;
510 for (i = objectList.begin(); i != objectList.end() && (*i)->id < object->id; ++i);
513 event.setParam(
"object",
object);
516 objectList.insert(i,
object);
524 event.setParam(
"object",
object);
527 objectList.remove(
object);