comparison OrthancServer/DicomProtocol/DicomUserConnection.cpp @ 1285:5730f374e4e6

Access to called AET and remote AET from Lua scripts
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Feb 2015 15:00:42 +0100
parents b17b6bd59747
children 6e7e5ed91c2d
comparison
equal deleted inserted replaced
1284:21ea32170764 1285:5730f374e4e6
452 452
453 // Figure out which of the accepted presentation contexts should be used 453 // Figure out which of the accepted presentation contexts should be used
454 int presID = ASC_findAcceptedPresentationContextID(pimpl_->assoc_, sopClass); 454 int presID = ASC_findAcceptedPresentationContextID(pimpl_->assoc_, sopClass);
455 if (presID == 0) 455 if (presID == 0)
456 { 456 {
457 throw OrthancException("DicomUserConnection: The C-FIND command is not supported by the distant AET"); 457 throw OrthancException("DicomUserConnection: The C-FIND command is not supported by the remote AET");
458 } 458 }
459 459
460 T_DIMSE_C_FindRQ request; 460 T_DIMSE_C_FindRQ request;
461 memset(&request, 0, sizeof(request)); 461 memset(&request, 0, sizeof(request));
462 request.MessageID = pimpl_->assoc_->nextMsgID++; 462 request.MessageID = pimpl_->assoc_->nextMsgID++;
544 544
545 // Figure out which of the accepted presentation contexts should be used 545 // Figure out which of the accepted presentation contexts should be used
546 int presID = ASC_findAcceptedPresentationContextID(pimpl_->assoc_, sopClass); 546 int presID = ASC_findAcceptedPresentationContextID(pimpl_->assoc_, sopClass);
547 if (presID == 0) 547 if (presID == 0)
548 { 548 {
549 throw OrthancException("DicomUserConnection: The C-MOVE command is not supported by the distant AET"); 549 throw OrthancException("DicomUserConnection: The C-MOVE command is not supported by the remote AET");
550 } 550 }
551 551
552 T_DIMSE_C_MoveRQ request; 552 T_DIMSE_C_MoveRQ request;
553 memset(&request, 0, sizeof(request)); 553 memset(&request, 0, sizeof(request));
554 request.MessageID = pimpl_->assoc_->nextMsgID++; 554 request.MessageID = pimpl_->assoc_->nextMsgID++;
612 612
613 DicomUserConnection::DicomUserConnection() : 613 DicomUserConnection::DicomUserConnection() :
614 pimpl_(new PImpl), 614 pimpl_(new PImpl),
615 preferredTransferSyntax_(DEFAULT_PREFERRED_TRANSFER_SYNTAX), 615 preferredTransferSyntax_(DEFAULT_PREFERRED_TRANSFER_SYNTAX),
616 localAet_("STORESCU"), 616 localAet_("STORESCU"),
617 distantAet_("ANY-SCP"), 617 remoteAet_("ANY-SCP"),
618 distantHost_("127.0.0.1") 618 remoteHost_("127.0.0.1")
619 { 619 {
620 distantPort_ = 104; 620 remotePort_ = 104;
621 manufacturer_ = ModalityManufacturer_Generic; 621 manufacturer_ = ModalityManufacturer_Generic;
622 622
623 SetTimeout(10); 623 SetTimeout(10);
624 pimpl_->net_ = NULL; 624 pimpl_->net_ = NULL;
625 pimpl_->params_ = NULL; 625 pimpl_->params_ = NULL;
640 } 640 }
641 641
642 642
643 void DicomUserConnection::Connect(const RemoteModalityParameters& parameters) 643 void DicomUserConnection::Connect(const RemoteModalityParameters& parameters)
644 { 644 {
645 SetDistantApplicationEntityTitle(parameters.GetApplicationEntityTitle()); 645 SetRemoteApplicationEntityTitle(parameters.GetApplicationEntityTitle());
646 SetDistantHost(parameters.GetHost()); 646 SetRemoteHost(parameters.GetHost());
647 SetDistantPort(parameters.GetPort()); 647 SetRemotePort(parameters.GetPort());
648 SetDistantManufacturer(parameters.GetManufacturer()); 648 SetRemoteManufacturer(parameters.GetManufacturer());
649 } 649 }
650 650
651 651
652 void DicomUserConnection::SetLocalApplicationEntityTitle(const std::string& aet) 652 void DicomUserConnection::SetLocalApplicationEntityTitle(const std::string& aet)
653 { 653 {
656 Close(); 656 Close();
657 localAet_ = aet; 657 localAet_ = aet;
658 } 658 }
659 } 659 }
660 660
661 void DicomUserConnection::SetDistantApplicationEntityTitle(const std::string& aet) 661 void DicomUserConnection::SetRemoteApplicationEntityTitle(const std::string& aet)
662 { 662 {
663 if (distantAet_ != aet) 663 if (remoteAet_ != aet)
664 { 664 {
665 Close(); 665 Close();
666 distantAet_ = aet; 666 remoteAet_ = aet;
667 } 667 }
668 } 668 }
669 669
670 void DicomUserConnection::SetDistantManufacturer(ModalityManufacturer manufacturer) 670 void DicomUserConnection::SetRemoteManufacturer(ModalityManufacturer manufacturer)
671 { 671 {
672 if (manufacturer_ != manufacturer) 672 if (manufacturer_ != manufacturer)
673 { 673 {
674 Close(); 674 Close();
675 manufacturer_ = manufacturer; 675 manufacturer_ = manufacturer;
689 preferredTransferSyntax_ = preferredTransferSyntax; 689 preferredTransferSyntax_ = preferredTransferSyntax;
690 } 690 }
691 } 691 }
692 692
693 693
694 void DicomUserConnection::SetDistantHost(const std::string& host) 694 void DicomUserConnection::SetRemoteHost(const std::string& host)
695 { 695 {
696 if (distantHost_ != host) 696 if (remoteHost_ != host)
697 { 697 {
698 if (host.size() > HOST_NAME_MAX - 10) 698 if (host.size() > HOST_NAME_MAX - 10)
699 { 699 {
700 throw OrthancException("Distant host name is too long"); 700 throw OrthancException("Remote host name is too long");
701 } 701 }
702 702
703 Close(); 703 Close();
704 distantHost_ = host; 704 remoteHost_ = host;
705 } 705 }
706 } 706 }
707 707
708 void DicomUserConnection::SetDistantPort(uint16_t port) 708 void DicomUserConnection::SetRemotePort(uint16_t port)
709 { 709 {
710 if (distantPort_ != port) 710 if (remotePort_ != port)
711 { 711 {
712 Close(); 712 Close();
713 distantPort_ = port; 713 remotePort_ = port;
714 } 714 }
715 } 715 }
716 716
717 void DicomUserConnection::Open() 717 void DicomUserConnection::Open()
718 { 718 {
721 // Don't reopen the connection 721 // Don't reopen the connection
722 return; 722 return;
723 } 723 }
724 724
725 LOG(INFO) << "Opening a DICOM SCU connection from AET \"" << GetLocalApplicationEntityTitle() 725 LOG(INFO) << "Opening a DICOM SCU connection from AET \"" << GetLocalApplicationEntityTitle()
726 << "\" to AET \"" << GetDistantApplicationEntityTitle() << "\" on host " 726 << "\" to AET \"" << GetRemoteApplicationEntityTitle() << "\" on host "
727 << GetDistantHost() << ":" << GetDistantPort() 727 << GetRemoteHost() << ":" << GetRemotePort()
728 << " (manufacturer: " << EnumerationToString(GetDistantManufacturer()) << ")"; 728 << " (manufacturer: " << EnumerationToString(GetRemoteManufacturer()) << ")";
729 729
730 Check(ASC_initializeNetwork(NET_REQUESTOR, 0, /*opt_acse_timeout*/ pimpl_->acseTimeout_, &pimpl_->net_)); 730 Check(ASC_initializeNetwork(NET_REQUESTOR, 0, /*opt_acse_timeout*/ pimpl_->acseTimeout_, &pimpl_->net_));
731 Check(ASC_createAssociationParameters(&pimpl_->params_, /*opt_maxReceivePDULength*/ ASC_DEFAULTMAXPDU)); 731 Check(ASC_createAssociationParameters(&pimpl_->params_, /*opt_maxReceivePDULength*/ ASC_DEFAULTMAXPDU));
732 732
733 // Set this application's title and the called application's title in the params 733 // Set this application's title and the called application's title in the params
734 Check(ASC_setAPTitles(pimpl_->params_, localAet_.c_str(), distantAet_.c_str(), NULL)); 734 Check(ASC_setAPTitles(pimpl_->params_, localAet_.c_str(), remoteAet_.c_str(), NULL));
735 735
736 // Set the network addresses of the local and distant entities 736 // Set the network addresses of the local and remote entities
737 char localHost[HOST_NAME_MAX]; 737 char localHost[HOST_NAME_MAX];
738 gethostname(localHost, HOST_NAME_MAX - 1); 738 gethostname(localHost, HOST_NAME_MAX - 1);
739 739
740 char distantHostAndPort[HOST_NAME_MAX]; 740 char remoteHostAndPort[HOST_NAME_MAX];
741 741
742 #ifdef _MSC_VER 742 #ifdef _MSC_VER
743 _snprintf 743 _snprintf
744 #else 744 #else
745 snprintf 745 snprintf
746 #endif 746 #endif
747 (distantHostAndPort, HOST_NAME_MAX - 1, "%s:%d", distantHost_.c_str(), distantPort_); 747 (remoteHostAndPort, HOST_NAME_MAX - 1, "%s:%d", remoteHost_.c_str(), remotePort_);
748 748
749 Check(ASC_setPresentationAddresses(pimpl_->params_, localHost, distantHostAndPort)); 749 Check(ASC_setPresentationAddresses(pimpl_->params_, localHost, remoteHostAndPort));
750 750
751 // Set various options 751 // Set various options
752 Check(ASC_setTransportLayerType(pimpl_->params_, /*opt_secureConnection*/ false)); 752 Check(ASC_setTransportLayerType(pimpl_->params_, /*opt_secureConnection*/ false));
753 753
754 SetupPresentationContexts(preferredTransferSyntax_); 754 SetupPresentationContexts(preferredTransferSyntax_);