Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
executor_integration.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
30#pragma once
31
35
36#if LOGGER_HAS_IEXECUTOR
37
38#if __has_include(<kcenon/common/interfaces/executor_interface.h>)
39#include <kcenon/common/interfaces/executor_interface.h>
40#elif __has_include(<common/interfaces/executor_interface.h>)
41#include <common/interfaces/executor_interface.h>
42#endif
43
44#include <atomic>
45#include <functional>
46#include <memory>
47#include <mutex>
48#include <string>
49
51
57enum class executor_type {
61 none,
62
69
75 external
76};
77
115class LOGGER_SYSTEM_API executor_integration {
116public:
135 static void enable(std::shared_ptr<common::interfaces::IExecutor> executor = nullptr);
136
146 static void disable();
147
154 [[nodiscard]] static bool is_enabled() noexcept;
155
162 [[nodiscard]] static executor_type get_executor_type() noexcept;
163
176 static void set_executor(std::shared_ptr<common::interfaces::IExecutor> executor);
177
184 [[nodiscard]] static std::shared_ptr<common::interfaces::IExecutor> get_executor() noexcept;
185
207 [[nodiscard]] static bool submit_task(std::function<void()> task);
208
215 [[nodiscard]] static bool submit_task_delayed(
216 std::function<void()> task,
217 std::chrono::milliseconds delay_ms);
218
223 [[nodiscard]] static std::string get_executor_name() noexcept;
224
229 [[nodiscard]] static size_t pending_tasks() noexcept;
230
235 [[nodiscard]] static size_t worker_count() noexcept;
236
237private:
238 // Prevent instantiation - all methods are static
239 executor_integration() = delete;
240 ~executor_integration() = delete;
241 executor_integration(const executor_integration&) = delete;
242 executor_integration& operator=(const executor_integration&) = delete;
243
244 // Internal state
245 static std::atomic<executor_type> current_type_;
246 static std::shared_ptr<common::interfaces::IExecutor> executor_;
247 static std::mutex executor_mutex_;
248
253 static std::shared_ptr<common::interfaces::IExecutor> create_default_executor();
254};
255
271[[nodiscard]] constexpr bool has_executor_support() noexcept {
272 return true;
273}
274
275} // namespace kcenon::logger::integration
276
277#else // !LOGGER_HAS_IEXECUTOR
278
280
287public:
288 static void enable() noexcept {}
289 static void disable() noexcept {}
290 [[nodiscard]] static constexpr bool is_enabled() noexcept { return false; }
291 [[nodiscard]] static bool submit_task(std::function<void()>) noexcept { return false; }
292 [[nodiscard]] static std::string get_executor_name() noexcept { return "none"; }
293
294private:
296};
297
298[[nodiscard]] constexpr bool has_executor_support() noexcept {
299 return false;
300}
301
302} // namespace kcenon::logger::integration
303
304#endif // LOGGER_HAS_IEXECUTOR
Stub implementation when IExecutor is not available.
static bool submit_task(std::function< void()>) noexcept
DLL export/import macros for logger_system shared library support.
#define LOGGER_SYSTEM_API
@ standalone
Standalone backend using std::jthread.
constexpr bool has_executor_support() noexcept
Standalone IExecutor implementation using std::jthread.
Conditionally enables thread_system integration when available.