Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_INCLUDE_MODULE_H_ |
| 12 | #define MODULES_INCLUDE_MODULE_H_ |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 13 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 14 | #include "typedefs.h" // NOLINT(build/include) |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 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. |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 35 | virtual void Process() = 0; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 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 | }; |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 61 | } // namespace webrtc |
| 62 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 63 | #endif // MODULES_INCLUDE_MODULE_H_ |