1//===-- SBProgress.cpp --------------------------------------------------*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBProgress.h"
10#include "lldb/Core/Progress.h"
11#include "lldb/Utility/Instrumentation.h"
12
13using namespace lldb;
14
15SBProgress::SBProgress(const char *title, const char *details,
16 SBDebugger &debugger) {
17 LLDB_INSTRUMENT_VA(this, title, details, debugger);
18
19 m_opaque_up = std::make_unique<lldb_private::Progress>(
20 args&: title, args&: details, /*total=*/args: std::nullopt, args: debugger.get(),
21 /*minimum_report_time=*/args: std::nullopt,
22 args: lldb_private::Progress::Origin::eExternal);
23}
24
25SBProgress::SBProgress(const char *title, const char *details,
26 uint64_t total_units, SBDebugger &debugger) {
27 LLDB_INSTRUMENT_VA(this, title, details, total_units, debugger);
28
29 m_opaque_up = std::make_unique<lldb_private::Progress>(
30 args&: title, args&: details, args&: total_units, args: debugger.get(),
31 /*minimum_report_time=*/args: std::nullopt,
32 args: lldb_private::Progress::Origin::eExternal);
33}
34
35SBProgress::SBProgress(SBProgress &&rhs)
36 : m_opaque_up(std::move(rhs.m_opaque_up)) {}
37
38SBProgress::~SBProgress() = default;
39
40void SBProgress::Increment(uint64_t amount, const char *description) {
41 LLDB_INSTRUMENT_VA(amount, description);
42
43 if (!m_opaque_up)
44 return;
45
46 std::optional<std::string> description_opt;
47 if (description && description[0])
48 description_opt = description;
49 m_opaque_up->Increment(amount, updated_detail: std::move(description_opt));
50}
51
52void SBProgress::Finalize() {
53 // The lldb_private::Progress object is designed to be RAII and send the end
54 // progress event when it gets destroyed. So force our contained object to be
55 // destroyed and send the progress end event. Clearing this object also allows
56 // all other methods to quickly return without doing any work if they are
57 // called after this method.
58 m_opaque_up.reset();
59}
60
61lldb_private::Progress &SBProgress::ref() const { return *m_opaque_up; }
62

source code of lldb/source/API/SBProgress.cpp