IOSimpleReporter.cpp [plain text]
#include <IOKit/IOKernelReportStructs.h>
#include <IOKit/IOKernelReporters.h>
#include "IOReporterDefs.h"
#define super IOReporter
OSDefineMetaClassAndStructors(IOSimpleReporter, IOReporter);
IOSimpleReporter*
IOSimpleReporter::with(IOService *reportingService,
IOReportCategories categories,
IOReportUnit unit)
{
IOSimpleReporter *reporter, *rval = NULL;
reporter = new IOSimpleReporter;
if (!reporter) goto finish;
if (!reporter->initWith(reportingService, categories, unit)) {
goto finish;
}
rval = reporter;
finish:
if (!rval) {
OSSafeReleaseNULL(reporter);
}
return rval;
}
bool
IOSimpleReporter::initWith(IOService *reportingService,
IOReportCategories categories,
IOReportUnit unit)
{
IOReportChannelType channelType = {
.categories = categories,
.report_format = kIOReportFormatSimple,
.nelements = 1,
.element_idx = 0
};
return super::init(reportingService, channelType, unit);
}
IOReturn
IOSimpleReporter::setValue(uint64_t channel_id,
int64_t value)
{
IOReturn res = kIOReturnError;
IOSimpleReportValues simple_values;
int element_index = 0;
lockReporter();
if (getFirstElementIndex(channel_id, &element_index) != kIOReturnSuccess) {
res = kIOReturnBadArgument;
goto finish;
}
if (copyElementValues(element_index, (IOReportElementValues *)&simple_values) != kIOReturnSuccess) {
res = kIOReturnBadArgument;
goto finish;
}
simple_values.simple_value = value;
res = setElementValues(element_index, (IOReportElementValues *)&simple_values);
finish:
unlockReporter();
return res;
}
IOReturn
IOSimpleReporter::incrementValue(uint64_t channel_id,
int64_t increment)
{
IOReturn res = kIOReturnError;
IOSimpleReportValues simple_values;
int element_index = 0;
lockReporter();
if (getFirstElementIndex(channel_id, &element_index) != kIOReturnSuccess) {
res = kIOReturnBadArgument;
goto finish;
}
if (copyElementValues(element_index, (IOReportElementValues *)&simple_values) != kIOReturnSuccess){
res = kIOReturnBadArgument;
goto finish;
}
simple_values.simple_value += increment;
res = setElementValues(element_index, (IOReportElementValues *)&simple_values);
finish:
unlockReporter();
return res;
}
int64_t
IOSimpleReporter::getValue(uint64_t channel_id)
{
IOSimpleReportValues *values = NULL;
int64_t simple_value = (int64_t)kIOReportInvalidValue;
int index = 0;
lockReporter();
if (getFirstElementIndex(channel_id, &index) == kIOReturnSuccess) {
values = (IOSimpleReportValues *)getElementValues(index);
if (values != NULL)
simple_value = values->simple_value;
}
unlockReporter();
return simple_value;
}