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
|
<HTML>
<HEAD>
<!-- refpage -->
<TITLE>gen_event</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Erlang Systems]" SRC="min_head.gif"></A>
<H1>gen_event</H1>
</CENTER>
<H3>MODULE</H3>
<UL>
gen_event</UL>
<H3>MODULE SUMMARY</H3>
<UL>
Generic Event Handling Behaviour</UL>
<H3>DESCRIPTION</H3>
<UL>
<P>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.<P> 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 <STRONG>OTP Design Principles</STRONG> for more information.<P>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:<PRE>gen_event module Callback module
--------------- -------------
gen_event:start -----> -
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
</PRE>
<P>Since each event handler is one callback module, an event manager
will have several callback modules which are added and deleted
dynamically. Therefore <CODE>gen_event</CODE> is more tolerant of callback
module errors than the other behaviours. If a callback function for
an installed event handler fails with <CODE>Reason</CODE>, or returns a
bad value <CODE>Term</CODE>, the event manager will not fail. It will delete
the event handler by calling the callback function
<CODE>Module:terminate/2</CODE> (see below), giving as argument
<CODE>{error,{'EXIT',Reason}}</CODE> or <CODE>{error,Term}</CODE>, respectively.
No other event handler will be affected.<P>The <CODE>sys</CODE> module can be used for debugging an event manager.<P>Note that an event manager <STRONG>does</STRONG> trap exit signals
automatically.
<P>Unless otherwise stated, all functions in this module fail if
the specified event manager does not exist or if bad arguments are
given.</UL>
<H3>EXPORTS</H3>
<P><A NAME="start%0"><STRONG><CODE>start() -> Result</CODE></STRONG></A><BR>
<A NAME="start%1"><STRONG><CODE>start(EventMgrName) -> Result</CODE></STRONG></A><BR>
<A NAME="start_link%0"><STRONG><CODE>start_link() -> Result</CODE></STRONG></A><BR>
<A NAME="start_link%1"><STRONG><CODE>start_link(EventMgrName) -> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgrName = {local,Name} | {global,Name}</CODE></STRONG><BR>
<STRONG><CODE> Name = atom()</CODE></STRONG><BR>
<STRONG><CODE>Result = {ok,Pid} | {error,{already_started,Pid}}</CODE></STRONG><BR>
<STRONG><CODE> Pid = pid()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates an event manager.<P>An event manager started using <CODE>start_link</CODE> is linked to
the calling process. This function must be used if the event
manager is included in a supervision tree. An event manager started
using <CODE>start</CODE> is not linked to the calling process.<P>If <CODE>EventMgrName={local,Name}</CODE>, the event manager is
registered locally as <CODE>Name</CODE> using <CODE>register/2</CODE>.
If <CODE>EventMgrName={global,Name}</CODE>, the event manager is
registered globally as <CODE>Name</CODE> using
<CODE>global:register_name/2</CODE>. If no name is provided, the event
manager is not registered.<P>If the event manager is successfully created the function
returns <CODE>{ok,Pid}</CODE>, where <CODE>Pid</CODE> is the pid of the event
manager. If there already exists a process with the specified
<CODE>EventMgrName</CODE> the function returns
<CODE>{error,{already_started,Pid}}</CODE>, where <CODE>Pid</CODE> is the pid
of that process.</UL>
<P><A NAME="add_handler%3"><STRONG><CODE>add_handler(EventMgrRef, Handler, Args) -> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgr = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE> Name = Node = atom()</CODE></STRONG><BR>
<STRONG><CODE>Handler = Module | {Module,Id}</CODE></STRONG><BR>
<STRONG><CODE> Module = atom()</CODE></STRONG><BR>
<STRONG><CODE> Id = term()</CODE></STRONG><BR>
<STRONG><CODE>Args = term()</CODE></STRONG><BR>
<STRONG><CODE>Result = ok | {'EXIT',Reason} | term()</CODE></STRONG><BR>
<STRONG><CODE> Reason = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Adds a new event handler to the event manager <CODE>EventMgrRef</CODE>.
The event manager will call <CODE>Module:init/1</CODE> to initiate
the event handler and its internal state.<P><CODE>EventMgrRef</CODE> can be:<P><UL>
<LI>the pid,</LI><BR>
<LI><CODE>Name</CODE>, if the event manager is locally registered,
</LI><BR>
<LI><CODE>{Name,Node}</CODE>, if the event manager is locally
registered at another node, or</LI><BR>
<LI><CODE>{global,Name}</CODE>, if the event manager is globally
registered.</LI><BR>
</UL>
<P><CODE>Handler</CODE> is the name of the callback module <CODE>Module</CODE> or
a tuple <CODE>{Module,Id}</CODE>, where <CODE>Id</CODE> is any term.
The <CODE>{Module,Id}</CODE> representation makes it possible to
identify a specific event handler when there are several event
handlers using the same callback module.<P><CODE>Args</CODE> is an arbitrary term which is passed as the argument
to <CODE>Module:init/1</CODE>.<P>If <CODE>Module:init/1</CODE> returns a correct value, the event
manager adds the event handler and this function returns
<CODE>ok</CODE>. If <CODE>Module:init/1</CODE> fails with <CODE>Reason</CODE> or
returns an unexpected value <CODE>Term</CODE>, the event handler is
ignored and this function returns <CODE>{'EXIT',Reason}</CODE> or
<CODE>Term</CODE>, respectively.</UL>
<P><A NAME="add_sup_handler%3"><STRONG><CODE>add_sup_handler(EventMgrRef, Handler, Args) -> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgr = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE> Name = Node = atom()</CODE></STRONG><BR>
<STRONG><CODE>Handler = Module | {Module,Id}</CODE></STRONG><BR>
<STRONG><CODE> Module = atom()</CODE></STRONG><BR>
<STRONG><CODE> Id = term()</CODE></STRONG><BR>
<STRONG><CODE>Args = term()</CODE></STRONG><BR>
<STRONG><CODE>Result = ok | {'EXIT',Reason} | term()</CODE></STRONG><BR>
<STRONG><CODE> Reason = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Adds a new event handler in the same way as <CODE>add_handler/3</CODE>
but will also supervise the connection between the event handler
and the calling process.<P><UL>
<LI>If the calling process later terminates with <CODE>Reason</CODE>,
the event manager will delete the event handler by calling
<CODE>Module:terminate/2</CODE> with <CODE>{stop,Reason}</CODE> as argument.
</LI><BR>
<LI>If the event handler later is deleted, the event manager
sends a message<CODE>{gen_event_EXIT,Handler,Reason}</CODE> to
the calling process. <CODE>Reason</CODE> is one of the following:
<UL>
<LI> <CODE>normal</CODE>, if the event handler has been removed due to a
call to <CODE>delete_handler/3</CODE>, or <CODE>remove_handler</CODE>
has been returned by a callback function (see below).
</LI><BR>
<LI> <CODE>shutdown</CODE>, if the event handler has been removed
because the event manager is terminating.
</LI><BR>
<LI> <CODE>{swapped,NewHandler,Pid}</CODE>, if the process <CODE>Pid</CODE>
has replaced the event handler with another event handler
<CODE>NewHandler</CODE> using a call to <CODE>swap_handler/3</CODE> or
<CODE>swap_sup_handler/3</CODE>.
</LI><BR>
<LI> a term, if the event handler is removed due to an error.
Which term depends on the error.
</LI><BR>
</UL>
</LI><BR>
</UL>
<P>See <CODE>add_handler/3</CODE> for a description of the arguments
and return values.</UL>
<P><A NAME="notify%2"><STRONG><CODE>notify(EventMgrRef, Event) -> ok</CODE></STRONG></A><BR>
<A NAME="sync_notify%2"><STRONG><CODE>sync_notify(EventMgrRef, Event) -> ok</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgrRef = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE> Name = Node = atom()</CODE></STRONG><BR>
<STRONG><CODE>Event = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Sends an event notification to the event manager
<CODE>EventMgrRef</CODE>. The event manager will call
<CODE>Module:handle_event/2</CODE> for each installed event handler to
handle the event.<P><CODE>notify</CODE> is asynchronous and will return immediately after
the event notification has been sent. <CODE>sync_notify</CODE> is
synchronous in the sense that it will return <CODE>ok</CODE> after
the event has been handled by all event handlers.<P>See <CODE>add_handler/3</CODE> for a description of <CODE>EventMgrRef</CODE>.
<P><CODE>Event</CODE> is an arbitrary term which is passed as one of
the arguments to <CODE>Module:handle_event/2</CODE>.<P><CODE>notify</CODE> will not fail even if the specified event manager
does not exist, unless it is specified as <CODE>Name</CODE>.
</UL>
<P><A NAME="call%3"><STRONG><CODE>call(EventMgrRef, Handler, Request) -> Result</CODE></STRONG></A><BR>
<A NAME="call%4"><STRONG><CODE>call(EventMgrRef, Handler, Request, Timeout) -> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgrRef = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE> Name = Node = atom()</CODE></STRONG><BR>
<STRONG><CODE>Handler = Module | {Module,Id}</CODE></STRONG><BR>
<STRONG><CODE> Module = atom()</CODE></STRONG><BR>
<STRONG><CODE> Id = term()</CODE></STRONG><BR>
<STRONG><CODE>Request = term()</CODE></STRONG><BR>
<STRONG><CODE>Timeout = int()>0 | infinity</CODE></STRONG><BR>
<STRONG><CODE>Result = Reply | {error,Error}</CODE></STRONG><BR>
<STRONG><CODE> Reply = term()</CODE></STRONG><BR>
<STRONG><CODE> Error = bad_module | {'EXIT',Reason} | term()</CODE></STRONG><BR>
<STRONG><CODE>  Reason = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Makes a synchronous call to the event handler <CODE>Handler</CODE>
installed in the event manager <CODE>EventMgrRef</CODE> by sending a
request and waiting until a reply arrives or a timeout occurs.
The event manager will call <CODE>Module:handle_call/2</CODE> to handle
the request.<P>See <CODE>add_handler/3</CODE> for a description of <CODE>EventMgrRef</CODE>
and <CODE>Handler</CODE>.<P><CODE>Request</CODE> is an arbitrary term which is passed as one of
the arguments to <CODE>Module:handle_call/2</CODE>.<P><CODE>Timeout</CODE> is an integer greater than zero which specifies
how many milliseconds to wait for a reply, or the atom
<CODE>infinity</CODE> to wait indefinitely. Default value is 5000.
If no reply is received within the specified time, the function
call fails.<P>The return value <CODE>Reply</CODE> is defined in the return value of
<CODE>Module:handle_call/2</CODE>. If the specified event handler is not
installed, the function returns <CODE>{error,bad_module}</CODE>. If
the callback function fails with <CODE>Reason</CODE> or returns an
unexpected value <CODE>Term</CODE>, this function returns
<CODE>{error,{'EXIT',Reason}}</CODE> or <CODE>{error,Term}</CODE>,
respectively.</UL>
<P><A NAME="delete_handler%3"><STRONG><CODE>delete_handler(EventMgrRef, Handler, Args) -> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgrRef = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE> Name = Node = atom()</CODE></STRONG><BR>
<STRONG><CODE>Handler = Module | {Module,Id}</CODE></STRONG><BR>
<STRONG><CODE> Module = atom()</CODE></STRONG><BR>
<STRONG><CODE> Id = term()</CODE></STRONG><BR>
<STRONG><CODE>Args = term()</CODE></STRONG><BR>
<STRONG><CODE>Result = term() | {error,module_not_found} | {'EXIT',Reason}</CODE></STRONG><BR>
<STRONG><CODE> Reason = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Deletes an event handler from the event manager
<CODE>EventMgrRef</CODE>. The event manager will call
<CODE>Module:terminate/2</CODE> to terminate the event handler.<P>See <CODE>add_handler/3</CODE> for a description of <CODE>EventMgrRef</CODE>
and <CODE>Handler</CODE>.<P><CODE>Args</CODE> is an arbitrary term which is passed as one of
the arguments to <CODE>Module:terminate/2</CODE>.<P>The return value is the return value of <CODE>Module:terminate/2</CODE>.
If the specified event handler is not installed, the function
returns <CODE>{error,module_not_found}</CODE>. If the callback function
fails with <CODE>Reason</CODE>, the function returns
<CODE>{'EXIT',Reason}</CODE>.</UL>
<P><A NAME="swap_handler%5"><STRONG><CODE>swap_handler(EventMgrRef, {Handler1,Args1}, {Handler2,Args2})
-> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgrRef = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE> Name = Node = atom()</CODE></STRONG><BR>
<STRONG><CODE>Handler1 = Handler2 = Module | {Module,Id}</CODE></STRONG><BR>
<STRONG><CODE> Module = atom()</CODE></STRONG><BR>
<STRONG><CODE> Id = term()</CODE></STRONG><BR>
<STRONG><CODE>Args1 = Args2 = term()</CODE></STRONG><BR>
<STRONG><CODE>Result = ok | {error,Error}</CODE></STRONG><BR>
<STRONG><CODE> Error = {'EXIT',Reason} | term()</CODE></STRONG><BR>
<STRONG><CODE>  Reason = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Replaces an old event handler with a new event handler in
the event manager <CODE>EventMgrRef</CODE>.<P>See <CODE>add_handler/3</CODE> for a description of the arguments.<P>First the old event handler <CODE>Handler1</CODE> is deleted.
The event manager calls <CODE>Module1:terminate(Args1, ...)</CODE>,
where <CODE>Module1</CODE> is the callback module of <CODE>Handler1</CODE>,
and collects the return value.<P>Then the new event handler <CODE>Handler2</CODE> is added and initiated
by calling <CODE>Module2:init({Args2,Term})</CODE>, where <CODE>Module2</CODE>
is the callback module of <CODE>Handler2</CODE> and <CODE>Term</CODE>
the return value of <CODE>Module1:terminate/2</CODE>. This makes it
possible to transfer information from <CODE>Handler1</CODE> to
<CODE>Handler2</CODE>.<P>The new handler will be added even if the the specified old event
handler is not installed in which case <CODE>Term=error</CODE>, or if
<CODE>Module1:terminate/2</CODE> fails with <CODE>Reason</CODE> in which case
<CODE>Term={'EXIT',Reason}</CODE>.
The old handler will be deleted even if <CODE>Module2:init/1</CODE>
fails.<P>If there was a supervised connection between <CODE>Handler1</CODE> and
a process <CODE>Pid</CODE>, there will be a supervised connection
between <CODE>Handler2</CODE> and <CODE>Pid</CODE> instead.<P>If <CODE>Module2:init/1</CODE> returns a correct value, this function
returns <CODE>ok</CODE>. If <CODE>Module2:init/1</CODE> fails with
<CODE>Reason</CODE> or returns an unexpected value <CODE>Term</CODE>, this
this function returns <CODE>{error,{'EXIT',Reason}}</CODE> or
<CODE>{error,Term}</CODE>, respectively.</UL>
<P><A NAME="swap_sup_handler%5"><STRONG><CODE>swap_sup_handler(EventMgrRef, {Handler1,Args1}, {Handler2,Args2})
-> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgrRef = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE> Name = Node = atom()</CODE></STRONG><BR>
<STRONG><CODE>Handler1 = Handler 2 = Module | {Module,Id}</CODE></STRONG><BR>
<STRONG><CODE> Module = atom()</CODE></STRONG><BR>
<STRONG><CODE> Id = term()</CODE></STRONG><BR>
<STRONG><CODE>Args1 = Args2 = term()</CODE></STRONG><BR>
<STRONG><CODE>Result = ok | {error,Error}</CODE></STRONG><BR>
<STRONG><CODE> Error = {'EXIT',Reason} | term()</CODE></STRONG><BR>
<STRONG><CODE>  Reason = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Replaces an event handler in the event manager <CODE>EventMgrRef</CODE>
in the same way as <CODE>swap_handler/3</CODE> but will also supervise
the connection between <CODE>Handler2</CODE> and the calling process.<P>See <CODE>swap_handler/3</CODE> for a description of the arguments
and return values.</UL>
<P><A NAME="which_handlers%1"><STRONG><CODE>which_handlers(EventMgrRef) -> [Handler]</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgrRef = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE> Name = Node = atom()</CODE></STRONG><BR>
<STRONG><CODE>Handler = Module | {Module,Id}</CODE></STRONG><BR>
<STRONG><CODE> Module = atom()</CODE></STRONG><BR>
<STRONG><CODE> Id = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a list of all event handlers installed in the event
manager <CODE>EventMgrRef</CODE>.<P>See <CODE>add_handler/3</CODE> for a description of <CODE>EventMgrRef</CODE>
and <CODE>Handler</CODE>.</UL>
<P><A NAME="stop%1"><STRONG><CODE>stop(EventMgrRef) -> ok</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>EventMgrRef = Name | {Name,Node} | {global,Name} | pid()</CODE></STRONG><BR>
<STRONG><CODE>Name = Node = atom()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Terminates the event manager <CODE>EventMgrRef</CODE>. Before
terminating, the event manager will call
<CODE>Module:terminate(stop,...)</CODE> for each installed event
handler.<P>See <CODE>add_handler/3</CODE> for a description of the argument.</UL>
<H3>CALLBACK FUNCTIONS</H3>
<UL>
<P>The following functions should be exported from a <CODE>gen_event</CODE>
callback module.</UL>
<H3>EXPORTS</H3>
<P><A NAME="Module:init%1"><STRONG><CODE>Module:init(InitArgs) -> {ok,State}</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>InitArgs = Args | {Args,Term}</CODE></STRONG><BR>
<STRONG><CODE> Args = Term = term()</CODE></STRONG><BR>
<STRONG><CODE>State = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Whenever a new event handler is added to an event manager,
this function is called to initialize the event handler.<P>If the event handler is added due to a call to
<CODE>gen_event:add_handler/3</CODE> or
<CODE>gen_event:add_sup_handler/3</CODE>, <CODE>InitArgs</CODE> is
the <CODE>Args</CODE> argument of these functions.<P>If the event handler is replacing another event handler due to
a call to <CODE>gen_event:swap_handler/3</CODE> or
<CODE>gen_event:swap_sup_handler/3</CODE>, or due to a <CODE>swap</CODE>
return tuple from one of the other callback functions,
<CODE>InitArgs</CODE> is a tuple <CODE>{Args,Term}</CODE> where <CODE>Args</CODE> is
the argument provided in the function call/return tuple and
<CODE>Term</CODE> is the result of terminating the old event handler,
see <CODE>gen_event:swap_handler/3</CODE>.<P>The function should return <CODE>{ok,State}</CODE> where <CODE>State</CODE>
is the initial internal state of the event handler.</UL>
<P><A NAME="Module:handle_event%2"><STRONG><CODE>Module:handle_event(Event, State) -> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Event = term()</CODE></STRONG><BR>
<STRONG><CODE>State = term()</CODE></STRONG><BR>
<STRONG><CODE>Result = {ok,NewState}</CODE></STRONG><BR>
<STRONG><CODE> | {swap_handler,Args1,NewState,Handler2,Args2} |
remove_handler</CODE></STRONG><BR>
<STRONG><CODE> NewState = term()</CODE></STRONG><BR>
<STRONG><CODE> Args1 = Args2 = term()</CODE></STRONG><BR>
<STRONG><CODE> Handler2 = Module2 | {Module2,Id}</CODE></STRONG><BR>
<STRONG><CODE>  Module2 = atom()</CODE></STRONG><BR>
<STRONG><CODE>  Id = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Whenever an event manager receives an event sent using
<CODE>gen_event:notify/2</CODE> or <CODE>gen_event:sync_notify/2</CODE>, this
function is called for each installed event handler to handle
the event.<P><CODE>Event</CODE> is the <CODE>Event</CODE> argument of
<CODE>notify</CODE>/<CODE>sync_notify</CODE>.<P><CODE>State</CODE> is the internal state of the event handler.<P>If the function returns <CODE>{ok,NewState}</CODE> the event handler
will remain in the event manager with the possible updated
internal state <CODE>NewState</CODE>.<P>If the function returns
<CODE>{swap_handler,Args1,NewState,Handler2,Args2}</CODE> the event
handler will be replaced by <CODE>Handler2</CODE> by first calling
<CODE>Module:terminate(Args1,NewState)</CODE> and then
<CODE>Module2:init({Args2,Term})</CODE> where <CODE>Term</CODE> is the return
value of <CODE>Module:terminate/2</CODE>.
See <CODE>gen_event:swap_handler/3</CODE> for more information.<P>If the function returns <CODE>remove_handler</CODE> the event handler
will be deleted by calling
<CODE>Module:terminate(remove_handler,State)</CODE>.</UL>
<P><A NAME="Module:handle_call%2"><STRONG><CODE>Module:handle_call(Request, State) -> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Request = term()</CODE></STRONG><BR>
<STRONG><CODE>State = term()</CODE></STRONG><BR>
<STRONG><CODE>Result = {ok,Reply,NewState}</CODE></STRONG><BR>
<STRONG><CODE> | {swap_handler,Reply,Args1,NewState,Handler2,Args2}</CODE></STRONG><BR>
<STRONG><CODE> | {remove_handler, Reply}</CODE></STRONG><BR>
<STRONG><CODE> Reply = term()</CODE></STRONG><BR>
<STRONG><CODE> NewState = term()</CODE></STRONG><BR>
<STRONG><CODE> Args1 = Args2 = term()</CODE></STRONG><BR>
<STRONG><CODE> Handler2 = Module2 | {Module2,Id}</CODE></STRONG><BR>
<STRONG><CODE>  Module2 = atom()</CODE></STRONG><BR>
<STRONG><CODE>  Id = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Whenever an event manager receives a request sent using
<CODE>gen_event:call/3,4</CODE>, this function is called for
the specified event handler to handle the request.<P><CODE>Request</CODE> is the <CODE>Request</CODE> argument of <CODE>call</CODE>.<P><CODE>State</CODE> is the internal state of the event handler.<P>The return values are the same as for <CODE>handle_event/2</CODE>
except they also contain a term <CODE>Reply</CODE> which is the reply
given back to the client as the return value of <CODE>call</CODE>.</UL>
<P><A NAME="Module:handle_info%2"><STRONG><CODE>Module:handle_info(Info, State) -> Result</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Info = term()</CODE></STRONG><BR>
<STRONG><CODE>State = term()</CODE></STRONG><BR>
<STRONG><CODE>Result = {ok,NewState}</CODE></STRONG><BR>
<STRONG><CODE> | {swap_handler,Args1,NewState,Handler2,Args2} |
remove_handler</CODE></STRONG><BR>
<STRONG><CODE> NewState = term()</CODE></STRONG><BR>
<STRONG><CODE> Args1 = Args2 = term()</CODE></STRONG><BR>
<STRONG><CODE> Handler2 = Module2 | {Module2,Id}</CODE></STRONG><BR>
<STRONG><CODE>  Module2 = atom()</CODE></STRONG><BR>
<STRONG><CODE>  Id = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>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).<P><CODE>Info</CODE> is the received message.<P>See <CODE>Module:handle_event/2</CODE> for a description of State
and possible return values.</UL>
<P><A NAME="Module:terminate%2"><STRONG><CODE>Module:terminate(Arg, State) -> term()</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Arg = Args | {stop,Reason} | stop | remove_handler</CODE></STRONG><BR>
<STRONG><CODE> | {error,{'EXIT',Reason}} | {error,Term}</CODE></STRONG><BR>
<STRONG><CODE> Args = Reason = Term = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Whenever an event handler is deleted from an event manager,
this function is called. It should be the opposite of
<CODE>Module:init/1</CODE> and do any necessary cleaning up.<P>If the event handler is deleted due to a call to
<CODE>gen_event:delete_handler</CODE>, <CODE>gen_event:swap_handler/3</CODE>
or <CODE>gen_event:swap_sup_handler/3</CODE>, <CODE>Arg</CODE> is
the <CODE>Args</CODE> argument of this function call.<P><CODE>Arg={stop,Reason}</CODE> if the event handler has a supervised
connection to a process which has terminated with reason
<CODE>Reason</CODE>.<P><CODE>Arg=stop</CODE> if the event handler is deleted because
the event manager is terminating.<P><CODE>Arg=remove_handler</CODE> if the event handler is deleted because
another callback function has returned <CODE>remove_handler</CODE> or
<CODE>{remove_handler,Reply}</CODE>.<P><CODE>Arg={error,Term}</CODE> if the event handler is deleted because
a callback function returned an unexpected value <CODE>Term</CODE>,
or <CODE>Arg={error,{'EXIT',Reason}}</CODE> if a callback function
failed.<P><CODE>State</CODE> is the internal state of the event handler.<P>The function may return any term. If the event handler is
deleted due to a call to <CODE>gen_event:delete_handler</CODE>,
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 <CODE>init</CODE> function of the new event handler. Otherwise
the return value is ignored.</UL>
<P><A NAME="Module:code_change%3"><STRONG><CODE>Module:code_change(OldVsn, State, Extra) -> {ok, NewState}</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>OldVsn = undefined | term()</CODE></STRONG><BR>
<STRONG><CODE>State = NewState = term()</CODE></STRONG><BR>
<STRONG><CODE>Extra = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>This function is called for each installed event handler they
should update the internal state due to code replacement, i.e. when
the instruction
<CODE>{update,Module,Change,PrePurge,PostPurge,Modules</CODE> where
<CODE>Change={advanced,Extra}</CODE> has been given to the release
handler. See <STRONG>SASL User's Guide</STRONG> for more information.<P><CODE>OldVsn</CODE> is the <CODE>vsn</CODE> attribute of the old version of
the callback module <CODE>Module</CODE>, or <CODE>undefined</CODE> if no such
attribute is defined.<P><CODE>State</CODE> is the internal state of the event handler.<P><CODE>Extra</CODE> is the same as in the <CODE>{advanced,Extra}</CODE> part
of the update instruction.<P>The function should return <CODE>{ok,NewState}</CODE>, where
<CODE>NewState</CODE> is the updated internal state.</UL>
<H3>SEE ALSO</H3>
<UL>
<P>supervisor(3), sys(3)</UL>
<H3>AUTHORS</H3>
<UL>
Gunilla Hugosson - support@erlang.ericsson.se<BR>
</UL>
<CENTER>
<HR>
<FONT SIZE=-1>stdlib 1.10<BR>
Copyright © 1991-2001
<A HREF="http://www.erlang.se">Ericsson Utvecklings AB</A><BR>
<!--#include virtual="/ssi/otp_footer.html"-->
</FONT>
</CENTER>
</BODY>
</HTML>
|