Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
control_task_executor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_ctl/control_task_executor.h
10 //! @brief Control task executor.
11 
12 #ifndef ROC_CTL_CONTROL_TASK_EXECUTOR_H_
13 #define ROC_CTL_CONTROL_TASK_EXECUTOR_H_
14 
15 #include "roc_ctl/control_task.h"
16 
17 namespace roc {
18 namespace ctl {
19 
20 //! Control task executor interface.
21 //! @see ControlTaskExecutor.
23 public:
24  virtual ~IControlTaskExecutor();
25 
26 private:
27  friend class ControlTaskQueue;
28 
29  //! Execute task function.
30  virtual ControlTaskResult execute_task(ControlTask& task,
31  ControlTaskFunc task_func) = 0;
32 };
33 
34 //! Control task executor.
35 //! @tparam E is the derived class.
36 //! @remarks
37 //! If a class E wants to be capable of implementing its own tasks, it should
38 //! inherit from ControlTaskExecutor<E>. This will enable the control queue
39 //! to invoke tasks implemented as methods of E.
40 template <class E> class ControlTaskExecutor : public IControlTaskExecutor {
41 private:
42  virtual ControlTaskResult execute_task(ControlTask& task, ControlTaskFunc task_func) {
43  // We cast ourselves to derived class, cast task function to derived
44  // class method, and invoke it.
45  return (static_cast<E*>(this)
46  ->*(reinterpret_cast<ControlTaskResult (E::*)(ControlTask&)>(
47  task_func)))(task);
48  }
49 };
50 
51 } // namespace ctl
52 } // namespace roc
53 
54 #endif // ROC_CTL_CONTROL_TASK_EXECUTOR_H_
Base class for control tasks.
Definition: control_task.h:53
Control task executor interface.
Control task.
ControlTaskResult
Control task execution result.
Definition: control_task.h:34
ControlTaskResult(IControlTaskExecutor::* ControlTaskFunc)(ControlTask &)
Control task implementation function. Holds a pointer to method of a class derived from IControlTaskE...
Definition: control_task.h:50
Root namespace.