2 * Copyright (C) ARM Limited 2010-2014. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include "SessionXML.h"
16 #include "OlyUtility.h"
17 #include "SessionData.h"
19 static const char* TAG_SESSION = "session";
20 static const char* TAG_IMAGE = "image";
22 static const char* ATTR_VERSION = "version";
23 static const char* ATTR_CALL_STACK_UNWINDING = "call_stack_unwinding";
24 static const char* ATTR_BUFFER_MODE = "buffer_mode";
25 static const char* ATTR_SAMPLE_RATE = "sample_rate";
26 static const char* ATTR_DURATION = "duration";
27 static const char* ATTR_PATH = "path";
28 static const char* ATTR_LIVE_RATE = "live_rate";
30 SessionXML::SessionXML(const char *str) {
31 parameters.buffer_mode[0] = 0;
32 parameters.sample_rate[0] = 0;
33 parameters.duration = 0;
34 parameters.call_stack_unwinding = false;
35 parameters.live_rate = 0;
36 parameters.images = NULL;
38 mSessionXML = (const char *)str;
39 logg->logMessage(mSessionXML);
42 SessionXML::~SessionXML() {
44 free((char *)mSessionXML);
48 void SessionXML::parse() {
52 tree = mxmlLoadString(NULL, mSessionXML, MXML_NO_CALLBACK);
53 node = mxmlFindElement(tree, tree, TAG_SESSION, NULL, NULL, MXML_DESCEND);
56 sessionTag(tree, node);
61 logg->logError(__FILE__, __LINE__, "No session tag found in the session.xml file");
65 void SessionXML::sessionTag(mxml_node_t *tree, mxml_node_t *node) {
67 if (mxmlElementGetAttr(node, ATTR_VERSION)) version = strtol(mxmlElementGetAttr(node, ATTR_VERSION), NULL, 10);
69 logg->logError(__FILE__, __LINE__, "Invalid session.xml version: %d", version);
73 // copy to pre-allocated strings
74 if (mxmlElementGetAttr(node, ATTR_BUFFER_MODE)) {
75 strncpy(parameters.buffer_mode, mxmlElementGetAttr(node, ATTR_BUFFER_MODE), sizeof(parameters.buffer_mode));
76 parameters.buffer_mode[sizeof(parameters.buffer_mode) - 1] = 0; // strncpy does not guarantee a null-terminated string
78 if (mxmlElementGetAttr(node, ATTR_SAMPLE_RATE)) {
79 strncpy(parameters.sample_rate, mxmlElementGetAttr(node, ATTR_SAMPLE_RATE), sizeof(parameters.sample_rate));
80 parameters.sample_rate[sizeof(parameters.sample_rate) - 1] = 0; // strncpy does not guarantee a null-terminated string
84 parameters.call_stack_unwinding = util->stringToBool(mxmlElementGetAttr(node, ATTR_CALL_STACK_UNWINDING), false);
85 if (mxmlElementGetAttr(node, ATTR_DURATION)) parameters.duration = strtol(mxmlElementGetAttr(node, ATTR_DURATION), NULL, 10);
86 if (mxmlElementGetAttr(node, ATTR_LIVE_RATE)) parameters.live_rate = strtol(mxmlElementGetAttr(node, ATTR_LIVE_RATE), NULL, 10);
89 node = mxmlGetFirstChild(node);
91 if (mxmlGetType(node) != MXML_ELEMENT) {
92 node = mxmlWalkNext(node, tree, MXML_NO_DESCEND);
95 if (strcmp(TAG_IMAGE, mxmlGetElement(node)) == 0) {
98 node = mxmlWalkNext(node, tree, MXML_NO_DESCEND);
102 void SessionXML::sessionImage(mxml_node_t *node) {
103 int length = strlen(mxmlElementGetAttr(node, ATTR_PATH));
104 struct ImageLinkList *image;
106 image = (struct ImageLinkList *)malloc(sizeof(struct ImageLinkList));
107 image->path = (char*)malloc(length + 1);
108 image->path = strdup(mxmlElementGetAttr(node, ATTR_PATH));
109 image->next = parameters.images;
110 parameters.images = image;