comparison Framework/Loaders/LoaderStateMachine.cpp @ 964:91f827272c1f toa2019082701

Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 27 Aug 2019 14:28:19 +0200
parents a7351ad54960
children 38409549db43
comparison
equal deleted inserted replaced
962:e70d75f199c5 964:91f827272c1f
21 21
22 #include "LoaderStateMachine.h" 22 #include "LoaderStateMachine.h"
23 23
24 #include <Core/OrthancException.h> 24 #include <Core/OrthancException.h>
25 25
26 #if 0
27 extern bool logbgo233;
28 extern bool logbgo115;
29 #endif
30
26 namespace OrthancStone 31 namespace OrthancStone
27 { 32 {
28 void LoaderStateMachine::State::Handle(const OrthancRestApiCommand::SuccessMessage& message) 33 void LoaderStateMachine::State::Handle(const OrthancRestApiCommand::SuccessMessage& message)
29 { 34 {
30 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 35 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
43 } 48 }
44 49
45 50
46 void LoaderStateMachine::Schedule(OracleCommandWithPayload* command) 51 void LoaderStateMachine::Schedule(OracleCommandWithPayload* command)
47 { 52 {
53 #if 0
54 if (logbgo233) {
55 if (logbgo115)
56 LOG(TRACE) << " LoaderStateMachine::Schedule()";
57 }
58 #endif
59
48 std::auto_ptr<OracleCommandWithPayload> protection(command); 60 std::auto_ptr<OracleCommandWithPayload> protection(command);
49 61
50 if (command == NULL) 62 if (command == NULL)
51 { 63 {
52 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); 64 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
56 { 68 {
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, 69 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
58 "The payload must contain the next state"); 70 "The payload must contain the next state");
59 } 71 }
60 72
73 #if 0
74 if (logbgo233) {
75 if (logbgo115)
76 LOG(TRACE) << " * LoaderStateMachine::Schedule(): adding command with addr: " << std::hex << protection.get() << std::dec << " pendingCommands_.size() is now : " << pendingCommands_.size()+1;
77 }
78 #endif
61 pendingCommands_.push_back(protection.release()); 79 pendingCommands_.push_back(protection.release());
80
62 Step(); 81 Step();
63 } 82 }
64 83
65 84
66 void LoaderStateMachine::Start() 85 void LoaderStateMachine::Start()
67 { 86 {
68 if (active_) 87 if (active_)
69 { 88 {
70 LOG(ERROR) << "LoaderStateMachine::Start() called while active_ is true"; 89 LOG(TRACE) << "LoaderStateMachine::Start() called while active_ is true";
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 90 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
72 } 91 }
73 92
74 active_ = true; 93 active_ = true;
75 94
80 } 99 }
81 100
82 101
83 void LoaderStateMachine::Step() 102 void LoaderStateMachine::Step()
84 { 103 {
104 #if 0
105 if (logbgo115)
106 LOG(TRACE) << " LoaderStateMachine::Step(): pendingCommands_.size() = " << pendingCommands_.size();
107 #endif
85 if (!pendingCommands_.empty() && 108 if (!pendingCommands_.empty() &&
86 activeCommands_ < simultaneousDownloads_) 109 activeCommands_ < simultaneousDownloads_)
87 { 110 {
88 oracle_.Schedule(*this, pendingCommands_.front()); 111
112 IOracleCommand* nextCommand = pendingCommands_.front();
113
114 #if 0
115 if (logbgo233) {
116 if (logbgo115)
117 LOG(TRACE) << " * LoaderStateMachine::Step(): activeCommands_ (" << activeCommands_ << ") < simultaneousDownloads_ (" << simultaneousDownloads_ << ") --> will Schedule command addr " << std::hex << nextCommand << std::dec;
118 }
119 #endif
120
121 oracle_.Schedule(*this, nextCommand);
89 pendingCommands_.pop_front(); 122 pendingCommands_.pop_front();
90 123
91 activeCommands_++; 124 activeCommands_++;
125 }
126 else
127 {
128 #if 0
129 if (logbgo233) {
130 if (logbgo115)
131 LOG(TRACE) << " * pendingCommands_.size() == " << pendingCommands_.size() << " LoaderStateMachine::Step(): activeCommands_ (" << activeCommands_ << ") >= simultaneousDownloads_ (" << simultaneousDownloads_ << ") --> will NOT Schedule anything";
132 }
133 #endif
92 } 134 }
93 } 135 }
94 136
95 137
96 void LoaderStateMachine::Clear() 138 void LoaderStateMachine::Clear()