Class: Winsvc::Control

Inherits:
Struct
  • Object
show all
Defined in:
lib/winsvc.rb

Overview

A control message delivered to the service body. Every instance is frozen.

control      :stop :shutdown :preshutdown :pause :continue :power :session_change
event_type   Integer|nil — PBT_* (:power), WTS_* (:session_change)
session_id   Integer|nil — WTSSESSION_NOTIFICATION.dwSessionId (:session_change)
data         String|nil  — frozen ASCII-8BIT POWERBROADCAST_SETTING bytes
                         (≤ 512, truncated beyond) for PBT_POWERSETTINGCHANGE
time         Float       — Process::CLOCK_MONOTONIC seconds at delivery

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeControl

Every instance is frozen at construction (§2.4).



118
119
120
121
# File 'lib/winsvc.rb', line 118

def initialize(*)
  super
  freeze
end

Instance Attribute Details

#controlObject

Returns the value of attribute control

Returns:

  • (Object)

    the current value of control



115
116
117
# File 'lib/winsvc.rb', line 115

def control
  @control
end

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



115
116
117
# File 'lib/winsvc.rb', line 115

def data
  @data
end

#event_typeObject

Returns the value of attribute event_type

Returns:

  • (Object)

    the current value of event_type



115
116
117
# File 'lib/winsvc.rb', line 115

def event_type
  @event_type
end

#session_idObject

Returns the value of attribute session_id

Returns:

  • (Object)

    the current value of session_id



115
116
117
# File 'lib/winsvc.rb', line 115

def session_id
  @session_id
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



115
116
117
# File 'lib/winsvc.rb', line 115

def time
  @time
end

Class Method Details

.from_raw(raw) ⇒ Object

Build a frozen Control from one raw C record [code, etype, sid, data, tick].



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/winsvc.rb', line 129

def self.from_raw(raw)
  code, etype, sid, data, _tick = raw
  sym = CONTROL_SYMBOLS[code] || :unknown
  event_type = sym == :power || sym == :session_change ? etype : nil
  session_id = sym == :session_change ? sid : nil
  new(control: sym,
      event_type: event_type,
      session_id: session_id,
      data: data, # already frozen ASCII-8BIT or nil
      time: Process.clock_gettime(Process::CLOCK_MONOTONIC))
end

Instance Method Details

#stop?Boolean

True for the stop-class controls (:stop, :shutdown, :preshutdown).

Returns:

  • (Boolean)


124
125
126
# File 'lib/winsvc.rb', line 124

def stop?
  STOP_CLASS.include?(control)
end