blob: c3e3030397c5d2a8053392329ff3fb91765268ec [file] [log] [blame]
perkj@google.comef04cf42011-09-02 09:47:28 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
perkj@google.comef04cf42011-09-02 09:47:28 +00003 *
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
11#ifndef MODULES_INTERFACE_MODULE_H_
12#define MODULES_INTERFACE_MODULE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pbos@webrtc.org57eb8582013-11-11 10:20:27 +000014#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
perkj@google.comef04cf42011-09-02 09:47:28 +000016namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000017
perkj@google.comef04cf42011-09-02 09:47:28 +000018class Module {
19 public:
tommi@webrtc.org41617152015-01-29 12:12:49 +000020 // Returns the number of milliseconds until the module wants a worker
perkj@google.comef04cf42011-09-02 09:47:28 +000021 // thread to call Process.
tommi@webrtc.org41617152015-01-29 12:12:49 +000022 // This method is called on the same worker thread as Process will
23 // be called on.
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +000024 virtual int64_t TimeUntilNextProcess() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000025
perkj@google.comef04cf42011-09-02 09:47:28 +000026 // Process any pending tasks such as timeouts.
tommi@webrtc.org41617152015-01-29 12:12:49 +000027 // Called on a worker thread.
perkj@google.comef04cf42011-09-02 09:47:28 +000028 virtual int32_t Process() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000029
perkj@google.comef04cf42011-09-02 09:47:28 +000030 protected:
31 virtual ~Module() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000032};
33
tommi@webrtc.org41617152015-01-29 12:12:49 +000034// Reference counted version of the Module interface.
perkj@google.comef04cf42011-09-02 09:47:28 +000035class RefCountedModule : public Module {
36 public:
37 // Increase the reference count by one.
38 // Returns the incremented reference count.
tommi@webrtc.org41617152015-01-29 12:12:49 +000039 virtual int32_t AddRef() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000040
perkj@google.comef04cf42011-09-02 09:47:28 +000041 // Decrease the reference count by one.
42 // Returns the decreased reference count.
43 // Returns 0 if the last reference was just released.
tommi@webrtc.org41617152015-01-29 12:12:49 +000044 // When the reference count reaches 0 the object will self-destruct.
45 virtual int32_t Release() = 0;
perkj@google.comef04cf42011-09-02 09:47:28 +000046
47 protected:
48 virtual ~RefCountedModule() {}
49};
50
51} // namespace webrtc
52
53#endif // MODULES_INTERFACE_MODULE_H_