1c55a96383497a772a307b346368133960b02ad03Eric Laurent/*
2c55a96383497a772a307b346368133960b02ad03Eric Laurent *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3c55a96383497a772a307b346368133960b02ad03Eric Laurent *
4c55a96383497a772a307b346368133960b02ad03Eric Laurent *  Use of this source code is governed by a BSD-style license
5c55a96383497a772a307b346368133960b02ad03Eric Laurent *  that can be found in the LICENSE file in the root of the source
6c55a96383497a772a307b346368133960b02ad03Eric Laurent *  tree. An additional intellectual property rights grant can be found
7c55a96383497a772a307b346368133960b02ad03Eric Laurent *  in the file PATENTS.  All contributing project authors may
8c55a96383497a772a307b346368133960b02ad03Eric Laurent *  be found in the AUTHORS file in the root of the source tree.
9c55a96383497a772a307b346368133960b02ad03Eric Laurent */
10c55a96383497a772a307b346368133960b02ad03Eric Laurent
11c55a96383497a772a307b346368133960b02ad03Eric Laurent#ifndef MODULES_INTERFACE_MODULE_H_
12c55a96383497a772a307b346368133960b02ad03Eric Laurent#define MODULES_INTERFACE_MODULE_H_
13c55a96383497a772a307b346368133960b02ad03Eric Laurent
14c55a96383497a772a307b346368133960b02ad03Eric Laurent#include <assert.h>
15e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
16e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#include "typedefs.h"
17e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
18c55a96383497a772a307b346368133960b02ad03Eric Laurentnamespace webrtc {
19c55a96383497a772a307b346368133960b02ad03Eric Laurent
20c55a96383497a772a307b346368133960b02ad03Eric Laurentclass Module {
21c55a96383497a772a307b346368133960b02ad03Eric Laurent public:
22c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Change the unique identifier of this object.
23c55a96383497a772a307b346368133960b02ad03Eric Laurent  virtual int32_t ChangeUniqueId(const int32_t id) = 0;
24e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
25c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Returns the number of milliseconds until the module want a worker
26c55a96383497a772a307b346368133960b02ad03Eric Laurent  // thread to call Process.
27c55a96383497a772a307b346368133960b02ad03Eric Laurent  virtual int32_t TimeUntilNextProcess() = 0;
28e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
29c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Process any pending tasks such as timeouts.
30c55a96383497a772a307b346368133960b02ad03Eric Laurent  virtual int32_t Process() = 0;
31c55a96383497a772a307b346368133960b02ad03Eric Laurent
32c55a96383497a772a307b346368133960b02ad03Eric Laurent protected:
33c55a96383497a772a307b346368133960b02ad03Eric Laurent  virtual ~Module() {}
34c55a96383497a772a307b346368133960b02ad03Eric Laurent};
35e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
36c55a96383497a772a307b346368133960b02ad03Eric Laurent// Reference counted version of the module interface.
37c55a96383497a772a307b346368133960b02ad03Eric Laurentclass RefCountedModule : public Module {
38c55a96383497a772a307b346368133960b02ad03Eric Laurent public:
39c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Increase the reference count by one.
40c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Returns the incremented reference count.
41c55a96383497a772a307b346368133960b02ad03Eric Laurent  // TODO(perkj): Make this pure virtual when Chromium have implemented
42c55a96383497a772a307b346368133960b02ad03Eric Laurent  // reference counting ADM and Video capture module.
43c55a96383497a772a307b346368133960b02ad03Eric Laurent  virtual int32_t AddRef() {
44c55a96383497a772a307b346368133960b02ad03Eric Laurent    assert(!"Not implemented.");
45c55a96383497a772a307b346368133960b02ad03Eric Laurent    return 1;
46c55a96383497a772a307b346368133960b02ad03Eric Laurent  }
47e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
48c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Decrease the reference count by one.
49c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Returns the decreased reference count.
50c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Returns 0 if the last reference was just released.
51c55a96383497a772a307b346368133960b02ad03Eric Laurent  // When the reference count reach 0 the object will self-destruct.
52c55a96383497a772a307b346368133960b02ad03Eric Laurent  // TODO(perkj): Make this pure virtual when Chromium have implemented
53c55a96383497a772a307b346368133960b02ad03Eric Laurent  // reference counting ADM and Video capture module.
54c55a96383497a772a307b346368133960b02ad03Eric Laurent  virtual int32_t Release() {
55c55a96383497a772a307b346368133960b02ad03Eric Laurent    assert(!"Not implemented.");
56c55a96383497a772a307b346368133960b02ad03Eric Laurent    return 1;
57c55a96383497a772a307b346368133960b02ad03Eric Laurent  }
58e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
59c55a96383497a772a307b346368133960b02ad03Eric Laurent protected:
60c55a96383497a772a307b346368133960b02ad03Eric Laurent  virtual ~RefCountedModule() {}
61e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent};
62e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
63c55a96383497a772a307b346368133960b02ad03Eric Laurent}  // namespace webrtc
64e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
65c55a96383497a772a307b346368133960b02ad03Eric Laurent#endif  // MODULES_INTERFACE_MODULE_H_
66