Class: Ragweed::Event

Inherits:
Object show all
Defined in:
lib/ragweed/wrap32/event.rb

Instance Method Summary collapse

Constructor Details

#initialize(p = nil, h = nil) ⇒ Event

You can just do WinEvent.new to get a new anonymous handle, and then call .handle on it to find out what the handle was. Communicate your pid and the handle value, somehow, to a remote process. That process can get the same event by passing a WinProcess and the handle here.

So, in Process1 (assume pid 668, and handle 300):

e = WinEvent.new puts #{ get_current_process_id }: #{ e.handle }“

And in Process2:

e = WinEvent.new(WinProcess.new(668), 300)

Now both processes share an event.



22
23
24
25
# File 'lib/ragweed/wrap32/event.rb', line 22

def initialize(p=nil, h=nil)
  @p = p
  @h = (@p.dup_handle(h) if h) || create_event
end

Instance Method Details

#on(&block) ⇒ Object

A wait loop.



44
45
46
47
48
49
# File 'lib/ragweed/wrap32/event.rb', line 44

def on(&block)
  while 1
    wait
    break if not yield
  end
end

#resetObject

Force the event back to unsignalled state.



39
40
41
# File 'lib/ragweed/wrap32/event.rb', line 39

def reset
  Ragweed::Wrap32::reset_event(@h)
end

#signalObject

Signal the event; anyone waiting on it is now released.



34
35
36
# File 'lib/ragweed/wrap32/event.rb', line 34

def signal
  Ragweed::Wrap32::set_event(@h)
end

#waitObject

Don’t return until the event is signalled. Note that you can’t break this with timeouts or CTR-C.



29
30
31
# File 'lib/ragweed/wrap32/event.rb', line 29

def wait
  Ragweed::Wrap32::wait_for_single_object @h
end