bool event_mobile_save(EVENT_DATA *event) { D_MOBILE *dMob; /* Check to see if there is an owner of this event. * If there is no owner, we return TRUE, because * it's the safest - and post a bug message. */ if ((dMob = event->owner.dMob) == NULL) { bug("event_mobile_save: no owner."); return TRUE; } /* save the actual player file */ save_player(dMob); /* enqueue a new event to save the pfile in 2 minutes */ event = alloc_event(); event->fun = &event_mobile_save; event->type = EVENT_MOBILE_SAVE; add_event_mobile(event, dMob, 2 * 60 * PULSES_PER_SECOND); return FALSE; }
inline EVENT_DATA *respawn_event( void ) { EVENT_DATA *event; event = alloc_event(); event->fun = &event_instance_respawn; event->type = EVENT_RESPAWN; return event; }
/* quick event creation */ inline EVENT_DATA *decay_event( void ) { EVENT_DATA *event; event = alloc_event(); event->fun = &event_instance_decay; event->type = EVENT_DECAY; return event; }
static void gen_disp_events(int *newval) { int i, pending; static int oldval[6] = {0, 0, 0, 0, 0, 0}; struct smag_event *newev; pending = 0; for(i=0; i<6; i++) { if(newval[i] == oldval[i]) { continue; } oldval[i] = newval[i]; newev = alloc_event(); if(newev) { newev->data.type = INP_MOTION; newev->data.idx = i; newev->data.val = newval[i]; newev->next = 0; if(input.evhead) { input.evtail->next = newev; input.evtail = newev; } else input.evhead = input.evtail = newev; pending = 1; } } if(pending) { newev = alloc_event(); if(newev) { newev->data.type = INP_FLUSH; newev->next = 0; } if(input.evhead) { input.evtail->next = newev; input.evtail = newev; } else { input.evhead = input.evtail = newev; } } }
/* function :: init_events_socket() * arguments :: the mobile * ====================================================== * this function should be called when a socket connects, * it will initialize all updating events for that socket. */ void init_events_socket(D_SOCKET *dSock) { EVENT_DATA *event; /* disconnect/idle */ event = alloc_event(); event->fun = &event_socket_idle; event->type = EVENT_SOCKET_IDLE; add_event_socket(event, dSock, 5 * 60 * PULSES_PER_SECOND); }
/* function :: init_events_mobile() * arguments :: the mobile * ====================================================== * this function should be called when a player is loaded, * it will initialize all updating events for that player. */ void init_events_player(D_MOBILE *dMob) { EVENT_DATA *event; /* save the player every 2 minutes */ event = alloc_event(); event->fun = &event_mobile_save; event->type = EVENT_MOBILE_SAVE; add_event_mobile(event, dMob, 2 * 60 * PULSES_PER_SECOND); }
BOOLEAN compdev_post_event_select_driver(PUSB_DEV_MANAGER dev_mgr, DEV_HANDLE dev_handle) { PUSB_EVENT pevent; BOOLEAN bret; PUSB_DEV pdev; USE_BASIC_NON_PENDING_IRQL; if (dev_mgr == NULL || dev_handle == 0) return FALSE; if (usb_query_and_lock_dev(dev_mgr, dev_handle, &pdev) != STATUS_SUCCESS) return FALSE; KeAcquireSpinLockAtDpcLevel(&dev_mgr->event_list_lock); lock_dev(pdev, TRUE); if (dev_state(pdev) == USB_DEV_STATE_ZOMB) { bret = FALSE; goto LBL_OUT; } pevent = alloc_event(&dev_mgr->event_pool, 1); if (pevent == NULL) { bret = FALSE; goto LBL_OUT; } pevent->flags = USB_EVENT_FLAG_ACTIVE; pevent->event = USB_EVENT_DEFAULT; pevent->pdev = pdev; pevent->context = 0; pevent->param = 0; pevent->pnext = 0; //vertical queue for serialized operation pevent->process_event = compdev_event_select_if_driver; pevent->process_queue = event_list_default_process_queue; InsertTailList(&dev_mgr->event_list, &pevent->event_link); KeSetEvent(&dev_mgr->wake_up_event, 0, FALSE); // wake up the dev_mgr_thread bret = TRUE; LBL_OUT: unlock_dev(pdev, TRUE); KeReleaseSpinLockFromDpcLevel(&dev_mgr->event_list_lock); usb_unlock_dev(pdev); return bret; }
bool event_game_tick(EVENT_DATA *event) { ITERATOR Iter; ENTITY_INSTANCE *instance; AttachIterator(&Iter, eInstances_list); while ((instance = (ENTITY_INSTANCE *) NextInList(&Iter)) != NULL) text_to_entity( instance, "Tick! The event queue is working.\r\n" ); DetachIterator(&Iter); event = alloc_event(); event->fun = &event_game_tick; event->type = EVENT_GAME_TICK; add_event_game(event, 10 * 60 * PULSES_PER_SECOND); return FALSE; }
static void gen_button_event(int button, int new_state) { struct smag_event *newev = alloc_event(); if(!newev) { return; } newev->data.type = INP_BUTTON; newev->data.idx = button; newev->data.val = new_state; newev->next = 0; if(input.evhead) { input.evtail->next = newev; input.evtail = newev; } else { input.evhead = input.evtail = newev; } }
/* event_game_tick is just to show how to make global events * which can be used to update the game. */ bool event_game_tick(EVENT_DATA *event) { ITERATOR Iter; D_MOBILE *dMob; /* send a tick message to everyone */ /* AttachIterator(&Iter, dmobile_list); while ((dMob = (D_MOBILE *) NextInList(&Iter)) != NULL) { text_to_mobile(dMob, "Tick!\n\r"); } DetachIterator(&Iter); */ /* enqueue another game tick in 10 minutes */ event = alloc_event(); event->fun = &event_game_tick; event->type = EVENT_GAME_TICK; add_event_game(event, 10 * 60 * PULSES_PER_SECOND); return FALSE; }
static int handle_security_event(const struct ast_security_event_common *sec) { struct ast_event *event; const struct ast_security_event_ie_type *ies; unsigned int i; if (!(event = alloc_event(sec))) { return -1; } for (ies = ast_security_event_get_required_ies(sec->event_type), i = 0; ies[i].ie_type != AST_EVENT_IE_END; i++) { if (add_ie(&event, sec, ies + i, REQUIRED)) { goto return_error; } } for (ies = ast_security_event_get_optional_ies(sec->event_type), i = 0; ies[i].ie_type != AST_EVENT_IE_END; i++) { if (add_ie(&event, sec, ies + i, NOT_REQUIRED)) { goto return_error; } } if (ast_event_queue(event)) { goto return_error; } return 0; return_error: if (event) { ast_event_destroy(event); } return -1; }
/* function :: init_event_queue() * arguments :: what section to initialize. * ====================================================== * This function is used to initialize the event queue, * and the first section should be initialized at boot, * the second section should be called after all areas, * players, monsters, etc has been loaded into memory, * and it should contain all maintanence events. */ void init_event_queue(int section) { EVENT_DATA *event; int i; if (section == 1) { for (i = 0; i < MAX_EVENT_HASH; i++) { eventqueue[i] = AllocList(); } event_free = AllocStack(); global_events = AllocList(); } else if (section == 2) { event = alloc_event(); event->fun = &event_game_tick; event->type = EVENT_GAME_TICK; add_event_game(event, 10 * 60 * PULSES_PER_SECOND); } }
/* * Create a ust_registry_event from the given parameters and add it to the * registry hash table. If event_id is valid, it is set with the newly created * event id. * * On success, return 0 else a negative value. The created event MUST be unique * so on duplicate entry -EINVAL is returned. On error, event_id is untouched. * * Should be called with session registry mutex held. */ int ust_registry_create_event(struct ust_registry_session *session, uint64_t chan_key, int session_objd, int channel_objd, char *name, char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel_value, char *model_emf_uri, int buffer_type, uint32_t *event_id_p, struct ust_app *app) { int ret; uint32_t event_id; struct cds_lfht_node *nptr; struct ust_registry_event *event = NULL; struct ust_registry_channel *chan; assert(session); assert(name); assert(sig); assert(event_id_p); rcu_read_lock(); /* * This should not happen but since it comes from the UST tracer, an * external party, don't assert and simply validate values. */ if (session_objd < 0 || channel_objd < 0) { ret = -EINVAL; goto error_free; } chan = ust_registry_channel_find(session, chan_key); if (!chan) { ret = -EINVAL; goto error_free; } /* Check if we've reached the maximum possible id. */ if (ust_registry_is_max_id(chan->used_event_id)) { ret = -ENOENT; goto error_free; } event = alloc_event(session_objd, channel_objd, name, sig, nr_fields, fields, loglevel_value, model_emf_uri, app); if (!event) { ret = -ENOMEM; goto error_free; } DBG3("UST registry creating event with event: %s, sig: %s, id: %u, " "chan_objd: %u, sess_objd: %u, chan_id: %u", event->name, event->signature, event->id, event->channel_objd, event->session_objd, chan->chan_id); /* * This is an add unique with a custom match function for event. The node * are matched using the event name and signature. */ nptr = cds_lfht_add_unique(chan->ht->ht, chan->ht->hash_fct(event, lttng_ht_seed), chan->ht->match_fct, event, &event->node.node); if (nptr != &event->node.node) { if (buffer_type == LTTNG_BUFFER_PER_UID) { /* * This is normal, we just have to send the event id of the * returned node and make sure we destroy the previously allocated * event object. */ destroy_event(event); event = caa_container_of(nptr, struct ust_registry_event, node.node); assert(event); event_id = event->id; } else {
extern void * evt_alloc(int type, va_list args) { tcvp_event_t *te = alloc_event(type, sizeof(*te), NULL); return te; }
static void load_area( const char * name ) { lua_State *L = area_loader; //shortcut name int status; char filename[MAX_BUFFER]; D_AREA *area; EVENT_DATA *event; log_string( "--Loading %s", name ); snprintf( filename, MAX_BUFFER, "../areas/%s", name ); if( ( status = luaL_loadfile( L, filename ) ) ) { bug( "ERROR: Can not find area file %s(%s)", filename, lua_tostring( L, -1 ) ); return; } if( lua_pcall( L, 0, 1, 0 ) ) { bug( "ERROR: Unable to parse area file (%s)", lua_tostring( L, -1 ) ); return; } if( ( area = new_area() ) == NULL ) { bug( "ERROR: Unable to allocate memory for area." ); return; } //load the area stats if( load_area_stats( L, area ) == FALSE ) //syntax errors in the area file { log_string( "----stats (failed)" ); return; } else { log_string( "----stats" ); } //load the actual rooms, stored in the table 'rooms' if( load_area_rooms( L, area ) == FALSE ) { log_string( "----rooms(failed)" ); //failing room load == fail area load return; } else { log_string( "----rooms" ); } //load the objects, stored in table 'objects' if( load_area_objects( L, area ) == FALSE ) { log_string( "----objects(failed)" ); } else { log_string( "----objects" ); } //load the NPCs, stored in table 'mobiles' if( load_area_mobiles( L, area ) == FALSE ) { log_string( "----mobiles(failed)" ); } else { log_string( "----mobiles" ); } //enqueue its first reset if( ( event = alloc_event() ) == NULL ) { bug( "Error: (System) Unable to allocate memory for new event!" ); exit( 1 ); } event->fun = event_reset_area; event->type = EVENT_RESET_AREA; event->owner.dArea = area; add_event_game( event, area->reset_time * 60 * PULSES_PER_SECOND ); return; }