示例#1
0
/*
 * Mark an event to be released.  Because we may be traversing the queue
 * when this is called, we must wait until later to actually remove
 * the event.
 */
void
event_release(
    event_handle_t *handle)
{
    assert(handle != NULL);

    event_debug(1, _("event: release (mark): %p data=%jd, type=%s\n"),
		    handle, handle->data,
		    event_type2str(handle->type));
    assert(!handle->is_dead);

    /* Mark it as dead and leave it for the event_loop to remove */
    handle->is_dead = TRUE;
}
示例#2
0
文件: event.c 项目: hangie/amanda
/* Return TRUE if we have any events outstanding that can be dispatched
 * by GMainLoop.  Recall EV_WAIT events appear in all_events, but are
 * not dispatched by GMainLoop.  */
static gboolean
any_mainloop_events(void)
{
    GSList *iter;

    for (iter = all_events; iter != NULL; iter = g_slist_next(iter)) {
	event_handle_t *hdl = (event_handle_t *)iter->data;
	event_debug(2, _("list %p: %s/%jd\n"), hdl, event_type2str((hdl)->type), (hdl)->data);
	if (hdl->type != EV_WAIT)
	    return TRUE;
    }

    return FALSE;
}
示例#3
0
文件: events.cpp 项目: LubosD/twinkle
t_event_queue::~t_event_queue() {
	log_file->write_header("t_event_queue::~t_event_queue", LOG_NORMAL, LOG_INFO);
	log_file->write_raw("Clean up event queue.\n");

	while (!ev_queue.empty())
	{
		t_event *e = ev_queue.front();
		ev_queue.pop();
		log_file->write_raw("\nDeleting unprocessed event: \n");
		log_file->write_raw("Type: ");
		log_file->write_raw(event_type2str(e->get_type()));
		log_file->write_raw(", Pointer: ");
		log_file->write_raw(ptr2str(e));
		log_file->write_endl();
		MEMMAN_DELETE(e);
		delete e;
	}

	log_file->write_footer();
}
示例#4
0
文件: event.c 项目: code-mx/amanda
event_handle_t *
event_create(
    event_id_t data,
    event_type_t type,
    event_fn_t fn,
    void *arg)
{
    event_handle_t *handle;

    g_static_mutex_lock(&event_mutex);

    /* sanity-checking */
    if ((type == EV_READFD) || (type == EV_WRITEFD)) {
	/* make sure we aren't given a high fd that will overflow a fd_set */
	if (data >= (int)FD_SETSIZE) {
	    error(_("event_register: Invalid file descriptor %jd"), data);
	    /*NOTREACHED*/
	}
    } else if (type == EV_TIME) {
	if (data <= 0) {
	    error(_("event_register: interval for EV_TIME must be greater than 0; got %jd"), data);
	}
    }

    handle = g_new0(event_handle_t, 1);
    handle->fn = fn;
    handle->arg = arg;
    handle->type = type;
    handle->data = data;
    handle->is_dead = FALSE;

    event_debug(1, _("event: register: %p->data=%jd, type=%s\n"),
		    handle, handle->data, event_type2str(handle->type));

    g_static_mutex_unlock(&event_mutex);
    return handle;
}
示例#5
0
event_handle_t *
event_register(
    event_id_t data,
    event_type_t type,
    event_fn_t fn,
    void *arg)
{
    event_handle_t *handle;
    GIOCondition cond;

    /* sanity-checking */
    if ((type == EV_READFD) || (type == EV_WRITEFD)) {
	/* make sure we aren't given a high fd that will overflow a fd_set */
	if (data >= (int)FD_SETSIZE) {
	    error(_("event_register: Invalid file descriptor %jd"), data);
	    /*NOTREACHED*/
	}
    } else if (type == EV_TIME) {
	if (data <= 0) {
	    error(_("event_register: interval for EV_TIME must be greater than 0; got %jd"), data);
	}
    }

    handle = g_new0(event_handle_t, 1);
    handle->fn = fn;
    handle->arg = arg;
    handle->type = type;
    handle->data = data;
    handle->is_dead = FALSE;

    event_debug(1, _("event: register: %p->data=%jd, type=%s\n"),
		    handle, handle->data, event_type2str(handle->type));

    /* add to the list of events */
    all_events = g_slist_prepend(all_events, (gpointer)handle);

    /* and set up the GSource for this event */
    switch (type) {
	case EV_READFD:
	case EV_WRITEFD:
	    /* create a new source */
	    if (type == EV_READFD) {
		cond = G_IO_IN | G_IO_HUP | G_IO_ERR;
	    } else {
		cond = G_IO_OUT | G_IO_ERR;
	    }

	    handle->source = new_fdsource(data, cond);

	    /* attach it to the default GMainLoop */
	    g_source_attach(handle->source, NULL);
	    handle->source_id = g_source_get_id(handle->source);

	    /* And set its callbacks */
	    g_source_set_callback(handle->source, event_handle_callback,
				  (gpointer)handle, NULL);

	    /* drop our reference to it, so when it's detached, it will be
	     * destroyed. */
	    g_source_unref(handle->source);
	    break;

	case EV_TIME:
	    /* Glib provides a nice shortcut for timeouts.  The *1000 converts
	     * seconds to milliseconds. */
	    handle->source_id = g_timeout_add(data * 1000, event_handle_callback,
					      (gpointer)handle);

	    /* But it doesn't give us the source directly.. */
	    handle->source = g_main_context_find_source_by_id(NULL, handle->source_id);
	    /* EV_TIME must always be handled after EV_READ */
	    g_source_set_priority(handle->source, 10);
	    break;

	case EV_WAIT:
	    /* nothing to do -- these are handled independently of GMainLoop */
	    break;

	default:
	    error(_("Unknown event type %s"), event_type2str(type));
    }

    return handle;
}
示例#6
0
文件: event.c 项目: code-mx/amanda
void
event_activate(
    event_handle_t *handle)
{
    GIOCondition cond;
    assert(handle != NULL);

    g_static_mutex_lock(&event_mutex);

    /* add to the list of events */
    all_events = g_slist_prepend(all_events, (gpointer)handle);

    /* and set up the GSource for this event */
    switch (handle->type) {
	case EV_READFD:
	case EV_WRITEFD:
	    /* create a new source */
	    if (handle->type == EV_READFD) {
		cond = G_IO_IN | G_IO_HUP | G_IO_ERR;
	    } else {
		cond = G_IO_OUT | G_IO_ERR;
	    }

	    handle->source = new_fdsource(handle->data, cond);

	    /* attach it to the default GMainLoop */
	    g_source_attach(handle->source, NULL);
	    handle->source_id = g_source_get_id(handle->source);

	    /* And set its callbacks */
	    g_source_set_callback(handle->source, event_handle_callback,
				  (gpointer)handle, NULL);

	    /* drop our reference to it, so when it's detached, it will be
	     * destroyed. */
	    g_source_unref(handle->source);
	    break;

	case EV_TIME:
	    /* Glib provides a nice shortcut for timeouts.  The *1000 converts
	     * seconds to milliseconds. */
	    handle->source_id = g_timeout_add(handle->data * 1000, event_handle_callback,
					      (gpointer)handle);

	    /* But it doesn't give us the source directly.. */
	    handle->source = g_main_context_find_source_by_id(NULL, handle->source_id);
	    /* EV_TIME must always be handled after EV_READ */
	    g_source_set_priority(handle->source, 10);
	    break;

	case EV_WAIT:
	    /* nothing to do -- these are handled independently of GMainLoop */
	    break;

	default:
	    error(_("Unknown event type %s"), event_type2str(handle->type));
    }

    g_static_mutex_unlock(&event_mutex);
    return;
}