summaryrefslogtreecommitdiff
path: root/ipl/mprocs/evinit.icn
blob: 09a2ee6b363de09eacf335e173c6a8e47604c2bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
############################################################################
#
#	File:     evinit.icn
#
#	Subject:  Procedures for event monitoring
#
#	Author:   Ralph E. Griswold
#
#	Date:     November 5, 1995
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This file provides initialization for event monitors.
#
#  This file is intended for use with event monitors running under
#  MT Icon.
#
############################################################################

$include "evdefs.icn"

procedure EvInit(f,input,output,error)
   if not MTEvInit(f,input,output,error) then fail
   return
end

procedure EvTerm(win)
  if &eventsource === (Monitored | EventSource) then {
    if type(win) == "window" then
      Event(win)
    }
end
#
# MultiThread EventMon support, from file mtsupport.icn
#

global Monitored, EventSource, MTEventMask

#
# If EvInit is called with a string or a list, run as a standalone MT-based
# event monitor -- load the icode file and overload certain EvMon symbols.
#
# This operation is skipped if &eventsource has already been initialized,
#  presumably by some event broker such as Eve.
#
procedure MTEvInit(f,input,output,error)

   if \&eventsource then return

   if type(f) == "string" then {
      &eventsource := EventSource := Monitored := load(f,,input,output,error) | fail
      EvGet     :=: MTEvGet
      }
   else if type(f) == "list" then {
      &eventsource := EventSource := Monitored := load(f[1],f[2:0],input,output,error) | fail
      EvGet     :=: MTEvGet
      }
   return &eventsource
end

procedure MTEvGet(c,flag)
   static lastcset
   initial {
      lastcset := ''
      }

   if c ~=== lastcset then {
     lastcset := c
     eventmask(\(Monitored | EventSource) ,\c | &cset,&main)
     }
   return MTEvGet(c,flag)
end

#
# Eve-specific extensions to the general model
#
procedure EvQuit()
  EvSignal("quit")
end

procedure EvSignal(x)
   if type(x) == "cset" then
      write(&errout, "EvSignal(", image(x), ") is ambiguous.")
   return x @ &eventsource
end