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>
33 //#define IORDEBUG_LEGEND 1
35 #ifdef IORDEBUG_LEGEND
36 #define IORLEGENDLOG(fmt, args...) \
38 IOLog("IOReportLegend | "); \
43 #define IORLEGENDLOG(fmt, args...)
47 #define super OSObject
48 OSDefineMetaClassAndStructors(IOReportLegend
, OSObject
);
51 IOReportLegend::with(OSArray
*legend
)
53 IOReportLegend
*iorLegend
= new IOReportLegend
;
58 if (iorLegend
->initWith(legend
) != kIOReturnSuccess
) {
70 /* must clean up everything if it fails */
72 IOReportLegend::initWith(OSArray
*legend
)
74 if (legend
) _reportLegend
= OSArray::withArray(legend
);
76 if (_reportLegend
== NULL
)
77 return kIOReturnError
;
79 else return kIOReturnSuccess
;
84 IOReportLegend::free(void)
86 if (_reportLegend
) _reportLegend
->release();
92 IOReportLegend::getLegend(void)
98 IOReportLegend::addReporterLegend(IOService
*reportingService
,
100 const char *groupName
,
101 const char *subGroupName
)
103 IOReturn res
= kIOReturnError
;
104 IOReportLegend
*legend
;
106 // No need to check groupName and subGroupName because optional params
107 if (!reportingService
|| !reporter
) {
111 legend
= IOReportLegend::with(OSDynamicCast(OSArray
, reportingService
->getProperty(kIOReportLegendKey
)));
115 legend
->addReporterLegend(reporter
, groupName
, subGroupName
);
116 reportingService
->setProperty(kIOReportLegendKey
, legend
->getLegend());
117 reportingService
->setProperty(kIOReportLegendPublicKey
, true);
119 res
= kIOReturnSuccess
;
128 IOReportLegend::addLegendEntry(IOReportLegendEntry
*legendEntry
,
129 const char *groupName
,
130 const char *subGroupName
)
132 kern_return_t res
= kIOReturnError
;
133 const OSSymbol
*tmpGroupName
= NULL
;
134 const OSSymbol
*tmpSubGroupName
= NULL
;
136 if (!legendEntry
) goto finish
;
139 tmpGroupName
= OSSymbol::withCString(groupName
);
143 tmpSubGroupName
= OSSymbol::withCString(subGroupName
);
146 // It is ok to call appendLegendWith() if tmpGroups are NULL
148 res
= organizeLegend(legendEntry
, tmpGroupName
, tmpSubGroupName
);
150 if (tmpGroupName
) tmpGroupName
->release();
151 if (tmpSubGroupName
) tmpSubGroupName
->release();
160 IOReportLegend::addReporterLegend(IOReporter
*reporter
,
161 const char *groupName
,
162 const char *subGroupName
)
164 IOReturn res
= kIOReturnError
;
165 IOReportLegendEntry
*legendEntry
= NULL
;
169 legendEntry
= reporter
->createLegend();
173 res
= addLegendEntry(legendEntry
, groupName
, subGroupName
);
174 legendEntry
->release();
183 IOReportLegend::organizeLegend(IOReportLegendEntry
*legendEntry
,
184 const OSSymbol
*groupName
,
185 const OSSymbol
*subGroupName
)
187 IOReturn res
= kIOReturnError
;
190 return res
= kIOReturnBadArgument
;
192 if (!groupName
&& subGroupName
)
193 return res
= kIOReturnBadArgument
;
195 IORLEGENDLOG("IOReportLegend::organizeLegend");
196 // Legend is empty, enter first node
197 if (_reportLegend
== NULL
) {
198 IORLEGENDLOG("IOReportLegend::new legend creation");
199 _reportLegend
= OSArray::withCapacity(1);
202 return kIOReturnNoMemory
;
206 legendEntry
->setObject(kIOReportLegendGroupNameKey
, groupName
);
209 legendEntry
->setObject(kIOReportLegendSubGroupNameKey
, subGroupName
);
211 _reportLegend
->setObject(legendEntry
);
213 // callers can now safely release legendEntry (it is part of _reportLegend)
215 return res
= kIOReturnSuccess
;