MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SystemBackend.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <expected>
4
5namespace MayaFlux::Core {
6
7/**
8 * @enum SystemDialogError
9 * @brief Failure modes for OS dialog operations.
10 */
11enum class SystemDialogError : uint8_t {
12 Cancelled, ///< User dismissed the dialog without completing it.
13 BackendError, ///< Platform backend failed to open or communicate.
14 NotSupported, ///< No implementation available on this platform build.
15};
16
17/**
18 * @struct SystemFileFilter
19 * @brief A named group of accepted file extensions for dialog filters.
20 */
22 std::string name;
23 std::vector<std::string> extensions;
24};
25
26/**
27 * @brief Result type delivered to all file dialog callbacks.
28 */
29using FileDialogResult = std::expected<std::filesystem::path, SystemDialogError>;
30
31/**
32 * @brief Callback type for all file dialog operations.
33 */
34using FileDialogCallback = std::function<void(FileDialogResult)>;
35
36/**
37 * @class SystemBackend
38 * @brief Abstract interface for native OS service backends.
39 *
40 * Implemented per platform: DBusBackend (Linux), COMBackend (Windows),
41 * NSBackend (macOS). Portal::System owns a single instance and routes
42 * all OS surface calls through it.
43 *
44 * Lifecycle is minimal: initialize() acquires any persistent platform
45 * resource (e.g. a D-Bus session connection); shutdown() releases it.
46 * There is no start()/stop() because no continuous thread is driven
47 * at this level - each operation is self-contained.
48 *
49 * All dialog operations are non-blocking at the interface level.
50 * The callback is invoked exactly once per call, on whichever thread
51 * the platform backend uses to deliver its response. Callers that need
52 * thread affinity must marshal the result themselves.
53 */
54class MAYAFLUX_API SystemBackend {
55public:
56 virtual ~SystemBackend() = default;
57
58 SystemBackend() = default;
59 SystemBackend(const SystemBackend&) = delete;
61 SystemBackend(SystemBackend&&) noexcept = default;
62 SystemBackend& operator=(SystemBackend&&) noexcept = default;
63
64 /**
65 * @brief Acquire any persistent platform resources required by this backend.
66 * @return True if the backend is ready for use.
67 */
68 [[nodiscard]] virtual bool initialize() = 0;
69
70 /**
71 * @brief Release all platform resources held by this backend.
72 */
73 virtual void shutdown() = 0;
74
75 /**
76 * @brief Return true if initialize() has completed successfully.
77 */
78 [[nodiscard]] virtual bool is_initialized() const = 0;
79
80 /**
81 * @brief Present a native open-file dialog.
82 *
83 * @param callback Invoked with the chosen path or a SystemDialogError.
84 * @param filters Extension filter groups shown in the dialog.
85 * @param start_dir Directory the dialog opens in. Platform default if empty.
86 */
87 virtual void open_file(
88 FileDialogCallback callback,
89 std::vector<SystemFileFilter> filters,
90 std::filesystem::path start_dir) = 0;
91
92 /**
93 * @brief Present a native save-file dialog.
94 *
95 * @param callback Invoked with the chosen path or a SystemDialogError.
96 * @param suggested_name Filename pre-filled in the dialog name field.
97 * @param filters Extension filter groups shown in the dialog.
98 * @param start_dir Directory the dialog opens in. Platform default if empty.
99 */
100 virtual void save_file(
101 FileDialogCallback callback,
102 std::string suggested_name,
103 std::vector<SystemFileFilter> filters,
104 std::filesystem::path start_dir) = 0;
105};
106
107} // namespace MayaFlux::Core
SystemBackend(const SystemBackend &)=delete
virtual ~SystemBackend()=default
SystemBackend(SystemBackend &&) noexcept=default
SystemBackend & operator=(const SystemBackend &)=delete
Abstract interface for native OS service backends.
void initialize()
Definition main.cpp:11
SystemDialogError
Failure modes for OS dialog operations.
@ BackendError
Platform backend failed to open or communicate.
@ NotSupported
No implementation available on this platform build.
@ Cancelled
User dismissed the dialog without completing it.
std::function< void(FileDialogResult)> FileDialogCallback
Callback type for all file dialog operations.
std::expected< std::filesystem::path, SystemDialogError > FileDialogResult
Result type delivered to all file dialog callbacks.
std::vector< std::string > extensions
A named group of accepted file extensions for dialog filters.