HalTypes.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_hal_Types_h
  6. #define mozilla_hal_Types_h
  7. #include "ipc/IPCMessageUtils.h"
  8. #include "mozilla/Observer.h"
  9. namespace mozilla {
  10. namespace hal {
  11. /**
  12. * These constants specify special values for content process IDs. You can get
  13. * a content process ID by calling ContentChild::GetID() or
  14. * ContentParent::GetChildID().
  15. */
  16. const uint64_t CONTENT_PROCESS_ID_UNKNOWN = uint64_t(-1);
  17. const uint64_t CONTENT_PROCESS_ID_MAIN = 0;
  18. /**
  19. * These are defined by libhardware, specifically, hardware/libhardware/include/hardware/lights.h
  20. * in the gonk subsystem.
  21. * If these change and are exposed to JS, make sure nsIHal.idl is updated as well.
  22. */
  23. enum ShutdownMode {
  24. eHalShutdownMode_Unknown = -1,
  25. eHalShutdownMode_PowerOff = 0,
  26. eHalShutdownMode_Reboot = 1,
  27. eHalShutdownMode_Restart = 2,
  28. eHalShutdownMode_Count = 3
  29. };
  30. // Note that we rely on the order of this enum's entries. Higher priorities
  31. // should have larger int values.
  32. enum ProcessPriority {
  33. PROCESS_PRIORITY_UNKNOWN = -1,
  34. PROCESS_PRIORITY_BACKGROUND,
  35. PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE,
  36. PROCESS_PRIORITY_FOREGROUND_KEYBOARD,
  37. // The special class for the preallocated process, high memory priority but
  38. // low CPU priority.
  39. PROCESS_PRIORITY_PREALLOC,
  40. // Any priority greater than or equal to FOREGROUND is considered
  41. // "foreground" for the purposes of priority testing, for example
  42. // CurrentProcessIsForeground().
  43. PROCESS_PRIORITY_FOREGROUND,
  44. PROCESS_PRIORITY_FOREGROUND_HIGH,
  45. PROCESS_PRIORITY_MASTER,
  46. NUM_PROCESS_PRIORITY
  47. };
  48. /**
  49. * Values that can be passed to hal::SetCurrentThreadPriority(). These should be
  50. * functional in nature, such as COMPOSITOR, instead of levels, like LOW/HIGH.
  51. * This allows us to tune our priority scheme for the system in one place such
  52. * that it makes sense holistically for the overall operating system. On gonk
  53. * or android we may want different priority schemes than on windows, etc.
  54. */
  55. enum ThreadPriority {
  56. THREAD_PRIORITY_COMPOSITOR,
  57. NUM_THREAD_PRIORITY
  58. };
  59. /**
  60. * Convert a ProcessPriority enum value to a string. The strings returned by
  61. * this function are statically allocated; do not attempt to free one!
  62. *
  63. * If you pass an unknown process priority, we fatally assert in debug
  64. * builds and otherwise return "???".
  65. */
  66. const char*
  67. ProcessPriorityToString(ProcessPriority aPriority);
  68. /**
  69. * Convert a ThreadPriority enum value to a string. The strings returned by
  70. * this function are statically allocated; do not attempt to free one!
  71. *
  72. * If you pass an unknown process priority, we assert in debug builds
  73. * and otherwise return "???".
  74. */
  75. const char *
  76. ThreadPriorityToString(ThreadPriority aPriority);
  77. /**
  78. * Used by ModifyWakeLock
  79. */
  80. enum WakeLockControl {
  81. WAKE_LOCK_REMOVE_ONE = -1,
  82. WAKE_LOCK_NO_CHANGE = 0,
  83. WAKE_LOCK_ADD_ONE = 1,
  84. NUM_WAKE_LOCK
  85. };
  86. } // namespace hal
  87. } // namespace mozilla
  88. namespace IPC {
  89. /**
  90. * Serializer for ShutdownMode.
  91. */
  92. template <>
  93. struct ParamTraits<mozilla::hal::ShutdownMode>
  94. : public ContiguousEnumSerializer<
  95. mozilla::hal::ShutdownMode,
  96. mozilla::hal::eHalShutdownMode_Unknown,
  97. mozilla::hal::eHalShutdownMode_Count>
  98. {};
  99. /**
  100. * WakeLockControl serializer.
  101. */
  102. template <>
  103. struct ParamTraits<mozilla::hal::WakeLockControl>
  104. : public ContiguousEnumSerializer<
  105. mozilla::hal::WakeLockControl,
  106. mozilla::hal::WAKE_LOCK_REMOVE_ONE,
  107. mozilla::hal::NUM_WAKE_LOCK>
  108. {};
  109. template <>
  110. struct ParamTraits<mozilla::hal::ProcessPriority>:
  111. public ContiguousEnumSerializer<
  112. mozilla::hal::ProcessPriority,
  113. mozilla::hal::PROCESS_PRIORITY_UNKNOWN,
  114. mozilla::hal::NUM_PROCESS_PRIORITY> {
  115. };
  116. } // namespace IPC
  117. #endif // mozilla_hal_Types_h