FakeSMCKey *FakeSMCDevice::addKeyWithHandler(const char *name, const char *type, unsigned char size, IOService *handler) { IORecursiveLockLock(device_lock); FakeSMCKey* key; if ((key = getKey(name))) { HWSensorsErrorLog("key %s already handled", name); if (key->getHandler() != NULL) { // TODO: check priority? HWSensorsErrorLog("key %s already handled", name); key = 0; } else { key->setType(type); key->setSize(size); key->setHandler(handler); } } else { FakeSMCDebugLog("adding key %s with handler, type: %s, size: %d", name, type, size); if ((key = FakeSMCKey::withHandler(name, type, size, handler))) { keys->setObject(key); updateKeyCounterKey(); } } IORecursiveLockUnlock(device_lock); if (!key) HWSensorsErrorLog("failed to create key %s", name); return key; }
FakeSMCKey *FakeSMCKeyStore::addKeyWithHandler(const char *name, const char *type, unsigned char size, FakeSMCKeyHandler *handler) { FakeSMCKey *key = 0; KEYSLOCK; if ((key = getKey(name))) { FakeSMCKeyHandler *existedHandler = key->getHandler(); if (handler->getProbeScore() < existedHandler->getProbeScore()) { HWSensorsErrorLog("key %s already handled with prioritized handler %s", name, existedHandler ? existedHandler->getName() : "*Unreferenced*"); key = 0; } else { HWSensorsInfoLog("key %s handler %s has been replaced with new prioritized handler %s", name, existedHandler ? existedHandler->getName() : "*Unreferenced*", handler ? handler->getName() : "*Unreferenced*"); key->setType(type); key->setSize(size); key->setHandler(handler); } } else { HWSensorsDebugLog("adding key %s with handler, type: %s, size: %d", name, type, size); if ((key = FakeSMCKey::withHandler(name, type, size, handler))) { ////KEYSLOCK; keys->setObject(key); ////KEYSUNLOCK; updateKeyCounterKey(); } } KEYSUNLOCK; if (!key) HWSensorsErrorLog("addKeyWithHandler: failed to create key %s", name); return key; }
FakeSMCKey *FakeSMCDevice::addKeyWithHandler(const char *name, const char *type, unsigned char size, IOService *handler) { KEYSLOCK; FakeSMCKey *key; if ((key = getKey(name))) { IOService *existedHandler = key->getHandler(); if (getHandlingPriority(handler) < getHandlingPriority(existedHandler)) { HWSensorsErrorLog("key %s already handled with prioritized handler %s", name, existedHandler ? existedHandler->getName() : "*Unreferenced*"); key = 0; } else { HWSensorsInfoLog("key %s handler %s has been replaced with new prioritized handler %s", name, existedHandler ? existedHandler->getName() : "*Unreferenced*", handler ? handler->getName() : "*Unreferenced*"); key->setType(type); key->setSize(size); key->setHandler(handler); } } else { FakeSMCDebugLog("adding key %s with handler, type: %s, size: %d", name, type, size); if ((key = FakeSMCKey::withHandler(name, type, size, handler))) { keys->setObject(key); updateKeyCounterKey(); } else { HWSensorsErrorLog("failed to create key %s", name); } } KEYSUNLOCK; return key; }
FakeSMCKey *FakeSMCDevice::addKeyWithValue(const char *name, const char *type, unsigned char size, const void *value) { KEYSLOCK; FakeSMCKey* key; if ((key = getKey(name))) { if (type && strncmp(type, key->getType(), 4) == 0) { key->setType(type); } if (value) { key->setSize(size); key->setValueFromBuffer(value, size); } #ifdef DEBUG if (debug) { if (strncmp("NATJ", key->getKey(), 5) == 0) { UInt8 val = *(UInt8*)key->getValue(); switch (val) { case 0: HWSensorsInfoLog("Ninja Action Timer Job: do nothing"); break; case 1: HWSensorsInfoLog("Ninja Action Timer Job: force shutdown to S5"); break; case 2: HWSensorsInfoLog("Ninja Action Timer Job: force restart"); break; case 3: HWSensorsInfoLog("Ninja Action Timer Job: force startup"); break; default: break; } } else if (strncmp("NATi", key->getKey(), 5) == 0) { UInt16 val = *(UInt16*)key->getValue(); HWSensorsInfoLog("Ninja Action Timer is set to %d", val); } else if (strncmp("MSDW", key->getKey(), 5) == 0) { UInt8 val = *(UInt8*)key->getValue(); switch (val) { case 0: HWSensorsInfoLog("display is now asleep"); break; case 1: HWSensorsInfoLog("display is now awake"); break; default: break; } } } FakeSMCDebugLog("value updated for key %s, type: %s, size: %d", name, type, size); #endif } else { FakeSMCDebugLog("adding key %s with value, type: %s, size: %d", name, type, size); OSString *wellKnownType = 0; if (!type) wellKnownType = OSDynamicCast(OSString, types->getObject(name)); key = FakeSMCKey::withValue(name, type ? type : wellKnownType ? wellKnownType->getCStringNoCopy() : 0, size, value); if (key) { keys->setObject(key); updateKeyCounterKey(); } } KEYSUNLOCK; if (!key) HWSensorsErrorLog("failed to create key %s", name); return key; }
FakeSMCKey *FakeSMCDevice::addKeyWithValue(const char *name, const char *type, unsigned char size, const void *value) { IORecursiveLockLock(device_lock); FakeSMCKey* key; if ((key = getKey(name))) { if (value) { key->setType(type); key->setSize(size); key->setValueFromBuffer(value, size); } if (debug) { if (strncmp("NATJ", key->getKey(), 5) == 0) { UInt8 val = *(UInt8*)key->getValue(); switch (val) { case 0: HWSensorsInfoLog("Ninja Action Timer Job: do nothing"); break; case 1: HWSensorsInfoLog("Ninja Action Timer Job: force shutdown to S5"); break; case 2: HWSensorsInfoLog("Ninja Action Timer Job: force restart"); break; case 3: HWSensorsInfoLog("Ninja Action Timer Job: force startup"); break; default: break; } } else if (strncmp("NATi", key->getKey(), 5) == 0) { UInt16 val = *(UInt16*)key->getValue(); HWSensorsInfoLog("Ninja Action Timer is set to %d", val); } else if (strncmp("MSDW", key->getKey(), 5) == 0) { UInt8 val = *(UInt8*)key->getValue(); switch (val) { case 0: HWSensorsInfoLog("display is now asleep"); break; case 1: HWSensorsInfoLog("display is now awake"); break; default: break; } } } FakeSMCDebugLog("updating value for key %s, type: %s, size: %d", name, type, size); } else { FakeSMCDebugLog("adding key %s with value, type: %s, size: %d", name, type, size); if ((key = FakeSMCKey::withValue(name, type, size, value))) { keys->setObject(key); updateKeyCounterKey(); } } IORecursiveLockUnlock(device_lock); if (!key) HWSensorsErrorLog("failed to create key %s", name); return key; }