File: gdcmPDUFactory.cxx

package info (click to toggle)
gdcm 3.0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 26,880 kB
  • sloc: cpp: 203,477; ansic: 78,582; xml: 48,129; python: 3,459; cs: 2,308; java: 1,629; lex: 1,290; sh: 334; php: 128; makefile: 117
file content (360 lines) | stat: -rw-r--r-- 11,784 bytes parent folder | download | duplicates (4)
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*=========================================================================
 *
 *  Copyright NumFOCUS
 *
 *  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.txt
 *
 *  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.
 *
 *=========================================================================*/
/*
basically, given an initial byte, construct the appropriate PDU.
this way, the event loop doesn't have to know about all the different PDU types.

name and date: 25 Sept 2010 mmr

Update on 27 sept 2010 mmr: since this is where all PDUs are included, also use this
class to construct specific instances of PDUs, and return the BasePDU class.
*/
#include "gdcmPDUFactory.h"
#include "gdcmAAbortPDU.h"
#include "gdcmAAssociateACPDU.h"
#include "gdcmAAssociateRJPDU.h"
#include "gdcmAAssociateRQPDU.h"
#include "gdcmAReleaseRPPDU.h"
#include "gdcmAReleaseRQPDU.h"
#include "gdcmPDataTFPDU.h"
#include "gdcmCompositeMessageFactory.h"
#include "gdcmNormalizedMessageFactory.h"
#include "gdcmBaseRootQuery.h"
#include "gdcmBasePDU.h"

namespace gdcm
{
namespace network
{

//eventually needs to be smartpointer'd
BasePDU* PDUFactory::ConstructPDU(uint8_t itemtype)
{
  BasePDU* thePDU = nullptr;
  switch (itemtype)
    {
  case 0x01:
    thePDU = new AAssociateRQPDU;
    break;
  case 0x02:
    thePDU = new AAssociateACPDU;
    break;
  case 0x03:
    thePDU = new AAssociateRJPDU;
    break;
  case 0x04:
    thePDU = new PDataTFPDU;
    break;
  case 0x05:
    thePDU = new AReleaseRQPDU;
    break;
  case 0x06:
    thePDU = new AReleaseRPPDU;
    break;
  case 0x07:
    thePDU = new AAbortPDU;
    break;
    //default is that the PDU remains null
    }
  if( !thePDU )
    {
    gdcmErrorMacro( "Could not construct PDU for itemtype: " << (int)itemtype );
    }
  return thePDU;
}

//determine which event was received by the PDU type
EEventID PDUFactory::DetermineEventByPDU(const BasePDU* inPDU)
{
  if(inPDU)
    {
    const AAssociateRQPDU* theAAssociateRQPDU = dynamic_cast<const AAssociateRQPDU*>(inPDU);
    if (theAAssociateRQPDU != nullptr)
      {
      return eAASSOCIATE_RQPDUreceived;
      }
    const AAssociateACPDU* theAAssociateACPDU = dynamic_cast<const AAssociateACPDU*>(inPDU);
    if (theAAssociateACPDU != nullptr)
      {
      return eASSOCIATE_ACPDUreceived;
      }
    const AAssociateRJPDU* theAAssociateRJPDU = dynamic_cast<const AAssociateRJPDU*>(inPDU);
    if (theAAssociateRJPDU != nullptr)
      {
      return eASSOCIATE_RJPDUreceived;
      }
    const PDataTFPDU* thePDataTFPDU = dynamic_cast<const PDataTFPDU*>(inPDU);
    if (thePDataTFPDU != nullptr)
      {
      ///
      const PresentationDataValue &pdv = thePDataTFPDU->GetPresentationDataValue(0);
      (void)pdv;
#if 0
      int mh = pdv.GetMessageHeader();
      if( mh == 3 )
        {
        // E.2 MESSAGE CONTROL HEADER ENCODING
        // If bit 1 is set to 1, the following fragment shall contain the last
        // fragment of a Message Data Set or of a Message Command.
        std::cout << "This was the last fragment of the message data set" << std::endl;
        }
#endif
      return ePDATATFPDU;
      }
    const AReleaseRQPDU* theAReleaseRQPDU = dynamic_cast<const AReleaseRQPDU*>(inPDU);
    if (theAReleaseRQPDU != nullptr)
      {
      return eARELEASE_RQPDUReceivedOpen;
      }
    const AReleaseRPPDU* theAReleaseRPPDU = dynamic_cast<const AReleaseRPPDU*>(inPDU);
    if (theAReleaseRPPDU != nullptr)
      {
      return eARELEASE_RPPDUReceived;
      }
    const AAbortPDU* theAAbortPDU = dynamic_cast<const AAbortPDU*>(inPDU);
    if (theAAbortPDU != nullptr)
      {
      return eAABORTPDUReceivedOpen;
      }
    }
  return eEventDoesNotExist;
}

BasePDU* PDUFactory::ConstructReleasePDU()
{
  AReleaseRQPDU* theAReleaseRQPDU = new AReleaseRQPDU();

  return theAReleaseRQPDU;
}
BasePDU* PDUFactory::ConstructAbortPDU()
{
  AAbortPDU* theAAbortPDU = new AAbortPDU();

  return theAAbortPDU;
}
std::vector<BasePDU*> PDUFactory::CreateCEchoPDU(const ULConnection& inConnection)
{
  std::vector<PresentationDataValue> pdv =
    CompositeMessageFactory::ConstructCEchoRQ(inConnection);
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;
}

std::vector<BasePDU*> PDUFactory::CreateCMovePDU(const ULConnection&
  inConnection, const BaseRootQuery* inRootQuery)
{
  std::vector<PresentationDataValue> pdv =
    CompositeMessageFactory::ConstructCMoveRQ(inConnection, inRootQuery );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;
}

std::vector<BasePDU*> PDUFactory::CreateCStoreRQPDU(const ULConnection& inConnection,
  const File& file, bool writeDataSet /*= true*/ )
{
  std::vector<PresentationDataValue> pdv =
    CompositeMessageFactory::ConstructCStoreRQ(inConnection, file, writeDataSet );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU;
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;
}

std::vector<BasePDU*> PDUFactory::CreateCStoreRSPPDU(const DataSet* inDataSet,
  const BasePDU* inPDU)
{
  std::vector<PresentationDataValue> pdv =
    CompositeMessageFactory::ConstructCStoreRSP(inDataSet, inPDU );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU;
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;
}

std::vector<BasePDU*> PDUFactory::CreateCFindPDU(const ULConnection& inConnection,
  const BaseRootQuery* inRootQuery)
{
//still have to build this!
  std::vector<PresentationDataValue> pdv =
    CompositeMessageFactory::ConstructCFindRQ(inConnection, inRootQuery );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;


}

std::vector<BasePDU*> PDUFactory::CreateNEventReportPDU		(const ULConnection& inConnection, const BaseQuery *inQuery)
{
//still have to build this!
  std::vector<PresentationDataValue> pdv =
	  NormalizedMessageFactory::ConstructNEventReport(inConnection, inQuery );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;


}
std::vector<BasePDU*> PDUFactory::CreateNGetPDU				(const ULConnection& inConnection, const BaseQuery *inQuery)
{
//still have to build this!
  std::vector<PresentationDataValue> pdv =
    NormalizedMessageFactory::ConstructNGet(inConnection, inQuery );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;


}
std::vector<BasePDU*> PDUFactory::CreateNSetPDU				(const ULConnection& inConnection, const BaseQuery *inQuery)
{
//still have to build this!
  std::vector<PresentationDataValue> pdv =
    NormalizedMessageFactory::ConstructNSet(inConnection, inQuery );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;


}
std::vector<BasePDU*> PDUFactory::CreateNActionPDU			(const ULConnection& inConnection, const BaseQuery *inQuery)
{
//still have to build this!
  std::vector<PresentationDataValue> pdv =
    NormalizedMessageFactory::ConstructNAction(inConnection, inQuery );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;


}
std::vector<BasePDU*> PDUFactory::CreateNCreatePDU			(const ULConnection& inConnection, const BaseQuery *inQuery)
{
//still have to build this!
  std::vector<PresentationDataValue> pdv =
	  NormalizedMessageFactory::ConstructNCreate(inConnection, inQuery );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;


}
std::vector<BasePDU*> PDUFactory::CreateNDeletePDU			(const ULConnection& inConnection, const BaseQuery *inQuery)
{
//still have to build this!
  std::vector<PresentationDataValue> pdv =
    NormalizedMessageFactory::ConstructNDelete(inConnection, inQuery );
  std::vector<PresentationDataValue>::iterator pdvItor;
  std::vector<BasePDU*> outVector;
  for (pdvItor = pdv.begin(); pdvItor < pdv.end(); pdvItor++)
    {
    PDataTFPDU* thePDataTFPDU = new PDataTFPDU();
    thePDataTFPDU->AddPresentationDataValue( *pdvItor );
    outVector.push_back(thePDataTFPDU);
    }
  return outVector;


}


//given data pdus, produce the presentation data values stored within.
//all operations have these as the payload of the data sending operation
//however, echo does not have a dataset in the pdv.
std::vector<PresentationDataValue> PDUFactory::GetPDVs(const std::vector<BasePDU*> & inDataPDUs)
{
  std::vector<BasePDU*>::const_iterator itor;
  std::vector<PresentationDataValue> outPDVs;
  for (itor = inDataPDUs.begin(); itor < inDataPDUs.end(); itor++)
    {
    PDataTFPDU* thePDataTFPDU = dynamic_cast<PDataTFPDU*>(*itor);
    if (thePDataTFPDU == nullptr)
      {
      assert(0); //shouldn't really get here.
      return outPDVs; //just stop now, no longer with data pdus.
      }
    size_t theNumPDVsinPDU = thePDataTFPDU->GetNumberOfPresentationDataValues();
    for (size_t i = 0; i < theNumPDVsinPDU; i++)
      {
      outPDVs.push_back(thePDataTFPDU->GetPresentationDataValue(i));
      }
    }
  return outPDVs;
}
} // end namespace network
} // end namespace gdcm