-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathedslib_displaydb_iterator.c
More file actions
268 lines (250 loc) · 10.9 KB
/
Copy pathedslib_displaydb_iterator.c
File metadata and controls
268 lines (250 loc) · 10.9 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* LEW-19710-1, CCSDS SOIS Electronic Data Sheet Implementation
*
* Copyright (c) 2020 United States Government as represented by
* the Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* \file edslib_displaydb_iterator.c
* \ingroup fsw
* \author joseph.p.hickey@nasa.gov
*
* Implementation of internal EDS library functions to walk through an EDS
* structure. This actually uses the basic walk routine and combines that
* data with supplemental data from the name dictionary and provides a
* single callback to the user that has the full set of information.
*
* Linked as part of the "full" EDS runtime library
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "edslib_displaydb.h"
#include "edslib_internal.h"
/*----------------------------------------------------------------
*
* EdsLib internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
EdsLib_Iterator_Rc_t EdsLib_DisplayIterator_Wrapper(const EdsLib_DatabaseObject_t *GD,
EdsLib_Iterator_CbType_t CbType,
const EdsLib_DataTypeIterator_StackEntry_t *EntityInfo,
void *OpaqueArg)
{
EdsLib_DisplayDB_InternalIterator_ControlBlock_t *Iterator =
(EdsLib_DisplayDB_InternalIterator_ControlBlock_t *)OpaqueArg;
EdsLib_DisplayIterator_StackEntry_t *TopEnt;
const char *EntityName;
EdsLib_Iterator_Rc_t RetCode;
RetCode = EDSLIB_ITERATOR_RC_DEFAULT;
EntityName = NULL;
switch (CbType)
{
case EDSLIB_ITERATOR_CBTYPE_START:
{
TopEnt = Iterator->NextStackEntry;
++Iterator->NextStackEntry;
/*
* note it is possible to get a NULL display info here, as the display
* info is loaded separately and therefore can be missing.
*/
TopEnt->DisplayInf = EdsLib_DisplayDB_GetEntry(GD, &EntityInfo->Details.RefObj);
while (TopEnt->DisplayInf != NULL && TopEnt->DisplayInf->DisplayHint == EDSLIB_DISPLAYHINT_REFERENCE_TYPE)
{
TopEnt->DisplayInf = EdsLib_DisplayDB_GetEntry(GD, &TopEnt->DisplayInf->DisplayArg.RefObj);
}
break;
}
case EDSLIB_ITERATOR_CBTYPE_MEMBER:
{
TopEnt = Iterator->NextStackEntry - 1;
if (TopEnt->DisplayInf)
{
if (TopEnt->DisplayInf->DisplayHint == EDSLIB_DISPLAYHINT_MEMBER_NAMETABLE)
{
EntityName = TopEnt->DisplayInf->DisplayArg.NameTable[EntityInfo->CurrIndex];
}
else if (TopEnt->DisplayInf->DisplayHint == EDSLIB_DISPLAYHINT_ENUM_SYMTABLE)
{
const EdsLib_SymbolTableEntry_t *TableEnt =
EdsLib_DisplaySymbolLookup_GetByValue(TopEnt->DisplayInf->DisplayArg.SymTable,
TopEnt->DisplayInf->DisplayArgTableSize,
EntityInfo->CurrIndex);
if (TableEnt != NULL)
{
EntityName = TableEnt->SymName;
}
}
}
break;
}
case EDSLIB_ITERATOR_CBTYPE_END:
{
--Iterator->NextStackEntry;
break;
}
default:
break;
}
if (EntityInfo->Details.EntryType == EDSLIB_ENTRYTYPE_BASE_TYPE)
{
/*
* This is a "hidden base type" structure.
* This means that the members of this structure will be iterated as if
* they are members of the parent structure, just like an inherited type
* in the typical OO paradigm. In this case we descend _without_ giving
* the typical user callback.
*/
if (CbType == EDSLIB_ITERATOR_CBTYPE_MEMBER)
{
RetCode = EDSLIB_ITERATOR_RC_DESCEND;
}
else
{
RetCode = EDSLIB_ITERATOR_RC_CONTINUE;
}
}
else
{
RetCode = Iterator->NextCallback(GD, CbType, EntityInfo, EntityName, Iterator->NextCallbackArg);
}
return RetCode;
}
/*----------------------------------------------------------------
*
* EdsLib internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
EdsLib_Iterator_Rc_t
EdsLib_DisplayUserIterator_BaseName_Callback(const EdsLib_DatabaseObject_t *GD,
EdsLib_Iterator_CbType_t CbType,
const EdsLib_DataTypeIterator_StackEntry_t *EntityInfo,
const char *EntityName,
void *OpaqueArg)
{
EdsLib_DisplayUserIterator_BaseName_ControlBlock_t *CtrlBlock = OpaqueArg;
EdsLib_EntityDescriptor_t ParamBuff;
if (CbType == EDSLIB_ITERATOR_CBTYPE_MEMBER)
{
memset(&ParamBuff, 0, sizeof(ParamBuff));
ParamBuff.EntityInfo.Offset = EntityInfo->StartOffset;
ParamBuff.EntityInfo.MaxSize.Bits = EntityInfo->EndOffset.Bits - EntityInfo->StartOffset.Bits;
ParamBuff.EntityInfo.MaxSize.Bytes = EntityInfo->EndOffset.Bytes - EntityInfo->StartOffset.Bytes;
ParamBuff.EntityInfo.EdsId = EdsLib_Encode_StructId(&EntityInfo->Details.RefObj);
ParamBuff.FullName = EntityName;
ParamBuff.SeqNum = EntityInfo->CurrIndex;
CtrlBlock->UserCallback(CtrlBlock->UserArg, &ParamBuff);
}
return EDSLIB_ITERATOR_RC_CONTINUE;
}
/*----------------------------------------------------------------
*
* EdsLib internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
EdsLib_Iterator_Rc_t
EdsLib_DisplayUserIterator_FullName_Callback(const EdsLib_DatabaseObject_t *GD,
EdsLib_Iterator_CbType_t CbType,
const EdsLib_DataTypeIterator_StackEntry_t *EntityInfo,
const char *EntityName,
void *OpaqueArg)
{
EdsLib_DisplayUserIterator_FullName_ControlBlock_t *CtrlBlock = OpaqueArg;
EdsLib_DisplayUserIterator_FullName_StackEntry_t *TopEnt;
EdsLib_Iterator_Rc_t RetCode;
RetCode = EDSLIB_ITERATOR_RC_DEFAULT;
switch (CbType)
{
case EDSLIB_ITERATOR_CBTYPE_START:
{
TopEnt = CtrlBlock->NextEntry;
++CtrlBlock->NextEntry;
TopEnt->ScratchOffset = strlen(CtrlBlock->ScratchNameBuffer);
TopEnt->HasNamedMembers = (EntityInfo->DataDictPtr->BasicType == EDSLIB_BASICTYPE_CONTAINER
|| EntityInfo->DataDictPtr->BasicType == EDSLIB_BASICTYPE_COMPONENT);
if (TopEnt->HasNamedMembers && TopEnt->ScratchOffset > 0
&& TopEnt->ScratchOffset < (sizeof(CtrlBlock->ScratchNameBuffer) - 1))
{
CtrlBlock->ScratchNameBuffer[TopEnt->ScratchOffset] = '.';
++TopEnt->ScratchOffset;
CtrlBlock->ScratchNameBuffer[TopEnt->ScratchOffset] = 0;
}
break;
}
case EDSLIB_ITERATOR_CBTYPE_MEMBER:
{
TopEnt = CtrlBlock->NextEntry - 1;
if (EntityName != NULL)
{
/*
* For arrays, the name will be suffixed with a C-style array index i.e. parent[index]
* For structures, append a single '.' character as a C-style field delineator i.e "parent.member"
*/
if (EntityInfo->Details.EntryType == EDSLIB_ENTRYTYPE_ARRAY_ELEMENT)
{
snprintf(&CtrlBlock->ScratchNameBuffer[TopEnt->ScratchOffset],
sizeof(CtrlBlock->ScratchNameBuffer) - TopEnt->ScratchOffset,
"[%s]",
EntityName);
}
else
{
snprintf(&CtrlBlock->ScratchNameBuffer[TopEnt->ScratchOffset],
sizeof(CtrlBlock->ScratchNameBuffer) - TopEnt->ScratchOffset,
"%s",
EntityName);
}
}
else if (EntityInfo->Details.EntryType == EDSLIB_ENTRYTYPE_ARRAY_ELEMENT)
{
snprintf(&CtrlBlock->ScratchNameBuffer[TopEnt->ScratchOffset],
sizeof(CtrlBlock->ScratchNameBuffer) - TopEnt->ScratchOffset,
"[%u]",
(unsigned int)EntityInfo->CurrIndex);
}
else
{
/* No name */
CtrlBlock->ScratchNameBuffer[TopEnt->ScratchOffset] = 0;
}
if (EntityInfo->DataDictPtr->NumSubElements > 0)
{
RetCode = EDSLIB_ITERATOR_RC_DESCEND;
}
else if (CtrlBlock->ScratchNameBuffer[TopEnt->ScratchOffset] != 0)
{
RetCode = EdsLib_DisplayUserIterator_BaseName_Callback(GD,
CbType,
EntityInfo,
CtrlBlock->ScratchNameBuffer,
&CtrlBlock->Base);
}
break;
}
case EDSLIB_ITERATOR_CBTYPE_END:
{
--CtrlBlock->NextEntry;
break;
}
default:
break;
}
return RetCode;
}