blob: fc2a1b5fc96eb2913bb2e37bc1f0257ffc5593ef [file] [log] [blame]
Henrik Kjellanderff761fb2015-11-04 08:31:52 +01001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_INCLUDE_MODULE_H_
12#define MODULES_INCLUDE_MODULE_H_
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010013
Mirko Bonadei71207422017-09-15 13:58:09 +020014#include "typedefs.h" // NOLINT(build/include)
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010015
16namespace webrtc {
17
18class ProcessThread;
19
20class 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.
pbosa26ac922016-02-25 04:50:01 -080035 virtual void Process() = 0;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010036
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 Kjellanderff761fb2015-11-04 08:31:52 +010061} // namespace webrtc
62
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020063#endif // MODULES_INCLUDE_MODULE_H_