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 #define IOKIT_ENABLE_SHARED_PTR
31 #include <libkern/c++/OSSharedPtr.h>
32 #include <IOKit/IOKernelReportStructs.h>
33 #include <IOKit/IOKernelReporters.h>
34 #include "IOReporterDefs.h"
36 #define super IOReporter
37 OSDefineMetaClassAndStructors(IOSimpleReporter
, IOReporter
);
40 OSSharedPtr
<IOSimpleReporter
>
41 IOSimpleReporter::with(IOService
*reportingService
,
42 IOReportCategories categories
,
45 OSSharedPtr
<IOSimpleReporter
> reporter
;
47 reporter
= OSMakeShared
<IOSimpleReporter
>();
52 if (!reporter
->initWith(reportingService
, categories
, unit
)) {
60 IOSimpleReporter::initWith(IOService
*reportingService
,
61 IOReportCategories categories
,
64 // fully specify the channel type for the superclass
65 IOReportChannelType channelType
= {
66 .categories
= categories
,
67 .report_format
= kIOReportFormatSimple
,
72 return super::init(reportingService
, channelType
, unit
);
77 IOSimpleReporter::setValue(uint64_t channel_id
,
80 IOReturn res
= kIOReturnError
;
81 IOSimpleReportValues simple_values
;
82 int element_index
= 0;
86 if (getFirstElementIndex(channel_id
, &element_index
) != kIOReturnSuccess
) {
87 res
= kIOReturnBadArgument
;
92 if (copyElementValues(element_index
, (IOReportElementValues
*)&simple_values
) != kIOReturnSuccess
) {
93 res
= kIOReturnBadArgument
;
97 simple_values
.simple_value
= value
;
98 res
= setElementValues(element_index
, (IOReportElementValues
*)&simple_values
);
107 IOSimpleReporter::incrementValue(uint64_t channel_id
,
110 IOReturn res
= kIOReturnError
;
111 IOSimpleReportValues simple_values
;
112 int element_index
= 0;
116 if (getFirstElementIndex(channel_id
, &element_index
) != kIOReturnSuccess
) {
117 res
= kIOReturnBadArgument
;
121 if (copyElementValues(element_index
, (IOReportElementValues
*)&simple_values
) != kIOReturnSuccess
) {
122 res
= kIOReturnBadArgument
;
126 simple_values
.simple_value
+= increment
;
128 res
= setElementValues(element_index
, (IOReportElementValues
*)&simple_values
);
136 IOSimpleReporter::getValue(uint64_t channel_id
)
138 IOSimpleReportValues
*values
= NULL
;
139 int64_t simple_value
= (int64_t)kIOReportInvalidValue
;
144 if (getFirstElementIndex(channel_id
, &index
) == kIOReturnSuccess
) {
145 values
= (IOSimpleReportValues
*)getElementValues(index
);
147 if (values
!= NULL
) {
148 simple_value
= values
->simple_value
;