Chapter 7: Coding the Application

FFILibrary subclass: #FFICranky
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Cranky'
getBuffermem
^ self ffiCall: #( uint get_buffermem() ) module: 'ffilibc.so'
unixModuleName
^ 'ffilibc.so'
getBuffermem
^ self ffiCall: #( uint get_buffermem() )
getCachedmem
^ self ffiCall: #( uint get_cachedmem() )
getCpuCount
^ self ffiCall: #( uint get_cpu_count() )
getCpuFreq
^ self ffiCall: #( uint get_cpu_freq() )
getCpuTemp
^ self ffiCall: #( float get_cpu_temp() )
getCpuUsage
^ self ffiCall: #( double get_cpu_usage() )
getFreemem
^ self ffiCall: #( uint get_freemem() )
getFreeswap
^ self ffiCall: #( uint get_freeswap() )
getFsAvail
^ self ffiCall: #( uint get_fs_avail() )
getFsTotalsize
^ self ffiCall: #( uint get_fs_totalsize() )
getMachine
^ self ffiCall: #( String get_machine() )
getNodename
^ self ffiCall: #( String get_nodename() )
getNumprocs
^ self ffiCall: #( uint get_numprocs() )
getRelease
^ self ffiCall: #( String get_release() )
getSysname
^ self ffiCall: #( String get_sysname() )
getTotalmem
^ self ffiCall: #( uint get_totalmem() )
getTotalswap
^ self ffiCall: #( uint get_totalswap() )
getUptime
^ self ffiCall: #( uint get_uptime() )
getVersion
^ self ffiCall: #( String get_version() )
FFILibrary class»uniqueInstance
uniqueInstance ifNil: [ uniqueInstance := super new ].
^ uniqueInstance
FFILibrary class
instanceVariableNames: 'uniqueInstance'
StringMorph subclass: #MyStringMorph
instanceVariableNames: 'block'
classVariableNames: ''
poolDictionaries: ''
category: 'Cranky'
MyStringMorph class»update: aBlock
^ self new update: aBlock
initialize
super initialize
update: aBlock
block := aBlock
step
self contents: block value
stepTime
^ 2000 "in milliseconds"
Object subclass: #InfoLine
instanceVariableNames: 'label info'
classVariableNames: ''
poolDictionaries: ''
category: 'Cranky'
InfoLine class»label: label contents: con at: pos
^ self new label: label contents: con at: pos
InfoLine class»label: label update: aBlock at: pos
^ self new label: label update: aBlock at: pos
label: lab contents: con at: pos
label := ((StringMorph contents: lab) color: Color white)
position: pos.
info := ((StringMorph contents: con) color: Color white)
position: 100@pos y
label: lab update: aBlock at: pos
label := ((StringMorph contents: lab) color: Color white)
position: pos.
info := ((MyStringMorph update: aBlock) color: Color white)
position: 100@pos y
info
^ info
info: anObject
info := anObject
label
^ label
label: anObject
label := anObject
Object subclass: #Cranky
instanceVariableNames: 'm s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19'
classVariableNames: ''
poolDictionaries: ''
category: 'Cranky'
initSystemfields
m addMorph: ((((StringMorph contents: '== System ==')
color: Color white) position: 0@75)
emphasis: 1).
s1 := InfoLine label: 'System name:'
contents: FFICranky uniqueInstance getSysname at: 0@90.
s2 := InfoLine label: 'Node name:'
contents: FFICranky uniqueInstance getNodename
at: s1 label position + (0@15).
s3 := InfoLine label: 'Release:'
contents: FFICranky uniqueInstance getRelease
at: s2 label position + (0@15).
s4 := InfoLine label: 'Version:'
contents: FFICranky uniqueInstance getVersion
at: s3 label position + (0@15).
s5 := InfoLine label: 'Machine:'
contents: FFICranky uniqueInstance getMachine
at: s4 label position + (0@15).
m addMorph: ((((StringMorph contents: '== Time ==')
color: Color white) position: s5 label position + (0@30))
emphasis: 1).
s6 := InfoLine label: 'Uptime:'
update: [FFICranky uniqueInstance getUptime asDuration
humanReadablePrintString]
at: s5 label position + (0@45).
m addMorph: s1 label; addMorph: s2 label; addMorph: s3 label;
addMorph: s4 label; addMorph: s5 label; addMorph: s6 label;
addMorph: s1 info; addMorph: s2 info; addMorph: s3 info;
addMorph: s4 info; addMorph: s5 info; addMorph: s6 info
initMemoryfields
m addMorph: ((((StringMorph contents: '== Memory ==')
color: Color white)
position: s6 label position + (0@30)) emphasis: 1).
s7 := InfoLine label: 'Free mem:'
update: [FFICranky uniqueInstance getFreemem
asStringWithCommas,' KB']
at: s6 label position + (0@45).
s8 := InfoLine label: 'Total mem:'
contents: FFICranky uniqueInstance getTotalmem
asStringWithCommas,' KB'
at: s7 label position + (0@15).
s9 := InfoLine label: 'Cached mem:'
update: [FFICranky uniqueInstance getCachedmem
asStringWithCommas,' KB']
at: s8 label position + (0@15).
s10 := InfoLine label: 'Buffer mem:'
update: [FFICranky uniqueInstance getBuffermem
asStringWithCommas,' KB']
at: s9 label position + (0@15).
s11 := InfoLine label: 'Free swap:'
update: [FFICranky uniqueInstance getFreeswap
asStringWithCommas,' KB']
at: s10 label position + (0@15).
s12 := InfoLine label: 'Total swap:'
contents: FFICranky uniqueInstance getTotalswap
asStringWithCommas,' KB'
at: s11 label position + (0@15).
s13 := InfoLine label: '# of processes:'
update: [FFICranky uniqueInstance getNumprocs asString]
at: s12 label position + (0@15).
m addMorph: s7 label; addMorph: s8 label; addMorph: s9 label;
addMorph: s10 label; addMorph: s11 label; addMorph: s12 label;
addMorph: s13 label; addMorph: s7 info; addMorph: s8 info;
addMorph: s9 info; addMorph: s10 info; addMorph: s11 info;
addMorph: s12 info; addMorph: s13 info
initSdCardfields
m addMorph: ((((StringMorph contents: '== SD card ==')
color: Color white)
position: s13 label position + (0@30)) emphasis: 1).
s14 := InfoLine label: 'Free space:'
update: [FFICranky uniqueInstance getFsAvail
asStringWithCommas,' MB']
at: s13 label position + (0@45).
s15 := InfoLine label: 'Total space:'
contents: FFICranky uniqueInstance getFsTotalsize
asStringWithCommas,' MB'
at: s14 label position + (0@15).
m addMorph: s14 label; addMorph: s15 label; addMorph: s14 info;
addMorph: s15 info
initCpuFields
m addMorph: ((((StringMorph contents: '== CPU ==')
color: Color white)
position: s15 label position + (0@30)) emphasis: 1).
s16 := InfoLine label: 'CPU usage'
update: [(FFICranky uniqueInstance getCpuUsage
printShowingDecimalPlaces: 1),'%']
at: s15 label position + (0@45).
s17 := InfoLine label: 'Frequency'
update: [FFICranky uniqueInstance getCpuFreq
asStringWithCommas,' MHz']
at: s16 label position + (0@15).
s18 := InfoLine label: 'CPU/GPU temp:'
update: [(FFICranky uniqueInstance getCpuTemp
printShowingDecimalPlaces: 1),' C']
at: s17 label position + (0@15).
s19 := InfoLine label: '# of cores:'
contents: FFICranky uniqueInstance getCpuCount asString
at: s18 label position + (0@15).
m addMorph: s16 label; addMorph: s17 label; addMorph: s18 label;
addMorph: s19 label; addMorph: s16 info; addMorph: s17 info;
addMorph: s18 info; addMorph: s19 info
initialize
| f |
f := Form fromFileNamed: 'hot_air_balloon_mysticmorning.jpg'.
m := ImageMorph new.
m form: f.
self initSystemfields.
self initMemoryfields.
self initSdCardfields.
self initCpuFields.
(m openInWindowLabeled: 'Cranky') location: 0@0 "place in top-left corner of Pharo window"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store