File: gdcmULActionAE.cxx

package info (click to toggle)
gdcm 3.0.21-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • 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 (277 lines) | stat: -rw-r--r-- 9,911 bytes parent folder | download | duplicates (5)
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
/*=========================================================================
 *
 *  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.
 *
 *=========================================================================*/
/*

This file contains the implementation for the classes for the AE Actions,
Association Establishment Related Actions (Table 9-6 of ps 3.8-2009).

Since each class is essentially a placeholder for a function pointer, I'm breaking with having
each class have its own file for the sake of brevity of the number of files.

*/

#include "gdcmULActionAE.h"
#include "gdcmARTIMTimer.h"
#include "gdcmAAssociateRQPDU.h"
#include "gdcmAAssociateACPDU.h"
#include "gdcmAAssociateRJPDU.h"

#include <socket++/echo.h>//for setting up the local socket

namespace gdcm
{
namespace network
{

//Issue TRANSPORT CONNECT request primitive to local transport service.
EStateID ULActionAE1::PerformAction(Subject *, ULEvent& , ULConnection& inConnection,
        bool& outWaitingForEvent, EEventID& outRaisedEvent){

  //opening a local socket
  outWaitingForEvent = false;
  if (!inConnection.InitializeConnection())
    {
    outRaisedEvent = eEventDoesNotExist;
    return eSta1Idle;
    }
  else
    {
    outRaisedEvent = eTransportConnConfirmLocal;
    }
  return eSta4LocalAssocDone;
}

//Send A-ASSOCIATE-RQ-PDU
EStateID ULActionAE2::PerformAction(Subject *, ULEvent& , ULConnection& inConnection,
  bool& outWaitingForEvent, EEventID& outRaisedEvent)
{
  AAssociateRQPDU thePDU;

  thePDU.SetCallingAETitle( inConnection.GetConnectionInfo().GetCallingAETitle() );
  thePDU.SetCalledAETitle( inConnection.GetConnectionInfo().GetCalledAETitle() );

  //the presentation context is now defined when the connection is first
  //desired to be established. The connection proposes these different
  //presentation contexts. ideally, we could refine it further to a particular
  //presentation context, but if the server supports many and we support many,
  //then an arbitrary decision can be made.
  std::vector<PresentationContextRQ> const & thePCS =
    inConnection.GetPresentationContexts();

  std::vector<PresentationContextRQ>::const_iterator itor;
  for (itor = thePCS.begin(); itor < thePCS.end(); itor++)
    {
    thePDU.AddPresentationContext(*itor);
    }

  thePDU.Write(*inConnection.GetProtocol());
  inConnection.GetProtocol()->flush();

  outWaitingForEvent = true;
  outRaisedEvent = eEventDoesNotExist;

  return eSta5WaitRemoteAssoc;
}

//Issue A-ASSOCIATE confirmation (accept) primitive
// NOTE: A-ASSOCIATE is NOT A-ASSOCIATE-AC
// PS 3.7 / Annex D for A-ASSOCIATE definition
EStateID ULActionAE3::PerformAction(Subject *, ULEvent& inEvent, ULConnection& inConnection,
        bool& outWaitingForEvent, EEventID& outRaisedEvent){


  // Mark please check this junk:
  assert(!inEvent.GetPDUs().empty());
  AAssociateACPDU* acpdu;
    acpdu = dynamic_cast<AAssociateACPDU*>(inEvent.GetPDUs()[0]);
  assert( acpdu );
  uint32_t maxpdu = acpdu->GetUserInformation().GetMaximumLengthSub().GetMaximumLength();
  inConnection.SetMaxPDUSize(maxpdu);

  // once again duplicate AAssociateACPDU vs ULConnection
  for( unsigned int index = 0; index < acpdu->GetNumberOfPresentationContextAC(); index++ ){
    PresentationContextAC const &pc = acpdu->GetPresentationContextAC(index);
    inConnection.AddAcceptedPresentationContext(pc);
  }

  outWaitingForEvent = false;
  outRaisedEvent = eEventDoesNotExist;//no event is raised,
  //wait for the user to try to send some data.
  return eSta6TransferReady;
}

//Issue A-ASSOCIATE confirmation (reject) primitive and close transport connection
EStateID ULActionAE4::PerformAction(Subject *, ULEvent& , ULConnection& ,
        bool& outWaitingForEvent, EEventID& outRaisedEvent){

  outWaitingForEvent = false;
  outRaisedEvent = eASSOCIATE_RJPDUreceived;
  return eSta1Idle;
}

//Issue Transport connection response primitive, start ARTIM timer
EStateID ULActionAE5::PerformAction(Subject *, ULEvent& , ULConnection& inConnection,
        bool& outWaitingForEvent, EEventID& outRaisedEvent){

  //issue response primitive; have to set that up
  inConnection.GetTimer().Start();

  outWaitingForEvent = false;
  outRaisedEvent = eTransportConnConfirmLocal;
  return eSta2Open;
}

//Stop ARTIM timer and if A-ASSOCIATE-RQ acceptable by service-provider:
//- issue A-ASSOCIATE indication primitive
//Next state: eSta3WaitLocalAssoc
//otherwise:
//- issue A-ASSOCIATE-RJ-PDU and start ARTIM timer
//Next state: eSta13AwaitingClose
EStateID ULActionAE6::PerformAction(Subject *, ULEvent& inEvent, ULConnection& inConnection,
        bool& outWaitingForEvent, EEventID& outRaisedEvent){

 // we are in a C-MOVE

  inConnection.GetTimer().Stop();

  //have to determine 'acceptability'
  //this is more server side than client, so it's a bit empty now
  //we have one server type, a store scp started on a cmove
  //so, it's defined as acceptable.
  bool acceptable = true;//for now, always accept
  if (inEvent.GetPDUs().empty()){
    acceptable = false; //can't accept an empty set of pdus.
    //also, requrie little endian, not sure how to set that, but it should be here.
  }
  AAssociateRQPDU* rqpdu;
  if (acceptable){
    rqpdu = dynamic_cast<AAssociateRQPDU*>(inEvent.GetPDUs()[0]);
    if (rqpdu == nullptr){
      acceptable = false;
    }
  }
  if (acceptable){
    outWaitingForEvent = false;//not waiting, now want to get the
    //sending of data underway.  Have to get info now
    outRaisedEvent = eAASSOCIATEresponseAccept;

    TransferSyntaxSub ts1;
    ts1.SetNameFromUID( UIDs::ImplicitVRLittleEndianDefaultTransferSyntaxforDICOM );

    AAssociateACPDU acpdu;

    assert( rqpdu->GetNumberOfPresentationContext() );
    for( unsigned int index = 0; index < rqpdu->GetNumberOfPresentationContext(); index++ )
      {
      // FIXME / HARDCODED We only ever accept Little Endian
      // FIXME we should check :
      // rqpdu.GetAbstractSyntax() contains LittleEndian
      PresentationContextAC pcac1;
      PresentationContextRQ const &pc = rqpdu->GetPresentationContext(index);
      //add the presentation context back into the connection,
      //so later functions will know what's allowed on this connection
      // BOGUS (MM):
      //inConnection.AddAcceptedPresentationContext(pc);

      const uint8_t id = pc.GetPresentationContextID();

      std::vector<TransferSyntaxSub> const & tsSet = pc.GetTransferSyntaxes();
      std::vector<TransferSyntaxSub>::const_iterator tsitor;
      // PS 3.8 Table 9-18 PRESENTATION CONTEXT ITEM FIELDS
      uint8_t result = 4; // transfer-syntaxes-not-supported (provider rejection)
      for (tsitor = tsSet.begin(); tsitor < tsSet.end(); tsitor++)
        {
        //gdcmDebugMacro( "Checking: [" << tsitor->GetName() << "] vs [" << ts1.GetName() << "]" << std::endl );
        if (strcmp(tsitor->GetName(), ts1.GetName()) == 0 )
          {
          result = 0; // 0 - acceptance
          inConnection.SetCStoreTransferSyntax( ts1 );
          pcac1.SetTransferSyntax( ts1 );
          }
        }
      if( result )
        {
        gdcmWarningMacro( "Could not find Implicit or Explicit Little Endian in Response. Giving another try" );
        // Okay little endian implicit was not found, this happen sometimes, for eg with DVTk, let's be nice and accept also Explicit
        TransferSyntaxSub ts2;
        ts2.SetNameFromUID( UIDs::ExplicitVRLittleEndian );
        for (tsitor = tsSet.begin(); tsitor < tsSet.end(); tsitor++)
          {
          //gdcmDebugMacro( "Checking: [" << tsitor->GetName() << "] vs [" << ts1.GetName() << "]" << std::endl );
          if (strcmp(tsitor->GetName(), ts2.GetName()) == 0 )
            {
            result = 0; // 0 - acceptance
            inConnection.SetCStoreTransferSyntax( ts2 );
            pcac1.SetTransferSyntax( ts2 );
            }
          }
        }
      if( result )
        {
        gdcmErrorMacro( "Could not find Implicit or Explicit Little Endian in Response. Giving up" );
        }
      pcac1.SetPresentationContextID( id );
      pcac1.SetReason( result );
      acpdu.AddPresentationContextAC( pcac1 );
    }
    assert( acpdu.GetNumberOfPresentationContextAC() );

    // Init AE-Titles:
    acpdu.InitFromRQ( *rqpdu );

    acpdu.Write( *inConnection.GetProtocol() );
    inConnection.GetProtocol()->flush();

    return eSta3WaitLocalAssoc;
  } else {

    outWaitingForEvent = false;
    outRaisedEvent = eAASSOCIATEresponseReject;
    AAssociateRJPDU thePDU;
    thePDU.Write(*inConnection.GetProtocol());
    inConnection.GetProtocol()->flush();
    inConnection.GetTimer().Stop();
    return eSta13AwaitingClose;
  }

}

//Send A-ASSOCIATE-AC PDU
EStateID ULActionAE7::PerformAction(Subject *, ULEvent& , ULConnection& ,
        bool& outWaitingForEvent, EEventID& outRaisedEvent)
{
  outWaitingForEvent = true;
  outRaisedEvent = eEventDoesNotExist;
  return eSta6TransferReady;
}

//Send A-ASSOCIATE-RJ PDU and start ARTIM timer
EStateID ULActionAE8::PerformAction(Subject *, ULEvent& , ULConnection& inConnection,
        bool& outWaitingForEvent, EEventID& outRaisedEvent)
{
  AAssociateRJPDU thePDU;
  thePDU.Write(*inConnection.GetProtocol());
  inConnection.GetTimer().Start();
  outWaitingForEvent = false;
  outRaisedEvent = eAASSOCIATEresponseReject;

  return eSta13AwaitingClose;
}

} // end namespace network
} // end namespace gdcm