Navigation Menu

Skip to content

Commit

Permalink
[datapipe] Make datapipe_t structure opaque
Browse files Browse the repository at this point in the history
Members of datapipe structures should not be accessed directly, but there
still are some legacy code hacks poking at the internals.

Make datapipe_t structure opaque outside datapipe module.

Add/tweak necessary accessor functions/macros to deal with the change.

Mark architectural sore points with FIXME comments.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Mar 7, 2019
1 parent 15a9e4c commit dcc0f24
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
38 changes: 38 additions & 0 deletions datapipe.c
Expand Up @@ -37,6 +37,24 @@
#define datapipe_init(datapipe, filtering, caching, datasize, value)\
datapipe_init_(&(datapipe), #datapipe, filtering, caching, datasize, value)

/* ========================================================================= *
* Types
* ========================================================================= */

struct datapipe_t
{
const char *dp_name; /**< Name of the datapipe */
GSList *dp_filters; /**< The filters */
GSList *dp_input_triggers; /**< Triggers called on indata */
GSList *dp_output_triggers; /**< Triggers called on outdata */
gconstpointer dp_cached_data; /**< Latest cached data */
gsize dp_datasize; /**< Size of data; NULL == automagic */
datapipe_filtering_t dp_read_only; /**< Datapipe is read only */
datapipe_cache_t dp_cache;
guint dp_gc_id;
guint dp_token;
};

/* ========================================================================= *
* Prototypes
* ========================================================================= */
Expand Down Expand Up @@ -467,6 +485,26 @@ datapipe_value(const datapipe_t *self)
return self->dp_cached_data;
}

/** Set value of datapipe
*
* Note: Do not use this function.
*
* This function exists only to facilitate legacy hacks in
* the display plugin - no new code should ever call it and
* it should be removed as soon as possible.
*
* The proper way to modify datapipe content is to use
* #datapipe_exec_full() function.
*
* @param self The datapipe
* @paran data The value, as void pointer
*/
void
datapipe_set_value(datapipe_t *self, gconstpointer data)
{
self->dp_cached_data = data;
}

/** Garbage collect stale callback slots
*
* While it can be assumed to be extremely rare, filters and triggers can end
Expand Down
18 changes: 4 additions & 14 deletions datapipe.h
Expand Up @@ -68,18 +68,7 @@ typedef enum {
*
* Only access this struct through the functions
*/
typedef struct {
const char *dp_name; /**< Name of the datapipe */
GSList *dp_filters; /**< The filters */
GSList *dp_input_triggers; /**< Triggers called on indata */
GSList *dp_output_triggers; /**< Triggers called on outdata */
gconstpointer dp_cached_data; /**< Latest cached data */
gsize dp_datasize; /**< Size of data; NULL == automagic */
datapipe_filtering_t dp_read_only; /**< Datapipe is read only */
datapipe_cache_t dp_cache;
guint dp_gc_id;
guint dp_token;
} datapipe_t;
typedef struct datapipe_t datapipe_t;

typedef struct
{
Expand Down Expand Up @@ -108,6 +97,7 @@ typedef struct
const char *datapipe_name (const datapipe_t *self);
gconstpointer datapipe_value (const datapipe_t *self);
gconstpointer datapipe_exec_full(datapipe_t *self, gconstpointer indata);
void datapipe_set_value(datapipe_t *self, gconstpointer data);

/* ------------------------------------------------------------------------- *
* MCE_DATAPIPE
Expand All @@ -126,10 +116,10 @@ void mce_datapipe_generate_inactivity (void);
* ========================================================================= */

/** Retrieve a gint from a datapipe */
# define datapipe_get_gint(_datapipe) (GPOINTER_TO_INT((_datapipe).dp_cached_data))
# define datapipe_get_gint(_datapipe) ((gint)(void*)datapipe_value(&(_datapipe)))

/** Retrieve a guint from a datapipe */
# define datapipe_get_guint(_datapipe) (GPOINTER_TO_UINT((_datapipe).dp_cached_data))
# define datapipe_get_guint(_datapipe) ((guint)(void*)datapipe_value(&(_datapipe)))

/* Helper for making display state requests
*
Expand Down
2 changes: 1 addition & 1 deletion mce.h
Expand Up @@ -473,7 +473,7 @@ void mce_quit_mainloop(void);
void mce_signal_handlers_remove(void);

#define display_state_get() ({\
gint res = GPOINTER_TO_INT(display_state_curr_pipe.dp_cached_data);\
gint res = datapipe_get_gint(display_state_curr_pipe);\
mce_log(LL_DEBUG, "display_state_curr=%s",\
display_state_repr(res));\
res;\
Expand Down
11 changes: 8 additions & 3 deletions modules/display.c
Expand Up @@ -7253,7 +7253,9 @@ static void mdy_display_state_enter(display_state_t prev_state,
}

/* Restore display_state_curr_pipe to valid value */
display_state_curr_pipe.dp_cached_data = GINT_TO_POINTER(next_state);
// FIXME: datapipe value should not be directly manipulated
datapipe_set_value(&display_state_curr_pipe,
GINT_TO_POINTER(next_state));

/* Run display state change triggers */
mce_log(LL_CRUCIAL, "current display state = %s",
Expand Down Expand Up @@ -7347,9 +7349,12 @@ static void mdy_display_state_leave(display_state_t prev_state,

mce_log(LL_CRUCIAL, "current display state = %s",
display_state_repr(state));
display_state_curr_pipe.dp_cached_data = GINT_TO_POINTER(state);

// FIXME: datapipe value should not be directly manipulated
datapipe_set_value(&display_state_curr_pipe,
GINT_TO_POINTER(state));
datapipe_exec_full(&display_state_curr_pipe,
display_state_curr_pipe.dp_cached_data);
GINT_TO_POINTER(state));
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/led.c
Expand Up @@ -3197,8 +3197,8 @@ const gchar *g_module_check_init(GModule *module)

/* Initialize sw breathing state data */
sw_breathing_init();
charger_state_trigger(charger_state_pipe.dp_cached_data);
battery_level_trigger(battery_level_pipe.dp_cached_data);
charger_state_trigger(datapipe_value(&charger_state_pipe));
battery_level_trigger(datapipe_value(&battery_level_pipe));

/* Evaluate initial active pattern state */
led_enable();
Expand Down

0 comments on commit dcc0f24

Please sign in to comment.