Esempio n. 1
0
/**
 * Handle system_state_pipe notifications
 *
 * @param data The system state stored in a pointer
 */
static void mia_datapipe_system_state_cb(gconstpointer data)
{
    system_state_t prev = system_state;
    system_state = GPOINTER_TO_INT(data);

    if( system_state == prev )
        goto EXIT;

    mce_log(LL_DEBUG, "system_state: %s -> %s",
            system_state_repr(prev),
            system_state_repr(system_state));

    if( prev == MCE_STATE_UNDEF )
        mia_datapipe_check_initial_state();

EXIT:
    return;
}
Esempio n. 2
0
/** Datapipe filter for inactivity
 *
 * @param data The unfiltered inactivity state;
 *             TRUE if the device is inactive,
 *             FALSE if the device is active
 *
 * @return The filtered inactivity state;
 *             TRUE if the device is inactive,
 *             FALSE if the device is active
 */
static gpointer mia_datapipe_device_inactive_cb(gpointer data)
{
    gboolean prev = device_inactive;
    device_inactive = GPOINTER_TO_INT(data);

    mce_log(LL_DEBUG, "input = %s",
            mia_inactivity_repr(device_inactive));

    /* No need to filter inactivity */
    if( device_inactive )
        goto EXIT;

    /* Never filter activity if display is in dimmed state.
     *
     * Whether we have arrived to dimmed state via expected or
     * unexpected routes, the touch input is active and ui side
     * event eater will ignore only the first event. If we do
     * not allow activity (and turn on the display) we will get
     * ui interaction in odd looking dimmed state that then gets
     * abruptly ended by blanking timer.
     */
    if( display_state_next == MCE_DISPLAY_DIM )
        goto EXIT;

    /* Activity tracking applies only to USER mode */
    if( system_state != MCE_STATE_USER ) {
        mce_log(LL_DEBUG, "system_state = %s; ignoring activity",
                system_state_repr(system_state));
        device_inactive = TRUE;
        goto EXIT;
    }

    /* Filter activity when lockscreen is active */
    if( submode & MCE_TKLOCK_SUBMODE ) {

        /* Default to: inactive */
        device_inactive = TRUE;

        /* Allow activity if display is already on */
        switch( display_state_next ) {
        case MCE_DISPLAY_ON:
            device_inactive = FALSE;
            break;

        default:
            break;
        }

        /* Allow activity if there is active alarm */
        switch( alarm_ui_state ) {
        case MCE_ALARM_UI_RINGING_INT32:
        case MCE_ALARM_UI_VISIBLE_INT32:
            device_inactive = FALSE;
            break;

        default:
            break;
        }

        /* Allow activity if there is active call */
        switch( call_state ) {
        case CALL_STATE_RINGING:
        case CALL_STATE_ACTIVE:
            device_inactive = FALSE;

        default:
            break;
        }

        if( device_inactive ) {
            mce_log(LL_DEBUG, "tklock enabled, no alarms or calls;"
                    " ignoring activity");
            goto EXIT;
        }
    }

    /* Filter activity when proximity sensor is covered */
    if( proximity_state == COVER_CLOSED ) {

        /* Allow activity if display is already on */
        switch( display_state_next ) {
        case MCE_DISPLAY_DIM:
        case MCE_DISPLAY_ON:
            break;

        default:
            mce_log(LL_DEBUG, "display=off, proximity=covered; ignoring activity");
            device_inactive = TRUE;
            goto EXIT;
        }
    }

EXIT:
    /* Handle inactivity state change */
    if( prev != device_inactive ) {
        mce_log(LL_DEBUG, "device_inactive: %s -> %s",
                mia_inactivity_repr(prev),
                mia_inactivity_repr(device_inactive));

        mia_dbus_send_inactivity_state(NULL);

        /* React to activity */
        if( !device_inactive )
            mia_activity_action_execute_all();
    }

    /* Restart/stop timer */
    mia_timer_start();

    /* Return filtered activity state */
    return GINT_TO_POINTER(device_inactive);
}
Esempio n. 3
0
File: mce-dsme.c Progetto: g7/mce
/**
 * Callback for pending I/O from dsmesock
 *
 * XXX: is the error policy reasonable?
 *
 * @param source Unused
 * @param condition Unused
 * @param data Unused
 * @return TRUE on success, FALSE on failure
 */
static gboolean mce_dsme_iowatch_cb(GIOChannel *source,
				    GIOCondition condition,
				    gpointer data)
{
	gboolean keep_going = TRUE;
	dsmemsg_generic_t *msg = 0;

	DSM_MSGTYPE_STATE_CHANGE_IND *msg2;

	(void)source;
	(void)data;

	if( condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) ) {
		if( !mce_dsme_shutting_down() )
			mce_log(LL_CRIT, "DSME socket hangup/error");
		keep_going = FALSE;
		goto EXIT;
	}

	if( !(msg = dsmesock_receive(mce_dsme_connection)) )
		goto EXIT;

	if( DSMEMSG_CAST(DSM_MSGTYPE_CLOSE, msg) ) {
		if( !mce_dsme_shutting_down() )
			mce_log(LL_WARN, "DSME socket closed");
		keep_going = FALSE;
	}
	else if( DSMEMSG_CAST(DSM_MSGTYPE_PROCESSWD_PING, msg) ) {
		mce_dsme_send_pong();
	}
	else if( (msg2 = DSMEMSG_CAST(DSM_MSGTYPE_STATE_CHANGE_IND, msg)) ) {
		system_state_t prev = system_state;
		system_state = mce_dsme_normalise_system_state(msg2->state);
		mce_log(LL_DEVEL, "DSME device state change: %d", system_state);

		/* If we're changing to a different state,
		 * add the transition flag, UNLESS the old state
		 * was MCE_STATE_UNDEF
		 */
		if( system_state != prev && prev != MCE_STATE_UNDEF )
			mce_add_submode_int32(MCE_TRANSITION_SUBMODE);

		switch (system_state) {
		case MCE_STATE_USER:
			execute_datapipe_output_triggers(&led_pattern_activate_pipe, MCE_LED_PATTERN_DEVICE_ON, USE_INDATA);
			break;

		case MCE_STATE_ACTDEAD:
		case MCE_STATE_BOOT:
		case MCE_STATE_UNDEF:
			break;

		case MCE_STATE_SHUTDOWN:
		case MCE_STATE_REBOOT:
			execute_datapipe_output_triggers(&led_pattern_deactivate_pipe, MCE_LED_PATTERN_DEVICE_ON, USE_INDATA);
			break;

		default:
			break;
		}

		mce_log(LL_DEVEL, "system_state: %s -> %s",
			system_state_repr(prev),
			system_state_repr(system_state));

		execute_datapipe(&system_state_pipe,
				 GINT_TO_POINTER(system_state),
				 USE_INDATA, CACHE_INDATA);
	}
	else {
		mce_log(LL_DEBUG, "Unhandled message type %s (0x%x) received from DSME",
			mce_dsme_msg_type_repr(msg->type_),
			msg->type_); /* <- unholy access of a private member */
	}

EXIT:
	free(msg);

	if( !keep_going ) {
		if( !mce_dsme_shutting_down() ) {
			mce_log(LL_WARN, "DSME i/o notifier disabled;"
				" assuming dsme was stopped");
		}

		/* mark notifier as removed */
		mce_dsme_iowatch_id = 0;

		/* close and wait for possible dsme restart */
		mce_dsme_disconnect();
	}

	return keep_going;
}