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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
|
.TH gen_event 3 "stdlib 1.15.3" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
gen_event \- Generic Event Handling Behaviour
.SH DESCRIPTION
.LP
A behaviour module for implementing event handling functionality\&. The OTP event handling model consists of a generic event manager process with an arbitrary number of event handlers which are added and deleted dynamically\&.
.LP
An event manager implemented using this module will have a standard set of interface functions and include functionality for tracing and error reporting\&. It will also fit into an OTP supervision tree\&. Refer to \fIOTP Design Principles\fR for more information\&.
.LP
Each event handler is implemented as a callback module exporting a pre-defined set of functions\&. The relationship between the behaviour functions and the callback functions can be illustrated as follows:
.nf
gen_event module Callback module
--------------- -------------
gen_event:start_link -----> -
gen_event:add_handler
gen_event:add_suphandler -----> Module:init/1
gen_event:notify
gen_event:sync_notify -----> Module:handle_event/2
gen_event:call -----> Module:handle_call/2
- -----> Module:handle_info/2
gen_event:delete_handler -----> Module:terminate/2
gen_event:swap_handler
gen_event:swap_sup_handler -----> Module1:terminate/2
Module2:init/1
gen_event:which_handlers -----> -
gen_event:stop -----> Module:terminate/2
- -----> Module:code_change/3
.fi
.LP
Since each event handler is one callback module, an event manager will have several callback modules which are added and deleted dynamically\&. Therefore \fIgen_event\fR is more tolerant of callback module errors than the other behaviours\&. If a callback function for an installed event handler fails with \fIReason\fR, or returns a bad value \fITerm\fR, the event manager will not fail\&. It will delete the event handler by calling the callback function \fIModule:terminate/2\fR (see below), giving as argument \fI{error, {\&'EXIT\&', Reason}}\fR or \fI{error, Term}\fR, respectively\&. No other event handler will be affected\&.
.LP
The \fIsys\fR module can be used for debugging an event manager\&.
.LP
Note that an event manager \fIdoes\fR trap exit signals automatically\&.
.LP
The gen_event process can go into hibernation (see erlang(3)) if a callback function in a handler module specifies \fI\&'hibernate\&'\fR in its return value\&. This might be useful if the server is expected to be idle for a long time\&. However this feature should be used with care as hibernation implies at least two garbage collections (when hibernating and shortly after waking up) and is not something you\&'d want to do between each event handled by a busy event manager\&.
.LP
It\&'s also worth noting that when multiple event handlers are invoked, it\&'s sufficient that one single event handler returns a \fI\&'hibernate\&'\fR request for the whole event manager to go into hibernation\&.
.LP
Unless otherwise stated, all functions in this module fail if the specified event manager does not exist or if bad arguments are given\&.
.SH EXPORTS
.LP
.B
start_link() -> Result
.br
.B
start_link(EventMgrName) -> Result
.br
.RS
.TP
Types
EventMgrName = {local, Name} | {global, Name}
.br
Name = atom()
.br
Result = {ok, Pid} | {error, {already_started, Pid}}
.br
Pid = pid()
.br
.RE
.RS
.LP
Creates an event manager process as part of a supervision tree\&. The function should be called, directly or indirectly, by the supervisor\&. It will, among other things, ensure that the event manager is linked to the supervisor\&.
.LP
If \fIEventMgrName={local, Name}\fR, the event manager is registered locally as \fIName\fR using \fIregister/2\fR\&. If \fIEventMgrName={global, Name}\fR, the event manager is registered globally as \fIName\fR using \fIglobal:register_name/2\fR\&. If no name is provided, the event manager is not registered\&.
.LP
If the event manager is successfully created the function returns \fI{ok, Pid}\fR, where \fIPid\fR is the pid of the event manager\&. If there already exists a process with the specified \fIEventMgrName\fR the function returns \fI{error, {already_started, Pid}}\fR, where \fIPid\fR is the pid of that process\&.
.RE
.LP
.B
start() -> Result
.br
.B
start(EventMgrName) -> Result
.br
.RS
.TP
Types
EventMgrName = {local, Name} | {global, Name}
.br
Name = atom()
.br
Result = {ok, Pid} | {error, {already_started, Pid}}
.br
Pid = pid()
.br
.RE
.RS
.LP
Creates a stand-alone event manager process, i\&.e\&. an event manager which is not part of a supervision tree and thus has no supervisor\&.
.LP
See \fIstart_link/0, 1\fR for a description of arguments and return values\&.
.RE
.LP
.B
add_handler(EventMgrRef, Handler, Args) -> Result
.br
.RS
.TP
Types
EventMgr = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
Handler = Module | {Module, Id}
.br
Module = atom()
.br
Id = term()
.br
Args = term()
.br
Result = ok | {\&'EXIT\&', Reason} | term()
.br
Reason = term()
.br
.RE
.RS
.LP
Adds a new event handler to the event manager \fIEventMgrRef\fR\&. The event manager will call \fIModule:init/1\fR to initiate the event handler and its internal state\&.
.LP
\fIEventMgrRef\fR can be:
.RS 2
.TP 2
*
the pid,
.TP 2
*
\fIName\fR, if the event manager is locally registered,
.TP 2
*
\fI{Name, Node}\fR, if the event manager is locally registered at another node, or
.TP 2
*
\fI{global, Name}\fR, if the event manager is globally registered\&.
.RE
.LP
\fIHandler\fR is the name of the callback module \fIModule\fR or a tuple \fI{Module, Id}\fR, where \fIId\fR is any term\&. The \fI{Module, Id}\fR representation makes it possible to identify a specific event handler when there are several event handlers using the same callback module\&.
.LP
\fIArgs\fR is an arbitrary term which is passed as the argument to \fIModule:init/1\fR\&.
.LP
If \fIModule:init/1\fR returns a correct value, the event manager adds the event handler and this function returns \fIok\fR\&. If \fIModule:init/1\fR fails with \fIReason\fR or returns an unexpected value \fITerm\fR, the event handler is ignored and this function returns \fI{\&'EXIT\&', Reason}\fR or \fITerm\fR, respectively\&.
.RE
.LP
.B
add_sup_handler(EventMgrRef, Handler, Args) -> Result
.br
.RS
.TP
Types
EventMgr = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
Handler = Module | {Module, Id}
.br
Module = atom()
.br
Id = term()
.br
Args = term()
.br
Result = ok | {\&'EXIT\&', Reason} | term()
.br
Reason = term()
.br
.RE
.RS
.LP
Adds a new event handler in the same way as \fIadd_handler/3\fR but will also supervise the connection between the event handler and the calling process\&.
.RS 2
.TP 2
*
If the calling process later terminates with \fIReason\fR, the event manager will delete the event handler by calling \fIModule:terminate/2\fR with \fI{stop, Reason}\fR as argument\&.
.TP 2
*
If the event handler later is deleted, the event manager sends a message\fI{gen_event_EXIT, Handler, Reason}\fR to the calling process\&. \fIReason\fR is one of the following:
.RS 2
.LP
.RS 2
.TP 2
-
\fInormal\fR, if the event handler has been removed due to a call to \fIdelete_handler/3\fR, or \fIremove_handler\fR has been returned by a callback function (see below)\&.
.TP 2
-
\fIshutdown\fR, if the event handler has been removed because the event manager is terminating\&.
.TP 2
-
\fI{swapped, NewHandler, Pid}\fR, if the process \fIPid\fR has replaced the event handler with another event handler \fINewHandler\fR using a call to \fIswap_handler/3\fR or \fIswap_sup_handler/3\fR\&.
.TP 2
-
a term, if the event handler is removed due to an error\&. Which term depends on the error\&.
.RE
.RE
.RE
.LP
See \fIadd_handler/3\fR for a description of the arguments and return values\&.
.RE
.LP
.B
notify(EventMgrRef, Event) -> ok
.br
.B
sync_notify(EventMgrRef, Event) -> ok
.br
.RS
.TP
Types
EventMgrRef = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
Event = term()
.br
.RE
.RS
.LP
Sends an event notification to the event manager \fIEventMgrRef\fR\&. The event manager will call \fIModule:handle_event/2\fR for each installed event handler to handle the event\&.
.LP
\fInotify\fR is asynchronous and will return immediately after the event notification has been sent\&. \fIsync_notify\fR is synchronous in the sense that it will return \fIok\fR after the event has been handled by all event handlers\&.
.LP
See \fIadd_handler/3\fR for a description of \fIEventMgrRef\fR\&.
.LP
\fIEvent\fR is an arbitrary term which is passed as one of the arguments to \fIModule:handle_event/2\fR\&.
.LP
\fInotify\fR will not fail even if the specified event manager does not exist, unless it is specified as \fIName\fR\&.
.RE
.LP
.B
call(EventMgrRef, Handler, Request) -> Result
.br
.B
call(EventMgrRef, Handler, Request, Timeout) -> Result
.br
.RS
.TP
Types
EventMgrRef = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
Handler = Module | {Module, Id}
.br
Module = atom()
.br
Id = term()
.br
Request = term()
.br
Timeout = int()>0 | infinity
.br
Result = Reply | {error, Error}
.br
Reply = term()
.br
Error = bad_module | {\&'EXIT\&', Reason} | term()
.br
Reason = term()
.br
.RE
.RS
.LP
Makes a synchronous call to the event handler \fIHandler\fR installed in the event manager \fIEventMgrRef\fR by sending a request and waiting until a reply arrives or a timeout occurs\&. The event manager will call \fIModule:handle_call/2\fR to handle the request\&.
.LP
See \fIadd_handler/3\fR for a description of \fIEventMgrRef\fR and \fIHandler\fR\&.
.LP
\fIRequest\fR is an arbitrary term which is passed as one of the arguments to \fIModule:handle_call/2\fR\&.
.LP
\fITimeout\fR is an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom \fIinfinity\fR to wait indefinitely\&. Default value is 5000\&. If no reply is received within the specified time, the function call fails\&.
.LP
The return value \fIReply\fR is defined in the return value of \fIModule:handle_call/2\fR\&. If the specified event handler is not installed, the function returns \fI{error, bad_module}\fR\&. If the callback function fails with \fIReason\fR or returns an unexpected value \fITerm\fR, this function returns \fI{error, {\&'EXIT\&', Reason}}\fR or \fI{error, Term}\fR, respectively\&.
.RE
.LP
.B
delete_handler(EventMgrRef, Handler, Args) -> Result
.br
.RS
.TP
Types
EventMgrRef = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
Handler = Module | {Module, Id}
.br
Module = atom()
.br
Id = term()
.br
Args = term()
.br
Result = term() | {error, module_not_found} | {\&'EXIT\&', Reason}
.br
Reason = term()
.br
.RE
.RS
.LP
Deletes an event handler from the event manager \fIEventMgrRef\fR\&. The event manager will call \fIModule:terminate/2\fR to terminate the event handler\&.
.LP
See \fIadd_handler/3\fR for a description of \fIEventMgrRef\fR and \fIHandler\fR\&.
.LP
\fIArgs\fR is an arbitrary term which is passed as one of the arguments to \fIModule:terminate/2\fR\&.
.LP
The return value is the return value of \fIModule:terminate/2\fR\&. If the specified event handler is not installed, the function returns \fI{error, module_not_found}\fR\&. If the callback function fails with \fIReason\fR, the function returns \fI{\&'EXIT\&', Reason}\fR\&.
.RE
.LP
.B
swap_handler(EventMgrRef, {Handler1,Args1}, {Handler2,Args2}) -> Result
.br
.RS
.TP
Types
EventMgrRef = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
Handler1 = Handler2 = Module | {Module, Id}
.br
Module = atom()
.br
Id = term()
.br
Args1 = Args2 = term()
.br
Result = ok | {error, Error}
.br
Error = {\&'EXIT\&', Reason} | term()
.br
Reason = term()
.br
.RE
.RS
.LP
Replaces an old event handler with a new event handler in the event manager \fIEventMgrRef\fR\&.
.LP
See \fIadd_handler/3\fR for a description of the arguments\&.
.LP
First the old event handler \fIHandler1\fR is deleted\&. The event manager calls \fIModule1:terminate(Args1, \&.\&.\&.)\fR, where \fIModule1\fR is the callback module of \fIHandler1\fR, and collects the return value\&.
.LP
Then the new event handler \fIHandler2\fR is added and initiated by calling \fIModule2:init({Args2, Term})\fR, where \fIModule2\fR is the callback module of \fIHandler2\fR and \fITerm\fR the return value of \fIModule1:terminate/2\fR\&. This makes it possible to transfer information from \fIHandler1\fR to \fIHandler2\fR\&.
.LP
The new handler will be added even if the the specified old event handler is not installed in which case \fITerm=error\fR, or if \fIModule1:terminate/2\fR fails with \fIReason\fR in which case \fITerm={\&'EXIT\&', Reason}\fR\&. The old handler will be deleted even if \fIModule2:init/1\fR fails\&.
.LP
If there was a supervised connection between \fIHandler1\fR and a process \fIPid\fR, there will be a supervised connection between \fIHandler2\fR and \fIPid\fR instead\&.
.LP
If \fIModule2:init/1\fR returns a correct value, this function returns \fIok\fR\&. If \fIModule2:init/1\fR fails with \fIReason\fR or returns an unexpected value \fITerm\fR, this this function returns \fI{error, {\&'EXIT\&', Reason}}\fR or \fI{error, Term}\fR, respectively\&.
.RE
.LP
.B
swap_sup_handler(EventMgrRef, {Handler1,Args1}, {Handler2,Args2}) -> Result
.br
.RS
.TP
Types
EventMgrRef = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
Handler1 = Handler 2 = Module | {Module, Id}
.br
Module = atom()
.br
Id = term()
.br
Args1 = Args2 = term()
.br
Result = ok | {error, Error}
.br
Error = {\&'EXIT\&', Reason} | term()
.br
Reason = term()
.br
.RE
.RS
.LP
Replaces an event handler in the event manager \fIEventMgrRef\fR in the same way as \fIswap_handler/3\fR but will also supervise the connection between \fIHandler2\fR and the calling process\&.
.LP
See \fIswap_handler/3\fR for a description of the arguments and return values\&.
.RE
.LP
.B
which_handlers(EventMgrRef) -> [Handler]
.br
.RS
.TP
Types
EventMgrRef = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
Handler = Module | {Module, Id}
.br
Module = atom()
.br
Id = term()
.br
.RE
.RS
.LP
Returns a list of all event handlers installed in the event manager \fIEventMgrRef\fR\&.
.LP
See \fIadd_handler/3\fR for a description of \fIEventMgrRef\fR and \fIHandler\fR\&.
.RE
.LP
.B
stop(EventMgrRef) -> ok
.br
.RS
.TP
Types
EventMgrRef = Name | {Name, Node} | {global, Name} | pid()
.br
Name = Node = atom()
.br
.RE
.RS
.LP
Terminates the event manager \fIEventMgrRef\fR\&. Before terminating, the event manager will call \fIModule:terminate(stop, \&.\&.\&.)\fR for each installed event handler\&.
.LP
See \fIadd_handler/3\fR for a description of the argument\&.
.RE
.SH CALLBACK FUNCTIONS
.LP
The following functions should be exported from a \fIgen_event\fR callback module\&.
.SH EXPORTS
.LP
.B
Module:init(InitArgs) -> {ok,State} | {ok,State,hibernate}
.br
.RS
.TP
Types
InitArgs = Args | {Args, Term}
.br
Args = Term = term()
.br
State = term()
.br
.RE
.RS
.LP
Whenever a new event handler is added to an event manager, this function is called to initialize the event handler\&.
.LP
If the event handler is added due to a call to \fIgen_event:add_handler/3\fR or \fIgen_event:add_sup_handler/3\fR, \fIInitArgs\fR is the \fIArgs\fR argument of these functions\&.
.LP
If the event handler is replacing another event handler due to a call to \fIgen_event:swap_handler/3\fR or \fIgen_event:swap_sup_handler/3\fR, or due to a \fIswap\fR return tuple from one of the other callback functions, \fIInitArgs\fR is a tuple \fI{Args, Term}\fR where \fIArgs\fR is the argument provided in the function call/return tuple and \fITerm\fR is the result of terminating the old event handler, see \fIgen_event:swap_handler/3\fR\&.
.LP
The function should return \fI{ok, State}\fR or \fI{ok, State, hibernate}\fR where \fIState\fR is the initial internal state of the event handler\&.
.LP
If \fI{ok, State, hibernate}\fR is returned, the event manager will go into hibernation (by calling proc_lib:hibernate/3), waiting for the next event to occur\&.
.RE
.LP
.B
Module:handle_event(Event, State) -> Result
.br
.RS
.TP
Types
Event = term()
.br
State = term()
.br
Result = {ok, NewState} | {ok, NewState, hibernate}
.br
| {swap_handler, Args1, NewState, Handler2, Args2} | remove_handler
.br
NewState = term()
.br
Args1 = Args2 = term()
.br
Handler2 = Module2 | {Module2, Id}
.br
Module2 = atom()
.br
Id = term()
.br
.RE
.RS
.LP
Whenever an event manager receives an event sent using \fIgen_event:notify/2\fR or \fIgen_event:sync_notify/2\fR, this function is called for each installed event handler to handle the event\&.
.LP
\fIEvent\fR is the \fIEvent\fR argument of \fInotify\fR/\fIsync_notify\fR\&.
.LP
\fIState\fR is the internal state of the event handler\&.
.LP
If the function returns \fI{ok, NewState}\fR or \fI{ok, NewState, hibernate}\fR the event handler will remain in the event manager with the possible updated internal state \fINewState\fR\&.
.LP
If \fI{ok, NewState, hibernate}\fR is returned, the event manager will also go into hibernation (by calling proc_lib:hibernate/3), waiting for the next event to occur\&. It is sufficient that one of the event handlers return \fI{ok, NewState, hibernate}\fR for the whole event manager process to hibernate\&.
.LP
If the function returns \fI{swap_handler, Args1, NewState, Handler2, Args2}\fR the event handler will be replaced by \fIHandler2\fR by first calling \fIModule:terminate(Args1, NewState)\fR and then \fIModule2:init({Args2, Term})\fR where \fITerm\fR is the return value of \fIModule:terminate/2\fR\&. See \fIgen_event:swap_handler/3\fR for more information\&.
.LP
If the function returns \fIremove_handler\fR the event handler will be deleted by calling \fIModule:terminate(remove_handler, State)\fR\&.
.RE
.LP
.B
Module:handle_call(Request, State) -> Result
.br
.RS
.TP
Types
Request = term()
.br
State = term()
.br
Result = {ok, Reply, NewState} | {ok, Reply, NewState, hibernate}
.br
| {swap_handler, Reply, Args1, NewState, Handler2, Args2}
.br
| {remove_handler, Reply}
.br
Reply = term()
.br
NewState = term()
.br
Args1 = Args2 = term()
.br
Handler2 = Module2 | {Module2, Id}
.br
Module2 = atom()
.br
Id = term()
.br
.RE
.RS
.LP
Whenever an event manager receives a request sent using \fIgen_event:call/3, 4\fR, this function is called for the specified event handler to handle the request\&.
.LP
\fIRequest\fR is the \fIRequest\fR argument of \fIcall\fR\&.
.LP
\fIState\fR is the internal state of the event handler\&.
.LP
The return values are the same as for \fIhandle_event/2\fR except they also contain a term \fIReply\fR which is the reply given back to the client as the return value of \fIcall\fR\&.
.RE
.LP
.B
Module:handle_info(Info, State) -> Result
.br
.RS
.TP
Types
Info = term()
.br
State = term()
.br
Result = {ok, NewState} | {ok, NewState, hibernate}
.br
| {swap_handler, Args1, NewState, Handler2, Args2} | remove_handler
.br
NewState = term()
.br
Args1 = Args2 = term()
.br
Handler2 = Module2 | {Module2, Id}
.br
Module2 = atom()
.br
Id = term()
.br
.RE
.RS
.LP
This function is called for each installed event handler when an event manager receives any other message than an event or a synchronous request (or a system message)\&.
.LP
\fIInfo\fR is the received message\&.
.LP
See \fIModule:handle_event/2\fR for a description of State and possible return values\&.
.RE
.LP
.B
Module:terminate(Arg, State) -> term()
.br
.RS
.TP
Types
Arg = Args | {stop, Reason} | stop | remove_handler
.br
| {error, {\&'EXIT\&', Reason}} | {error, Term}
.br
Args = Reason = Term = term()
.br
.RE
.RS
.LP
Whenever an event handler is deleted from an event manager, this function is called\&. It should be the opposite of \fIModule:init/1\fR and do any necessary cleaning up\&.
.LP
If the event handler is deleted due to a call to \fIgen_event:delete_handler\fR, \fIgen_event:swap_handler/3\fR or \fIgen_event:swap_sup_handler/3\fR, \fIArg\fR is the \fIArgs\fR argument of this function call\&.
.LP
\fIArg={stop, Reason}\fR if the event handler has a supervised connection to a process which has terminated with reason \fIReason\fR\&.
.LP
\fIArg=stop\fR if the event handler is deleted because the event manager is terminating\&.
.LP
\fIArg=remove_handler\fR if the event handler is deleted because another callback function has returned \fIremove_handler\fR or \fI{remove_handler, Reply}\fR\&.
.LP
\fIArg={error, Term}\fR if the event handler is deleted because a callback function returned an unexpected value \fITerm\fR, or \fIArg={error, {\&'EXIT\&', Reason}}\fR if a callback function failed\&.
.LP
\fIState\fR is the internal state of the event handler\&.
.LP
The function may return any term\&. If the event handler is deleted due to a call to \fIgen_event:delete_handler\fR, the return value of that function will be the return value of this function\&. If the event handler is to be replaced with another event handler due to a swap, the return value will be passed to the \fIinit\fR function of the new event handler\&. Otherwise the return value is ignored\&.
.RE
.LP
.B
Module:code_change(OldVsn, State, Extra) -> {ok, NewState}
.br
.RS
.TP
Types
OldVsn = Vsn | {down, Vsn}
.br
Vsn = term()
.br
State = NewState = term()
.br
Extra = term()
.br
.RE
.RS
.LP
This function is called for an installed event handler which should update its internal state during a release upgrade/downgrade, i\&.e\&. when the instruction \fI{update, Module, Change, \&.\&.\&.}\fR where \fIChange={advanced, Extra}\fR is given in the \fI\&.appup\fR file\&. See \fIOTP Design Principles\fR for more information\&.
.LP
In the case of an upgrade, \fIOldVsn\fR is \fIVsn\fR, and in the case of a downgrade, \fIOldVsn\fR is \fI{down, Vsn}\fR\&. \fIVsn\fR is defined by the \fIvsn\fR attribute(s) of the old version of the callback module \fIModule\fR\&. If no such attribute is defined, the version is the checksum of the BEAM file\&.
.LP
\fIState\fR is the internal state of the event handler\&.
.LP
\fIExtra\fR is passed as-is from the \fI{advanced, Extra}\fR part of the update instruction\&.
.LP
The function should return the updated internal state\&.
.RE
.SH SEE ALSO
.LP
supervisor(3), sys(3)
|