-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDbgTraceContext.cpp
More file actions
198 lines (181 loc) · 4.34 KB
/
DbgTraceContext.cpp
File metadata and controls
198 lines (181 loc) · 4.34 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* DbgTraceContext.cpp
*
* Created on: 14.04.2015
* Author: aschoepfer
*/
#include "DbgTraceContext.h"
#include "DbgTracePort.h"
#include "DbgTraceOut.h"
#include <string.h>
DbgTrace_Context* DbgTrace_Context::s_context = 0;
DbgTrace_Context::DbgTrace_Context(DbgCli_Topic* cliParentNode)
: m_contextDbgTopic(cliParentNode)
, m_firstPort(0)
, m_firstOut(0)
{
s_context = this;
}
DbgTrace_Port* DbgTrace_Context::getTracePort(const char* tag)
{
if(0 == m_firstPort)
{
// no ports, return
return 0;
}
else
{
// search port
DbgTrace_Port* tmpPort = m_firstPort;
while((0 != tmpPort))
{
if(0 == strncmp(tmpPort->getTag(), tag, DbgTrace_Port::s_cMaxPortTagLength))
{
// Port with this tag could be found
return tmpPort;
}
tmpPort = tmpPort->getNextPort();
}
return tmpPort;
}
}
void DbgTrace_Context::addTracePort(DbgTrace_Port* port)
{
// check if port with this tag already exists in the list.
DbgTrace_Port* tmpPort = m_firstPort;
DbgTrace_Port* previousPort = m_firstPort;
const char* portTag;
if(0 != port)
{
portTag = port->getTag();
while((0 != tmpPort))
{
if(0 == strncmp(tmpPort->getTag(), portTag, DbgTrace_Port::s_cMaxPortTagLength))
{
// fail, port with this tag already exists.
return;
}
previousPort = tmpPort;
tmpPort = tmpPort->getNextPort();
}
// no port with this tag, add port to list.
if(0 != previousPort)
{
previousPort->setNextPort(port);
}
else
{ // special adding of the very first out.
m_firstPort = port;
}
// Create DbgCliTopic and DbgCliCommands for this port
if(0 != m_contextDbgTopic)
{
port->createCliNodes(m_contextDbgTopic);
}
}
}
void DbgTrace_Context::deleteTracePort(const char* tag)
{
// check if port with this tag already exists in the list.
DbgTrace_Port* tmpPort = m_firstPort;
DbgTrace_Port* previousPort = m_firstPort;
while((0 != tmpPort))
{
if(0 == strncmp(tmpPort->getTag(), tag, DbgTrace_Port::s_cMaxPortTagLength))
{
// found the searched TracePort, change nextPort-ptrs
DbgTrace_Port* nextPort = tmpPort->getNextPort();
if(0 != nextPort)
{
previousPort->setNextPort(nextPort);
}
else
{
// found TracePort was the last one.
previousPort->setNextPort(0);
}
return;
}
previousPort = tmpPort;
tmpPort = tmpPort->getNextPort();
}
}
DbgTrace_Out* DbgTrace_Context::getTraceOut(const char* name)
{
if(0 == m_firstOut)
{
// no out's, return
return 0;
}
else
{
// search out
DbgTrace_Out* tmpOut = m_firstOut;
while((0 != tmpOut))
{
if(0 == strncmp(tmpOut->getName(), name, DbgTrace_Out::s_cMaxOutNameLength))
{
// Out with this name could be found
return tmpOut;
}
tmpOut = tmpOut->getNextOut();
}
return tmpOut;
}
}
void DbgTrace_Context::addTraceOut(DbgTrace_Out* out)
{
// check if out with this name already exists in the list.
DbgTrace_Out* tmpOut = m_firstOut;
DbgTrace_Out* previousOut = m_firstOut;
const char* outName;
if(0 != out)
{
outName = out->getName();
while((0 != tmpOut))
{
if(0 == strncmp(tmpOut->getName(), outName, DbgTrace_Out::s_cMaxOutNameLength))
{
// fail, out with this name already exists.
return;
}
previousOut = tmpOut;
tmpOut = tmpOut->getNextOut();
}
// no out with this name, add out to list.
if(0 != previousOut)
{
previousOut->setNextOut(out);
}
else
{ // special adding of the very first out.
m_firstOut = out;
}
}
}
void DbgTrace_Context::deleteTraceOut(const char* name)
{
// check if out with this name already exists in the list.
DbgTrace_Out* tmpOut = m_firstOut;
DbgTrace_Out* previousOut = m_firstOut;
while((0 != tmpOut))
{
if(0 == strncmp(tmpOut->getName(), name, DbgTrace_Out::s_cMaxOutNameLength))
{
// found the searched TraceOut, change nextOut-ptrs
DbgTrace_Out* nextOut = tmpOut->getNextOut();
if(0 != nextOut)
{
previousOut->setNextOut(nextOut);
}
else
{
// found TraceOut was the last one.
previousOut->setNextOut(0);
}
return;
}
previousOut = tmpOut;
tmpOut = tmpOut->getNextOut();
}
}