• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ IORegistryEntryCreateCFProperties函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中IORegistryEntryCreateCFProperties函数的典型用法代码示例。如果您正苦于以下问题:C++ IORegistryEntryCreateCFProperties函数的具体用法?C++ IORegistryEntryCreateCFProperties怎么用?C++ IORegistryEntryCreateCFProperties使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了IORegistryEntryCreateCFProperties函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: handle_drive

/*
 * Check whether an IORegistryEntry refers to a valid
 * I/O device, and if so, collect the information.
 */
static int
handle_drive(io_registry_entry_t drive, struct drivestats * dstat)
{
    io_registry_entry_t parent;
    CFMutableDictionaryRef     properties;
    CFStringRef         name;
    CFNumberRef         number;
    kern_return_t       status;

    /* get drive's parent */
    status = IORegistryEntryGetParentEntry(drive, kIOServicePlane, &parent);
    if (status != KERN_SUCCESS) {
	snmp_log(LOG_ERR, "diskio: device has no parent\n");
/*	fprintf(stderr, "device has no parent\n"); */
	return(1);
    }

    if (IOObjectConformsTo(parent, "IOBlockStorageDriver")) {

	/* get drive properties */
	status = IORegistryEntryCreateCFProperties(drive, &properties,
					    kCFAllocatorDefault, kNilOptions);
	if (status != KERN_SUCCESS) {
	    snmp_log(LOG_ERR, "diskio: device has no properties\n");
/*	    fprintf(stderr, "device has no properties\n"); */
	    return(1);
	}

	/* get BSD name and unitnumber from properties */
	name = (CFStringRef)CFDictionaryGetValue(properties,
					  CFSTR(kIOBSDNameKey));
	number = (CFNumberRef)CFDictionaryGetValue(properties,
					    CFSTR(kIOBSDUnitKey));

	/* Collect stats and if succesful store them with the name and unitnumber */
	if (name && number && !collect_drive_stats(parent, dstat->stats)) {

	    CFStringGetCString(name, dstat->name, MAXDRIVENAME, CFStringGetSystemEncoding());
	    CFNumberGetValue(number, kCFNumberSInt32Type, &dstat->bsd_unit_number);
	    num_drives++;
	}

	/* clean up, return success */
	CFRelease(properties);
	return(0);
    }

    /* failed, don't keep parent */
    IOObjectRelease(parent);
    return(1);
}
开发者ID:pexip,项目名称:os-net-snmp,代码行数:55,代码来源:diskio.c


示例2: myIORegistryEntryBSDNameMatchingCopyValue

CFDictionaryRef
myIORegistryEntryBSDNameMatchingCopyValue(const char * devname, Boolean parent)
{
    kern_return_t       	status;
    CFMutableDictionaryRef	properties = NULL;
    io_registry_entry_t 	service;

    service 
	= IOServiceGetMatchingService(kIOMasterPortDefault,
				      IOBSDNameMatching(kIOMasterPortDefault, 0, devname));
    if (service == MACH_PORT_NULL) {
	return (NULL);
    }
    if (parent) {
	io_registry_entry_t	parent_service;
	
	status = IORegistryEntryGetParentEntry(service, kIOServicePlane,
					       &parent_service);
	if (status == KERN_SUCCESS) {
	    status = IORegistryEntryCreateCFProperties(parent_service,
						       &properties,
						       kCFAllocatorDefault,
						       kNilOptions);
	    IOObjectRelease(parent_service);
	}
    }
    else {
	status = IORegistryEntryCreateCFProperties(service,
						   &properties,
						   kCFAllocatorDefault,
						   kNilOptions);
    }
    if (status != KERN_SUCCESS) {
	properties = NULL;
    }
    IOObjectRelease(service);
    return (properties);
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:38,代码来源:ioregpath.c


示例3: IOMasterPort

int IdlePlatform::secondsIdle()
{
  mach_port_t masterPort;
  io_iterator_t iter;
  io_registry_entry_t curObj;

  IOMasterPort(MACH_PORT_NULL, &masterPort);
  IOServiceGetMatchingServices(masterPort, IOServiceMatching("IOHIDSystem"), &iter);
  if (iter == 0)
    return -1;

  curObj = IOIteratorNext(iter);
  if (curObj == 0)
    return -1;

  CFMutableDictionaryRef properties = 0;
  CFTypeRef obj;
  int result = -1;

  if (IORegistryEntryCreateCFProperties(curObj, &properties, kCFAllocatorDefault, 0) == KERN_SUCCESS && properties != NULL) {
    obj = CFDictionaryGetValue(properties, CFSTR("HIDIdleTime"));
    CFRetain(obj);
  } else
    obj = NULL;

  if (obj) {
    uint64_t tHandle;

    CFTypeID type = CFGetTypeID(obj);

    if (type == CFDataGetTypeID())
      CFDataGetBytes((CFDataRef) obj, CFRangeMake(0, sizeof(tHandle)), (UInt8*) &tHandle);
    else if (type == CFNumberGetTypeID())
      CFNumberGetValue((CFNumberRef)obj, kCFNumberSInt64Type, &tHandle);
    else
      return -1;

    CFRelease(obj);

    // essentially divides by 10^9
    tHandle >>= 30;
    result = tHandle;
  }

  /* Release our resources */
  IOObjectRelease(curObj);
  IOObjectRelease(iter);
  CFRelease((CFTypeRef)properties);
  return result;
}
开发者ID:ChALkeR,项目名称:vacuum-im,代码行数:50,代码来源:idle_mac.cpp


示例4: getProperties

// gets all properties from an entry into a QMap
static QMap<QString, QVariant> getProperties(const io_registry_entry_t &entry)
{
    CFMutableDictionaryRef propertyDict = 0;

    if (IORegistryEntryCreateCFProperties(entry, &propertyDict, kCFAllocatorDefault, kNilOptions) != KERN_SUCCESS) {
        return QMap<QString, QVariant>();
    }

    QMap<QString, QVariant> result = q_toVariantMap(propertyDict);

    CFRelease(propertyDict);

    return result;
}
开发者ID:shainer,项目名称:solid,代码行数:15,代码来源:iokitdevice.cpp


示例5: OSX_ReadCDTOC

void OSX_ReadCDTOC(io_object_t cdobject) {
	CFMutableDictionaryRef cd_props = 0;
	CFDataRef cdTOCdata = NULL;
	char* cdTOCrawdata = NULL;
	
	if (IORegistryEntryCreateCFProperties(cdobject, &cd_props, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) return;
												
	cdTOCdata = (CFDataRef)CFDictionaryGetValue(cd_props, CFSTR (kIOCDMediaTOCKey));
	if (cdTOCdata != NULL) {
	   	Extract_cdTOCrawdata(cdTOCdata, cdTOCrawdata);
	}
	CFRelease(cd_props);
	cd_props = NULL;
	return;
}
开发者ID:DanDrusch,项目名称:atomicparsley,代码行数:15,代码来源:CDtoc.cpp


示例6: PRINT

IOReturn
SATSMARTClient::Probe ( CFDictionaryRef propertyTable,
                        io_service_t inService,
                        SInt32 *                order )
{

    CFMutableDictionaryRef dict    = NULL;
    IOReturn status  = kIOReturnBadArgument;

    PRINT ( ( "SATSMARTClient::Probe called\n" ) );

    // Sanity check
    if ( inService == 0 )
    {
        goto Exit;
    }

    status = IORegistryEntryCreateCFProperties ( inService, &dict, NULL, 0 );
    if ( status != kIOReturnSuccess )
    {
        goto Exit;
    }

    if ( !CFDictionaryContainsKey ( dict, CFSTR ( "IOCFPlugInTypes" ) ) )
    {
        goto Exit;
    }


    status = kIOReturnSuccess;


Exit:


    if ( dict != NULL )
    {

        CFRelease ( dict );
        dict = NULL;

    }


    PRINT ( ( "SATSMARTClient::Probe called %x\n",status ) );
    return status;

}
开发者ID:eitschpi,项目名称:OS-X-SAT-SMART-Driver,代码行数:48,代码来源:SATSMARTClient.cpp


示例7: genPCIDevice

void genPCIDevice(const io_service_t& device, QueryData& results) {
  Row r;

  // Get the device details
  CFMutableDictionaryRef details;
  IORegistryEntryCreateCFProperties(
      device, &details, kCFAllocatorDefault, kNilOptions);

  r["pci_slot"] = getIOKitProperty(details, "pcidebug");

  std::vector<std::string> properties;
  auto compatible = getIOKitProperty(details, "compatible");
  boost::trim(compatible);
  boost::split(properties, compatible, boost::is_any_of(" "));

  if (properties.size() < 2) {
    VLOG(1) << "Error parsing IOKit compatible properties";
    return;
  }

  size_t prop_index = 0;
  if (properties[1].find("pci") == 0 && properties[1].find("pciclass") != 0) {
    // There are two sets of PCI definitions.
    prop_index = 1;
  } else if (properties[0].find("pci") != 0) {
    VLOG(1) << "No vendor/model found";
    return;
  }

  std::vector<std::string> vendor;
  boost::split(vendor, properties[prop_index++], boost::is_any_of(","));
  r["vendor_id"] = vendor[0].substr(3);
  r["model_id"] = (vendor[1].size() == 3) ? "0" + vendor[1] : vendor[1];

  if (properties[prop_index].find("pciclass") == 0) {
    // There is a class definition.
    r["pci_class"] = properties[prop_index++].substr(9);
  }

  if (properties.size() > prop_index) {
    // There is a driver/ID.
    r["driver"] = properties[prop_index];
  }

  results.push_back(r);
  CFRelease(details);
}
开发者ID:JessicaWhite17,项目名称:osquery,代码行数:47,代码来源:pci_devices.cpp


示例8: record_device

/*
 * Determine whether an IORegistryEntry refers to a valid
 * I/O device, and if so, record it.
 */
static int
record_device(io_registry_entry_t drive)
{
    io_registry_entry_t parent;
    CFDictionaryRef properties;
    CFStringRef name;
    CFNumberRef number;
    kern_return_t status;

    /* get drive's parent */
    status = IORegistryEntryGetParentEntry(drive,
                                           kIOServicePlane, &parent);
    if (status != KERN_SUCCESS)
        errx(1, "device has no parent");
    if (IOObjectConformsTo(parent, "IOBlockStorageDriver")) {
        drivestat[num_devices].driver = parent;

        /* get drive properties */
        status = IORegistryEntryCreateCFProperties(drive,
                 (CFMutableDictionaryRef *)&properties,
                 kCFAllocatorDefault,
                 kNilOptions);
        if (status != KERN_SUCCESS)
            errx(1, "device has no properties");

        /* get name from properties */
        name = (CFStringRef)CFDictionaryGetValue(properties,
                CFSTR(kIOBSDNameKey));
        CFStringGetCString(name, drivestat[num_devices].name,
                           MAXDRIVENAME, CFStringGetSystemEncoding());

        /* get blocksize from properties */
        number = (CFNumberRef)CFDictionaryGetValue(properties,
                 CFSTR(kIOMediaPreferredBlockSizeKey));
        CFNumberGetValue(number, kCFNumberSInt64Type,
                         &drivestat[num_devices].blocksize);

        /* clean up, return success */
        CFRelease(properties);
        num_devices++;
        return(0);
    }

    /* failed, don't keep parent */
    IOObjectRelease(parent);
    return(1);
}
开发者ID:PaxGordon,项目名称:SEDarwin,代码行数:51,代码来源:iostat.c


示例9: genFDEStatusForBSDName

void genFDEStatusForBSDName(const std::string& bsd_name,
                            const std::string& uuid,
                            QueryData& results) {

  auto matching_dict =
      IOBSDNameMatching(kIOMasterPortDefault, kNilOptions, bsd_name.c_str());
  if (matching_dict == nullptr) {
    return;
  }

  auto service =
      IOServiceGetMatchingService(kIOMasterPortDefault, matching_dict);
  if (!service) {
    return;
  }

  CFMutableDictionaryRef properties;
  if (IORegistryEntryCreateCFProperties(
          service, &properties, kCFAllocatorDefault, kNilOptions) !=
      KERN_SUCCESS) {
    IOObjectRelease(service);
    return;
  }

  Row r;
  r["name"] = kDeviceNamePrefix + bsd_name;
  r["uuid"] = uuid;

  auto encrypted = getIOKitProperty(properties, kCoreStorageIsEncryptedKey_);
  if (encrypted.empty()) {
    r["encrypted"] = "0";
  } else {
    r["encrypted"] = encrypted;
    id_t uid;
    uuid_string_t uuid_string = {0};
    if (genUid(uid, uuid_string).ok()) {
      r["uid"] = BIGINT(uid);
      r["user_uuid"] = TEXT(uuid_string);
    }
  }
  r["type"] = (r.at("encrypted") == "1") ? kEncryptionType : std::string();

  results.push_back(r);
  CFRelease(properties);
  IOObjectRelease(service);
}
开发者ID:1514louluo,项目名称:osquery,代码行数:46,代码来源:disk_encryption.cpp


示例10: idleTime

long idleTime() {
    long idlesecs;
#ifdef LINUX
    bool _idleDetectionPossible;
    XScreenSaverInfo *_mit_info;

    int event_base, error_base;
    if(XScreenSaverQueryExtension(QX11Info::display(), &event_base, &error_base))
        _idleDetectionPossible = true;
    else
        _idleDetectionPossible = false;
    _mit_info = XScreenSaverAllocInfo();

    XScreenSaverQueryInfo(QX11Info::display(), QX11Info::appRootWindow(), _mit_info);

    idlesecs = (_mit_info->idle/1000);

#endif
#ifdef WINDOWS

    LASTINPUTINFO lif;
    lif.cbSize = sizeof(LASTINPUTINFO);
    GetLastInputInfo(&lif);
    DWORD tickCount = GetTickCount();
    idlesecs = (tickCount - lif.dwTime) / 1000;

#endif
#ifdef MAC
    idlesecs = -1;//int64_t
    io_iterator_t iter = 0;
    if (IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem"), &iter) == KERN_SUCCESS) {
        io_registry_entry_t entry = IOIteratorNext(iter);
        if (entry) {
            CFMutableDictionaryRef dict = NULL;
            if (IORegistryEntryCreateCFProperties(entry, &dict, kCFAllocatorDefault, 0) == KERN_SUCCESS) {
                CFNumberRef obj = (CFNumberRef)CFDictionaryGetValue(dict, CFSTR("HIDIdleTime"));
                if (obj) {
                    int64_t nanoseconds = 0;
                    if (CFNumberGetValue(obj, kCFNumberSInt64Type, &nanoseconds)) {
                        idlesecs = (nanoseconds >> 30); // Divide by 10^9 to convert from nanoseconds to seconds.
                    }
                }
                CFRelease(dict);
            }
开发者ID:crossleyjuan,项目名称:djon,代码行数:44,代码来源:util.cpp


示例11: genPCIDevice

void genPCIDevice(const io_service_t& device, QueryData& results) {
  Row r;

  // Get the device details
  CFMutableDictionaryRef details;
  IORegistryEntryCreateCFProperties(
      device, &details, kCFAllocatorDefault, kNilOptions);

  r["pci_slot"] = getIOKitProperty(details, "pcidebug");

  auto compatible = getIOKitProperty(details, "compatible");
  auto properties = IOKitPCIProperties(compatible);
  r["vendor_id"] = properties.vendor_id;
  r["model_id"] = properties.model_id;
  r["pci_class"] = properties.pci_class;
  r["driver"] = properties.driver;

  results.push_back(r);
  CFRelease(details);
}
开发者ID:theopolis,项目名称:osquery,代码行数:20,代码来源:pci_devices.cpp


示例12: myIORegistryEntryCopyValue

CFDictionaryRef
myIORegistryEntryCopyValue(const char * path)
{
    io_registry_entry_t 	service;
    kern_return_t       	status;
    CFMutableDictionaryRef	properties = NULL;

    service = IORegistryEntryFromPath(kIOMasterPortDefault, path);
    if (service == MACH_PORT_NULL) {
	return (NULL);
    }
    status = IORegistryEntryCreateCFProperties(service,
					       &properties,
					       kCFAllocatorDefault,
					       kNilOptions);
    if (status != KERN_SUCCESS) {
	properties = NULL;
    }
    IOObjectRelease(service);
    return (properties);
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:21,代码来源:ioregpath.c


示例13: PrintSpeedForDisc

static IOReturn
PrintSpeedForDisc ( io_object_t opticalMedia )
{
	
	IOReturn				error 		= kIOReturnError;
	CFMutableDictionaryRef	properties 	= NULL;
	CFStringRef				bsdNode		= NULL;
	const char *			bsdName		= NULL;
	
	error = IORegistryEntryCreateCFProperties ( opticalMedia,
												&properties,
												kCFAllocatorDefault,
												kNilOptions );
	require ( ( error == kIOReturnSuccess ), ErrorExit );
	
	bsdNode = ( CFStringRef ) CFDictionaryGetValue ( properties, CFSTR ( kIOBSDNameKey ) );
	require ( ( bsdNode != NULL ), ReleaseProperties );
	
	bsdName = CFStringGetCStringPtr ( bsdNode, CFStringGetSystemEncoding ( ) );
	require ( ( bsdName != NULL ), ReleaseProperties );
	
	error = PrintSpeedForBSDNode ( bsdName );
	require ( ( error == kIOReturnSuccess ), ReleaseProperties );
	
	
ReleaseProperties:
	
	
	require_quiet ( ( properties != NULL ), ErrorExit );
	CFRelease ( properties );
	properties = NULL;
	
	
ErrorExit:
	
	
	return error;
	
}
开发者ID:unofficial-opensource-apple,项目名称:IOSCSIArchitectureModelFamily,代码行数:39,代码来源:OpticalMediaSpeed.c


示例14: genUSBDevice

void genUSBDevice(const io_service_t& device, QueryData& results) {
  Row r;

  // Get the device details
  CFMutableDictionaryRef details;
  IORegistryEntryCreateCFProperties(
      device, &details, kCFAllocatorDefault, kNilOptions);

  r["usb_address"] = getUSBProperty(details, "USB Address");
  r["usb_port"] = getUSBProperty(details, "PortNum");

  r["model"] = getUSBProperty(details, "USB Product Name");
  r["model_id"] = getUSBProperty(details, "idProduct");
  r["vendor"] = getUSBProperty(details, "USB Vendor Name");
  r["vendor_id"] = getUSBProperty(details, "idVendor");
  r["serial"] = getUSBProperty(details, "iSerialNumber");

  auto non_removable = getUSBProperty(details, "non-removable");
  r["removable"] = (non_removable == "yes") ? "0" : "1";

  results.push_back(r);
  CFRelease(details);
}
开发者ID:JessicaWhite17,项目名称:osquery,代码行数:23,代码来源:usb_devices.cpp


示例15: main

int main(int argc, char **argv)
{
    mach_port_t		   masterPort;
    io_registry_entry_t	   root;
    CFDictionaryRef        props;
    kern_return_t          status;

    // Obtain the I/O Kit communication handle.

    status = IOMasterPort(bootstrap_port, &masterPort);
    assert(status == KERN_SUCCESS);

    // Obtain the registry root entry.

    root = IORegistryGetRootEntry(masterPort);
    assert(root);

    status = IORegistryEntryCreateCFProperties(root,
			(CFTypeRef *) &props,
			kCFAllocatorDefault, kNilOptions );
    assert( KERN_SUCCESS == status );
    assert( CFDictionaryGetTypeID() == CFGetTypeID(props));

    props = (CFDictionaryRef)
		CFDictionaryGetValue( props, CFSTR(kIOKitDiagnosticsKey));
    assert( props );
    assert( CFDictionaryGetTypeID() == CFGetTypeID(props));

    printNumber(props, CFSTR("Instance allocation"));
    printNumber(props, CFSTR("Container allocation"));
    printNumber(props, CFSTR("IOMalloc allocation"));

    CFRelease(props);
    IOObjectRelease(root);

    exit(0);	
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:37,代码来源:alloccount.c


示例16: genUnlockIdent

Status genUnlockIdent(CFDataRef& uuid) {
  auto chosen =
      IORegistryEntryFromPath(kIOMasterPortDefault, kIODeviceTreeChosenPath_);
  if (chosen == MACH_PORT_NULL) {
    return Status(1, "Could not open IOKit DeviceTree");
  }

  CFMutableDictionaryRef properties = nullptr;
  auto kr = IORegistryEntryCreateCFProperties(
      chosen, &properties, kCFAllocatorDefault, kNilOptions);
  IOObjectRelease(chosen);

  if (kr != KERN_SUCCESS) {
    return Status(1, "Could not get IOKit chosen properties");
  }

  if (properties == nullptr) {
    return Status(1, "Could not load IOKit properties");
  }

  CFTypeRef unlock_ident = nullptr;
  if (CFDictionaryGetValueIfPresent(
          properties, CFSTR("efilogin-unlock-ident"), &unlock_ident)) {
    if (CFGetTypeID(unlock_ident) != CFDataGetTypeID()) {
      return Status(1, "Unexpected data type for unlock ident");
    }
    uuid = CFDataCreateCopy(kCFAllocatorDefault, (CFDataRef)unlock_ident);
    if (uuid == nullptr) {
      return Status(1, "Could not get UUID");
    }
    CFRelease(properties);
    return Status(0, "ok");
  }

  return Status(1, "Could not get unlock ident");
}
开发者ID:1514louluo,项目名称:osquery,代码行数:36,代码来源:disk_encryption.cpp


示例17: QString

/**
 * \brief List of CD/DVD devices
 *
 * On Unix, this returns a list of /dev nodes which can be open()d.
 * Darwin doesn't have fixed devices for removables/pluggables,
 * so this method is actually useless as it stands.
 * In the long term, this method should return both a name,
 * and an opaque type? (for the IOKit io_object_t)
 */
QStringList MediaMonitorDarwin::GetCDROMBlockDevices()
{
    kern_return_t          kernResult;
    CFMutableDictionaryRef devices;
    io_iterator_t          iter;
    QStringList            list;
    QString                msg = QString("GetCDRomBlockDevices() - ");


    devices = IOServiceMatching(kIOBlockStorageDeviceClass);
    if (!devices)
    {
        LOG(VB_GENERAL, LOG_ALERT, msg + "No Storage Devices? Unlikely!");
        return list;
    }

    // Create an iterator across all parents of the service object passed in.
    kernResult = IOServiceGetMatchingServices(sMasterPort, devices, &iter);

    if (KERN_SUCCESS != kernResult)
    {
        LOG(VB_GENERAL, LOG_ALERT, msg +
            QString("IORegistryEntryCreateIterator returned %1")
                .arg(kernResult));
        return list;
    }
    if (!iter)
    {
        LOG(VB_GENERAL, LOG_ALERT, msg +
            "IORegistryEntryCreateIterator returned a NULL iterator");
        return list;
    }

    io_object_t  drive;

    while ((drive = IOIteratorNext(iter)))
    {
        CFMutableDictionaryRef  p = NULL;  // properties of drive

        IORegistryEntryCreateCFProperties(drive, &p, kCFAllocatorDefault, 0);
        if (p)
        {
            const void  *type = CFDictionaryGetValue(p, CFSTR("device-type"));

            if (CFEqual(type, CFSTR("DVD")) || CFEqual(type, CFSTR("CD")))
            {
                QString  desc = getModel(drive);

                list.append(desc);
                LOG(VB_MEDIA, LOG_INFO, desc.prepend("Found CD/DVD: "));
                CFRelease(p);
            }
        }
        else
            LOG(VB_GENERAL, LOG_ALERT, 
                     msg + "Could not retrieve drive properties");

        IOObjectRelease(drive);
    }

    IOObjectRelease(iter);

    return list;
}
开发者ID:royboy626,项目名称:mythtv,代码行数:73,代码来源:mediamonitor-darwin.cpp


示例18: devstats

static void
devstats(int perf_select, long double etime, int havelast)
{
    CFNumberRef number;
    CFDictionaryRef properties;
    CFDictionaryRef statistics;
    long double transfers_per_second;
    long double kb_per_transfer, mb_per_second;
    u_int64_t value;
    u_int64_t total_bytes, total_transfers, total_blocks, total_time;
    u_int64_t interval_bytes, interval_transfers, interval_blocks;
    u_int64_t interval_time;
    long double interval_mb;
    long double blocks_per_second, ms_per_transaction;
    kern_return_t status;
    int i;

    for (i = 0; i < num_devices; i++) {

        /*
         * If the drive goes away, we may not get any properties
         * for it.  So take some defaults.
         */
        total_bytes = 0;
        total_transfers = 0;
        total_time = 0;

        /* get drive properties */
        status = IORegistryEntryCreateCFProperties(drivestat[i].driver,
                 (CFMutableDictionaryRef *)&properties,
                 kCFAllocatorDefault,
                 kNilOptions);
        if (status != KERN_SUCCESS)
            err(1, "device has no properties");

        /* get statistics from properties */
        statistics = (CFDictionaryRef)CFDictionaryGetValue(properties,
                     CFSTR(kIOBlockStorageDriverStatisticsKey));
        if (statistics) {

            /*
             * Get I/O volume.
             */
            if ((number = (CFNumberRef)CFDictionaryGetValue(statistics,
                          CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey)))) {
                CFNumberGetValue(number, kCFNumberSInt64Type, &value);
                total_bytes += value;
            }
            if ((number = (CFNumberRef)CFDictionaryGetValue(statistics,
                          CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey)))) {
                CFNumberGetValue(number, kCFNumberSInt64Type, &value);
                total_bytes += value;
            }

            /*
             * Get I/O counts.
             */
            if ((number = (CFNumberRef)CFDictionaryGetValue(statistics,
                          CFSTR(kIOBlockStorageDriverStatisticsReadsKey)))) {
                CFNumberGetValue(number, kCFNumberSInt64Type, &value);
                total_transfers += value;
            }
            if ((number = (CFNumberRef)CFDictionaryGetValue(statistics,
                          CFSTR(kIOBlockStorageDriverStatisticsWritesKey)))) {
                CFNumberGetValue(number, kCFNumberSInt64Type, &value);
                total_transfers += value;
            }

            /*
             * Get I/O time.
             */
            if ((number = (CFNumberRef)CFDictionaryGetValue(statistics,
                          CFSTR(kIOBlockStorageDriverStatisticsLatentReadTimeKey)))) {
                CFNumberGetValue(number, kCFNumberSInt64Type, &value);
                total_time += value;
            }
            if ((number = (CFNumberRef)CFDictionaryGetValue(statistics,
                          CFSTR(kIOBlockStorageDriverStatisticsLatentWriteTimeKey)))) {
                CFNumberGetValue(number, kCFNumberSInt64Type, &value);
                total_time += value;
            }

        }
        CFRelease(properties);

        /*
         * Compute delta values and stats.
         */
        interval_bytes = total_bytes - drivestat[i].total_bytes;
        interval_transfers = total_transfers
                             - drivestat[i].total_transfers;
        interval_time = total_time - drivestat[i].total_time;

        /* update running totals, only once for -I */
        if ((Iflag == 0) || (drivestat[i].total_bytes == 0)) {
            drivestat[i].total_bytes = total_bytes;
            drivestat[i].total_transfers = total_transfers;
            drivestat[i].total_time = total_time;
        }

//.........这里部分代码省略.........
开发者ID:PaxGordon,项目名称:SEDarwin,代码行数:101,代码来源:iostat.c


示例19: get_via_generic_iokit

static void get_via_generic_iokit (double *ret_charge, /* {{{ */
		double *ret_current,
		double *ret_voltage)
{
	kern_return_t   status;
	io_iterator_t   iterator;
	io_object_t     io_obj;

	CFDictionaryRef bat_root_dict;
	CFArrayRef      bat_info_arry;
	CFIndex         bat_info_arry_len;
	CFIndex         bat_info_arry_pos;
	CFDictionaryRef bat_info_dict;

	double temp_double;

	status = IOServiceGetMatchingServices (kIOMasterPortDefault,
			IOServiceNameMatching ("battery"),
			&iterator);
	if (status != kIOReturnSuccess)
	{
		DEBUG ("IOServiceGetMatchingServices failed.");
		return;
	}

	while ((io_obj = IOIteratorNext (iterator)))
	{
		status = IORegistryEntryCreateCFProperties (io_obj,
				(CFMutableDictionaryRef *) &bat_root_dict,
				kCFAllocatorDefault,
				kNilOptions);
		if (status != kIOReturnSuccess)
		{
			DEBUG ("IORegistryEntryCreateCFProperties failed.");
			continue;
		}

		bat_info_arry = (CFArrayRef) CFDictionaryGetValue (bat_root_dict,
				CFSTR ("IOBatteryInfo"));
		if (bat_info_arry == NULL)
		{
			CFRelease (bat_root_dict);
			continue;
		}
		bat_info_arry_len = CFArrayGetCount (bat_info_arry);

		for (bat_info_arry_pos = 0;
				bat_info_arry_pos < bat_info_arry_len;
				bat_info_arry_pos++)
		{
			bat_info_dict = (CFDictionaryRef) CFArrayGetValueAtIndex (bat_info_arry, bat_info_arry_pos);

			if (*ret_charge == INVALID_VALUE)
			{
				temp_double = dict_get_double (bat_info_dict,
						"Capacity");
				if (temp_double != INVALID_VALUE)
					*ret_charge = temp_double / 1000.0;
			}

			if (*ret_current == INVALID_VALUE)
			{
				temp_double = dict_get_double (bat_info_dict,
						"Current");
				if (temp_double != INVALID_VALUE)
					*ret_current = temp_double / 1000.0;
			}

			if (*ret_voltage == INVALID_VALUE)
			{
				temp_double = dict_get_double (bat_info_dict,
						"Voltage");
				if (temp_double != INVALID_VALUE)
					*ret_voltage = temp_double / 1000.0;
			}
		}
		
		CFRelease (bat_root_dict);
	}

	IOObjectRelease (iterator);
} /* }}} void get_via_generic_iokit */
开发者ID:Civil,项目名称:collectd,代码行数:82,代码来源:battery.c


示例20: msg_Err

/****************************************************************************
 * darwin_getTOC: get the TOC
 ****************************************************************************/
static CDTOC *darwin_getTOC( vlc_object_t * p_this, const vcddev_t *p_vcddev )
{
    mach_port_t port;
    char *psz_devname;
    kern_return_t ret;
    CDTOC *pTOC = NULL;
    io_iterator_t iterator;
    io_registry_entry_t service;
    CFMutableDictionaryRef properties;
    CFDataRef data;

    /* get the device name */
    if( ( psz_devname = strrchr( p_vcddev->psz_dev, '/') ) != NULL )
        ++psz_devname;
    else
        psz_devname = p_vcddev->psz_dev;

    /* unraw the device name */
    if( *psz_devname == 'r' )
        ++psz_devname;

    /* get port for IOKit communication */
    if( ( ret = IOMasterPort( MACH_PORT_NULL, &port ) ) != KERN_SUCCESS )
    {
        msg_Err( p_this, "IOMasterPort: 0x%08x", ret );
        return( NULL );
    }

    /* get service iterator for the device */
    if( ( ret = IOServiceGetMatchingServices(
                    port, IOBSDNameMatching( port, 0, psz_devname ),
                    &iterator ) ) != KERN_SUCCESS )
    {
        msg_Err( p_this, "IOServiceGetMatchingServices: 0x%08x", ret );
        return( NULL );
    }

    /* first service */
    service = IOIteratorNext( iterator );
    IOObjectRelease( iterator );

    /* search for kIOCDMediaClass */
    while( service && !IOObjectConformsTo( service, kIOCDMediaClass ) )
    {
        if( ( ret = IORegistryEntryGetParentIterator( service,
                        kIOServicePlane, &iterator ) ) != KERN_SUCCESS )
        {
            msg_Err( p_this, "IORegistryEntryGetParentIterator: 0x%08x", ret );
            IOObjectRelease( service );
            return( NULL );
        }

        IOObjectRelease( service );
        service = IOIteratorNext( iterator );
        IOObjectRelease( iterator );
    }

    if( !service )
    {
        msg_Err( p_this, "search for kIOCDMediaClass came up empty" );
        return( NULL );
    }

    /* create a CF dictionary containing the TOC */
    if( ( ret = IORegistryEntryCreateCFProperties( service, &properties,
                    kCFAllocatorDefault, kNilOptions ) ) != KERN_SUCCESS )
    {
        msg_Err( p_this, "IORegistryEntryCreateCFProperties: 0x%08x", ret );
        IOObjectRelease( service );
        return( NULL );
    }

    /* get the TOC from the dictionary */
    if( ( data = (CFDataRef) CFDictionaryGetValue( properties,
                                    CFSTR(kIOCDMediaTOCKey) ) ) != NULL )
    {
        CFRange range;
        CFIndex buf_len;

        buf_len = CFDataGetLength( data ) + 1;
        range = CFRangeMake( 0, buf_len );

        if( ( pTOC = malloc( buf_len ) ) != NULL )
        {
            CFDataGetBytes( data, range, (u_char *)pTOC );
        }
    }
    else
    {
        msg_Err( p_this, "CFDictionaryGetValue failed" );
    }

    CFRelease( properties );
    IOObjectRelease( service );

    return( pTOC );
}
开发者ID:Geal,项目名称:vlc,代码行数:100,代码来源:cdrom.c



注:本文中的IORegistryEntryCreateCFProperties函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ IOSYMBOL函数代码示例发布时间:2022-05-30
下一篇:
C++ IOREF函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap