comparison OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 2072:f8d4543e3fef

Asynchronous flags to avoid waiting for the completion of image transfers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 14 Jul 2016 14:34:29 +0200
parents 27fd34970c52
children 21713ce8717b
comparison
equal deleted inserted replaced
2071:27fd34970c52 2072:f8d4543e3fef
683 return; 683 return;
684 } 684 }
685 685
686 std::string localAet = Toolbox::GetJsonStringField(request, "LocalAet", context.GetDefaultLocalApplicationEntityTitle()); 686 std::string localAet = Toolbox::GetJsonStringField(request, "LocalAet", context.GetDefaultLocalApplicationEntityTitle());
687 bool permissive = Toolbox::GetJsonBooleanField(request, "Permissive", false); 687 bool permissive = Toolbox::GetJsonBooleanField(request, "Permissive", false);
688 bool asynchronous = Toolbox::GetJsonBooleanField(request, "Asynchronous", false);
688 int moveOriginatorID = Toolbox::GetJsonIntegerField(request, "MoveOriginatorID", 0 /* By default, not a C-MOVE */); 689 int moveOriginatorID = Toolbox::GetJsonIntegerField(request, "MoveOriginatorID", 0 /* By default, not a C-MOVE */);
689 690
690 if (moveOriginatorID < 0 || 691 if (moveOriginatorID < 0 ||
691 moveOriginatorID >= 65536) 692 moveOriginatorID >= 65536)
692 { 693 {
703 static_cast<uint16_t>(moveOriginatorID))).AddInput(*it); 704 static_cast<uint16_t>(moveOriginatorID))).AddInput(*it);
704 } 705 }
705 706
706 job.SetDescription("HTTP request: Store-SCU to peer \"" + remote + "\""); 707 job.SetDescription("HTTP request: Store-SCU to peer \"" + remote + "\"");
707 708
708 if (context.GetScheduler().SubmitAndWait(job)) 709 if (asynchronous)
709 { 710 {
710 // Success 711 // Asynchronous mode: Submit the job, but don't wait for its completion
712 context.GetScheduler().Submit(job);
713 call.GetOutput().AnswerBuffer("{}", "application/json");
714 }
715 else if (context.GetScheduler().SubmitAndWait(job))
716 {
717 // Synchronous mode: We have submitted and waited for completion
711 call.GetOutput().AnswerBuffer("{}", "application/json"); 718 call.GetOutput().AnswerBuffer("{}", "application/json");
712 } 719 }
713 else 720 else
714 { 721 {
715 call.GetOutput().SignalError(HttpStatus_500_InternalServerError); 722 call.GetOutput().SignalError(HttpStatus_500_InternalServerError);
810 if (!GetInstancesToExport(request, instances, remote, call)) 817 if (!GetInstancesToExport(request, instances, remote, call))
811 { 818 {
812 return; 819 return;
813 } 820 }
814 821
822 bool asynchronous = Toolbox::GetJsonBooleanField(request, "Asynchronous", false);
823
815 WebServiceParameters peer; 824 WebServiceParameters peer;
816 Configuration::GetOrthancPeer(peer, remote); 825 Configuration::GetOrthancPeer(peer, remote);
817 826
818 ServerJob job; 827 ServerJob job;
819 for (std::list<std::string>::const_iterator 828 for (std::list<std::string>::const_iterator
822 job.AddCommand(new StorePeerCommand(context, peer, false)).AddInput(*it); 831 job.AddCommand(new StorePeerCommand(context, peer, false)).AddInput(*it);
823 } 832 }
824 833
825 job.SetDescription("HTTP request: POST to peer \"" + remote + "\""); 834 job.SetDescription("HTTP request: POST to peer \"" + remote + "\"");
826 835
827 if (context.GetScheduler().SubmitAndWait(job)) 836 if (asynchronous)
828 { 837 {
829 // Success 838 // Asynchronous mode: Submit the job, but don't wait for its completion
839 context.GetScheduler().Submit(job);
840 call.GetOutput().AnswerBuffer("{}", "application/json");
841 }
842 else if (context.GetScheduler().SubmitAndWait(job))
843 {
844 // Synchronous mode: We have submitted and waited for completion
830 call.GetOutput().AnswerBuffer("{}", "application/json"); 845 call.GetOutput().AnswerBuffer("{}", "application/json");
831 } 846 }
832 else 847 else
833 { 848 {
834 call.GetOutput().SignalError(HttpStatus_500_InternalServerError); 849 call.GetOutput().SignalError(HttpStatus_500_InternalServerError);