From a0a4d3308c32beabdd4caacf3242f8e719b953ec Mon Sep 17 00:00:00 2001 From: beltex Date: Tue, 2 Dec 2014 10:12:36 -0500 Subject: [PATCH] Move a few const props to global scope - Due to lack of type props for classes (for now). See https://github.com/beltex/SMCKit/issues/6 - This lets us make a few helper methods now type methods --- Example/main.swift | 3 +-- SMCKit/SMC.swift | 56 ++++++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Example/main.swift b/Example/main.swift index f936a29..bbc0277 100644 --- a/Example/main.swift +++ b/Example/main.swift @@ -1,6 +1,6 @@ /* * Simple example usage of SMCKit. Prints machine status: temperatures, fans, -* power, misc. +* battery, power, misc. * * main.swift * SMCKit @@ -24,7 +24,6 @@ import SMCKit - let smc = SMC() if (smc.open() != kIOReturnSuccess) { diff --git a/SMCKit/SMC.swift b/SMCKit/SMC.swift index 3de3b3b..c39b596 100644 --- a/SMCKit/SMC.swift +++ b/SMCKit/SMC.swift @@ -268,6 +268,29 @@ macro as defined in . private let SUB_IOKIT_COMMON: UInt32 = (0 & 0xfff) << 14 +// TODO: Below should all be type properties once supported by Swift. Issue #6. + + +/** +Name of the SMC IOService as seen in the IORegistry. You can view it either +via command line with ioreg or through the IORegistryExplorer app (found on +Apple's developer site - Hardware IO Tools for Xcode) +*/ +private let IOSERVICE_SMC = "AppleSMC" + + +/** +IOService for getMachineModel() +*/ +private let IOSERVICE_MODEL = "IOPlatformExpertDevice" + + +/** +Number of characters in an SMC key +*/ +private let SMC_KEY_SIZE = 4 + + //------------------------------------------------------------------------------ // MARK: GLOBAL PRIVATE FUNCTIONS //------------------------------------------------------------------------------ @@ -639,26 +662,6 @@ public class SMC { private var conn: io_connect_t = 0 - /** - Name of the SMC IOService as seen in the IORegistry. You can view it either - via command line with ioreg or through the IORegistryExplorer app (found on - Apple's developer site - Hardware IO Tools for Xcode) - */ - private let IOSERVICE_SMC = "AppleSMC" - - - /** - IOService for get machine model name - */ - private let IOSERVICE_MODEL = "IOPlatformExpertDevice" - - - /** - Number of characters in an SMC key - */ - private let SMC_KEY_SIZE = 4 - - //-------------------------------------------------------------------------- // MARK: PUBLIC INITIALIZERS //-------------------------------------------------------------------------- @@ -733,7 +736,7 @@ public class SMC { var result = false var err : NSError? let data : [String : AnyObject] = - ["Model" : getMachineModel(), + ["Model" : SMC.getMachineModel(), "Temperature" : temperatureInformation(), "Fan" : fanInformation()] @@ -1218,7 +1221,7 @@ public class SMC { // First call to AppleSMC - get key info - inputStruct.key = toUInt32(key) + inputStruct.key = SMC.toUInt32(key) inputStruct.data8 = UInt8(Selector.kSMCGetKeyInfo.rawValue) result = callSMC(&inputStruct, outputStruct: &outputStruct) @@ -1292,7 +1295,7 @@ public class SMC { var outputStruct = SMCParamStruct() // First call to AppleSMC - get key info - inputStruct.key = toUInt32(key) + inputStruct.key = SMC.toUInt32(key) inputStruct.data8 = UInt8(Selector.kSMCGetKeyInfo.rawValue) result = callSMC(&inputStruct, outputStruct: &outputStruct) @@ -1451,9 +1454,8 @@ public class SMC { :returns: The model name. */ - private func getMachineModel() -> String { + private class func getMachineModel() -> String { // This could be done using sysctl() as well - var model = String() // Find the service @@ -1518,7 +1520,7 @@ public class SMC { :returns: UInt32 translation of it with little-endian representation. Returns zero if key is not 4 characters in length. */ - private func toUInt32(key: String) -> UInt32 { + private class func toUInt32(key: String) -> UInt32 { var ans : Int32 = 0 var shift : Int32 = 24 @@ -1544,7 +1546,7 @@ public class SMC { :param: dataType The data type as returned from a SMC read key info call :returns: 4-byte multi-character constant representation */ - private func toString(dataType: UInt32) -> String { + private class func toString(dataType: UInt32) -> String { var ans = String() var shift : Int32 = 24