Repository navigation
Expand file tree
/
Copy pathpdata.cxx
More file actions
242 lines (207 loc) · 5.83 KB
/
Copy pathpdata.cxx
File metadata and controls
242 lines (207 loc) · 5.83 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
/****************************************************************************
Copyright (C) 1995, University of California, Davis
THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND THE UNIVERSITY
OF CALIFORNIA DOES NOT MAKE ANY WARRANTY ABOUT THE SOFTWARE, ITS
PERFORMANCE, ITS MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
USE, FREEDOM FROM ANY COMPUTER DISEASES OR ITS CONFORMITY TO ANY
SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND PERFORMANCE OF
THE SOFTWARE IS WITH THE USER.
Copyright of the software and supporting documentation is
owned by the University of California, and free access
is hereby granted as a license to use this software, copy this
software and prepare derivative works based upon this software.
However, any distribution of this software source code or
supporting documentation or derivative works (source code and
supporting documentation) must include this copyright notice.
****************************************************************************/
/***************************************************************************
*
* University of California, Davis
* UCDMC DICOM Network Transport Libraries
* Version 0.1 Beta
*
* Technical Contact: mhoskin@ucdavis.edu
*
***************************************************************************/
//20100619 bcb Fix gcc4 warnings, improve speed and made locals.
//20100717 mvh Merged (note: locals means changes parameter names)
//20130807 mvh Detect invalid Length returned to fix hanging thread issue
// Fixed >0 check on UINT32
# include "dicom.hpp"
INT MemoryBuffer :: ReadBinary ( BYTE * lData, UINT Count )
{
INT RetVal;
if ( Index == Length )
return ( -1 ); // end
if((Length - Index)<Count )
{
memcpy((void*)lData, (void*)&this->Data[Index], Length - Index);
RetVal = (INT) Length - Index;
Index = Length;
return ( RetVal );
}
memcpy((void*)lData, (void*)&this->Data[Index], Count);
Index += Count;
return ( Count );
}
BOOL MemoryBuffer :: SendBinary ( BYTE *, UINT )
{
return ( FALSE );
}
MemoryBuffer :: MemoryBuffer (
BYTE *lData,
UINT lLength,
BOOL Destruct,
UINT lInEndian )
#ifdef __GNUC__ //Faster with member initialization.
:Data(lData),
Length(lLength),
Index(0),
DestructFlag(Destruct)
{
#else
{
Index = 0;
this->Length = lLength;
this->Data = lData;
DestructFlag = Destruct;
#endif
SetIncomingEndian(lInEndian);
this->Index = lLength;
BufferSpace *aBS = new BufferSpace;
aBS->BufferSize = lLength;
aBS->isTemp = TRUE;
aBS->Data = lData;
InSize += lLength;
Incoming.Add(aBS);
}
MemoryBuffer :: ~MemoryBuffer ()
{
if(DestructFlag)
if(Data)
delete Data;
}
BOOL LinkedBuffer :: Fill(Buffer &Link, UINT Count)
{
LinkedTo = &Link;
return(Buffer :: Fill(Count));
}
INT LinkedBuffer :: ReadBinary(BYTE *Data, UINT Count)
{
if(LinkedTo->Read(Data, Count))
return(Count);
return(-1);
}
BOOL LinkedBuffer :: SendBinary(BYTE *Data, UINT Count)
{
LinkedTo->Write(Data, Count);
LinkedTo->Flush();
return ( TRUE );
}
UINT LinkedBuffer :: GetOutgoingSize()
{
return(OutSize);
}
UINT LinkedBuffer :: GetIncomingSize()
{
return(InSize);
}
BOOL LinkedBuffer :: Flush(Buffer &Link, UINT Count)
{
LinkedTo = &Link;
return(Buffer :: Flush(Count));
}
BOOL PDataTF :: ReadDynamic(Buffer &Link)
{
UINT32 Count;
if(!Length)
{
Link >> Reserved1;
Link >> Length;
}
//fprintf(stderr, "Reading P-DATA-TF: %d Length\n", Length);
Count = Length;
MsgStatus = 0; // continue
while ( (INT32)Count > 0) // (INT32) 20130807
{
Link >> pdv.Length;
if (pdv.Length > Count) return FALSE; // 20130807
Link >> pdv.PresentationContextID;
Link >> pdv.MsgHeader;
//fprintf(stderr, "Reading PDV: %d Length, %d ID, %x Header\n",
// pdv.Length, pdv.PresentationContextID, pdv.MsgHeader);
VRBuffer.Fill(Link, pdv.Length - 2);
//fprintf(stderr, "Finished reading PDV\n");
Count = Count - pdv.Length - sizeof(UINT32);
Length = Length - pdv.Length - sizeof(UINT32);
//fprintf(stderr, "Count = %d\n", Count);
if(IsThisTheLastFragment(pdv.MsgHeader))
{
MsgStatus = 1;
PresentationContextID = pdv.PresentationContextID;
return ( TRUE );
}
}
//fprintf(stderr, "done reading PDV's\n");
if(IsThisTheLastFragment(pdv.MsgHeader))
MsgStatus = 1;
PresentationContextID = pdv.PresentationContextID;
return ( TRUE );
}
BOOL PDataTF :: Write(Buffer &Link)
{
// Generate P-DATA-TF Messages.
UINT BlockSize, SentSize, TotalSize, TLength;
TotalSize = VRBuffer.GetOutgoingSize();
BlockSize = 4096;
SentSize = 0;
TLength = Length;
while(SentSize < TotalSize)
{
if((TotalSize - SentSize) < BlockSize)
BlockSize = TotalSize - SentSize;
if((BlockSize + SentSize) == TotalSize)
// if(BlockSize)
MsgHeader = MsgHeader | 0x02;
else
MsgHeader = MsgHeader & 0x01;
pdv.PresentationContextID = PresentationContextID;
pdv.MsgHeader = MsgHeader;
pdv.Length = BlockSize + 2;
Length = pdv.Length + sizeof(UINT32);
ItemType = 0x04;
Reserved1 = 0;
Link << ItemType;
Link << Reserved1;
Link << Length;
Link << pdv.Length;
Link << pdv.PresentationContextID;
Link << MsgHeader;
if(BlockSize)
VRBuffer.Flush(Link, BlockSize);
SentSize += BlockSize;
Link.Flush();
}
Length = TLength;
return ( TRUE );
}
PDataTF :: PDataTF()
#ifdef __GNUC__ //Faster with member initialization.
:ItemType(0x04),
Reserved1(0),
Length(0),
VRBuffer(),
MsgStatus(0),
Endian(NATIVE_ENDIAN),
pdv(),
PresentationContextID(0),
MsgHeader(0) {}
#else
{
ItemType = 0x04;
Length = 0;
}
#endif
PDataTF :: ~PDataTF()
{
}