Skip to content

Commit

Permalink
Move a few const props to global scope
Browse files Browse the repository at this point in the history
- Due to lack of type props for classes (for now). See
  #6
- This lets us make a few helper methods now type methods
  • Loading branch information
beltex committed Dec 2, 2014
1 parent 05ef783 commit a0a4d33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
3 changes: 1 addition & 2 deletions Example/main.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Simple example usage of SMCKit. Prints machine status: temperatures, fans,
* power, misc.
* battery, power, misc.
*
* main.swift
* SMCKit
Expand All @@ -24,7 +24,6 @@

import SMCKit


let smc = SMC()

if (smc.open() != kIOReturnSuccess) {
Expand Down
56 changes: 29 additions & 27 deletions SMCKit/SMC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,29 @@ macro as defined in <mach/error.h>.
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
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -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()]

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit a0a4d33

Please sign in to comment.