diff options
Diffstat (limited to 'tools/gator/daemon/EventsXML.cpp')
-rw-r--r-- | tools/gator/daemon/EventsXML.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tools/gator/daemon/EventsXML.cpp b/tools/gator/daemon/EventsXML.cpp new file mode 100644 index 000000000000..2a80482e0b8d --- /dev/null +++ b/tools/gator/daemon/EventsXML.cpp @@ -0,0 +1,70 @@ +/** + * Copyright (C) ARM Limited 2013. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include "EventsXML.h" + +#include "CapturedXML.h" +#include "Logging.h" +#include "OlyUtility.h" +#include "SessionData.h" + +char* EventsXML::getXML() { +#include "events_xml.h" // defines and initializes char events_xml[] and int events_xml_len + char path[PATH_MAX]; + mxml_node_t *xml; + FILE *fl; + + // Avoid unused variable warning + (void)events_xml_len; + + // Load the provided or default events xml + if (gSessionData->mEventsXMLPath) { + strncpy(path, gSessionData->mEventsXMLPath, PATH_MAX); + } else { + util->getApplicationFullPath(path, PATH_MAX); + strncat(path, "events.xml", PATH_MAX - strlen(path) - 1); + } + fl = fopen(path, "r"); + if (fl) { + xml = mxmlLoadFile(NULL, fl, MXML_NO_CALLBACK); + fclose(fl); + } else { + logg->logMessage("Unable to locate events.xml, using default"); + xml = mxmlLoadString(NULL, (char *)events_xml, MXML_NO_CALLBACK); + } + + // Add dynamic events from the drivers + mxml_node_t *events = mxmlFindElement(xml, xml, "events", NULL, NULL, MXML_DESCEND); + if (!events) { + logg->logMessage("Unable to find <events> node in the events.xml"); + handleException(); + } + for (Driver *driver = Driver::getHead(); driver != NULL; driver = driver->getNext()) { + driver->writeEvents(events); + } + + char* string = mxmlSaveAllocString(xml, mxmlWhitespaceCB); + mxmlDelete(xml); + + return string; +} + +void EventsXML::write(const char* path) { + char file[PATH_MAX]; + + // Set full path + snprintf(file, PATH_MAX, "%s/events.xml", path); + + char* buf = getXML(); + if (util->writeToDisk(file, buf) < 0) { + logg->logError(__FILE__, __LINE__, "Error writing %s\nPlease verify the path.", file); + handleException(); + } + + free(buf); +} |