]>
Commit | Line | Data |
---|---|---|
fe8ab488 A |
1 | /* |
2 | * Copyright (c) 2012-2013 Apple Computer, Inc. All Rights Reserved. | |
0a7de745 | 3 | * |
fe8ab488 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
fe8ab488 A |
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. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
fe8ab488 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
fe8ab488 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
fe8ab488 A |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ | |
28 | ||
29 | #include <IOKit/IOKernelReportStructs.h> | |
30 | #include <IOKit/IOKernelReporters.h> | |
31 | #include "IOReporterDefs.h" | |
32 | ||
33 | #define super IOReporter | |
34 | OSDefineMetaClassAndStructors(IOSimpleReporter, IOReporter); | |
35 | ||
36 | /* static */ | |
37 | IOSimpleReporter* | |
38 | IOSimpleReporter::with(IOService *reportingService, | |
0a7de745 A |
39 | IOReportCategories categories, |
40 | IOReportUnit unit) | |
fe8ab488 | 41 | { |
0a7de745 | 42 | IOSimpleReporter *reporter, *rval = NULL; |
fe8ab488 | 43 | |
0a7de745 | 44 | // kprintf("%s\n", __func__); // can't IORLOG() from static |
fe8ab488 | 45 | |
0a7de745 A |
46 | reporter = new IOSimpleReporter; |
47 | if (!reporter) { | |
48 | goto finish; | |
49 | } | |
fe8ab488 A |
50 | |
51 | ||
0a7de745 A |
52 | if (!reporter->initWith(reportingService, categories, unit)) { |
53 | goto finish; | |
54 | } | |
55 | ||
56 | // success | |
57 | rval = reporter; | |
58 | ||
fe8ab488 | 59 | finish: |
0a7de745 A |
60 | if (!rval) { |
61 | OSSafeReleaseNULL(reporter); | |
62 | } | |
63 | ||
64 | return rval; | |
fe8ab488 A |
65 | } |
66 | ||
67 | bool | |
68 | IOSimpleReporter::initWith(IOService *reportingService, | |
0a7de745 A |
69 | IOReportCategories categories, |
70 | IOReportUnit unit) | |
fe8ab488 | 71 | { |
0a7de745 A |
72 | // fully specify the channel type for the superclass |
73 | IOReportChannelType channelType = { | |
74 | .categories = categories, | |
75 | .report_format = kIOReportFormatSimple, | |
76 | .nelements = 1, | |
77 | .element_idx = 0 | |
78 | }; | |
79 | ||
80 | return super::init(reportingService, channelType, unit); | |
fe8ab488 A |
81 | } |
82 | ||
83 | ||
84 | IOReturn | |
85 | IOSimpleReporter::setValue(uint64_t channel_id, | |
0a7de745 | 86 | int64_t value) |
fe8ab488 | 87 | { |
0a7de745 A |
88 | IOReturn res = kIOReturnError; |
89 | IOSimpleReportValues simple_values; | |
90 | int element_index = 0; | |
91 | ||
92 | lockReporter(); | |
93 | ||
94 | if (getFirstElementIndex(channel_id, &element_index) != kIOReturnSuccess) { | |
95 | res = kIOReturnBadArgument; | |
96 | goto finish; | |
97 | } | |
98 | ||
99 | ||
100 | if (copyElementValues(element_index, (IOReportElementValues *)&simple_values) != kIOReturnSuccess) { | |
101 | res = kIOReturnBadArgument; | |
102 | goto finish; | |
103 | } | |
104 | ||
105 | simple_values.simple_value = value; | |
106 | res = setElementValues(element_index, (IOReportElementValues *)&simple_values); | |
107 | ||
fe8ab488 | 108 | finish: |
0a7de745 A |
109 | unlockReporter(); |
110 | return res; | |
fe8ab488 A |
111 | } |
112 | ||
113 | ||
114 | IOReturn | |
115 | IOSimpleReporter::incrementValue(uint64_t channel_id, | |
0a7de745 | 116 | int64_t increment) |
fe8ab488 | 117 | { |
0a7de745 A |
118 | IOReturn res = kIOReturnError; |
119 | IOSimpleReportValues simple_values; | |
120 | int element_index = 0; | |
121 | ||
122 | lockReporter(); | |
123 | ||
124 | if (getFirstElementIndex(channel_id, &element_index) != kIOReturnSuccess) { | |
125 | res = kIOReturnBadArgument; | |
126 | goto finish; | |
127 | } | |
128 | ||
129 | if (copyElementValues(element_index, (IOReportElementValues *)&simple_values) != kIOReturnSuccess) { | |
130 | res = kIOReturnBadArgument; | |
131 | goto finish; | |
132 | } | |
133 | ||
134 | simple_values.simple_value += increment; | |
135 | ||
136 | res = setElementValues(element_index, (IOReportElementValues *)&simple_values); | |
137 | ||
fe8ab488 | 138 | finish: |
0a7de745 A |
139 | unlockReporter(); |
140 | return res; | |
fe8ab488 A |
141 | } |
142 | ||
143 | int64_t | |
144 | IOSimpleReporter::getValue(uint64_t channel_id) | |
145 | { | |
0a7de745 A |
146 | IOSimpleReportValues *values = NULL; |
147 | int64_t simple_value = (int64_t)kIOReportInvalidValue; | |
148 | int index = 0; | |
149 | ||
150 | lockReporter(); | |
151 | ||
152 | if (getFirstElementIndex(channel_id, &index) == kIOReturnSuccess) { | |
153 | values = (IOSimpleReportValues *)getElementValues(index); | |
fe8ab488 | 154 | |
0a7de745 A |
155 | if (values != NULL) { |
156 | simple_value = values->simple_value; | |
157 | } | |
158 | } | |
159 | ||
160 | unlockReporter(); | |
161 | return simple_value; | |
162 | } |