| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #ifndef MODULES_INCLUDE_MODULE_H_ |
| 12 | #define MODULES_INCLUDE_MODULE_H_ |
| 13 |
| 14 | #include <stdint.h> |
| 15 |
| 16 | namespace webrtc { |
| 17 |
| 18 | class ProcessThread; |
| 19 |
| 20 | class Module { |
| 21 | public: |
| 22 | // Returns the number of milliseconds until the module wants a worker |
| 23 | // thread to call Process. |
| 24 | // This method is called on the same worker thread as Process will |
| 25 | // be called on. |
| 26 | // TODO(tommi): Almost all implementations of this function, need to know |
| 27 | // the current tick count. Consider passing it as an argument. It could |
| 28 | // also improve the accuracy of when the next callback occurs since the |
| 29 | // thread that calls Process() will also have it's tick count reference |
| 30 | // which might not match with what the implementations use. |
| 31 | virtual int64_t TimeUntilNextProcess() = 0; |
| 32 |
| 33 | // Process any pending tasks such as timeouts. |
| 34 | // Called on a worker thread. |
| 35 | virtual void Process() = 0; |
| 36 |
| 37 | // This method is called when the module is attached to a *running* process |
| 38 | // thread or detached from one. In the case of detaching, |process_thread| |
| 39 | // will be nullptr. |
| 40 | // |
| 41 | // This method will be called in the following cases: |
| 42 | // |
| 43 | // * Non-null process_thread: |
| 44 | // * ProcessThread::RegisterModule() is called while the thread is running. |
| 45 | // * ProcessThread::Start() is called and RegisterModule has previously |
| 46 | // been called. The thread will be started immediately after notifying |
| 47 | // all modules. |
| 48 | // |
| 49 | // * Null process_thread: |
| 50 | // * ProcessThread::DeRegisterModule() is called while the thread is |
| 51 | // running. |
| 52 | // * ProcessThread::Stop() was called and the thread has been stopped. |
| 53 | // |
| 54 | // NOTE: This method is not called from the worker thread itself, but from |
| 55 | // the thread that registers/deregisters the module or calls Start/Stop. |
| 56 | virtual void ProcessThreadAttached(ProcessThread* process_thread) {} |
| 57 |
| 58 | protected: |
| 59 | virtual ~Module() {} |
| 60 | }; |
| 61 | } // namespace webrtc |
| 62 |
| 63 | #endif // MODULES_INCLUDE_MODULE_H_ |
| 64 |