Exemple #1
0
    def SCU(self, ds, msgid):
        # build C-FIND primitive
        cfind = C_FIND_ServiceParameters()
        cfind.MessageID = msgid
        cfind.AffectedSOPClassUID = self.UID
        cfind.Priority = 0x0002
        cfind.Identifier = dsutils.encode(ds,
                                          self.transfersyntax.is_implicit_VR,
                                          self.transfersyntax.is_little_endian)

        # send c-find request
        self.DIMSE.Send(cfind, self.pcid, self.maxpdulength)
        while 1:
            time.sleep(0.001)
            # wait for c-find responses
            ans, id = self.DIMSE.Receive(Wait=False)
            if not ans:
                continue
            d = dsutils.decode(
                ans.Identifier, self.transfersyntax.is_implicit_VR,
                self.transfersyntax.is_little_endian)
            try:
                status = self.Code2Status(ans.Status.value).Type
            except:
                status = None
            if status != 'Pending':
                break
            yield status, d
        yield status, d
Exemple #2
0
    def SCP(self, msg):
        ds = dsutils.decode(msg.Identifier, self.transfersyntax.is_implicit_VR,
                            self.transfersyntax.is_little_endian)

        # make response
        rsp = C_FIND_ServiceParameters()
        rsp.MessageIDBeingRespondedTo = msg.MessageID
        rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID

        gen = self.AE.OnReceiveFind(self, ds)
        try:
            while 1:
                time.sleep(0.001)
                IdentifierDS, status = gen.next()
                rsp.Status = int(status)
                rsp.Identifier = dsutils.encode(
                    IdentifierDS,
                    self.transfersyntax.is_implicit_VR,
                    self.transfersyntax.is_little_endian)
                # send response
                self.DIMSE.Send(rsp, self.pcid, self.ACSE.MaxPDULength)
        except StopIteration:
            # send final response
            rsp = C_FIND_ServiceParameters()
            rsp.MessageIDBeingRespondedTo = msg.MessageID
            rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID
            rsp.Status = int(self.Success)
            self.DIMSE.Send(rsp, self.pcid, self.ACSE.MaxPDULength)
Exemple #3
0
 def SCP(self, msg):
     status = None
     #print self.transfersyntax.is_implicit_VR
     try:
         DS = dsutils.decode(msg.DataSet, 
                             self.transfersyntax.is_implicit_VR, 
                             self.transfersyntax.is_little_endian)
     except:
         status = self.CannotUnderstand
     # make response
     rsp = C_STORE_ServiceParameters()
     rsp.MessageIDBeingRespondedTo = msg.MessageID
     rsp.AffectedSOPInstanceUID = msg.AffectedSOPInstanceUID
     rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID
     # callback
     if not status:
         try:
             status = self.AE.OnReceiveStore(self, DS)
         except:
             raise
             print "There was an exception in OnReceiveStore callback"
             status = self.CannotUnderstand
     rsp.Status = int(status)
     #print "Status: %s" % status
     # send response
     self.DIMSE.Send(rsp, self.pcid, self.ACSE.MaxPDULength)
Exemple #4
0
    def Decode(self, pdata):
        """Constructs itself receiving a series of P-DATA primitives. Returns True when complete, False
        otherwise."""
	if pdata.__class__ <> P_DATA_ServiceParameters:
	    #not a pdata
	    return False
        if DEBUG: print "receiving"
        if pdata == None: return False
        ii = pdata
        for vv in ii.PresentationDataValueList:
            if DEBUG: print "DIMSE: ", str(unpack('b',vv[1][0]))
            # must be able to read P-DATA with several PDVs
            self.ID = vv[0]
            if unpack('b',vv[1][0])[0] in (1,3):
                if DEBUG: print "  command fragment", self.ID
                self.encoded_command_set += vv[1][1:]
                if unpack('b',vv[1][0])[0] == 3:
                    if DEBUG: print "  last command fragment", self.ID
                    self.CommandSet = dsutils.decode(self.encoded_command_set, self.ts.is_implicit_VR, self.ts.is_little_endian)
                    self.__class__ = MessageType[self.CommandSet[(0x0000,0x0100)].value]
                    if self.CommandSet[(0x0000,0x0800)].value == 0x0101:
                        # response: no dataset
                        return True
            elif unpack('b',vv[1][0])[0] in (0,2):
                self.DataSet += vv[1][1:]
                if DEBUG: print "  data fragment", self.ID
                if unpack('b',vv[1][0])[0] == 2:
                    if DEBUG: print "  last data fragment", self.ID
                    return True
            else:
                raise "Error"
	    
        return False
Exemple #5
0
    def SCP(self, msg):
        ds = dsutils.decode(msg.Identifier, self.transfersyntax.is_implicit_VR, self.transfersyntax.is_little_endian)
        
        # make response
        rsp = C_MOVE_ServiceParameters()
        rsp.MessageIDBeingRespondedTo = msg.MessageID.value
        rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID.value
        gen = self.AE.OnReceiveMove(self, ds, msg.MoveDestination.value)

        # first value returned by callback must be the complete remote AE specs
        remoteAE = gen.next()
        
        # request association to move destination
        ass = self.AE.RequestAssociation(remoteAE)
        nop = gen.next()
        print nop
        try:
            ncomp = 0
            nfailed = 0
            nwarning = 0
            ncompleted = 0
            while 1:
                DataSet = gen.next()
                # request an association with destination
                # send C-STORE
                s=str(UID2SOPClass(DataSet.SOPClassUID))
                ind = len(s)-s[::-1].find('.')
                obj = getattr(ass,s[ind:-2])
                status = obj.SCU(DataSet, ncompleted)
                if status.Type == 'Failed':
                     nfailed += 1
                if status.Type == 'Warning':
                    nwarning += 1
                rsp.Status =  int(self.Pending)
                rsp.NumberOfRemainingSubOperations = nop-ncompleted
                rsp.NumberOfCompletedSubOperations = ncompleted
                rsp.NumberOfFailedSubOperations = nfailed
                rsp.NumberOfWarningSubOperations = nwarning
                ncompleted += 1
                
                # send response
                self.DIMSE.Send(rsp, self.pcid, self.ACSE.MaxPDULength)
                print ncompleted
                
        except StopIteration:
            # send final response
            rsp = C_MOVE_ServiceParameters()
            rsp.MessageIDBeingRespondedTo = msg.MessageID.value
            rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID.value
            rsp.NumberOfRemainingSubOperations = nop-ncompleted
            rsp.NumberOfCompletedSubOperations = ncompleted
            rsp.NumberOfFailedSubOperations = nfailed
            rsp.NumberOfWarningSubOperations = nwarning
            rsp.Status = int(self.Success)
            self.DIMSE.Send(rsp, self.pcid, self.ACSE.MaxPDULength)
            ass.Release(0)
Exemple #6
0
    def SCU(self, ds, msgid):
        # build C-GET primitive
        cget = C_GET_ServiceParameters()
        cget.MessageID = msgid
        cget.AffectedSOPClassUID = self.UID
        cget.Priority = 0x0002
        cget.Identifier = dsutils.encode(ds,
                                         self.transfersyntax.is_implicit_VR,
                                         self.transfersyntax.is_little_endian)

        # send c-get primitive
        self.DIMSE.Send(cget, self.pcid, self.maxpdulength)

        while 1:
            # receive c-store
            msg, id = self.DIMSE.Receive(Wait=True)
            if msg.__class__ == C_GET_ServiceParameters:
                status = self.Code2Status(msg.Status.value)

                yield status,msg

                if status.Type != 'Pending':
                    break # last answer

            elif msg.__class__ == C_STORE_ServiceParameters:
                # send c-store response
                rsp = C_STORE_ServiceParameters()
                rsp.MessageIDBeingRespondedTo = msg.MessageID
                rsp.AffectedSOPInstanceUID = msg.AffectedSOPInstanceUID
                rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID

                try:
                    d = dsutils.decode(
                        msg.DataSet, self.transfersyntax.is_implicit_VR,
                        self.transfersyntax.is_little_endian)
                    SOPClass = UID2SOPClass(d.SOPClassUID)
                    SOPClass.transfersyntax = self.transfersyntax
                    status = self.AE.OnReceiveStore(SOPClass, d)
                except:
                    # cannot understand
                    status = self.CannotUnderstand

                rsp.Status = int(status)

                self.DIMSE.Send(rsp, id, self.maxpdulength)
Exemple #7
0
    def SCP(self, msg):
        ds = dsutils.decode(msg.Identifier, self.transfersyntax.is_implicit_VR,
                            self.transfersyntax.is_little_endian)

        # make response
        rsp = C_GET_ServiceParameters()
        rsp.MessageIDBeingRespondedTo = msg.MessageID.value
        rsp.AffectedSOPClassUID = msg.AffectedSOPClassUID.value
        rsp.Status = int(self.Pending)

        rsp.NumberOfRemainingSubOperations = 0
        rsp.NumberOfCompletedSubOperations = 0
        rsp.NumberOfFailedSubOperations = 0
        rsp.NumberOfWarningSubOperations = 0

        self.DIMSE.Send(rsp, self.pcid, self.maxpdulength)

        gen = self.AE.OnReceiveGet(self, ds)
        # # build C-STORE primitive
        csto = C_STORE_ServiceParameters()
        csto.MessageID = 0
        for ds in gen:
            csto.AffectedSOPClassUID = ds.SOPClassUID
            csto.AffectedSOPInstanceUID = ds.SOPInstanceUID
            csto.Priority = 0x0002
            csto.DataSet = dsutils.encode(ds,
                                          self.transfersyntax.is_implicit_VR,
                                          self.transfersyntax.is_little_endian)
            # send cstore request
            self.DIMSE.Send(csto, self.pcid, self.maxpdulength)

            # wait for c-store response
            ans, id = self.DIMSE.Receive(Wait=True)
            # TODO: Handle the answers coming back
            if self.Code2Status(ans.Status.value).Type != 'Success':
                pass

        # TODO: Set various values on the rsp here
        rsp.Status = int(self.Success)
        self.DIMSE.Send(rsp, self.pcid, self.maxpdulength)