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";
29 static const char *ATTR_CAPTURE_WORKING_DIR = "capture_working_dir";
30 static const char *ATTR_CAPTURE_COMMAND = "capture_command";
31 static const char *ATTR_CAPTURE_USER = "capture_user";
33 SessionXML::SessionXML(const char *str) {
34 parameters.buffer_mode[0] = 0;
35 parameters.sample_rate[0] = 0;
36 parameters.call_stack_unwinding = false;
37 parameters.live_rate = 0;
39 logg->logMessage(mSessionXML);
42 SessionXML::~SessionXML() {
45 void SessionXML::parse() {
49 tree = mxmlLoadString(NULL, mSessionXML, MXML_NO_CALLBACK);
50 node = mxmlFindElement(tree, tree, TAG_SESSION, NULL, NULL, MXML_DESCEND);
53 sessionTag(tree, node);
58 logg->logError(__FILE__, __LINE__, "No session tag found in the session.xml file");
62 void SessionXML::sessionTag(mxml_node_t *tree, mxml_node_t *node) {
64 if (mxmlElementGetAttr(node, ATTR_VERSION)) version = strtol(mxmlElementGetAttr(node, ATTR_VERSION), NULL, 10);
66 logg->logError(__FILE__, __LINE__, "Invalid session.xml version: %d", version);
70 // copy to pre-allocated strings
71 if (mxmlElementGetAttr(node, ATTR_BUFFER_MODE)) {
72 strncpy(parameters.buffer_mode, mxmlElementGetAttr(node, ATTR_BUFFER_MODE), sizeof(parameters.buffer_mode));
73 parameters.buffer_mode[sizeof(parameters.buffer_mode) - 1] = 0; // strncpy does not guarantee a null-terminated string
75 if (mxmlElementGetAttr(node, ATTR_SAMPLE_RATE)) {
76 strncpy(parameters.sample_rate, mxmlElementGetAttr(node, ATTR_SAMPLE_RATE), sizeof(parameters.sample_rate));
77 parameters.sample_rate[sizeof(parameters.sample_rate) - 1] = 0; // strncpy does not guarantee a null-terminated string
79 if (mxmlElementGetAttr(node, ATTR_CAPTURE_WORKING_DIR)) gSessionData->mCaptureWorkingDir = strdup(mxmlElementGetAttr(node, ATTR_CAPTURE_WORKING_DIR));
80 if (mxmlElementGetAttr(node, ATTR_CAPTURE_COMMAND)) gSessionData->mCaptureCommand = strdup(mxmlElementGetAttr(node, ATTR_CAPTURE_COMMAND));
81 if (mxmlElementGetAttr(node, ATTR_CAPTURE_USER)) gSessionData->mCaptureUser = strdup(mxmlElementGetAttr(node, ATTR_CAPTURE_USER));
84 parameters.call_stack_unwinding = util->stringToBool(mxmlElementGetAttr(node, ATTR_CALL_STACK_UNWINDING), false);
85 if (mxmlElementGetAttr(node, ATTR_DURATION)) gSessionData->mDuration = 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 = gSessionData->mImages;
110 gSessionData->mImages = image;