|
21 | 21 |
|
22 | 22 | #include "openPMD/IO/AbstractIOHandlerImpl.hpp" |
23 | 23 |
|
| 24 | +#include "openPMD/Error.hpp" |
| 25 | +#include "openPMD/IO/AbstractIOHandler.hpp" |
24 | 26 | #include "openPMD/IO/IOTask.hpp" |
25 | 27 | #include "openPMD/Streaming.hpp" |
26 | 28 | #include "openPMD/auxiliary/Environment.hpp" |
@@ -87,13 +89,74 @@ void AbstractIOHandlerImpl::writeToStderr([[maybe_unused]] Args &&...args) const |
87 | 89 | } |
88 | 90 | } |
89 | 91 |
|
90 | | -std::future<void> AbstractIOHandlerImpl::flush() |
| 92 | +namespace |
| 93 | +{ |
| 94 | + void verifyFlushType(Operation op, FlushLevel l) |
| 95 | + { |
| 96 | + auto do_throw = [&](char const *least_flush_level) { |
| 97 | + std::stringstream err; |
| 98 | + err << "Operation " << op << " is not allowed below flush level " |
| 99 | + << least_flush_level << ", but flush level was " << l << "."; |
| 100 | + throw error::Internal(err.str()); |
| 101 | + }; |
| 102 | + switch (op) |
| 103 | + { |
| 104 | + case Operation::ADVANCE: |
| 105 | + case Operation::CREATE_FILE: |
| 106 | + case Operation::CHECK_FILE: |
| 107 | + case Operation::OPEN_FILE: |
| 108 | + case Operation::CLOSE_FILE: |
| 109 | + case Operation::DELETE_FILE: |
| 110 | + case Operation::DEREGISTER: |
| 111 | + case Operation::TOUCH: |
| 112 | + case Operation::LIST_ATTS: |
| 113 | + case Operation::LIST_PATHS: |
| 114 | + case Operation::OPEN_PATH: |
| 115 | + case Operation::SET_WRITTEN: |
| 116 | + case Operation::CREATE_PATH: |
| 117 | + break; |
| 118 | + case Operation::CLOSE_PATH: |
| 119 | + case Operation::DELETE_PATH: |
| 120 | + case Operation::CREATE_DATASET: |
| 121 | + case Operation::EXTEND_DATASET: |
| 122 | + case Operation::OPEN_DATASET: |
| 123 | + case Operation::DELETE_DATASET: |
| 124 | + case Operation::LIST_DATASETS: |
| 125 | + if (!flush_level::flush_hierarchy(l)) |
| 126 | + { |
| 127 | + do_throw("SkeletonOnly (hierarchy operations)"); |
| 128 | + } |
| 129 | + break; |
| 130 | + case Operation::GET_BUFFER_VIEW: |
| 131 | + case Operation::DELETE_ATT: |
| 132 | + case Operation::WRITE_ATT: |
| 133 | + case Operation::READ_ATT: |
| 134 | + case Operation::READ_ATT_ALLSTEPS: |
| 135 | + case Operation::AVAILABLE_CHUNKS: |
| 136 | + if (!flush_level::write_attributes(l)) |
| 137 | + { |
| 138 | + do_throw("InternalFlush (metadata operations)"); |
| 139 | + } |
| 140 | + break; |
| 141 | + case Operation::WRITE_DATASET: |
| 142 | + case Operation::READ_DATASET: |
| 143 | + if (!flush_level::write_datasets(l)) |
| 144 | + { |
| 145 | + do_throw("UserFlush (flushpoint operations)"); |
| 146 | + } |
| 147 | + break; |
| 148 | + } |
| 149 | + } |
| 150 | +} // namespace |
| 151 | + |
| 152 | +std::future<void> AbstractIOHandlerImpl::flush(FlushLevel l) |
91 | 153 | { |
92 | 154 | using namespace auxiliary; |
93 | 155 |
|
94 | 156 | while (!(*m_handler).m_work.empty()) |
95 | 157 | { |
96 | 158 | IOTask &i = (*m_handler).m_work.front(); |
| 159 | + // verifyFlushType(i.operation, l); |
97 | 160 | try |
98 | 161 | { |
99 | 162 | switch (i.operation) |
@@ -467,6 +530,7 @@ std::future<void> AbstractIOHandlerImpl::flush() |
467 | 530 | break; |
468 | 531 | } |
469 | 532 | } |
| 533 | + verifyFlushType(i.operation, l); |
470 | 534 | } |
471 | 535 | catch (...) |
472 | 536 | { |
|
0 commit comments