/*! Copies the given object with its type and properties @param obj the object to copy @return the new, duplicate object */ tap_obj* copyObject (tap_obj* obj) { property* props = copyProperty(obj->props); property* cprop = props->next; while (cprop != NULL) { cprop = copyProperty(cprop); cprop = cprop->next; } return newObject(obj->type, props); }
bool IOUSBNub::USBCompareProperty( OSDictionary * matching, const OSSymbol * key ) { // We return success iff we match the key in the dictionary with the key in // the property table. // OSObject *value; bool matches = false; OSObject *myProperty = NULL; value = matching->getObject( key ); if ( value) { myProperty = copyProperty(key); if (myProperty) { matches = value->isEqualTo( myProperty); myProperty->release(); } } else matches = false; return matches; }
bool ACPIBacklightPanel::doUpdate( void ) { DbgLog("enter %s::%s()\n", this->getName(),__FUNCTION__); bool result = false; OSDictionary* newDict = 0; OSDictionary* allParams = OSDynamicCast(OSDictionary, _display->copyProperty(gIODisplayParametersKey)); if (allParams) { newDict = OSDictionary::withDictionary(allParams); allParams->release(); } OSDictionary* backlightParams = OSDictionary::withCapacity(2); ////OSDictionary* linearParams = OSDictionary::withCapacity(2); //REVIEW_REHABMAN: myParams is not used... OSDictionary* myParams = OSDynamicCast(OSDictionary, copyProperty(gIODisplayParametersKey)); if (/*linearParams && */backlightParams && myParams) { //DbgLog("%s: ACPILevel min %d, max %d, value %d\n", this->getName(), min, max, _value); IODisplay::addParameter(backlightParams, gIODisplayBrightnessKey, kBacklightLevelMin, kBacklightLevelMax); IODisplay::setParameter(backlightParams, gIODisplayBrightnessKey, _committed_value); ////IODisplay::addParameter(linearParams, gIODisplayLinearBrightnessKey, 0, 0x710); ////IODisplay::setParameter(linearParams, gIODisplayLinearBrightnessKey, ((_index-min) * 0x710 + (max-min)/2) / (max-min)); OSNumber * num = OSNumber::withNumber(0ULL, 32); OSDictionary * commitParams = OSDictionary::withCapacity(1); commitParams->setObject("reg", num); backlightParams->setObject(gIODisplayParametersCommitKey, commitParams); num->release(); commitParams->release(); if (newDict) { newDict->merge(backlightParams); ////newDict->merge(linearParams); _display->setProperty(gIODisplayParametersKey, newDict); newDict->release(); } else _display->setProperty(gIODisplayParametersKey, backlightParams); //refresh properties here too setProperty(gIODisplayParametersKey, backlightParams); backlightParams->release(); myParams->release(); ////linearParams->release(); result = true; } DbgLog("exit %s::%s()\n", this->getName(),__FUNCTION__); return result; }
void DataUtility::cloneData(DataPtr _target, DataPtr _prototype) { MYGUI_ASSERT(_target != _prototype, "Error clone self"); MYGUI_ASSERT(_target->getType() == _prototype->getType(), "Error clone different types"); MYGUI_ASSERT(_target->getChilds().size() == 0, "Target not empty"); copyProperty(_target, _prototype); for (Data::VectorData::const_iterator child = _prototype->getChilds().begin(); child != _prototype->getChilds().end(); child ++) { DataPtr data = Data::CreateInstance(); data->setType((*child)->getType()); _target->addChild(data); cloneData(data, *child); } }
void Mpris2Player::updateFromMap(const QVariantMap &map) { QMap<QString, QVariant>::const_iterator i = map.constBegin(); while (i != map.constEnd()) { // Properties QVariant::Type type = propertyType(i.key()); if (type != QVariant::Invalid) copyProperty(i.key(), i.value(), type); // Capabilities Capability capability = capabilityFromName(i.key()); if (capability != NoCapabilities) { if (i.value().type() == QVariant::Bool) { if (i.value().toBool()) m_capabilities |= capability; else m_capabilities &= ~capability; } else { const char *gotTypeCh = QDBusMetaType::typeToSignature(i.value().userType()); QString gotType = gotTypeCh ? QString::fromUtf8(gotTypeCh) : QStringLiteral("<unknown>"); qCWarning(MPRIS2_PLAYER) << m_serviceName << "exports" << i.key() << "as D-Bus type" << gotType << "but it should be D-Bus type \"b\""; } } // Fake the CanStop capability if (capability == CanControl || i.key() == QStringLiteral("PlaybackStatus")) { if ((m_capabilities & CanControl) && i.value().toString() != QStringLiteral("Stopped")) { qCDebug(MPRIS2_PLAYER) << "Enabling stop capability"; m_capabilities |= CanStop; } else { qCDebug(MPRIS2_PLAYER) << "Disabling stop capability"; m_capabilities &= ~CanStop; } } ++i; } }
IOReturn com_evoluent_driver_VerticalMouse::StartFinalProcessing() { OSNumber *curResPtr, *resPrefPtr; UInt32 curResInt, resPrefInt; IOFixed curRes, resPref; IOReturn err = kIOReturnSuccess; OSBoolean * boolObj; OSObject * propertyObj = NULL; USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing", this); _switchBackOnRestart = FALSE; propertyObj = copyProperty("SwitchTo800DPI"); boolObj = OSDynamicCast( OSBoolean, propertyObj ); if ( boolObj && boolObj->isTrue() ) { // USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - found switchTo800DPI resolution property", this); _switchTo800dpiFlag = true; } if (propertyObj) propertyObj->release(); propertyObj = copyProperty("SwitchTo2000FPS"); boolObj = OSDynamicCast( OSBoolean, propertyObj ); if ( boolObj && boolObj->isTrue() ) { // USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - found switchTo2000fps resolution property", this); _switchTo2000fpsFlag = true; } if (propertyObj) propertyObj->release(); if ( _switchTo2000fpsFlag ) { IOUSBDevRequest devReq; // Write the 2000 FPS value to the mouse // devReq.bmRequestType = 0x40; devReq.bRequest = 0x01; devReq.wValue = 0x05AC; devReq.wIndex = 0xd810; devReq.wLength = 0x0000; devReq.pData = NULL; err = _device->DeviceRequest(&devReq, 5000, 0); if (err) { USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - sending 1st part of FPS change received error 0x%x", this, err); } else { devReq.bmRequestType = 0x40; devReq.bRequest = 0x01; devReq.wValue = 0x05AC; devReq.wIndex = 0xdc11; devReq.wLength = 0x0000; devReq.pData = NULL; err = _device->DeviceRequest(&devReq, 5000, 0); if (err) { USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - sending 2nd part of FPS change received error 0x%x", this, err); } } #if FORMOUSETESTING UInt8 hi,lo; UInt16 fps; // Read back the value: // devReq.bmRequestType = 0xc0; devReq.bRequest = 0x01; devReq.wValue = 0x05AC; devReq.wIndex = 0x0011; devReq.wLength = 1; devReq.pData = &hi; err = _device->DeviceRequest(&devReq, 5000, 0); if (err) USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - error reading hi byte: 0x%x", this, err); devReq.bmRequestType = 0xc0; devReq.bRequest = 0x01; devReq.wValue = 0x05AC; devReq.wIndex = 0x0010; devReq.wLength = 1; devReq.pData = &lo; err = _device->DeviceRequest(&devReq, 5000, 0); if (err) USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - read reading lo byte: 0x%x", this, err); fps = hi; fps = (fps << 8) | lo; USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - read : 0x%x", this, fps ); #endif err = super::StartFinalProcessing(); if (err) { USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - super returned error 0x%x", this, err); } } if ( _switchTo800dpiFlag ) { propertyObj = copyProperty(kIOHIDPointerResolutionKey); curResPtr = OSDynamicCast( OSNumber, propertyObj ); if (curResPtr) { curResInt = curResPtr->unsigned32BitValue(); USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - found current resolution property - value 0x%lx", this, curResInt); } else { curResInt = kDefaultFixedResolution; USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - no current property found - using default 0x%lx", this, curResInt); } if (propertyObj) propertyObj->release(); propertyObj = copyProperty(("xResolutionPref")); resPrefPtr = OSDynamicCast( OSNumber, propertyObj ); if (resPrefPtr) resPrefInt = resPrefPtr->unsigned32BitValue(); else { resPrefInt = kDefaultFixedResolution * 2; USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - no preference property found - using default 0x%lx", this, resPrefInt); } if (propertyObj) propertyObj->release(); resPref = (IOFixed) resPrefInt; curRes = (IOFixed) curResInt; if (resPref != curRes) { if (switchTo800dpi) { IOUSBDevRequest devReq; devReq.bmRequestType = 0x40; devReq.bRequest = 0x01; devReq.wValue = 0x05AC; devReq.wIndex = 0x0452; devReq.wLength = 0x0000; devReq.pData = NULL; err = _device->DeviceRequest(&devReq, 5000, 0); if (err) { USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - error (%x) setting resolution", this, err); } else { // with this mouse, we do NOT want to start reading on the interrupt pipe, nor do // we want to call super::start. We just want to wait for the device to get terminated USBLog(3, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - waiting for click mouse termination", this); } } } else { // If we are already at the correct resolution for OSX, OK. But what if we are going // back to OS 9? On restart, switch back to boot setup. Power Manager will tell us // when we are going to restart. // _switchBackOnRestart = TRUE; err = super::StartFinalProcessing(); if (err) { USBLog(1, "com_evoluent_driver_VerticalMouse[%p]::StartFinalProcessing - error (%p) from super::StartFinalProcessing", this, (void*)err); } } } return err; }
bool ZFSDatasetProxy::start(IOService *provider) { OSObject *property = NULL, *size = NULL; OSString *nameString = NULL; OSNumber *sizeNum = NULL; OSDictionary *deviceDict = NULL, *protocolDict = NULL; const OSSymbol *virtualSymbol = NULL, *internalSymbol = NULL; const char *cstr = NULL; char *pstring = NULL; int plen = 0; bool started = false; size = copyProperty(kZFSPoolSizeKey, gIOServicePlane, (kIORegistryIterateRecursively|kIORegistryIterateParents)); property = copyProperty(kZFSPoolNameKey, gIOServicePlane, (kIORegistryIterateRecursively|kIORegistryIterateParents)); if (!size || !property) { dprintf("couldn't get pool name or size"); goto error; } nameString = OSDynamicCast(OSString, property); if (!nameString) { dprintf("missing pool name"); goto error; } #if 0 /* Try hard to get the name string */ do { nameString = OSDynamicCast(OSString, property); if (nameString) nameString->retain(); if (!nameString) { OSSymbol *nameSymbol; nameSymbol = OSDynamicCast(OSSymbol, property); if (!nameSymbol) { dprintf("couldn't get name"); goto error; } nameString = OSString::withCString( nameSymbol->getCStringNoCopy()); } } while (0); #endif sizeNum = OSDynamicCast(OSNumber, size); if (!sizeNum) { dprintf("invalid size"); goto error; } _pool_bcount = sizeNum->unsigned64BitValue() / DEV_BSIZE; sizeNum = 0; size->release(); size = 0; cstr = nameString->getCStringNoCopy(); if (!cstr || (plen = strlen(cstr) + 1) == 1) { goto error; } pstring = (char *)IOMalloc(plen); if (!pstring) { goto error; } snprintf(pstring, plen, "%s", cstr); productString = pstring; pstring = 0; if (IOBlockStorageDevice::start(provider) == false) { dprintf("BlockStorageDevice start failed"); goto error; } started = true; deviceDict = OSDynamicCast(OSDictionary, getProperty(kIOPropertyDeviceCharacteristicsKey)); if (deviceDict) { /* Clone a new dictionary */ deviceDict = OSDictionary::withDictionary(deviceDict); if (!deviceDict) { dprintf("dict clone failed"); goto error; } } if (!deviceDict) { dprintf("creating new device dict"); deviceDict = OSDictionary::withCapacity(1); } if (!deviceDict) { dprintf("missing device dict"); goto error; } deviceDict->setObject(kIOPropertyProductNameKey, nameString); OSSafeReleaseNULL(nameString); if (setProperty(kIOPropertyDeviceCharacteristicsKey, deviceDict) == false) { dprintf("device dict setProperty failed"); goto error; } OSSafeReleaseNULL(deviceDict); protocolDict = OSDynamicCast(OSDictionary, getProperty(kIOPropertyProtocolCharacteristicsKey)); if (protocolDict) { /* Clone a new dictionary */ protocolDict = OSDictionary::withDictionary(protocolDict); if (!protocolDict) { dprintf("dict clone failed"); goto error; } } if (!protocolDict) { dprintf("creating new protocol dict"); protocolDict = OSDictionary::withCapacity(1); } if (!protocolDict) { dprintf("missing protocol dict"); goto error; } virtualSymbol = OSSymbol::withCString( kIOPropertyPhysicalInterconnectTypeVirtual); internalSymbol = OSSymbol::withCString( kIOPropertyInternalKey); if (!virtualSymbol || !internalSymbol) { dprintf("symbol alloc failed"); goto error; } protocolDict->setObject(kIOPropertyPhysicalInterconnectTypeKey, virtualSymbol); protocolDict->setObject(kIOPropertyPhysicalInterconnectLocationKey, internalSymbol); OSSafeReleaseNULL(virtualSymbol); OSSafeReleaseNULL(internalSymbol); if (setProperty(kIOPropertyProtocolCharacteristicsKey, protocolDict) == false) { dprintf("protocol dict setProperty failed"); goto error; } OSSafeReleaseNULL(protocolDict); registerService(kIOServiceAsynchronous); return (true); error: OSSafeReleaseNULL(size); OSSafeReleaseNULL(property); OSSafeReleaseNULL(deviceDict); OSSafeReleaseNULL(protocolDict); OSSafeReleaseNULL(nameString); OSSafeReleaseNULL(virtualSymbol); OSSafeReleaseNULL(internalSymbol); if (pstring) IOFree(pstring, plen); if (started) IOBlockStorageDevice::stop(provider); return (false); }
expression* expr = newExpressionStr(newString(strDup("hi"))); property* prop = newProperty("sample-prop", newTypelist(TYPE_STR), PROP_PRIVACY_PRIVATE, PROP_RANGE_GLOBAL, expr); SHOULD_EQUAL(strcmp(prop->name, "sample-prop"), 0) SHOULD_EQUAL(prop->privacy & PROP_PRIVACY_PRIVATE, PROP_PRIVACY_PRIVATE) SHOULD_EQUAL(prop->range & PROP_RANGE_GLOBAL, PROP_RANGE_GLOBAL) SHOULD_EQUAL(strcmp(prop->value->ev.strval->content, "hi"), 0) freeExpr(expr); freeProp(prop); END_IT END_DESCRIBE DESCRIBE(copyProperty, "property* copyProperty (property* prop)") IT("Copies the given property and its content") expression* expr = newExpressionInt(101); property* prop1 = newProperty("prop1", newTypelistWithNext(TYPE_INT, newTypelist(TYPE_FLO)), PROP_PRIVACY_PUBLIC, PROP_RANGE_GLOBAL, expr); property* prop2 = copyProperty(prop1); SHOULD_NOT_EQUAL(prop1, prop2) SHOULD_EQUAL(strcmp(prop1->name, prop2->name), 0) SHOULD_NOT_EQUAL(prop1->types, prop2->types) SHOULD_EQUAL(prop1->types->type, prop2->types->type) SHOULD_EQUAL(prop1->types->next->type, prop2->types->next->type) SHOULD_EQUAL(prop1->privacy, prop2->privacy) SHOULD_EQUAL(prop1->range, prop2->range) SHOULD_NOT_EQUAL(prop1->value, prop2->value) SHOULD_EQUAL(prop1->value->ev.intval, prop2->value->ev.intval) freeExpr(expr); freeProp(prop1); freeProp(prop2); END_IT END_DESCRIBE
IOReturn IOHIDevice::setParamProperties( OSDictionary * dict ) { IOHIDEventService * eventService = NULL; if ( dict->getObject(kIOHIDEventServicePropertiesKey) == NULL ) { IOService * service = getProvider(); if ( service ) eventService = OSDynamicCast(IOHIDEventService, service); } if ( dict->getObject(kIOHIDDeviceParametersKey) == kOSBooleanTrue ) { OSDictionary * deviceParameters = OSDynamicCast(OSDictionary, copyProperty(kIOHIDParametersKey)); if ( !deviceParameters ) { deviceParameters = OSDictionary::withCapacity(4); } else { if (deviceParameters->setOptions(0, 0) & OSDictionary::kImmutable) { OSDictionary * temp = deviceParameters; deviceParameters = OSDynamicCast(OSDictionary, temp->copyCollection()); temp->release(); } else { // do nothing } } if ( deviceParameters ) { // RY: Because K&M Prefs and Admin still expect device props to be // top level, let's continue to set them via setProperty. When we get // Max to migrate over, we can remove the interator code and use: // deviceParameters->merge(dict); // deviceParameters->removeObject(kIOHIDResetKeyboardKey); // deviceParameters->removeObject(kIOHIDResetPointerKey); // setProperty(kIOHIDParametersKey, deviceParameters); // deviceParameters->release(); OSCollectionIterator * iterator = OSCollectionIterator::withCollection(dict); if ( iterator ) { OSSymbol * key; while ( ( key = (OSSymbol *)iterator->getNextObject() ) ) if ( !key->isEqualTo(kIOHIDResetKeyboardKey) && !key->isEqualTo(kIOHIDResetPointerKey) && !key->isEqualTo(kIOHIDScrollResetKey) && !key->isEqualTo(kIOHIDDeviceParametersKey) && !key->isEqualTo(kIOHIDResetLEDsKey) && !key->isEqualTo(kIOUserClientClassKey) && !key->isEqualTo(kIOClassKey) && !key->isEqualTo(kIOProviderClassKey) && !key->isEqualTo(kIOKitDebugKey)) { OSObject * value = dict->getObject(key); deviceParameters->setObject(key, value); setProperty(key, value); } iterator->release(); } setProperty(kIOHIDParametersKey, deviceParameters); deviceParameters->release(); // RY: Propogate up to IOHIDEventService level if ( eventService ) eventService->setSystemProperties(dict); } else { return kIOReturnNoMemory; } } return( kIOReturnSuccess ); }
bool IOHIDInterface::start( IOService * provider ) { OSNumber * number; if ( !super::start(provider) ) return false; _owner = OSDynamicCast( IOHIDDevice, provider ); if ( !_owner ) return false; _transportString = (OSString*)copyProperty(kIOHIDTransportKey); _manufacturerString = (OSString*)copyProperty(kIOHIDManufacturerKey); _productString = (OSString*)copyProperty(kIOHIDProductKey); _serialNumberString = (OSString*)copyProperty(kIOHIDSerialNumberKey); if (_transportString && !OSDynamicCast(OSString, _transportString)) OSSafeReleaseNULL(_transportString); if (_manufacturerString && !OSDynamicCast(OSString, _manufacturerString)) OSSafeReleaseNULL(_manufacturerString); if (_productString && !OSDynamicCast(OSString, _productString)) OSSafeReleaseNULL(_productString); if (_serialNumberString && !OSDynamicCast(OSString, _serialNumberString)) OSSafeReleaseNULL(_serialNumberString); number = (OSNumber*)copyProperty(kIOHIDLocationIDKey); if ( OSDynamicCast(OSNumber, number) ) _locationID = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)copyProperty(kIOHIDVendorIDKey); if ( OSDynamicCast(OSNumber, number) ) _vendorID = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)copyProperty(kIOHIDVendorIDSourceKey); if ( OSDynamicCast(OSNumber, number) ) _vendorIDSource = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)copyProperty(kIOHIDProductIDKey); if ( OSDynamicCast(OSNumber, number) ) _productID = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)copyProperty(kIOHIDVersionNumberKey); if ( OSDynamicCast(OSNumber, number) ) _version = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)copyProperty(kIOHIDCountryCodeKey); if ( number ) _countryCode = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)_owner->copyProperty(kIOHIDMaxInputReportSizeKey); if ( OSDynamicCast(OSNumber, number) ) _maxReportSize[kIOHIDReportTypeInput] = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)_owner->copyProperty(kIOHIDMaxOutputReportSizeKey); if ( OSDynamicCast(OSNumber, number) ) _maxReportSize[kIOHIDReportTypeOutput] = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)_owner->copyProperty(kIOHIDMaxFeatureReportSizeKey); if ( OSDynamicCast(OSNumber, number) ) _maxReportSize[kIOHIDReportTypeFeature] = number->unsigned32BitValue(); OSSafeReleaseNULL(number); number = (OSNumber*)_owner->copyProperty(kIOHIDReportIntervalKey); if ( OSDynamicCast(OSNumber, number) ) _reportInterval = number->unsigned32BitValue(); OSSafeReleaseNULL(number); registerService(kIOServiceAsynchronous); return true; }