#include <time.h>
#include "mn_agentadv.h"
#include "mn.h"
#include "hashtable.h"
Include dependency graph for mn_handler.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Data Structures | |
struct | handler |
struct | event_FA |
struct | event_INTERFACE |
Defines | |
#define | MICRO_SECONDS_TO_WAIT_INFO_REPLY 500000 |
#define | FA_ADV_EXPIRE 0 |
#define | FA_ADV_RECEIVE 1 |
#define | FA_GET 2 |
#define | INTERFACE_INIT 3 |
#define | INTERFACE_DOWN 4 |
Functions | |
int | handler_unregister (int event_type, int(*func)(void *data)) |
int | handler_register (int event_type, int(*func)(void *data)) |
int | handler_unregister_all (int event_type) |
int | handler_call_all (int event_type, void *data) |
int | mn_handlers_init (void) |
#define FA_ADV_EXPIRE 0 |
Definition at line 38 of file mn_handler.h.
Referenced by clean_agentadv(), clean_up(), event_type_str(), handler_call_all(), handler_register(), handler_unregister(), and handler_unregister_all().
#define FA_ADV_RECEIVE 1 |
Definition at line 39 of file mn_handler.h.
Referenced by clean_up(), event_type_str(), handler_call_all(), handler_register(), handler_unregister(), and handler_unregister_all().
#define FA_GET 2 |
Definition at line 40 of file mn_handler.h.
Referenced by clean_up(), event_type_str(), get_fa(), handler_call_all(), handler_register(), handler_unregister(), handler_unregister_all(), and mn_handlers_init().
#define INTERFACE_DOWN 4 |
Definition at line 49 of file mn_handler.h.
Referenced by clean_up(), event_type_str(), handler_call_all(), handler_register(), handler_unregister(), handler_unregister_all(), mn_handlers_init(), and MONITOR_register_module().
#define INTERFACE_INIT 3 |
Definition at line 48 of file mn_handler.h.
Referenced by clean_up(), event_type_str(), handler_call_all(), handler_register(), handler_unregister(), handler_unregister_all(), mn_handlers_init(), and MONITOR_register_module().
#define MICRO_SECONDS_TO_WAIT_INFO_REPLY 500000 |
Definition at line 29 of file mn_handler.h.
int handler_call_all | ( | int | event_type, | |
void * | data | |||
) |
Definition at line 487 of file mn_handler.c.
References DEBUG(), event_type_str(), FA_ADV_EXPIRE, FA_ADV_RECEIVE, FA_GET, handler::func, INTERFACE_DOWN, and INTERFACE_INIT.
Referenced by clean_agentadv(), and get_fa().
00488 { 00489 struct list *handlers; 00490 struct node *iterator; 00491 struct handler *p; 00492 int num = 0; 00493 int ret = 0; 00494 00495 switch (event_type) { 00496 case FA_ADV_RECEIVE: 00497 handlers = &fa_adv_rec_handlers; 00498 break; 00499 case FA_ADV_EXPIRE: 00500 handlers = &fa_adv_exp_handlers; 00501 break; 00502 case FA_GET: 00503 handlers = &fa_get_handlers; 00504 break; 00505 case INTERFACE_INIT: 00506 handlers = &interface_init_handlers; 00507 break; 00508 case INTERFACE_DOWN: 00509 handlers = &interface_down_handlers; 00510 break; 00511 default: 00512 DEBUG(DEBUG_HANDLERS, "handler_call_all: Unknown event " 00513 "type (%d)", event_type); 00514 return 2; 00515 } 00516 00517 iterator = list_get_first(handlers); 00518 while (iterator != NULL) { 00519 p = (struct handler *) iterator; 00520 if (p->func != NULL) { 00521 ret = (*p->func)(data); 00522 num++; 00523 if (ret == -1) { 00524 DEBUG(DEBUG_HANDLERS, "handler_call_all: " 00525 "handler returned -1. %d handlers " 00526 "called\n", num); 00527 return -1; 00528 } 00529 } 00530 iterator = list_get_next(iterator); 00531 } 00532 00533 DEBUG(DEBUG_HANDLERS, "handler_call_all: %d \"%s\" Event " 00534 "handlers called\n", num, event_type_str(event_type)); 00535 00536 return 0; 00537 }
Here is the call graph for this function:
int handler_register | ( | int | event_type, | |
int(*)(void *data) | func | |||
) |
Definition at line 340 of file mn_handler.c.
References DEBUG(), event_type_str(), FA_ADV_EXPIRE, FA_ADV_RECEIVE, FA_GET, INTERFACE_DOWN, and INTERFACE_INIT.
Referenced by mn_handlers_init(), and MONITOR_register_module().
00341 { 00342 static int inited = 0; 00343 struct handler *new; 00344 00345 /* Init all lists for now */ 00346 if (!inited) { 00347 init_handler_lists(); 00348 inited = 1; 00349 } 00350 00351 new = calloc(1, sizeof(struct handler)); 00352 if (new == NULL) { 00353 DEBUG(DEBUG_HANDLERS, "handler_register: calloc: %s", 00354 strerror(errno)); 00355 return 1; 00356 } 00357 00358 list_init_node(&new->listnode); 00359 new->func = func; 00360 00361 switch (event_type) { 00362 case FA_ADV_RECEIVE: 00363 list_add_tail(&fa_adv_rec_handlers, &new->listnode); 00364 break; 00365 case FA_ADV_EXPIRE: 00366 list_add_tail(&fa_adv_exp_handlers, &new->listnode); 00367 break; 00368 case FA_GET: 00369 list_add_tail(&fa_get_handlers, &new->listnode); 00370 break; 00371 case INTERFACE_INIT: 00372 list_add_tail(&interface_init_handlers, &new->listnode); 00373 break; 00374 case INTERFACE_DOWN: 00375 list_add_tail(&interface_down_handlers, &new->listnode); 00376 break; 00377 default: 00378 DEBUG(DEBUG_HANDLERS, "handler_register: Unknown event " 00379 "type (%d)\n", event_type); 00380 return 2; 00381 } 00382 00383 DEBUG(DEBUG_HANDLERS, "handler_register: \"%s\" Event handler " 00384 "registered\n", event_type_str(event_type)); 00385 00386 return 0; 00387 }
Here is the call graph for this function:
int handler_unregister | ( | int | event_type, | |
int(*)(void *data) | func | |||
) |
Definition at line 396 of file mn_handler.c.
References DEBUG(), event_type_str(), FA_ADV_EXPIRE, FA_ADV_RECEIVE, FA_GET, handler::func, INTERFACE_DOWN, and INTERFACE_INIT.
Referenced by handler_unregister_all().
00397 { 00398 struct list *handlers; 00399 struct node *iterator; 00400 struct handler *p; 00401 00402 switch (event_type) { 00403 case FA_ADV_RECEIVE: 00404 handlers = &fa_adv_rec_handlers; 00405 break; 00406 case FA_ADV_EXPIRE: 00407 handlers = &fa_adv_exp_handlers; 00408 break; 00409 case FA_GET: 00410 handlers = &fa_get_handlers; 00411 break; 00412 case INTERFACE_INIT: 00413 handlers = &interface_init_handlers; 00414 break; 00415 case INTERFACE_DOWN: 00416 handlers = &interface_down_handlers; 00417 break; 00418 default: 00419 DEBUG(DEBUG_HANDLERS, "handler_unregister: Unknown event type " 00420 "(%d)\n", event_type); 00421 return -2; 00422 } 00423 00424 iterator = list_get_first(handlers); 00425 while (iterator != NULL) { 00426 p = (struct handler *) iterator; 00427 if (p->func == func) { 00428 list_remove(iterator); 00429 DEBUG(DEBUG_HANDLERS, "handler_unregister: " 00430 "\"%s\" Event handler unregistered\n", 00431 event_type_str(event_type)); 00432 free(p); 00433 return 0; 00434 } 00435 iterator = list_get_next(iterator); 00436 } 00437 00438 /* List is empty or no such handler found */ 00439 return -1; 00440 }
Here is the call graph for this function:
int handler_unregister_all | ( | int | event_type | ) |
Definition at line 444 of file mn_handler.c.
References DEBUG(), FA_ADV_EXPIRE, FA_ADV_RECEIVE, FA_GET, handler::func, handler_unregister(), INTERFACE_DOWN, and INTERFACE_INIT.
Referenced by clean_up().
00445 { 00446 struct node *iterator; 00447 struct list *handlers; 00448 struct handler *p; 00449 int i = 0, r; 00450 00451 switch (event_type) { 00452 case FA_ADV_RECEIVE: 00453 handlers = &fa_adv_rec_handlers; 00454 break; 00455 case FA_ADV_EXPIRE: 00456 handlers = &fa_adv_exp_handlers; 00457 break; 00458 case FA_GET: 00459 handlers = &fa_get_handlers; 00460 break; 00461 case INTERFACE_INIT: 00462 handlers = &interface_init_handlers; 00463 break; 00464 case INTERFACE_DOWN: 00465 handlers = &interface_down_handlers; 00466 break; 00467 default: 00468 DEBUG(DEBUG_HANDLERS, "handler_unregister_all: Unknown event " 00469 "type (%d)\n", event_type); 00470 return -2; 00471 } 00472 00473 iterator = list_get_first(handlers); 00474 while (iterator != NULL) { 00475 p = (struct handler *) iterator; 00476 iterator = list_get_next(iterator); 00477 r = handler_unregister(event_type, p->func); 00478 if (!r) 00479 i++; 00480 } 00481 00482 return i; 00483 }
Here is the call graph for this function:
int mn_handlers_init | ( | void | ) |
Definition at line 540 of file mn_handler.c.
References DEBUG(), FA_GET, handler_register(), INTERFACE_DOWN, and INTERFACE_INIT.
Referenced by mn_init().
00541 { 00542 /* Register the MN default handler for FA selection (for now 00543 * must be the first one in the handler list) */ 00544 DEBUG(DEBUG_HANDLERS, "Register MN default FA_GET handler\n"); 00545 handler_register(FA_GET, mn_default_FA_GET_handler); 00546 00547 /* Register the MN default handler for interface initialization */ 00548 DEBUG(DEBUG_HANDLERS, "Register MN default INTERFACE_INIT handler\n"); 00549 handler_register(INTERFACE_INIT, mn_default_INTERFACE_INIT_handler); 00550 00551 /* Register the MN default handler for interface down event */ 00552 DEBUG(DEBUG_HANDLERS, "Register MN default INTERFACE_DOWN handler\n"); 00553 handler_register(INTERFACE_DOWN, mn_default_INTERFACE_DOWN_handler); 00554 00555 return 0; 00556 }
Here is the call graph for this function: