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
;
52 if (!reporter
->initWith(reportingService
, categories
, unit
)) {
61 OSSafeReleaseNULL(reporter
);
68 IOSimpleReporter::initWith(IOService
*reportingService
,
69 IOReportCategories categories
,
72 // fully specify the channel type for the superclass
73 IOReportChannelType channelType
= {
74 .categories
= categories
,
75 .report_format
= kIOReportFormatSimple
,
80 return super::init(reportingService
, channelType
, unit
);
85 IOSimpleReporter::setValue(uint64_t channel_id
,
88 IOReturn res
= kIOReturnError
;
89 IOSimpleReportValues simple_values
;
90 int element_index
= 0;
94 if (getFirstElementIndex(channel_id
, &element_index
) != kIOReturnSuccess
) {
95 res
= kIOReturnBadArgument
;
100 if (copyElementValues(element_index
, (IOReportElementValues
*)&simple_values
) != kIOReturnSuccess
) {
101 res
= kIOReturnBadArgument
;
105 simple_values
.simple_value
= value
;
106 res
= setElementValues(element_index
, (IOReportElementValues
*)&simple_values
);
115 IOSimpleReporter::incrementValue(uint64_t channel_id
,
118 IOReturn res
= kIOReturnError
;
119 IOSimpleReportValues simple_values
;
120 int element_index
= 0;
124 if (getFirstElementIndex(channel_id
, &element_index
) != kIOReturnSuccess
) {
125 res
= kIOReturnBadArgument
;
129 if (copyElementValues(element_index
, (IOReportElementValues
*)&simple_values
) != kIOReturnSuccess
) {
130 res
= kIOReturnBadArgument
;
134 simple_values
.simple_value
+= increment
;
136 res
= setElementValues(element_index
, (IOReportElementValues
*)&simple_values
);
144 IOSimpleReporter::getValue(uint64_t channel_id
)
146 IOSimpleReportValues
*values
= NULL
;
147 int64_t simple_value
= (int64_t)kIOReportInvalidValue
;
152 if (getFirstElementIndex(channel_id
, &index
) == kIOReturnSuccess
) {
153 values
= (IOSimpleReportValues
*)getElementValues(index
);
155 if (values
!= NULL
) {
156 simple_value
= values
->simple_value
;