module.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef MODULES_INCLUDE_MODULE_H_
  11. #define MODULES_INCLUDE_MODULE_H_
  12. #include <stdint.h>
  13. namespace webrtc {
  14. class ProcessThread;
  15. class Module {
  16. public:
  17. // Returns the number of milliseconds until the module wants a worker
  18. // thread to call Process.
  19. // This method is called on the same worker thread as Process will
  20. // be called on.
  21. // TODO(tommi): Almost all implementations of this function, need to know
  22. // the current tick count. Consider passing it as an argument. It could
  23. // also improve the accuracy of when the next callback occurs since the
  24. // thread that calls Process() will also have it's tick count reference
  25. // which might not match with what the implementations use.
  26. virtual int64_t TimeUntilNextProcess() = 0;
  27. // Process any pending tasks such as timeouts.
  28. // Called on a worker thread.
  29. virtual void Process() = 0;
  30. // This method is called when the module is attached to a *running* process
  31. // thread or detached from one. In the case of detaching, |process_thread|
  32. // will be nullptr.
  33. //
  34. // This method will be called in the following cases:
  35. //
  36. // * Non-null process_thread:
  37. // * ProcessThread::RegisterModule() is called while the thread is running.
  38. // * ProcessThread::Start() is called and RegisterModule has previously
  39. // been called. The thread will be started immediately after notifying
  40. // all modules.
  41. //
  42. // * Null process_thread:
  43. // * ProcessThread::DeRegisterModule() is called while the thread is
  44. // running.
  45. // * ProcessThread::Stop() was called and the thread has been stopped.
  46. //
  47. // NOTE: This method is not called from the worker thread itself, but from
  48. // the thread that registers/deregisters the module or calls Start/Stop.
  49. virtual void ProcessThreadAttached(ProcessThread* process_thread) {}
  50. protected:
  51. virtual ~Module() {}
  52. };
  53. } // namespace webrtc
  54. #endif // MODULES_INCLUDE_MODULE_H_