Exemplo n.º 1
0
/* ------------------------------------------------------------------------- */
char
event_unregister_listener(const struct game_t* game,
                          const char* event_directory,
                          event_callback_func callback)
{
    struct event_t* event;

    if(!(event = event_get(game, event_directory)))
    {
        llog(LOG_WARNING, game, NULL, 3, "Tried to unregister from event \"",
            event_directory, "\", but the event does not exist.");
        return 0;
    }

    { UNORDERED_VECTOR_FOR_EACH(&event->listeners, struct event_listener_t, listener)
    {
        if(listener->exec == callback)
        {
            unordered_vector_erase_element(&event->listeners, listener);
            return 1;
        }
    }}

    llog(LOG_WARNING, game, NULL, 3, "Tried to unregister from event \"",
        event_directory, "\", but the listener was not found.");

    return 0;
}
void i_silc_channel_change_request(struct channel_connection *chconn,
								struct event *event,
								async_change_request_callback_t *cb,
								struct client_async_cmd_context *context)
{
	const char *new_topic = event_get(event, "topic");
	struct i_silc_channel_connection *silc_chconn =
					(struct i_silc_channel_connection *)chconn;
	struct i_silc_gateway_connection *silc_gwconn =
					(struct i_silc_gateway_connection *)chconn->gwconn;
	bool ret;
	SilcChannelEntry ch = silc_chconn->channel_entry;
	SilcClient client;
	SilcClientConnection conn;

	if( *new_topic == '\0' ) {
		cb(CLIENT_CMDERR_ARGS, context);
		return;
	}

	client = silc_gwconn->client;
	conn = silc_gwconn->conn;

	ret = silc_client_command_call(client, conn, NULL, "TOPIC", ch->channel_name,
									new_topic, NULL);

	if( !ret )
		cb(CLIENT_CMDERR_SILC_CANTSEND, context);
}
Exemplo n.º 3
0
Arquivo: event.c Projeto: barak/lush
/* process_pending_events --
 * Process currently pending events
 * by calling event-hook and event-idle
 * until no events are left.
 */
void process_pending_events(void)
{
   MM_ENTER;
   int timer_fired = 0;
   call_spoll();
   at *hndl = ev_peek();
   for(;;) {
      while (hndl) {
         /* Call the handler method <handle> */
         at *event = event_get(hndl, true);
         if (CONSP(event)) {
            class_t *cl = classof(hndl);
            at *m = getmethod(cl, at_handle);
            if (m) {
               at *args = new_cons(quote(event), NIL);
               send_message(NIL, hndl, at_handle, args);
            }
         }
         /* Check for more events */
         call_spoll();
         hndl = ev_peek();
      }

      /* Check for timer events */
      if (timer_fired)
         break;
      timer_fire();
      timer_fired = 1;
      hndl = ev_peek();
   }
   MM_EXIT;
}
Exemplo n.º 4
0
void event_remove(const event_t &criterion) {
    event_list_t new_list;

    if (debug_level >= 3) {
        wcstring desc = event_desc_compact(criterion);
        debug(3, "unregister: %ls\n", desc.c_str());
    }

    // Because of concurrency issues (env_remove could remove an event that is currently being
    // executed), env_remove does not actually free any events - instead it simply moves all events
    // that should be removed from the event list to the killme list, and the ones that shouldn't be
    // killed to new_list, and then drops the empty events-list.
    if (s_event_handlers.empty()) return;

    for (size_t i = 0; i < s_event_handlers.size(); i++) {
        event_t *n = s_event_handlers.at(i);
        if (event_match(criterion, *n)) {
            killme.push_back(n);

            // If this event was a signal handler and no other handler handles the specified signal
            // type, do not handle that type of signal any more.
            if (n->type == EVENT_SIGNAL) {
                event_t e = event_t::signal_event(n->param1.signal);
                if (event_get(e, 0) == 1) {
                    signal_handle(e.param1.signal, 0);
                    set_signal_observed(e.param1.signal, 0);
                }
            }
        } else {
            new_list.push_back(n);
        }
    }
    s_event_handlers.swap(new_list);
}
Exemplo n.º 5
0
/**
 * @brief Parses the actual individual event nodes.
 *
 *    @param parent Parent node to parse.
 *    @return 0 on success.
 */
static int events_parseActive( xmlNodePtr parent )
{
   char *buf;
   unsigned int id;
   int data;
   xmlNodePtr node, cur;
   Event_t *ev;

   node = parent->xmlChildrenNode;
   do {
      if (!xml_isNode(node,"event"))
         continue;

      xmlr_attr(node,"name",buf);
      if (buf==NULL) {
         WARN("Event has missing 'name' attribute, skipping.");
         continue;
      }
      data = event_dataID( buf );
      if (data < 0) {
         WARN("Event in save has name '%s' but event data not found matching name. Skipping.", buf);
         free(buf);
         continue;
      }
      free(buf);
      xmlr_attr(node,"id",buf);
      if (buf==NULL) {
         WARN("Event with data '%s' has missing 'id' attribute, skipping.", event_dataName(data));
         continue;
      }
      id = atoi(buf);
      free(buf);
      if (id==0) {
         WARN("Event with data '%s' has invalid 'id' attribute, skipping.", event_dataName(data));
         continue;
      }

      /* Create the event. */
      event_create( data, &id );
      ev = event_get( id );
      if (ev == NULL) {
         WARN("Event with data '%s' was not created, skipping.", event_dataName(data));
         continue;
      }
      ev->save = 1; /* Should save by default again. */

      /* Get the data. */
      cur = node->xmlChildrenNode;
      do {
         if (xml_isNode(cur,"lua"))
            nxml_unpersistLua( ev->L, cur );
      } while (xml_nextNode(cur));

      /* Claims. */
      if (xml_isNode(node,"claims"))
         ev->claims = claim_xmlLoad( node );
   } while (xml_nextNode(node));

   return 0;
}
Exemplo n.º 6
0
/**
 * @brief Checks to see if an event should be saved.
 */
int event_save( unsigned int eventid )
{
   Event_t *ev;
   ev = event_get(eventid);
   if (ev == NULL)
      return 0;
   return ev->save;
}
Exemplo n.º 7
0
/**
 * @brief Generates a new event ID.
 */
static unsigned int event_genID (void)
{
   unsigned int id;
   do {
      id = ++event_genid; /* Create unique ID. */
   } while (event_get(id) != NULL);
   return id;
}
Exemplo n.º 8
0
Arquivo: event.c Projeto: Arakash/naev
/**
 * @brief Starts running a function, allows programmer to set up arguments.
 */
lua_State *event_runStart( unsigned int eventid, const char *func )
{
   Event_t *ev;

   ev = event_get( eventid );
   if (ev == NULL)
      return NULL;

   return event_setupLua( ev, func );
}
Exemplo n.º 9
0
Arquivo: event.c Projeto: Arakash/naev
/**
 * @brief Runs a function previously set up with event_runStart.
 */
int event_runFunc( unsigned int eventid, const char *func, int nargs )
{
   Event_t *ev;

   ev = event_get( eventid );
   if (ev == NULL)
      return 0;

   return event_runLuaFunc( ev, func, nargs );
}
Exemplo n.º 10
0
Arquivo: event.c Projeto: Arakash/naev
/**
 * @brief Runs the event function.
 *
 *    @param eventid ID of the event to run Lua function on.
 *    @param func Name of the function to run.
 *    @return 0 on success.
 */
int event_run( unsigned int eventid, const char *func )
{
   Event_t *ev;

   ev = event_get( eventid );
   if (ev == NULL)
      return -1;

   return event_runLua( ev, func );
}
Exemplo n.º 11
0
Arquivo: event.c Projeto: Arakash/naev
/**
 * @brief Gets the name of the event data.
 *
 *    @param ev Event to get name of data from.
 *    @return Name of data ev has.
 */
const char *event_getData( unsigned int eventid )
{
   Event_t *ev;

   ev = event_get( eventid );
   if (ev == NULL)
      return NULL;

   return event_data[ ev->data ].name;
}
Exemplo n.º 12
0
Arquivo: event.c Projeto: Arakash/naev
/**
 * @brief Checks to see if an event is unique.
 *
 *    @param eventid ID of event to see if is unique.
 *    @return 0 if isn't unique, 1 if is.
 */
int event_isUnique( unsigned int eventid )
{
   Event_t *ev;

   ev = event_get( eventid );
   if (ev == NULL)
      return -1;

   return !!(event_data[ ev->data ].flags & EVENT_FLAG_UNIQUE);
}
Exemplo n.º 13
0
void event_remove(event_t *criterion)
{

    size_t i;
    event_list_t new_list;

    CHECK(criterion,);

    /*
      Because of concurrency issues (env_remove could remove an event
      that is currently being executed), env_remove does not actually
      free any events - instead it simply moves all events that should
      be removed from the event list to the killme list, and the ones
      that shouldn't be killed to new_list, and then drops the empty
      events-list.
    */

    if (events.empty())
        return;

    for (i=0; i<events.size(); i++)
    {
        event_t *n = events.at(i);
        if (event_match(criterion, n))
        {
            killme.push_back(n);

            /*
              If this event was a signal handler and no other handler handles
              the specified signal type, do not handle that type of signal any
              more.
            */
            if (n->type == EVENT_SIGNAL)
            {
                event_t e = event_t::signal_event(n->param1.signal);
                if (event_get(&e, 0) == 1)
                {
                    signal_handle(e.param1.signal, 0);
                }
            }
        }
        else
        {
            new_list.push_back(n);
        }
    }
    signal_block();
    events.swap(new_list);
    signal_unblock();
}
Exemplo n.º 14
0
void			architecture_handler_exception(t_uint32	n,
						       t_uint32	code)
{
  i_event		id;
  o_event*		o;

  /*
   * 1)
   */

  assert(architecture_context_locate() == STATUS_OK);

  /*
   * 2)
   */

  id = (i_event)(ARCHITECTURE_IDT_EXCEPTION_BASE + n);

  if (event_exist(id) != TRUE)
    {
      architecture_handler_spurious((t_uint32)id);

      return;
    }

  /*
   * 3)
   */

  assert(event_get(id, &o) == STATUS_OK);

  /*
   * 4)
   */

  _architecture.error = code;

  /*
   * 5)
   */

  assert(event_notify(id) == STATUS_OK);

  /*
   * 6)
   */

  _architecture.error = 0;
}
Exemplo n.º 15
0
/* process_pending_events --
   Process currently pending events
   by calling event-hook and event-idle
   until no events are left. */
void 
process_pending_events(void)
{
  at *hndl;
  at *event;
  int timer_fired = 0;
  call_spoll();
  hndl = ev_peek();
  for(;;)
    {
      while (hndl)
        {
          /* Call the handler method <handle> */
          LOCK(hndl);
          event = event_get(hndl, TRUE);
          if (CONSP(event))
            {
              at *cl = classof(hndl);
              if (EXTERNP(cl, &class_class))
                {
                  at *m = checksend(cl->Object, at_handle);
                  if (m)
                    {
                      at *args = new_cons(event,NIL);
                      UNLOCK(m);
                      argeval_ptr = eval_nothing;
                      m = send_message(NIL,hndl,at_handle,args);
                      argeval_ptr = eval_std;
                      UNLOCK(args);
                    }
                  UNLOCK(m);
                }
              UNLOCK(cl);
            }
          UNLOCK(event);
          UNLOCK(hndl);
          /* Check for more events */
          call_spoll();
          hndl = ev_peek();
        }
      /* Check for timer events */
      if (timer_fired)
        break;
      timer_fire();
      timer_fired = 1;
      hndl = ev_peek();
    }
}
Exemplo n.º 16
0
t_status	interface_event_attribute_data(o_syscall*	message)
{
  o_event*		o;

  if (event_get(message->u.request.u.event_attribute_data.arg1, &o) != STATUS_OK)
    {
      message->u.reply.error = STATUS_ERROR;
    }
  else
    {
      message->u.reply.error = STATUS_OK;
      message->u.reply.u.event_attribute_data.result1 = o->data;
    }

  return (STATUS_OK);
}
Exemplo n.º 17
0
Arquivo: event.c Projeto: barak/lush
static at *test_event_sub(int arg_number, at **arg_array, int remove)
{
   /* Validate parameters */
   at *handler = NIL;
   if (arg_number == 0)
      handler = current_window_handler();
   else if (arg_number == 1)
      handler = APOINTER(1);
   else 
      ARG_NUMBER(-1);

   /* Perform */
   call_spoll();
   at *r = handler ? event_get(handler, remove) : event_peek();
   return r;
}
Exemplo n.º 18
0
static void event_test()
{
	// test vectors
	const int add[] = {0,2,3,10,6 ,4,0,16,0 ,16,16,16,16,16,16,0};
	const int get[] = {2,0,6,0 ,16,0,4,0 ,16,0,0,0,0,0,0,16};

	event_clear();
	for (int i=0;i<sizeof(add)/sizeof(int);i++)
	{
		printf("round %d:+%d-%d:",i,add[i],get[i]);
		for (int j=0;j<add[i];j++) event_push((event){.raw=i});
		for (int j=0;j<get[i];j++) printf("%2d ",event_get(i));
		//printf("in: %p out:%p start:%p end:%p",evt_in, evt_out, QUEUE_START,QUEUE_END);
		if (event_full()) printf(" - now full ");
		if (event_empty()) printf("- now empty ");
		printf("\n");
	}
static void silc_cmd_channel_part(struct event *event)
{
	const char *channel_name = event_get(event, EVENT_KEY_CHANNEL_NAME);
	struct presence *presence;
	struct channel_connection *chconn;
	struct i_silc_gateway_connection *silc_gwconn;

	if( !client_command_get_presence(event, &presence))
		return;

	silc_gwconn = (struct i_silc_gateway_connection *)presence->gwconn;
	chconn = channel_connection_lookup(presence->gwconn, channel_name);
	if( !IS_SILC_CHCONN(chconn) )
		return;

	if( chconn->joined == TRUE )
		silc_client_command_call(silc_gwconn->client, silc_gwconn->conn,
				NULL, "LEAVE", channel_name, NULL);
}
Exemplo n.º 20
0
void			architecture_handler_irq(t_uint32	n)
{
  i_event		id;
  o_event*		o;

  /*
   * 1)
   */

  assert(architecture_context_locate() == STATUS_OK);

  /*
   * 2)
   */

  id = (i_event)(ARCHITECTURE_IDT_IRQ_BASE + n);

  if (event_exist(id) != TRUE)
    {
      architecture_handler_spurious((t_uint32)id);

      return;
    }

  /*
   * 3)
   */

  assert(event_get(id, &o) == STATUS_OK);

  /*
   * 4)
   */

  assert(event_notify(id) == STATUS_OK);

  /*
   * 5)
   */

  platform_pic_acknowledge(n);
}
Exemplo n.º 21
0
static ssize_t
xts_read(struct file *filp, char *buffer, size_t count, loff_t * ppos)
{
	DECLARE_WAITQUEUE(wait, current);
	struct xts_dev *dev = filp->private_data;
	char *ptr = buffer;
	int err = 0;

	add_wait_queue(&dev->read_wait, &wait);
	while (count >= sizeof (struct ts_event)) {
		err = -ERESTARTSYS;
		if (signal_pending(current))
			break;

		if (event_pending(dev)) {
			struct ts_event *evt = event_get(dev);

			err = copy_to_user(ptr, evt, sizeof (struct ts_event));
			event_pull(dev);

			if (err)
				break;

			ptr += sizeof (struct ts_event);
			count -= sizeof (struct ts_event);
			continue;
		}

		set_current_state(TASK_INTERRUPTIBLE);
		err = -EAGAIN;
		if (filp->f_flags & O_NONBLOCK)
			break;
		schedule();
	}
	current->state = TASK_RUNNING;
	remove_wait_queue(&dev->read_wait, &wait);

	return ptr == buffer ? err : ptr - buffer;
}
Exemplo n.º 22
0
/* ------------------------------------------------------------------------- */
char
event_register_listener(const struct game_t* game,
                        const char* event_directory,
                        event_callback_func callback)
{
    struct event_t* event;
    struct event_listener_t* new_listener;

    assert(game);
    assert(event_directory);
    assert(callback);

    /* make sure event exists */
    if(!(event = event_get(game, event_directory)))
    {
        llog(LOG_WARNING, game, NULL, 3, "Tried to register as a listener to "
            "event \"", event_directory, "\", but the event does not exist.");
        return 0;
    }

    /* make sure listener hasn't already registered to this event */
    { UNORDERED_VECTOR_FOR_EACH(&event->listeners, struct event_listener_t, listener)
    {
        if(listener->exec == callback)
        {
            llog(LOG_WARNING, game, NULL, 3, "Already registered as a listener"
                " to event \"", event->directory, "\"");
            return 0;
        }
    }}

    /* create event listener object */
    new_listener = (struct event_listener_t*) unordered_vector_push_emplace(&event->listeners);
    new_listener->exec = callback;

    return 1;
}
Exemplo n.º 23
0
void			architecture_handler_syscall(t_uint32	n)
{
  i_event		id;
  o_event*		o;

  /*
   * 1)
   */

  assert(architecture_context_locate() == STATUS_OK);

  /*
   * 2)
   */

  id = (i_event)(ARCHITECTURE_IDT_SYSCALL_BASE + n);

  if (event_exist(id) != TRUE)
    {
      architecture_handler_spurious((t_uint32)id);

      return;
    }

  /*
   * 3)
   */

  assert(event_get(id, &o) == STATUS_OK);

  /*
   * 4)
   */

  assert(event_notify(id) == STATUS_OK);
}
Exemplo n.º 24
0
void kbd_emulate_gamepad (void)
{
	// kbd codes in order of gamepad buttons
	static const uint8_t kbd_gamepad[] = {0x07, 0x09, 0x08, 0x15, 0xE0, 0xE4, 0x2c, 0x28, 0x52, 0x51, 0x50, 0x4f }; 
	// 
	struct event e;
	do {
		e=event_get();
		for (int i=0;i<12;i++) 
		{
			if (kbd_gamepad[i]==e.kbd.key) 
			switch (e.type)
			{
				case evt_keyboard_press  :
					gamepad_buttons[0] |= (1<<i);
				break;
			
				case evt_keyboard_release : 
					gamepad_buttons[0] &= ~(1<<i);
				break;
			}
		}
	} while (e.type);
}
Exemplo n.º 25
0
void bsod_frame()
{
    static const char *HEX_Digits = "0123456789ABCDEF";
    struct event e;
    e=event_get();
    while (e.type != no_event) 
    {
        switch(e.type)
        {
        case evt_keyboard_press: 
            switch (e.kbd.key)
            {
            case 0x52:
                move_cursor_up();
                break;
            case 0x51:
                move_cursor_down();
                break;
            case 0x50:
                move_cursor_left();
                break;
            case 0x4F:
                move_cursor_right();
                break;
            default:
                if (e.kbd.key < 100)
                {
                    if (e.kbd.key == 42) // backspace
                    {
                        move_cursor_left();
                        vram[cursor.y][cursor.x] = 32;
                    }
                    else if (e.kbd.key == 40) // enter
                    {
                        //move_cursor_return();
                        // special behavior here...
                    }
                    else
                    {
                        vram[cursor.y][cursor.x] = e.kbd.sym;
                        move_cursor_right();
                    }
                }
                message("pressed %d with mod %d\n", e.kbd.key, e.kbd.mod);
                print_at(31,18,"KB pressed      ");
                vram[18][45]=HEX_Digits[(e.kbd.key>>4) & 0xF];
                vram[18][46]=HEX_Digits[e.kbd.key&0xf];
            }
            break;

        case evt_keyboard_release: 
            print_at(31,18,"KB released     ");
            vram[18][45]=HEX_Digits[(e.kbd.key>>4) & 0xF];
            vram[18][46]=HEX_Digits[e.kbd.key&0xf];
            break;

        case evt_device_change:
            // It seems the disconnect event is not sent currently...
            if (e.device.type == device_unconnected)
                print_at(31, 18, "dev. unconnected");
            else if (e.device.type == device_keyboard)
                print_at(31, 18, "keyboard found! ");
            break;

        case evt_user:
            print_at(31, 18, "user event      ");
            break;
        
        default:
            print_at(31, 18, "UNHANDLED       ");
        }
        e=event_get();
    }
}
Exemplo n.º 26
0
/**
 * @brief Tests to see if an event has claimed a system.
 */
int event_testClaims( unsigned int eventid, int sys )
{
   Event_t *ev;
   ev = event_get( eventid );
   return claim_testSys( ev->claims, sys );
}