aboutsummaryrefslogtreecommitdiff
path: root/tests/profiling/timelineDecoder/TimelineDecoder.cpp
blob: b6f051b74560de4bb88bab663f6b7b52e1e00a66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// Copyright © 2019 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "ITimelineDecoder.h"

ErrorCode CreateEntity(const Entity entity, Model* model)
{
    if (model == nullptr || model->m_EntityCb == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_EntityCb(entity, model);
    return ErrorCode::ErrorCode_Success;
}

ErrorCode CreateEventClass(const EventClass eventClass, Model* model)
{
    if (model == nullptr || model->m_EventClassCb == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_EventClassCb(eventClass, model);
    return ErrorCode::ErrorCode_Success;
}

ErrorCode CreateEvent(const Event event, Model* model)
{
    if (model == nullptr || model->m_EventCb == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_EventCb(event, model);
    return ErrorCode::ErrorCode_Success;
}

ErrorCode CreateLabel(const Label label, Model* model)
{
    if (model == nullptr || model->m_LabelCb == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_LabelCb(label, model);
    return ErrorCode::ErrorCode_Success;
}

ErrorCode CreateRelationship(Relationship relationship, Model* model)
{
    if (model == nullptr || model->m_RelationshipCb == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_RelationshipCb(relationship, model);
    return ErrorCode::ErrorCode_Success;
}

ErrorCode SetEntityCallback(OnNewEntityCallback cb, Model* model)
{
    if (cb == nullptr || model == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_EntityCb = cb;
    return ErrorCode::ErrorCode_Success;
}

ErrorCode SetEventClassCallback(OnNewEventClassCallback cb, Model* model)
{
    if (cb == nullptr || model == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_EventClassCb = cb;
    return ErrorCode::ErrorCode_Success;
}

ErrorCode SetEventCallback(OnNewEventCallback cb, Model* model)
{
    if (cb == nullptr || model == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_EventCb = cb;
    return ErrorCode::ErrorCode_Success;
}

ErrorCode SetLabelCallback(OnNewLabelCallback cb, Model* model)
{
    if (cb == nullptr || model == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_LabelCb = cb;
    return ErrorCode::ErrorCode_Success;
}

ErrorCode SetRelationshipCallback(OnNewRelationshipCallback cb, Model* model)
{
    if (cb == nullptr || model == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }
    model->m_RelationshipCb = cb;
    return ErrorCode::ErrorCode_Success;
}

ErrorCode CreateModel(Model** model)
{
    Model* modelPtr = new Model;

    modelPtr->m_EntityCount = 0;
    modelPtr->m_EventClassCount = 0;
    modelPtr->m_EventCount = 0;
    modelPtr->m_LabelCount = 0;
    modelPtr->m_RelationshipCount = 0;

    *model = modelPtr;
    return ErrorCode::ErrorCode_Success;
}

ErrorCode DestroyModel(Model** model)
{
    if (*model == nullptr)
    {
        return ErrorCode::ErrorCode_Fail;
    }

    Model* modelPtr = *model;

    for (uint32_t i = 0; i < modelPtr->m_EntityCount; ++i)
    {
        delete modelPtr->m_Entities[i];
    }

    for (uint32_t i = 0; i < modelPtr->m_EventClassCount; ++i)
    {
        delete modelPtr->m_EventClasses[i];
    }

    for (uint32_t i = 0; i < modelPtr->m_EventCount; ++i)
    {
        delete[] modelPtr->m_Events[i]->m_ThreadId;
        delete modelPtr->m_Events[i];
    }

    for (uint32_t i = 0; i < modelPtr->m_LabelCount; ++i)
    {
        delete[] modelPtr->m_Labels[i]->m_Name;
        delete modelPtr->m_Labels[i];
    }

    for (uint32_t i = 0; i < modelPtr->m_RelationshipCount; ++i)
    {
        delete modelPtr->m_Relationships[i];
    }

    delete[] modelPtr->m_Entities;
    delete[] modelPtr->m_EventClasses;
    delete[] modelPtr->m_Events;
    delete[] modelPtr->m_Labels;
    delete[] modelPtr->m_Relationships;

    delete modelPtr;
    return ErrorCode::ErrorCode_Success;
}