本文整理汇总了C++中OSString类的典型用法代码示例。如果您正苦于以下问题:C++ OSString类的具体用法?C++ OSString怎么用?C++ OSString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OSString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: secureSleepSystemOptions
IOReturn RootDomainUserClient::secureSleepSystemOptions(
const void *inOptions,
IOByteCount inOptionsSize,
uint32_t *returnCode)
{
int local_priv = 0;
int admin_priv = 0;
IOReturn ret = kIOReturnNotPrivileged;
OSDictionary *unserializedOptions = NULL;
OSString *unserializeErrorString = NULL;
ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
local_priv = (kIOReturnSuccess == ret);
ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
admin_priv = (kIOReturnSuccess == ret);
if (inOptions)
{
unserializedOptions = OSDynamicCast( OSDictionary,
OSUnserializeXML((const char *)inOptions, inOptionsSize, &unserializeErrorString));
if (!unserializedOptions) {
IOLog("IOPMRootDomain SleepSystem unserialization failure: %s\n",
unserializeErrorString ? unserializeErrorString->getCStringNoCopy() : "Unknown");
}
}
if ( (local_priv || admin_priv) && fOwner )
{
proc_t p;
p = (proc_t)get_bsdtask_info(fOwningTask);
if (p) {
fOwner->setProperty("SleepRequestedByPID", proc_pid(p), 32);
}
if (unserializedOptions)
{
// Publish Sleep Options in registry under root_domain
fOwner->setProperty( kRootDomainSleepOptionsKey, unserializedOptions);
*returnCode = fOwner->sleepSystemOptions( unserializedOptions );
unserializedOptions->release();
} else {
// No options
// Clear any pre-existing options
fOwner->removeProperty( kRootDomainSleepOptionsKey );
*returnCode = fOwner->sleepSystemOptions( NULL );
}
} else {
*returnCode = kIOReturnNotPrivileged;
}
return kIOReturnSuccess;
}
示例2: OSDynamicCast
FakeSMCSensor *FakeSMCPlugin::addSensor(OSObject *node, kFakeSMCCategory category, UInt32 group, UInt32 index)
{
SYNCLOCK;
FakeSMCSensor *sensor = NULL;
if (node) {
float reference = 0, gain = 0, offset = 0;
OSString *abbriviation = NULL;
if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, node)) {
if ((abbriviation = OSDynamicCast(OSString, dictionary->getObject("name")))) {
FakeSMCSensor::parseModifiers(dictionary, &reference, &gain, &offset);
}
}
else abbriviation = OSDynamicCast(OSString, node);
if (abbriviation)
sensor = addSensor(abbriviation->getCStringNoCopy(), category, group, index, reference, gain, offset);
}
SYNCUNLOCK;
return sensor;
}
示例3: snprintf
bool
IOFWUserAsyncStreamListener::serialize(OSSerialize *s) const
{
if (s->previouslySerialized(this))
return true ;
char temp[256] ;
if ( fFlags )
{
snprintf(temp+strlen(temp), sizeof(temp), ", flags:") ;
}
else
{
snprintf(temp+strlen(temp), sizeof(temp), ", no flags") ;
}
OSString* string = OSString::withCString(temp) ;
if (!string)
return false ;
bool result = string->serialize(s) ;
string->release() ;
return result ;
}
示例4: addString
bool OSSerialize::previouslySerialized(const OSMetaClassBase *o)
{
char temp[16];
OSString *tagString;
if (binary) return (binarySerialize(o));
// look it up
tagString = (OSString *)tags->getObject((const OSSymbol *) o);
// xx-review: no error checking here for addString calls!
// does it exist?
if (tagString) {
addString("<reference IDREF=\"");
addString(tagString->getCStringNoCopy());
addString("\"/>");
return true;
}
// build a tag
snprintf(temp, sizeof(temp), "%u", tag++);
tagString = OSString::withCString(temp);
// add to tag dictionary
tags->setObject((const OSSymbol *) o, tagString);// XXX check return
tagString->release();
return false;
}
示例5: OSDynamicCast
void SuperIO::LoadConfiguration(IOService* provider) {
m_Service = provider;
OSBoolean* fanControl = OSDynamicCast(OSBoolean, provider->getProperty("Enable Fan Control"));
m_FanControl = fanControl->getValue();
OSBoolean* alternateRegisters = OSDynamicCast(OSBoolean, provider->getProperty("Register number alternative variant"));
m_AlternateRegisters = alternateRegisters->getValue();
OSArray* fanIDs = OSDynamicCast(OSArray, provider->getProperty("Fan Names"));
if (fanIDs) fanIDs = OSArray::withArray(fanIDs);
if (fanIDs) {
UInt32 count = fanIDs->getCount();
if(count > 5)
count = 5;
for (UInt32 i = 0; i < count; i++) {
OSString* name = OSDynamicCast(OSString, fanIDs->getObject(i));
FanName[i] = name->getCStringNoCopy();
}
fanIDs->release();
}
}
示例6: while
UInt32 FakeSMCKeyStore::addKeysFromDictionary(OSDictionary* dictionary)
{
UInt32 keysAdded = 0;
if (dictionary) {
if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) {
while (const OSSymbol *key = (const OSSymbol *)iterator->getNextObject()) {
if (OSArray *array = OSDynamicCast(OSArray, dictionary->getObject(key))) {
if (OSIterator *aiterator = OSCollectionIterator::withCollection(array)) {
OSString *type = OSDynamicCast(OSString, aiterator->getNextObject());
OSData *value = OSDynamicCast(OSData, aiterator->getNextObject());
if (type && value) {
addKeyWithValue(key->getCStringNoCopy(), type->getCStringNoCopy(), value->getLength(), value->getBytesNoCopy());
keysAdded++;
}
OSSafeRelease(aiterator);
}
}
key = 0;
}
OSSafeRelease(iterator);
}
}
return keysAdded;
}
示例7: OSDynamicCast
OSObject* FileNVRAM::cast(const OSSymbol* key, OSObject* obj)
{
const char* legacy[] = {
"boot-args",
"boot-script",
};
OSString* str = OSDynamicCast(OSString, key);
if (str)
{
for (int i = 0; i < sizeof(legacy)/sizeof(char*); i++)
{
if (str->isEqualTo(legacy[i]))
{
LOG(NOTICE, "Found legacy key %s\n", str->getCStringNoCopy());
// add null char, convert to OSString
OSData* data = OSDynamicCast(OSData, obj);
if (data)
{
data->appendByte(0x00, 1);
return OSString::withCString((const char*)data->getBytesNoCopy());
}
}
}
}
return obj;
}
示例8: bzero
OSString * ACPIBacklightPanel::getACPIPath(IOACPIPlatformDevice * acpiDevice)
{
OSString * separator = OSString::withCStringNoCopy(".");
OSArray * array = OSArray::withCapacity(10);
char devicePath[512];
bzero(devicePath, sizeof(devicePath));
IOACPIPlatformDevice * parent = acpiDevice;
IORegistryIterator * iter = IORegistryIterator::iterateOver(acpiDevice, gIOACPIPlane, kIORegistryIterateParents | kIORegistryIterateRecursively);
if (iter)
{
do {
array->setObject(parent->copyName(gIOACPIPlane));
array->setObject(separator);
parent = OSDynamicCast(IOACPIPlatformDevice, iter->getNextObject());
} while (parent);
iter->release();
int offset = 0;
OSString * str = OSDynamicCast(OSString, array->getLastObject());
for (int i = array->getCount()-2; ((i>=0) || ((offset + str->getLength()) > sizeof(devicePath))) ; i--)
{
str = OSDynamicCast(OSString, array->getObject(i));
strncpy(devicePath + offset, str->getCStringNoCopy(), str->getLength());
offset += str->getLength();
}
}
return OSString::withCString(devicePath);
}
示例9: willReadSensorValue
bool ACPISensors::willReadSensorValue(FakeSMCSensor *sensor, float *outValue)
{
UInt32 value = 0;
OSString *method = NULL;
if (sensor->getIndex() < methods->getCount() && (method = (OSString*)methods->getObject(sensor->getIndex()))) {
if (kIOReturnSuccess == acpiDevice->evaluateInteger(method->getCStringNoCopy(), &value)) {
switch(sensor->getGroup()) {
case kFakeSMCTemperatureSensor:
// all temperatures returned from ACPI should be in Kelvins?
if (useKelvins)
*outValue = ((float)value - (float)0xAAC) / (float)0xA;
else
*outValue = (float)value;
break;
case kFakeSMCVoltageSensor:
case kFakeSMCCurrentSensor:
case kFakeSMCPowerSensor:
// all voltages returned from ACPI should be in millivolts?
*outValue = (float)value * 0.001f;
break;
case kFakeSMCTachometerSensor:
default:
*outValue = (float)value;
break;
}
}
else return false;
}
else return false;
return true;
}
示例10: OSDynamicCast
bool FakeSMC::start(IOService *provider)
{
if (!super::start(provider))
return false;
OSString *vendor = OSDynamicCast(OSString, getProperty(kFakeSMCFirmwareVendor));
int arg_value = 1;
if (PE_parse_boot_argn("-fakesmc-force-start", &arg_value, sizeof(arg_value))) {
HWSensorsInfoLog("firmware vendor check disabled");
}
else if (vendor && vendor->isEqualTo("Apple")) {
HWSensorsFatalLog("forbidding start on Apple hardware");
return false;
}
if (!smcDevice->initAndStart(provider, this)) {
HWSensorsInfoLog("failed to initialize SMC device");
return false;
}
registerService();
// Load keys from NVRAM
if (PE_parse_boot_argn("-fakesmc-use-nvram", &arg_value, sizeof(arg_value))) {
if (UInt32 count = smcDevice->loadKeysFromNVRAM())
HWSensorsInfoLog("%d key%s loaded from NVRAM", count, count == 1 ? "" : "s");
else
HWSensorsInfoLog("NVRAM will be used to store system written keys...");
}
return true;
}
示例11: LOG
bool FileNVRAM::setProperty(const OSSymbol *aKey, OSObject *anObject)
{
// Verify permissions.
if (IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator) != kIOReturnSuccess)
{
// Not priveleged!
return false;
}
// Check for SIP configuration variables.
if ((strncmp("csr-data", aKey->getCStringNoCopy(), 8) == 0) || (strncmp("csr-active-config", aKey->getCStringNoCopy(), 17) == 0))
{
// We have a match so first verify the entitlements.
if (IOUserClient::copyClientEntitlement(current_task(), "com.apple.private.iokit.nvram-csr") == NULL)
{
LOG(INFO, "setProperty(%s, (%s) %p) failed (not entitled)\n", aKey->getCStringNoCopy(), anObject->getMetaClass()->getClassName(), anObject);
// Not entitled!
return false;
}
}
OSSerialize *s = OSSerialize::withCapacity(1000);
if (anObject->serialize(s))
{
LOG(INFO, "setProperty(%s, (%s) %s) called\n", aKey->getCStringNoCopy(), anObject->getMetaClass()->getClassName(), s->text());
}
else
{
LOG(INFO, "setProperty(%s, (%s) %p) called\n", aKey->getCStringNoCopy(), anObject->getMetaClass()->getClassName(), anObject);
}
s->release();
// Check for special FileNVRAM properties:
if (strncmp(FILE_NVRAM_GUID ":", aKey->getCStringNoCopy(), MIN(aKey->getLength(), strlen(FILE_NVRAM_GUID ":"))) == 0)
{
unsigned long bytes = aKey->getLength() - strlen(FILE_NVRAM_GUID ":") + 1;
// Found GUID
char* newKey = (char*)IOMalloc(bytes);
snprintf(newKey, bytes+1, "%s", &(aKey->getCStringNoCopy()[strlen(FILE_NVRAM_GUID ":")]));
// Send d
OSString* str = OSString::withCString(newKey);
handleSetting(str, anObject, this);
str->release();
IOFree(newKey, bytes);
}
bool stat = IOService::setProperty(aKey, cast(aKey, anObject));
if (mInitComplete)
{
sync();
}
return stat;
}
示例12: OSDynamicCast
void IOPlatformExpert::registerNVRAMController(IONVRAMController * caller)
{
OSData * data;
IORegistryEntry * entry;
OSString * string = 0;
uuid_string_t uuid;
entry = IORegistryEntry::fromPath( "/efi/platform", gIODTPlane );
if ( entry )
{
data = OSDynamicCast( OSData, entry->getProperty( "system-id" ) );
if ( data && data->getLength( ) == 16 )
{
SHA1_CTX context;
uint8_t digest[ SHA_DIGEST_LENGTH ];
const uuid_t space = { 0x2A, 0x06, 0x19, 0x90, 0xD3, 0x8D, 0x44, 0x40, 0xA1, 0x39, 0xC4, 0x97, 0x70, 0x37, 0x65, 0xAC };
SHA1Init( &context );
SHA1Update( &context, space, sizeof( space ) );
SHA1Update( &context, data->getBytesNoCopy( ), data->getLength( ) );
SHA1Final( digest, &context );
digest[ 6 ] = ( digest[ 6 ] & 0x0F ) | 0x50;
digest[ 8 ] = ( digest[ 8 ] & 0x3F ) | 0x80;
uuid_unparse( digest, uuid );
string = OSString::withCString( uuid );
}
entry->release( );
}
if ( string == 0 )
{
entry = IORegistryEntry::fromPath( "/options", gIODTPlane );
if ( entry )
{
data = OSDynamicCast( OSData, entry->getProperty( "platform-uuid" ) );
if ( data && data->getLength( ) == sizeof( uuid_t ) )
{
uuid_unparse( ( uint8_t * ) data->getBytesNoCopy( ), uuid );
string = OSString::withCString( uuid );
}
entry->release( );
}
}
if ( string )
{
getProvider( )->setProperty( kIOPlatformUUIDKey, string );
publishResource( kIOPlatformUUIDKey, string );
string->release( );
}
publishResource("IONVRAM");
}
示例13: IOLog
bool net_lundman_zfs_zvol::start (IOService *provider)
{
bool res = super::start(provider);
IOLog("ZFS: Loading module ... \n");
/*
* Initialize /dev/zfs, this calls spa_init->dmu_init->arc_init-> etc
*/
zfs_ioctl_osx_init();
///sysctl_register_oid(&sysctl__debug_maczfs);
//sysctl_register_oid(&sysctl__debug_maczfs_stalk);
zfs_vfsops_init();
/*
* When is the best time to start the system_taskq? It is strictly
* speaking not used by SPL, but by ZFS. ZFS should really start it?
*/
system_taskq_init();
/*
* hostid is left as 0 on OSX, and left to be set if developers wish to
* use it. If it is 0, we will hash the hardware.uuid into a 32 bit
* value and set the hostid.
*/
if (!zone_get_hostid(NULL)) {
uint32_t myhostid = 0;
IORegistryEntry *ioregroot = IORegistryEntry::getRegistryRoot();
if(ioregroot) {
//IOLog("ioregroot is '%s'\n", ioregroot->getName(gIOServicePlane));
IORegistryEntry *macmodel = ioregroot->getChildEntry(gIOServicePlane);
if(macmodel) {
//IOLog("macmodel is '%s'\n", macmodel->getName(gIOServicePlane));
OSObject *ioplatformuuidobj;
//ioplatformuuidobj = ioregroot->getProperty("IOPlatformUUID", gIOServicePlane, kIORegistryIterateRecursively);
ioplatformuuidobj = macmodel->getProperty(kIOPlatformUUIDKey);
if(ioplatformuuidobj) {
OSString *ioplatformuuidstr = OSDynamicCast(OSString, ioplatformuuidobj);
//IOLog("IOPlatformUUID is '%s'\n", ioplatformuuidstr->getCStringNoCopy());
myhostid = fnv_32a_str(ioplatformuuidstr->getCStringNoCopy(),
FNV1_32A_INIT);
sysctlbyname("kern.hostid", NULL, NULL, &myhostid, sizeof(myhostid));
printf("ZFS: hostid set to %08x from UUID '%s'\n",
myhostid, ioplatformuuidstr->getCStringNoCopy());
}
}
}
}
return res;
}
示例14: setProperty
bool IOPlatformExpert::start( IOService * provider )
{
IORangeAllocator * physicalRanges;
OSData * busFrequency;
if (!super::start(provider))
return false;
// Register the presence or lack thereof a system
// PCI address mapper with the IOMapper class
#if 1
IORegistryEntry * regEntry = IORegistryEntry::fromPath("/u3/dart", gIODTPlane);
if (!regEntry)
regEntry = IORegistryEntry::fromPath("/dart", gIODTPlane);
if (regEntry) {
int debugFlags;
if (!PE_parse_boot_arg("dart", &debugFlags) || debugFlags)
setProperty(kIOPlatformMapperPresentKey, kOSBooleanTrue);
regEntry->release();
}
#endif
IOMapper::setMapperRequired(0 != getProperty(kIOPlatformMapperPresentKey));
gIOInterruptControllers = OSDictionary::withCapacity(1);
gIOInterruptControllersLock = IOLockAlloc();
// Correct the bus frequency in the device tree.
busFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.bus_clock_rate_hz, 4);
provider->setProperty("clock-frequency", busFrequency);
busFrequency->release();
gPlatformInterruptControllerName = (OSSymbol *)OSSymbol::withCStringNoCopy("IOPlatformInterruptController");
physicalRanges = IORangeAllocator::withRange(0xffffffff, 1, 16,
IORangeAllocator::kLocking);
assert(physicalRanges);
setProperty("Platform Memory Ranges", physicalRanges);
setPlatform( this );
gIOPlatform = this;
PMInstantiatePowerDomains();
// Parse the serial-number data and publish a user-readable string
OSData* mydata = (OSData*) (provider->getProperty("serial-number"));
if (mydata != NULL) {
OSString *serNoString = createSystemSerialNumberString(mydata);
if (serNoString != NULL) {
provider->setProperty(kIOPlatformSerialNumberKey, serNoString);
serNoString->release();
}
}
return( configure(provider) );
}
示例15: setStringInDict
static void setStringInDict(OSDictionary* dict, const char* key, const char* value)
{
OSString* str = OSString::withCStringNoCopy(value);
if (str)
{
dict->setObject(key, str);
str->release();
}
}