]> git.saurik.com Git - apple/libc.git/blob - sys/OSThermalNotification.c
618bf58ef787079b5cae2b2a137536bbbdccdaa8
[apple/libc.git] / sys / OSThermalNotification.c
1 /*
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include <dispatch/dispatch.h>
25 #include <libkern/OSThermalNotification.h>
26 #include <notify.h>
27
28 #define OSThermalStatusName "com.apple.system.thermalstatus"
29
30 const char * const kOSThermalNotificationName = OSThermalStatusName;
31
32 static const char * const kOSThermalMitigationNames[kOSThermalMitigationCount] = {
33 OSThermalStatusName,
34 "com.apple.system.thermalmitigation.70percenttorch",
35 "com.apple.system.thermalmitigation.70percentbacklight",
36 "com.apple.system.thermalmitigation.50percenttorch",
37 "com.apple.system.thermalmitigation.50percentbacklight",
38 "com.apple.system.thermalmitigation.disabletorch",
39 "com.apple.system.thermalmitigation.25percentbacklight",
40 "com.apple.system.thermalmitigation.disablemapshalo",
41 "com.apple.system.thermalmitigation.appterminate",
42 "com.apple.system.thermalmitigation.devicerestart"
43 };
44
45 static int tokens[kOSThermalMitigationCount];
46 static dispatch_once_t predicates[kOSThermalMitigationCount];
47
48 OSThermalNotificationLevel _OSThermalNotificationLevelForBehavior(int behavior)
49 {
50 uint64_t val = OSThermalNotificationLevelAny;
51 if (behavior >= 0 && behavior < kOSThermalMitigationCount) {
52 dispatch_once(&predicates[behavior], ^{
53 (void)notify_register_check(kOSThermalMitigationNames[behavior], &tokens[behavior]);
54 });
55 (void)notify_get_state(tokens[behavior], &val);
56 }
57 return (OSThermalNotificationLevel)val;
58 }
59
60 void _OSThermalNotificationSetLevelForBehavior(int level, int behavior)
61 {
62 uint64_t val = (uint64_t)level;
63 if (behavior >= 0 && behavior < kOSThermalMitigationCount) {
64 dispatch_once(&predicates[behavior], ^{
65 (void)notify_register_check(kOSThermalMitigationNames[behavior], &tokens[behavior]);
66 });
67 (void)notify_set_state(tokens[behavior], val);
68 }
69 }
70
71
72 OSThermalNotificationLevel OSThermalNotificationCurrentLevel(void)
73 {
74 return _OSThermalNotificationLevelForBehavior(kOSThermalMitigationNone);
75 }