|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
A specialized job class that encapsulates user-defined callbacks. More...
#include <callback_job.h>


Public Member Functions | |
| callback_job (const std::function< std::optional< std::string >(void)> &callback, const std::string &name="callback_job") | |
Constructs a new callback_job instance with a parameterless callback. | |
| callback_job (const std::function< common::VoidResult(void)> &callback, const std::string &name="callback_job") | |
Constructs a new callback_job instance with a parameterless callback using modern error handling. | |
| callback_job (const std::function< std::optional< std::string >(const std::vector< uint8_t > &)> &data_callback, const std::vector< uint8_t > &data, const std::string &name="data_callback_job") | |
Constructs a new callback_job instance with a data-based callback. | |
| callback_job (const std::function< common::VoidResult(const std::vector< uint8_t > &)> &data_callback, const std::vector< uint8_t > &data, const std::string &name="data_callback_job") | |
Constructs a new callback_job instance with a data-based callback using modern error handling. | |
| ~callback_job (void) override | |
| Virtual destructor for proper cleanup in derived classes. | |
| auto | do_work (void) -> common::VoidResult override |
| Executes the appropriate callback function to perform the job's work. | |
Public Member Functions inherited from kcenon::thread::job | |
| auto | get_job_id () const -> std::uint64_t |
| Gets the unique ID of this job. | |
| auto | get_enqueue_time () const -> std::chrono::steady_clock::time_point |
| Gets the time when this job was created (enqueued). | |
| job (const std::string &name="job") | |
Constructs a new job with an optional human-readable name. | |
| job (const std::vector< uint8_t > &data, const std::string &name="data_job") | |
Constructs a new job with associated raw byte data and a name. | |
| virtual | ~job (void) |
Virtual destructor for the job class to allow proper cleanup in derived classes. | |
| auto | get_name (void) const -> std::string |
| Retrieves the name of this job. | |
| virtual auto | set_cancellation_token (const cancellation_token &token) -> void |
| Sets a cancellation token that can be used to cancel the job. | |
| virtual auto | get_cancellation_token () const -> cancellation_token |
| Gets the cancellation token associated with this job. | |
| virtual auto | set_job_queue (const std::shared_ptr< job_queue > &job_queue) -> void |
Associates this job with a specific job_queue. | |
| virtual auto | get_job_queue (void) const -> std::shared_ptr< job_queue > |
Retrieves the job_queue associated with this job, if any. | |
| virtual auto | to_string (void) const -> std::string |
| Provides a string representation of the job for logging or debugging. | |
| auto | with_on_complete (std::function< void(common::VoidResult)> callback) -> job & |
| Attaches a completion callback to this job. | |
| auto | with_on_error (std::function< void(const common::error_info &)> callback) -> job & |
| Attaches an error callback to this job. | |
| auto | with_priority (job_priority priority) -> job & |
| Sets the priority level for this job. | |
| auto | with_cancellation (const cancellation_token &token) -> job & |
| Attaches a cancellation token to this job via composition. | |
| auto | with_retry (const retry_policy &policy) -> job & |
| Attaches a retry policy to this job. | |
| auto | with_timeout (std::chrono::milliseconds timeout) -> job & |
| Sets a timeout for job execution. | |
| auto | get_priority () const -> job_priority |
| Gets the priority level of this job. | |
| auto | get_retry_policy () const -> std::optional< retry_policy > |
| Gets the retry policy of this job. | |
| auto | get_timeout () const -> std::optional< std::chrono::milliseconds > |
| Gets the timeout duration for this job. | |
| auto | has_explicit_cancellation () const -> bool |
| Checks if this job has an explicit cancellation set via composition. | |
| auto | has_components () const -> bool |
| Checks if this job has any composed components. | |
Protected Attributes | |
| std::function< common::VoidResult(void)> | callback_ |
| Stores the user-defined callback that does not take any parameters. | |
| std::function< common::VoidResult(const std::vector< uint8_t > &)> | data_callback_ |
Stores the user-defined callback that takes a std::vector<uint8_t>. | |
| std::function< std::optional< std::string >(void)> | old_callback_ |
| Compatibility layer for the old style callbacks. | |
| std::function< std::optional< std::string >(const std::vector< uint8_t > &)> | old_data_callback_ |
Protected Attributes inherited from kcenon::thread::job | |
| std::string | name_ |
| The descriptive name of the job, used primarily for identification and logging. | |
| std::vector< uint8_t > | data_ |
| An optional container of raw byte data that may be used by the job. | |
| std::weak_ptr< job_queue > | job_queue_ |
A weak reference to the job_queue that currently manages this job. | |
| cancellation_token | cancellation_token_ |
| The cancellation token associated with this job. | |
Additional Inherited Members | |
Protected Member Functions inherited from kcenon::thread::job | |
| auto | invoke_callbacks (const common::VoidResult &result) -> void |
| Invokes the completion callbacks if they are set. | |
A specialized job class that encapsulates user-defined callbacks.
The callback_job class provides two main mechanisms for defining job behavior:
callback_), for general-purpose tasks.std::vector<uint8_t> as a parameter (data_callback_), allowing you to pass raw data to the job when it is constructed.Callbacks return common::VoidResult for success/error indication. Legacy callbacks returning std::optional<std::string> are also supported and automatically converted.
job_builder instead.Definition at line 43 of file callback_job.h.
| kcenon::thread::callback_job::callback_job | ( | const std::function< std::optional< std::string >(void)> & | callback, |
| const std::string & | name = "callback_job" ) |
Constructs a new callback_job instance with a parameterless callback.
Constructs a callback job with legacy error-returning callback.
Use this constructor if your job logic does not require any input data.
| callback | A function object that performs the job's work.
|
| name | An optional name for this job (default is "callback_job"). |
Example:
Implementation details:
Error Conversion:
Performance Considerations:
| callback | Legacy callback function returning optional error string |
| name | Descriptive name for this job (for debugging/logging) |
Definition at line 47 of file callback_job.cpp.
| kcenon::thread::callback_job::callback_job | ( | const std::function< common::VoidResult(void)> & | callback, |
| const std::string & | name = "callback_job" ) |
Constructs a new callback_job instance with a parameterless callback using modern error handling.
Constructs a callback job with modern result_void-returning callback.
| callback | A function object that performs the job's work.
|
| name | An optional name for this job (default is "callback_job"). |
Implementation details:
Modern Error Handling:
| callback | Modern callback function returning result_void |
| name | Descriptive name for this job (for debugging/logging) |
Definition at line 79 of file callback_job.cpp.
References kcenon::thread::callback.
| kcenon::thread::callback_job::callback_job | ( | const std::function< std::optional< std::string >(const std::vector< uint8_t > &)> & | data_callback, |
| const std::vector< uint8_t > & | data, | ||
| const std::string & | name = "data_callback_job" ) |
Constructs a new callback_job instance with a data-based callback.
Constructs a data-based callback job with legacy error handling.
Use this constructor if your job logic requires raw byte data to process.
| data_callback | A function object that performs the job's work, taking a std::vector<uint8_t> as its input.
|
| data | A vector of bytes that will be passed to data_callback when the job is executed. |
| name | An optional name for this job (default is "data_callback_job"). |
Example:
Implementation details:
Data Processing:
Error Conversion:
| data_callback | Legacy data-processing callback |
| data | Binary data to be processed by the callback |
| name | Descriptive name for this job |
Definition at line 108 of file callback_job.cpp.
| kcenon::thread::callback_job::callback_job | ( | const std::function< common::VoidResult(const std::vector< uint8_t > &)> & | data_callback, |
| const std::vector< uint8_t > & | data, | ||
| const std::string & | name = "data_callback_job" ) |
Constructs a new callback_job instance with a data-based callback using modern error handling.
Constructs a data-based callback job with modern error handling.
| data_callback | A function object that performs the job's work, taking a std::vector<uint8_t> as its input.
|
| data | A vector of bytes that will be passed to data_callback when the job is executed. |
| name | An optional name for this job (default is "data_callback_job"). |
Implementation details:
Data Handling:
| data_callback | Modern data-processing callback |
| data | Binary data to be processed by the callback |
| name | Descriptive name for this job |
Definition at line 142 of file callback_job.cpp.
|
override |
Virtual destructor for proper cleanup in derived classes.
Destroys the callback job.
Implementation details:
Definition at line 157 of file callback_job.cpp.
|
nodiscardoverridevirtual |
Executes the appropriate callback function to perform the job's work.
Executes the callback job by calling the appropriate callback function.
std::optional<std::string> std::nullopt if the job completes successfully.std::string indicating an error message if the job fails.This method is typically called by a job-processing mechanism (e.g., a thread pool) rather than directly by user code. However, manual invocation is possible if desired.
The logic internally checks which callback has been provided:
data_callback_ is set, do_work() invokes it with the associated data.callback_.Implementation details:
Execution Priority:
Performance Considerations:
Error Propagation:
Reimplemented from kcenon::thread::job.
Definition at line 185 of file callback_job.cpp.
References kcenon::thread::job::do_work().

|
protected |
Stores the user-defined callback that does not take any parameters.
This callback is only valid if the callback_job was constructed via the parameterless constructor. If this member is used, data_callback_ should be null.
Definition at line 159 of file callback_job.h.
|
protected |
Stores the user-defined callback that takes a std::vector<uint8_t>.
This callback is only valid if the callback_job was constructed via the data-based constructor. If this member is used, callback_ should be null.
Definition at line 167 of file callback_job.h.
|
protected |
Compatibility layer for the old style callbacks.
Definition at line 172 of file callback_job.h.
|
protected |
Definition at line 173 of file callback_job.h.