-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdrtable.c
170 lines (143 loc) · 3.44 KB
/
sdrtable.c
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
/*
* sdrtable.c: simple data recorder table management
* library.
*
* Copyright (c) 2001-2007, California Institute of Technology.
* ALL RIGHTS RESERVED. U.S. Government Sponsorship
* acknowledged.
*
* Author: Scott Burleigh, JPL
*
* This library implements the Simple Data Recorder system's
* self-delimiting tables.
*
* Modification History:
* Date Who What
* 4-3-96 APS Abstracted IPC services and task control.
* 5-1-96 APS Ported to sparc-sunos4.
* 12-20-00 SCB Revised for sparc-sunos5.
* 6-8-07 SCB Divided sdr.c library into separable components.
*/
#include "sdrP.h"
#include "sdrtable.h"
/* Private definition of SDR table structure. */
typedef struct
{
Address userData;
int rowSize;
int rowCount;
Object rows; /* an array */
} SdrTable;
/* * * Table management functions * * */
Object Sdr_table_create(const char *file, int line, Sdr sdrv, int rowSize,
int rowCount)
{
SdrTable tableBuffer;
Object table;
if (!(sdr_in_xn(sdrv)))
{
oK(_iEnd(file, line, _notInXnMsg()));
return 0;
}
joinTrace(sdrv, file, line);
if (rowSize < 1 || rowCount < 1)
{
oK(_xniEnd(file, line, _apiErrMsg(), sdrv));
return 0;
}
tableBuffer.userData = 0;
tableBuffer.rowSize = rowSize;
tableBuffer.rowCount = rowCount;
tableBuffer.rows = _sdrmalloc(sdrv, rowSize * rowCount);
if (tableBuffer.rows == 0)
{
oK(_iEnd(file, line, "tableBuffer.rows"));
return 0;
}
table = _sdrzalloc(sdrv, sizeof tableBuffer);
if (table == 0)
{
oK(_iEnd(file, line, "table"));
return 0;
}
sdrPut((Address) table, tableBuffer);
return table;
}
Address sdr_table_user_data(Sdr sdrv, Object table)
{
SdrTable tableBuffer;
CHKZERO(sdrFetchSafe(sdrv));
CHKZERO(table);
sdrFetch(tableBuffer, (Address) table);
return tableBuffer.userData;
}
void Sdr_table_user_data_set(const char *file, int line, Sdr sdrv,
Object table, Address data)
{
SdrTable tableBuffer;
if (!(sdr_in_xn(sdrv)))
{
oK(_iEnd(file, line, _notInXnMsg()));
return;
}
joinTrace(sdrv, file, line);
if (table == 0)
{
oK(_xniEnd(file, line, "table", sdrv));
return;
}
sdrFetch(tableBuffer, (Address) table);
tableBuffer.userData = data;
sdrPut((Address) table, tableBuffer);
}
void sdr_table_dimensions(Sdr sdrv, Object table, int *rowSize,
int *rowCount)
{
SdrTable tableBuffer;
CHKVOID(table);
CHKVOID(rowSize);
CHKVOID(rowCount);
sdrFetch(tableBuffer, (Address) table);
*rowSize = tableBuffer.rowSize;
*rowCount = tableBuffer.rowCount;
}
void sdr_table_stage(Sdr sdrv, Object table)
{
SdrTable tableBuffer;
CHKVOID(table);
sdrFetch(tableBuffer, (Address) table);
sdr_stage(sdrv, NULL, tableBuffer.rows, 0);
}
Address sdr_table_row(Sdr sdrv, Object table, unsigned int rowNbr)
{
SdrTable tableBuffer;
Address addr;
CHKERR(table);
sdrFetch(tableBuffer, (Address) table);
CHKERR(rowNbr < tableBuffer.rowCount);
addr = ((Address) (tableBuffer.rows)) + (rowNbr * tableBuffer.rowSize);
return addr;
}
void Sdr_table_destroy(const char *file, int line, Sdr sdrv, Object table)
{
SdrTable tableBuffer;
if (!(sdr_in_xn(sdrv)))
{
oK(_iEnd(file, line, _notInXnMsg()));
return;
}
joinTrace(sdrv, file, line);
if (table == 0)
{
oK(_xniEnd(file, line, _apiErrMsg(), sdrv));
return;
}
sdrFetch(tableBuffer, (Address) table);
sdrFree(tableBuffer.rows);
/* just in case user mistakenly accesses later... */
tableBuffer.rowSize = 0;
tableBuffer.rowCount = 0;
tableBuffer.rows = 0;
sdrPut((Address) table, tableBuffer);
sdrFree(table);
}