2 * Copyright (c) 2012-2013 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <IOKit/IOKernelReportStructs.h>
30 #include <IOKit/IOKernelReporters.h>
31 #include "IOReporterDefs.h"
33 #define super IOReporter
34 OSDefineMetaClassAndStructors(IOSimpleReporter
, IOReporter
);
38 IOSimpleReporter::with(IOService
*reportingService
,
39 IOReportCategories categories
,
42 IOSimpleReporter
*reporter
, *rval
= NULL
;
44 // kprintf("%s\n", __func__); // can't IORLOG() from static
46 reporter
= new IOSimpleReporter
;
47 if (!reporter
) goto finish
;
50 if (!reporter
->initWith(reportingService
, categories
, unit
)) {
59 OSSafeReleaseNULL(reporter
);
66 IOSimpleReporter::initWith(IOService
*reportingService
,
67 IOReportCategories categories
,
70 // fully specify the channel type for the superclass
71 IOReportChannelType channelType
= {
72 .categories
= categories
,
73 .report_format
= kIOReportFormatSimple
,
78 return super::init(reportingService
, channelType
, unit
);
83 IOSimpleReporter::setValue(uint64_t channel_id
,
86 IOReturn res
= kIOReturnError
;
87 IOSimpleReportValues simple_values
;
88 int element_index
= 0;
92 if (getFirstElementIndex(channel_id
, &element_index
) != kIOReturnSuccess
) {
93 res
= kIOReturnBadArgument
;
98 if (copyElementValues(element_index
, (IOReportElementValues
*)&simple_values
) != kIOReturnSuccess
) {
99 res
= kIOReturnBadArgument
;
103 simple_values
.simple_value
= value
;
104 res
= setElementValues(element_index
, (IOReportElementValues
*)&simple_values
);
113 IOSimpleReporter::incrementValue(uint64_t channel_id
,
116 IOReturn res
= kIOReturnError
;
117 IOSimpleReportValues simple_values
;
118 int element_index
= 0;
122 if (getFirstElementIndex(channel_id
, &element_index
) != kIOReturnSuccess
) {
123 res
= kIOReturnBadArgument
;
127 if (copyElementValues(element_index
, (IOReportElementValues
*)&simple_values
) != kIOReturnSuccess
){
128 res
= kIOReturnBadArgument
;
132 simple_values
.simple_value
+= increment
;
134 res
= setElementValues(element_index
, (IOReportElementValues
*)&simple_values
);
142 IOSimpleReporter::getValue(uint64_t channel_id
)
144 IOSimpleReportValues
*values
= NULL
;
145 int64_t simple_value
= (int64_t)kIOReportInvalidValue
;
150 if (getFirstElementIndex(channel_id
, &index
) == kIOReturnSuccess
) {
152 values
= (IOSimpleReportValues
*)getElementValues(index
);
155 simple_value
= values
->simple_value
;