perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 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 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame^] | 11 | #ifndef WEBRTC_MODULES_INCLUDE_MODULE_H_ |
| 12 | #define WEBRTC_MODULES_INCLUDE_MODULE_H_ |
| 13 | |
| 14 | #pragma message("WARNING: webrtc/modules/include is DEPRECATED; use webrtc/modules/include") |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
pbos@webrtc.org | 57eb858 | 2013-11-11 10:20:27 +0000 | [diff] [blame] | 16 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 18 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 20 | class ProcessThread; |
| 21 | |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 22 | class Module { |
| 23 | public: |
tommi@webrtc.org | 4161715 | 2015-01-29 12:12:49 +0000 | [diff] [blame] | 24 | // Returns the number of milliseconds until the module wants a worker |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 25 | // thread to call Process. |
tommi@webrtc.org | 4161715 | 2015-01-29 12:12:49 +0000 | [diff] [blame] | 26 | // This method is called on the same worker thread as Process will |
| 27 | // be called on. |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 28 | // TODO(tommi): Almost all implementations of this function, need to know |
| 29 | // the current tick count. Consider passing it as an argument. It could |
| 30 | // also improve the accuracy of when the next callback occurs since the |
| 31 | // thread that calls Process() will also have it's tick count reference |
| 32 | // which might not match with what the implementations use. |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame] | 33 | virtual int64_t TimeUntilNextProcess() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 35 | // Process any pending tasks such as timeouts. |
tommi@webrtc.org | 4161715 | 2015-01-29 12:12:49 +0000 | [diff] [blame] | 36 | // Called on a worker thread. |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 37 | virtual int32_t Process() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 39 | // This method is called when the module is attached to a *running* process |
| 40 | // thread or detached from one. In the case of detaching, |process_thread| |
| 41 | // will be nullptr. |
| 42 | // |
| 43 | // This method will be called in the following cases: |
| 44 | // |
| 45 | // * Non-null process_thread: |
| 46 | // * ProcessThread::RegisterModule() is called while the thread is running. |
| 47 | // * ProcessThread::Start() is called and RegisterModule has previously |
| 48 | // been called. The thread will be started immediately after notifying |
| 49 | // all modules. |
| 50 | // |
| 51 | // * Null process_thread: |
| 52 | // * ProcessThread::DeRegisterModule() is called while the thread is |
| 53 | // running. |
| 54 | // * ProcessThread::Stop() was called and the thread has been stopped. |
| 55 | // |
| 56 | // NOTE: This method is not called from the worker thread itself, but from |
| 57 | // the thread that registers/deregisters the module or calls Start/Stop. |
| 58 | virtual void ProcessThreadAttached(ProcessThread* process_thread) {} |
| 59 | |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 60 | protected: |
| 61 | virtual ~Module() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
tommi@webrtc.org | 4161715 | 2015-01-29 12:12:49 +0000 | [diff] [blame] | 64 | // Reference counted version of the Module interface. |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 65 | class RefCountedModule : public Module { |
| 66 | public: |
| 67 | // Increase the reference count by one. |
| 68 | // Returns the incremented reference count. |
Magnus Jedvert | 1b40a9a | 2015-10-12 15:50:43 +0200 | [diff] [blame] | 69 | virtual int32_t AddRef() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 71 | // Decrease the reference count by one. |
| 72 | // Returns the decreased reference count. |
| 73 | // Returns 0 if the last reference was just released. |
tommi@webrtc.org | 4161715 | 2015-01-29 12:12:49 +0000 | [diff] [blame] | 74 | // When the reference count reaches 0 the object will self-destruct. |
Magnus Jedvert | 1b40a9a | 2015-10-12 15:50:43 +0200 | [diff] [blame] | 75 | virtual int32_t Release() const = 0; |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 76 | |
| 77 | protected: |
Karl Wiberg | 2519c45 | 2015-04-07 16:12:57 +0200 | [diff] [blame] | 78 | ~RefCountedModule() override = default; |
perkj@google.com | ef04cf4 | 2011-09-02 09:47:28 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace webrtc |
| 82 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame^] | 83 | #endif // WEBRTC_MODULES_INCLUDE_MODULE_H_ |