@@ -19,6 +19,15 @@ function eventexec(event::T) where {T<:AbstractEventhdlr}
19
19
error (" eventexec not implemented for type $(T) " )
20
20
end
21
21
22
+ """
23
+ Default eventinit function.
24
+ """
25
+ function eventinit (event:: AbstractEventhdlr ) end
26
+
27
+ """
28
+ Default eventexit function.
29
+ """
30
+ function eventexit (event:: AbstractEventhdlr ) end
22
31
"""
23
32
This is the function that will be converted to a C function. It signature
24
33
matches the one given in the SCIP documentation for SCIP_DECL_EVENTEXEC.
@@ -30,17 +39,46 @@ function _eventexec(
30
39
eventhdlr:: Ptr{SCIP_Eventhdlr} ,
31
40
event:: Ptr{SCIP_Event} ,
32
41
eventdata:: Ptr{SCIP_EventData} ,
33
- )
42
+ ):: SCIP_RETCODE
34
43
# Get Julia object out of eventhandler data
35
44
data:: Ptr{SCIP_EventData} = SCIPeventhdlrGetData (eventhdlr)
36
45
event = unsafe_pointer_to_objref (data)
37
46
38
47
# call user method
39
48
eventexec (event)
49
+ return SCIP_OKAY
50
+ end
40
51
52
+ """
53
+ Internal function that will be converted to a C function and passed to SCIP as a callback.
54
+ Its signature matches the one given in the SCIP documentation for `SCIP_DECL_EVENTINIT`.
55
+ """
56
+ function _eventinit (
57
+ scip:: Ptr{SCIP_} ,
58
+ eventhdlr:: Ptr{SCIP_Eventhdlr} ,
59
+ ):: SCIP_RETCODE
60
+ # Get Julia object out of eventhandler data
61
+ data:: Ptr{SCIP_EventData} = SCIPeventhdlrGetData (eventhdlr)
62
+ event = unsafe_pointer_to_objref (data)
63
+
64
+ # call user method
65
+ eventinit (event)
41
66
return SCIP_OKAY
42
67
end
43
68
69
+ """
70
+ Internal function that will be converted to a C function passed to SCIP.
71
+ Its signature matches the one given in the SCIP documentation for `SCIP_DECL_EVENTEXIT`.
72
+ """
73
+ function _eventexit (
74
+ scip:: Ptr{SCIP_} ,
75
+ eventhdlr:: Ptr{SCIP_Eventhdlr} ,
76
+ ):: SCIP_RETCODE
77
+ data:: Ptr{SCIP_EventData} = SCIPeventhdlrGetData (eventhdlr)
78
+ event = unsafe_pointer_to_objref (data)
79
+ eventexit (event)
80
+ return SCIP_OKAY
81
+ end
44
82
"""
45
83
include_event_handler(scipd::SCIP.SCIPData, event_handler::EVENTHDLR; name="", desc="")
46
84
@@ -59,6 +97,10 @@ function include_event_handler(
59
97
name= " " ,
60
98
desc= " " ,
61
99
) where {EVENTHDLR<: AbstractEventhdlr }
100
+ _eventinit =
101
+ @cfunction (_eventinit, SCIP_RETCODE, (Ptr{SCIP_}, Ptr{SCIP_Eventhdlr}))
102
+ _eventexit =
103
+ @cfunction (_eventexit, SCIP_RETCODE, (Ptr{SCIP_}, Ptr{SCIP_Eventhdlr}))
62
104
_eventexec = @cfunction (
63
105
_eventexec,
64
106
SCIP_RETCODE,
@@ -80,7 +122,8 @@ function include_event_handler(
80
122
_eventexec,
81
123
eventhdlr,
82
124
)
83
-
125
+ @SCIP_CALL SCIPsetEventhdlrInit (scipd. scip[], eventhdlrptr[], _eventinit)
126
+ @SCIP_CALL SCIPsetEventhdlrExit (scipd. scip[], eventhdlrptr[], _eventexit)
84
127
@assert eventhdlrptr[] != C_NULL
85
128
# Persist in scip store against GC
86
129
scipd. eventhdlrs[event_handler] = eventhdlrptr[]
91
134
92
135
Catch an event in SCIP. This function is a wrapper around the SCIPcatchEvent function.
93
136
Warning! This function should only be called after the SCIP has been transformed.
137
+ Use this instead of calling SCIPcatchEvent directly.
94
138
"""
95
139
function catch_event (
96
140
scipd:: SCIP.SCIPData ,
@@ -102,3 +146,21 @@ function catch_event(
102
146
eventhdlrptr = scipd. eventhdlrs[eventhdlr]
103
147
@SCIP_CALL SCIPcatchEvent (scipd, eventtype, eventhdlrptr, C_NULL , C_NULL )
104
148
end
149
+
150
+ """
151
+ drop_event(scipd::SCIP.SCIPData, eventtype::SCIP_EVENTTYPE, eventhdlr::EVENTHDLR)
152
+
153
+ Drop an event in SCIP. This function is a wrapper around the SCIPdropEvent function.
154
+ Warning! This function should only be called after the SCIP has been transformed.
155
+ Use this instead of calling SCIPdropEvent directly.
156
+ """
157
+ function drop_event (
158
+ scipd:: SCIP.SCIPData ,
159
+ eventtype:: SCIP_EVENTTYPE ,
160
+ eventhdlr:: EVENTHDLR ,
161
+ ) where {EVENTHDLR<: AbstractEventhdlr }
162
+ @assert SCIPgetStage (scipd) != SCIP_STAGE_INIT
163
+ @assert SCIPgetStage (scipd) != SCIP_STAGE_PROBLEM
164
+ eventhdlrptr = scipd. eventhdlrs[eventhdlr]
165
+ @SCIP_CALL SCIPdropEvent (scipd, eventtype, eventhdlrptr, C_NULL , - 1 )
166
+ end
0 commit comments