示例#1
0
/**
 * Disconnect (if we haven't already been forcefully disconnected), clean up
 * after ourselves, and call all registered disconnect hooks.
 */
static void
teardown(void)
{
    struct dbus_core_hook *hook;

    if (bus_info.timer) {
        TimerFree(bus_info.timer);
        bus_info.timer = NULL;
    }

    /* We should really have pre-disconnect hooks and run them here, for
     * completeness.  But then it gets awkward, given that you can't
     * guarantee that they'll be called ... */
    if (bus_info.connection)
        dbus_connection_unref(bus_info.connection);

    RemoveBlockAndWakeupHandlers(block_handler, wakeup_handler, &bus_info);
    if (bus_info.fd != -1)
        RemoveGeneralSocket(bus_info.fd);
    bus_info.fd = -1;
    bus_info.connection = NULL;

    for (hook = bus_info.hooks; hook; hook = hook->next) {
        if (hook->disconnect)
            hook->disconnect(hook->data);
    }
}
示例#2
0
void
xf86DisableGeneralHandler(pointer handler)
{
    IHPtr ih;

    if (!handler)
	return;

    ih = handler;
    ih->enabled = FALSE;
    if (ih->fd >= 0)
	RemoveGeneralSocket(ih->fd);
}
示例#3
0
int
xf86RemoveGeneralHandler(pointer handler)
{
    IHPtr ih;
    int fd;

    if (!handler)
	return -1;

    ih = handler;
    fd = ih->fd;

    if (ih->fd >= 0)
	RemoveGeneralSocket(ih->fd);
    removeInputHandler(ih);

    return fd;
}
示例#4
0
void _sna_acpi_wakeup(struct sna *sna)
{
	char *eol;
	int n;

	n = read(sna->acpi.fd,
		 sna->acpi.event + sna->acpi.offset,
		 sna->acpi.remain);
	DBG(("%s: read %d bytes from acpid\n", __FUNCTION__, n));
	if (n <= 0) {
		/* We will get '0' if we run out of space whilst reading
		 * one event - that should never happen, so treat it as
		 * an error and give up.
		 */
		if (n < 0)
			n = errno;
		switch (n) {
		case EAGAIN:
		case EINTR:
			return;
		}

		DBG(("%s: error [%d], detaching from acpid\n", __FUNCTION__, n));

		/* XXX reattach later? */
		RemoveGeneralSocket(sna->acpi.fd);
		sna_acpi_fini(sna);
		return;
	}

	sna->acpi.event[sna->acpi.offset + n] = '\0';
	sna->acpi.offset += n;
	sna->acpi.remain -= n;

	DBG(("%s: event string [%d]: '%s'\n", __FUNCTION__, sna->acpi.offset, sna->acpi.event));

	do {
		eol = strchr(sna->acpi.event, '\n');
		if (eol == NULL)
			return;

		if (strncmp(sna->acpi.event, "ac_adapter", 10) == 0) {
			char *space = sna->acpi.event;
			int state = -1;

			/* ac_adapter ACAD 00000080 00000001 */

			space = strchr(space, ' ');
			if (space)
				space = strchr(space + 1, ' ');
			if (space)
				space = strchr(space + 1, ' ');
			if (space)
				state = atoi(space + 1);

			DBG(("%s: ac_adapter event new state=%d\n", __FUNCTION__, state));
			if (state)
				sna->flags &= ~SNA_POWERSAVE;
			else
				sna->flags |= SNA_POWERSAVE;
		}

		n = (sna->acpi.event + sna->acpi.offset) - ++eol;
		memmove(sna->acpi.event, eol, n+1);
		sna->acpi.offset = n;
		sna->acpi.remain = sizeof(sna->acpi.event) - 1 - n;
	} while (n);
}