Skip to content

Commit

Permalink
[datapipe] Normalize inactivity datapipe execution
Browse files Browse the repository at this point in the history
Pushing events to inactivity database is done directly via
datapipe_exec_full() and locally defined helper functions
such as mia_generate_activity() - which makes it difficult
to find all places where user activity is tracked.

Add common functions for generating activity and inactivity,
and use them throughout the mce code base.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Nov 20, 2018
1 parent 2018830 commit ae6c28b
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 46 deletions.
14 changes: 14 additions & 0 deletions datapipe.c
Expand Up @@ -1796,3 +1796,17 @@ void mce_datapipe_quit_bindings(datapipe_bindings_t *self)
/* Remove datapipe callbacks */
mce_datapipe_remove_handlers(self->handlers);
}

/** Helper for attempting to switch to active state
*/
void mce_datapipe_generate_activity(void)
{
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
}

/** Helper for switching to inactive state
*/
void mce_datapipe_generate_inactivity(void)
{
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(TRUE));
}
3 changes: 3 additions & 0 deletions datapipe.h
Expand Up @@ -118,6 +118,9 @@ void mce_datapipe_quit (void);
void mce_datapipe_init_bindings(datapipe_bindings_t *self);
void mce_datapipe_quit_bindings(datapipe_bindings_t *self);

void mce_datapipe_generate_activity (void);
void mce_datapipe_generate_inactivity (void);

/* ========================================================================= *
* Macros
* ========================================================================= */
Expand Down
3 changes: 1 addition & 2 deletions event-input.c
Expand Up @@ -1921,8 +1921,7 @@ evin_iomon_generate_activity(struct input_event *ev, bool cooked, bool raw)

if( t_cooked != t || (submode & MCE_SUBMODE_EVEATER) ) {
t_cooked = t;
datapipe_exec_full(&inactivity_event_pipe,
GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
}
}

Expand Down
15 changes: 6 additions & 9 deletions event-switches.c
Expand Up @@ -92,7 +92,7 @@ static gboolean generic_activity_iomon_cb(mce_io_mon_t *iomon, gpointer data, gs
(void)bytes_read;

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();

return FALSE;
}
Expand All @@ -119,7 +119,7 @@ static gboolean camera_launch_button_iomon_cb(mce_io_mon_t *iomon, gpointer data
}

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();

/* Update camera button state */
datapipe_exec_full(&camera_button_state_pipe,
Expand Down Expand Up @@ -171,8 +171,7 @@ static gboolean kbd_slide_iomon_cb(mce_io_mon_t *iomon, gpointer data, gsize byt
slide_state = COVER_OPEN;

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe,
GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
} else {
slide_state = COVER_CLOSED;
}
Expand Down Expand Up @@ -201,8 +200,7 @@ static gboolean lid_sensor_actual_iomon_cb(mce_io_mon_t *iomon, gpointer data, g
lid_state = COVER_OPEN;

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe,
GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
} else {
lid_state = COVER_CLOSED;
}
Expand Down Expand Up @@ -262,7 +260,7 @@ static gboolean usb_cable_iomon_cb(mce_io_mon_t *iomon, gpointer data, gsize byt
}

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();

datapipe_exec_full(&usb_cable_state_pipe,
GINT_TO_POINTER(cable_state));
Expand All @@ -288,8 +286,7 @@ static gboolean lens_cover_iomon_cb(mce_io_mon_t *iomon, gpointer data, gsize by
lens_cover_state = COVER_OPEN;

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe,
GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
} else {
lens_cover_state = COVER_CLOSED;
}
Expand Down
8 changes: 3 additions & 5 deletions modules/battery-bme.c
Expand Up @@ -326,7 +326,7 @@ static gboolean charger_charging_failed_dbus_cb(DBusMessage *const msg)
datapipe_exec_full(&led_pattern_deactivate_pipe, MCE_LED_PATTERN_BATTERY_CHARGING);

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();

status = TRUE;

Expand All @@ -351,8 +351,7 @@ static gboolean charger_connected_dbus_cb(DBusMessage *const msg)

if (cached_charger_connected != 1) {
/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe,
GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
cached_charger_connected = 1;
}

Expand Down Expand Up @@ -390,8 +389,7 @@ static gboolean charger_disconnected_dbus_cb(DBusMessage *const msg)

if (cached_charger_connected != 0) {
/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe,
GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
cached_charger_connected = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/battery-statefs.c
Expand Up @@ -805,7 +805,7 @@ mcebat_update_cb(gpointer user_data)
}

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
}

if( mcebat.status != prev.status ) {
Expand Down
2 changes: 1 addition & 1 deletion modules/battery-udev.c
Expand Up @@ -328,7 +328,7 @@ mcebat_update(const mcebat_t *curr)
}

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
}

if( prev.battery_status != curr->battery_status ) {
Expand Down
2 changes: 1 addition & 1 deletion modules/battery-upower.c
Expand Up @@ -709,7 +709,7 @@ mcebat_update_cb(gpointer user_data)
}

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
}

if( mcebat.status != prev.status ) {
Expand Down
2 changes: 1 addition & 1 deletion modules/camera.c
Expand Up @@ -121,7 +121,7 @@ static gboolean camera_popout_state_iomon_input_cb(mce_io_mon_t *iomon, gpointer
(void)bytes_read;

/* Generate activity */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();

if (popout_unlock == FALSE)
goto EXIT;
Expand Down
3 changes: 1 addition & 2 deletions modules/display.c
Expand Up @@ -7059,8 +7059,7 @@ static void mdy_orientation_generate_activity(void)
}

mce_log(LL_DEBUG, "orientation change; generate activity");
datapipe_exec_full(&inactivity_event_pipe,
GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();

EXIT:
return;
Expand Down
3 changes: 1 addition & 2 deletions modules/fingerprint.c
Expand Up @@ -1376,8 +1376,7 @@ fingerprint_datapipe_generate_activity(void)
}

mce_log(LL_DEBUG, "generating activity from fingerprint sensor");
datapipe_exec_full(&inactivity_event_pipe,
GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();

EXIT:
return;
Expand Down
24 changes: 4 additions & 20 deletions modules/inactivity.c
Expand Up @@ -77,8 +77,6 @@ G_MODULE_EXPORT module_info_struct module_info = {
* ------------------------------------------------------------------------- */

static const char *mia_inactivity_repr (bool inactive);
static void mia_generate_activity (void);
static void mia_generate_inactivity (void);

/* ------------------------------------------------------------------------- *
* DBUS_ACTION
Expand Down Expand Up @@ -276,20 +274,6 @@ static const char *mia_inactivity_repr(bool inactive)
return inactive ? "inactive" : "active";
}

/** Helper for attempting to switch to active state
*/
static void mia_generate_activity(void)
{
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
}

/** Helper for switching to inactive state
*/
static void mia_generate_inactivity(void)
{
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(TRUE));
}

/* ========================================================================= *
* DBUS_ACTION
* ========================================================================= */
Expand Down Expand Up @@ -494,7 +478,7 @@ static void mia_datapipe_proximity_sensor_actual_cb(gconstpointer data)
if( proximity_sensor_actual == COVER_OPEN &&
call_state == CALL_STATE_RINGING ) {
mce_log(LL_INFO, "proximity -> uncovered, call = ringing");
mia_generate_activity();
mce_datapipe_generate_activity();
}

EXIT:
Expand Down Expand Up @@ -652,7 +636,7 @@ static void mia_datapipe_interaction_expected_cb(gconstpointer data)
(submode & MCE_SUBMODE_TKLOCK) &&
display_state_next == MCE_DISPLAY_ON ) {
mce_log(LL_DEBUG, "interaction expected; generate activity");
mia_generate_activity();
mce_datapipe_generate_activity();
}

EXIT:
Expand Down Expand Up @@ -753,7 +737,7 @@ static void mia_datapipe_check_initial_state(void)
*/

mce_log(LL_DEBUG, "device state known");
mia_generate_activity();
mce_datapipe_generate_activity();

/* Make sure the current state gets broadcast even
* if the artificial activity gets suppressed. */
Expand Down Expand Up @@ -1284,7 +1268,7 @@ static gboolean mia_timer_cb(gpointer data)

mce_log(LL_DEBUG, "inactivity timeout triggered");

mia_generate_inactivity();
mce_datapipe_generate_inactivity();

return FALSE;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ut/ut_display.c
Expand Up @@ -1653,7 +1653,7 @@ START_TEST (ut_check_auto_dim)
expected_dim_time);

/* Generate activity so adaptive_dimming_index gets inc. */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
ut_assert_transition(ut_is_display_state_eq,
GINT_TO_POINTER(MCE_DISPLAY_ON));
}
Expand Down Expand Up @@ -1692,7 +1692,7 @@ START_TEST (ut_check_adaptive_dim_timeout)
expected_dim_time);

/* Generating activity the adaptive_dimming_index gets incremented */
datapipe_exec_full(&inactivity_event_pipe, GINT_TO_POINTER(FALSE));
mce_datapipe_generate_activity();
/* Verify adaptive_dimming_index=1 by meassuring rime to re-enter DIM */
expected_dim_time = ut_nth_possible_dim_timeout(forced_dti + 1);
ut_assert_transition(ut_is_display_state_eq,
Expand Down

0 comments on commit ae6c28b

Please sign in to comment.