67 return "complete_with_exceptions";
69 return "resource_limit";
184 : capacity_(std::max<std::size_t>(capacity, 2)), job_(nextJob_.fetch_add(1)),
185 started_(Clock::now())
193 std::uint64_t
job() const noexcept {
return job_; }
210 truncate(event.
stage, 256);
211 truncate(event.
code, 128);
212 std::lock_guard<std::mutex> guard(mutex_);
216 event.sequence = ++sequence_;
218 std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - started_).count();
220 percent_ = std::max(percent_, std::clamp(event.
percent, 0, 100));
221 event.percent = percent_;
225 pending_.back() = std::move(event);
228 if (pending_.size() == capacity_) {
229 const auto progress =
230 std::find_if(pending_.begin(), pending_.end(),
231 [](
const Event &e) { return e.kind == EventKind::Progress; });
232 if (progress != pending_.end())
233 pending_.erase(progress);
235 pending_.pop_front();
239 pending_.push_back(std::move(event));
249 std::lock_guard<std::mutex> guard(mutex_);
252 batch.
events.reserve(pending_.size());
253 while (!pending_.empty()) {
254 batch.
events.push_back(std::move(pending_.front()));
255 pending_.pop_front();
261 static void truncate(std::string &s, std::size_t limit)
263 if (s.size() <= limit)
265 while (limit > 0 && (
static_cast<unsigned char>(s[limit]) & 0xc0) == 0x80)
270 using Clock = std::chrono::steady_clock;
271 const std::size_t capacity_;
272 const std::uint64_t job_;
273 const Clock::time_point started_;
274 inline static std::atomic<std::uint64_t> nextJob_{1};
276 std::deque<Event> pending_;
277 std::uint64_t sequence_ = 0, dropped_ = 0;
279 bool finished_ =
false;
Batch drain()
Remove and return every pending event.
Definition events.hpp:247
EventChannel(std::size_t capacity=2048)
Create an empty channel with a new process-wide job id.
Definition events.hpp:183
void publish(Event event)
Queue one event without waiting for the consumer.
Definition events.hpp:206
std::uint64_t job() const noexcept
Id of this channel, unique among the channels created in the process.
Definition events.hpp:193
The Qt-free MeshKit library: job events and progress (meshkit::runtime), the neutral mesh model,...
RunStatus
Status of a running or finished operation (see statusName()).
Definition events.hpp:43
@ Infeasible
Input or policy cannot be satisfied; no result.
Definition events.hpp:50
@ ResourceLimit
Stopped at a resource cap or allocation failure; no result.
Definition events.hpp:47
@ Running
Still running; carried by intermediate events.
Definition events.hpp:44
@ CompleteWithExceptions
Finished with a result, but with recorded exceptions.
Definition events.hpp:46
@ Cancelled
Stopped because cancellation was requested; no result.
Definition events.hpp:48
@ Complete
Finished; every checked requirement holds.
Definition events.hpp:45
@ Failed
Stopped by an error such as an exception or I/O error; no result.
Definition events.hpp:49
Severity
Severity of an Event.
Definition events.hpp:20
@ Warning
Warning-level notification.
Definition events.hpp:20
@ Info
Informational; the default.
Definition events.hpp:20
@ Error
Failure; runJob() uses it for a Completed event of a job that did not complete.
Definition events.hpp:20
const char * statusName(RunStatus status) noexcept
Stable lower-case name of a status, as used by the Python bindings.
Definition events.hpp:59
EventKind
Kind of an Event.
Definition events.hpp:29
@ Completed
Final event of a job, carrying its final status; the channel ignores later events.
Definition events.hpp:29
@ StageCompleted
A stage has finished.
Definition events.hpp:29
@ Progress
Progress within a stage.
Definition events.hpp:29
@ Stage
A stage has started; Event::stage names it.
Definition events.hpp:29
@ Diagnostic
Informational diagnostic, e.g.
Definition events.hpp:29
Vertex and cell counters of an operation or event; -1 marks a value not available.
Definition events.hpp:81
std::int64_t vertices
Delivered vertex count, known once the output is assembled.
Definition events.hpp:94
std::int64_t workingVertices
Working vertex slots while meshing, unused and dead slots included.
Definition events.hpp:94
std::int64_t quads
Quadrilateral count.
Definition events.hpp:94
std::int64_t triangles
Triangle count (live triangles while refining, delivered triangles at the end).
Definition events.hpp:94
std::int64_t inserted
Vertices inserted by refinement so far.
Definition events.hpp:101
std::int64_t removed
Vertices removed by coarsening so far.
Definition events.hpp:101
std::int64_t cells() const noexcept
Total cell count.
Definition events.hpp:106
Events removed by one drain().
Definition events.hpp:172
std::vector< Event > events
Pending events in publication order, oldest first.
Definition events.hpp:173
std::uint64_t dropped
Total events evicted for overflow since the channel was constructed.
Definition events.hpp:175
One job notification passed through an EventChannel.
Definition events.hpp:121
std::string stage
Short stage name such as "triangulation" or "refinement"; publish() cuts longer text to at most 256 b...
Definition events.hpp:147
std::string message
Human-readable UTF-8 text; publish() cuts longer text to at most 8192 bytes plus "…".
Definition events.hpp:147
Counts counts
Counter snapshot when the event was produced.
Definition events.hpp:148
RunStatus status
RunStatus::Running for intermediate events; the final status on a Completed event.
Definition events.hpp:135
std::string code
Machine-readable code (the job's report code on Completed); publish() cuts longer text to at most 128...
Definition events.hpp:147
EventKind kind
Kind of notification.
Definition events.hpp:132
std::uint64_t job
Id of the publishing channel (EventChannel::job()); set by publish().
Definition events.hpp:129
int percent
Overall progress, 0 to 100, or negative (default -1) when not given.
Definition events.hpp:153
std::uint64_t sequence
Per-channel number, from 1, set by publish().
Definition events.hpp:129
Severity severity
Severity of the notification.
Definition events.hpp:133
std::int64_t elapsedMs
Milliseconds since the channel was constructed (steady clock); set by publish().
Definition events.hpp:131