3#include <pineforge/selected_window_plan.h>
15struct WindowPlanTestAccess;
56 pf_selected_plan_result_v1
raw{};
84 const std::string& expected_sha256_hex,
85 const std::filesystem::path& private_run_directory);
107 std::uint32_t
version() const noexcept {
return version_; }
109 const std::filesystem::path&
source_path() const noexcept {
return source_path_; }
115 std::uint64_t
source_size() const noexcept {
return source_size_; }
117 const std::filesystem::path&
snapshot_path() const noexcept {
return snapshot_path_; }
119 const std::string&
sha256() const noexcept {
return sha256_; }
122 return "selected-plan-utc-six-hours/v1";
126 friend struct detail::WindowPlanTestAccess;
127 using VersionFn =
decltype(&::pf_selected_plan_version);
128 using PlanFn =
decltype(&::pf_plan_selected_primary_v1);
138 static WindowPlanHelper load_impl(
const std::filesystem::path& absolute_path,
139 const std::string& expected_sha256_hex,
140 const std::filesystem::path& private_run_directory,
141 const std::function<
void()>& after_source_open,
142 const std::function<
void(
const std::filesystem::path&)>&
143 after_snapshot_close);
144 static VersionFn bind_version(
void* library);
145 static PlanFn bind_plan(
void* library);
146 void self_test()
const;
147 void close() noexcept;
149 std::filesystem::path source_path_;
150 std::filesystem::path snapshot_path_;
152 void* library_ =
nullptr;
153 PlanFn plan_ =
nullptr;
154 std::uint32_t version_ = 0;
155 std::uint64_t source_device_ = 0;
156 std::uint64_t source_inode_ = 0;
157 std::uint64_t source_size_ = 0;
Owns a verified, privately snapshotted standalone planner library.
std::uint64_t source_size() const noexcept
Returns the byte length of the opened, verified source.
~WindowPlanHelper()
Closes the library without deleting the snapshot.
WindowPlanHelper & operator=(WindowPlanHelper &&other) noexcept
Closes the previous library and transfers ownership without deleting either snapshot.
std::uint32_t version() const noexcept
Returns the validated bridge version, 1.
std::uint64_t source_inode() const noexcept
Returns the inode of the opened, verified source, even if its pathname was replaced.
const std::string & sha256() const noexcept
Returns the observed SHA-256 that matched the expected content before loading.
WindowPlanHelper(const WindowPlanHelper &)=delete
A library owner cannot be copied.
static constexpr const char * self_test_id() noexcept
Frozen behavior identifier; a later engine behavior change must bump this identifier.
WindowPlanHelper(WindowPlanHelper &&other) noexcept
Transfers ownership of the library and snapshot identity.
const std::filesystem::path & snapshot_path() const noexcept
Returns the absolute verified snapshot path actually passed to dlopen().
std::uint64_t source_device() const noexcept
Returns the device of the opened, verified source, even if its pathname was replaced.
WindowPlanHelper & operator=(const WindowPlanHelper &)=delete
A library owner cannot be copied.
PlanResult plan_selected_primary(const pf_bar_t *rows, std::size_t count, const PlanRequest &request) const
Calls the C bridge with exactly rows, without copying or repacking the bar array.
static WindowPlanHelper load(const std::filesystem::path &absolute_path, const std::string &expected_sha256_hex, const std::filesystem::path &private_run_directory)
Snapshots and hashes an absolute source path before loading any of its code.
const std::filesystem::path & source_path() const noexcept
Returns the absolute source path supplied to load(), for provenance only.
@ Ok
Every field is finite.
PlanStatus
Planner status words, independent of the C bridge's negative call return codes.
@ BoundaryUnaligned
T, E or F is not a script interval boundary.
@ FeedRangeInvalid
A supplied timestamp is outside [F, E).
@ RequestInvalid
The planner refused a request member or row pointer.
@ InternalError
The planner reported an internal failure as result data.
@ CalendarUnsupported
The calendar, clock or timeframe pairing is unsupported.
@ Ok
A complete plan is available.
@ RowsUnordered
Supplied timestamps are not strictly increasing.
Owned request strings and fixed-width fields for the selected primary C planner.
std::string script_tf
Primary script timeframe token.
std::string chart_timezone
Chart timezone; an empty string retains the engine default.
bool feed_tolerant
Enables the engine's feed-tolerant grouping.
std::string engine_timezone
Engine timezone; an empty string retains the engine default.
std::string input_tf
Explicit input timeframe token.
std::int64_t fed_start_ms
Supplied-feed floor F, in Unix milliseconds.
std::uint32_t preroll_bars
Requested pre-roll script groups N; the engine admits at most 5000.
std::int64_t end_ms
Exclusive selected end E, in Unix milliseconds.
std::string session
Session specification; an empty string retains the engine default.
std::int64_t start_ms
Selected start T, in Unix milliseconds.
Value copy of the complete 248-byte engine result, including planner refusals.
pf_selected_plan_result_v1 raw
Unmodified engine descriptor; optional timestamps are governed by present_mask.
bool ok() const noexcept
Returns whether this result contains a successful plan.
PlanStatus status() const noexcept
Returns the validated planner status, never a bridge-level return code.