datapipe.h 10.4 KB
Newer Older
1 2 3 4 5
/**
 * @file datapipe.h
 * Headers for the simple filter framework
 * <p>
 * Copyright © 2007 Nokia Corporation and/or its subsidiary(-ies).
6
 * Copyright (C) 2014-2019 Jolla Ltd.
7
 * Copyright (c) 2019 Open Mobile Platform LLC.
8 9
 * <p>
 * @author David Weinehall <david.weinehall@nokia.com>
10
 * @author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * mce is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * mce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with mce.  If not, see <http://www.gnu.org/licenses/>.
 */
24 25
#ifndef  _DATAPIPE_H_
# define _DATAPIPE_H_
26

27 28 29 30 31 32
# include <stdbool.h>
# include <glib.h>

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

34
/** Device lock states used in devicelock_state_pipe */
35 36 37
typedef enum
{
    /** Device lock is not active */
38
    DEVICELOCK_STATE_UNLOCKED  = 0,
39 40

    /** Device lock is active */
41
    DEVICELOCK_STATE_LOCKED    = 1,
42 43

    /** Initial startup value; from mce p.o.v. equals not active */
44 45
    DEVICELOCK_STATE_UNDEFINED = 2,
}  devicelock_state_t;
46

47
const char *devicelock_state_repr(devicelock_state_t state);
48

49 50 51 52
/**
 * Read only policy type
 */
typedef enum {
53 54 55
    DATAPIPE_FILTERING_ALLOWED = FALSE,  /**< The pipe is read/write */
    DATAPIPE_FILTERING_DENIED  = TRUE,   /**< The pipe is read only */
} datapipe_filtering_t;
56 57 58 59 60

/**
 * Policy used for caching indata
 */
typedef enum {
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    /** Data is passed through datapipe, but is not cached
     *
     * Suitable for stateless impulse and event data.
     */
    DATAPIPE_CACHE_NOTHING = 0,

    /** Update cache with unfiltered input value
     *
     * The cached value is set to unfiltered input value.
     *
     * Suitable for datapipes designed to be re-run in mind - in practice
     * this would be brightness control pipes where the input is setting
     * value and output is light sensor filtered hw brightness level.
     */
    DATAPIPE_CACHE_INDATA  = 1<<0,

    /** Update cache with filtered input value
     *
     * The cached value is set to filtered input value.
     */
    DATAPIPE_CACHE_OUTDATA = 1<<1,

    /* Update cache both with unfiltered and filtered input value
     *
     * The cached value is updated both before and after filtering.
     *
     * As this is the least likely option to cause differences between
     * direct datapipe polling and following notifications, it should
     * be used unless there is some specific reason not to.
     */
91 92
    DATAPIPE_CACHE_DEFAULT = (DATAPIPE_CACHE_INDATA |
                              DATAPIPE_CACHE_OUTDATA),
93
} datapipe_cache_t;
94

95 96 97 98 99
/**
 * Datapipe structure
 *
 * Only access this struct through the functions
 */
100
typedef struct datapipe_t datapipe_t;
101

102 103
typedef struct
{
104 105 106 107 108
    datapipe_t  *datapipe;
    void       (*output_cb)(gconstpointer data);
    void       (*input_cb)(gconstpointer data);
    gpointer   (*filter_cb)(gpointer data);
    bool         bound;
109 110 111 112 113 114 115 116 117
} datapipe_handler_t;

typedef struct
{
    const char         *module;
    datapipe_handler_t *handlers;
    guint               execute_id;
} datapipe_bindings_t;

118 119 120
/* ========================================================================= *
 * Functions
 * ========================================================================= */
121

122 123 124 125
/* ------------------------------------------------------------------------- *
 * DATAPIPE
 * ------------------------------------------------------------------------- */

126 127
const char     *datapipe_name     (const datapipe_t *self);
gconstpointer   datapipe_value    (const datapipe_t *self);
128 129
gconstpointer   datapipe_exec_full_real(datapipe_t *self, gconstpointer indata,
                                   const char *file, const char *func);
130
void            datapipe_set_value(datapipe_t *self, gconstpointer data);
131

132 133 134
#define datapipe_exec_full(PIPE_,DATA_)\
   datapipe_exec_full_real(PIPE_,DATA_,__FILE__,__func__)

135 136 137 138
/* ------------------------------------------------------------------------- *
 * MCE_DATAPIPE
 * ------------------------------------------------------------------------- */

139 140 141 142
void  mce_datapipe_init         (void);
void  mce_datapipe_quit         (void);
void  mce_datapipe_init_bindings(datapipe_bindings_t *self);
void  mce_datapipe_quit_bindings(datapipe_bindings_t *self);
143

144 145 146
void  mce_datapipe_generate_activity   (void);
void  mce_datapipe_generate_inactivity (void);

147 148 149 150 151
/* ========================================================================= *
 * Macros
 * ========================================================================= */

/** Retrieve a gint from a datapipe */
152
# define datapipe_get_gint(_datapipe) ((gint)(void*)datapipe_value(&(_datapipe)))
153 154

/** Retrieve a guint from a datapipe */
155
# define datapipe_get_guint(_datapipe) ((guint)(void*)datapipe_value(&(_datapipe)))
156

157 158 159 160 161
/* Helper for making display state requests
 *
 * This needs to be macro so that logging context stays
 * at the point of call.
 */
162
# define mce_datapipe_request_display_state(state_) do {\
163 164
    display_state_t cur_target = datapipe_get_gint(display_state_next_pipe);\
    display_state_t req_target = (display_state_t)(state_);\
165 166 167
    /* Use elevated logginng verbosity for requests that \
     * are likely to result in display power up. */ \
    int level = LL_DEBUG; \
168
    if( cur_target != req_target ) {\
169 170 171 172 173 174 175 176
        switch( req_target ) {\
        case MCE_DISPLAY_ON:\
        case MCE_DISPLAY_LPM_ON:\
            level = LL_CRUCIAL;\
            break;\
        default:\
            break;\
        }\
177
    }\
178
    mce_log(level, "display state req: %s",\
179
            display_state_repr(req_target));\
180 181 182 183
    /* But the request must always be fed to the datapipe \
     * because during already ongoing transition something \
     * else might be already queued up and we want't the \
     * last request to reach the queue to "win". */ \
184
    datapipe_exec_full(&display_state_request_pipe,\
185
                       GINT_TO_POINTER(req_target));\
186 187
} while(0)

188 189 190 191 192 193
/** Execute tklock request
 *
 * @param tklock_request Value from  tklock_request_t
 */
#define mce_datapipe_request_tklock(tklock_request) do {\
    mce_log(LL_DEBUG, "Requesting tklock=%s",\
194
            tklock_request_repr(tklock_request));\
195
    datapipe_exec_full(&tklock_request_pipe,\
196
                       GINT_TO_POINTER(tklock_request));\
197
}while(0)
198

199 200 201 202 203 204 205 206 207 208 209 210
/** Add reason -prefix for executing proximity_sensor_required_pipe request
 *
 * See #proximity_sensor_required_pipe for details.
 */
#define PROXIMITY_SENSOR_REQUIRED_ADD "+"

/** Remove reason -prefix for executing proximity_sensor_required_pipe request
 *
 * See #proximity_sensor_required_pipe for details.
 */
#define PROXIMITY_SENSOR_REQUIRED_REM "-"

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
/* ========================================================================= *
 * Datapipes
 * ========================================================================= */

/* Available datapipes */
extern datapipe_t led_brightness_pipe;
extern datapipe_t lpm_brightness_pipe;
extern datapipe_t device_inactive_pipe;
extern datapipe_t inactivity_event_pipe;
extern datapipe_t led_pattern_activate_pipe;
extern datapipe_t led_pattern_deactivate_pipe;
extern datapipe_t resume_detected_event_pipe;
extern datapipe_t user_activity_event_pipe;
extern datapipe_t display_state_curr_pipe;
extern datapipe_t display_state_request_pipe;
extern datapipe_t display_state_next_pipe;
extern datapipe_t uiexception_type_pipe;
extern datapipe_t display_brightness_pipe;
extern datapipe_t key_backlight_brightness_pipe;
extern datapipe_t keypress_event_pipe;
extern datapipe_t touchscreen_event_pipe;
extern datapipe_t lockkey_state_pipe;
extern datapipe_t init_done_pipe;
extern datapipe_t keyboard_slide_state_pipe;
extern datapipe_t keyboard_available_state_pipe;
extern datapipe_t lid_sensor_is_working_pipe;
extern datapipe_t lid_sensor_actual_pipe;
extern datapipe_t lid_sensor_filtered_pipe;
extern datapipe_t lens_cover_state_pipe;
extern datapipe_t proximity_sensor_actual_pipe;
241 242 243
extern datapipe_t proximity_sensor_effective_pipe;
extern datapipe_t proximity_sensor_required_pipe;
extern datapipe_t proximity_blanked_pipe;
244 245 246 247 248 249 250 251 252 253 254 255 256
extern datapipe_t light_sensor_actual_pipe;
extern datapipe_t light_sensor_filtered_pipe;
extern datapipe_t light_sensor_poll_request_pipe;
extern datapipe_t orientation_sensor_actual_pipe;
extern datapipe_t alarm_ui_state_pipe;
extern datapipe_t system_state_pipe;
extern datapipe_t master_radio_enabled_pipe;
extern datapipe_t submode_pipe;
extern datapipe_t call_state_pipe;
extern datapipe_t ignore_incoming_call_event_pipe;
extern datapipe_t call_type_pipe;
extern datapipe_t tklock_request_pipe;
extern datapipe_t interaction_expected_pipe;
257
extern datapipe_t charger_type_pipe;
258 259
extern datapipe_t charger_state_pipe;
extern datapipe_t battery_status_pipe;
260
extern datapipe_t battery_state_pipe;
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
extern datapipe_t battery_level_pipe;
extern datapipe_t topmost_window_pid_pipe;
extern datapipe_t camera_button_state_pipe;
extern datapipe_t inactivity_delay_pipe;
extern datapipe_t audio_route_pipe;
extern datapipe_t usb_cable_state_pipe;
extern datapipe_t jack_sense_state_pipe;
extern datapipe_t power_saving_mode_active_pipe;
extern datapipe_t thermal_state_pipe;
extern datapipe_t heartbeat_event_pipe;
extern datapipe_t compositor_service_state_pipe;
extern datapipe_t lipstick_service_state_pipe;
extern datapipe_t devicelock_service_state_pipe;
extern datapipe_t usbmoded_service_state_pipe;
extern datapipe_t ngfd_service_state_pipe;
extern datapipe_t ngfd_event_request_pipe;
extern datapipe_t dsme_service_state_pipe;
278
extern datapipe_t thermalmanager_service_state_pipe;
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
extern datapipe_t bluez_service_state_pipe;
extern datapipe_t packagekit_locked_pipe;
extern datapipe_t osupdate_running_pipe;
extern datapipe_t shutting_down_pipe;
extern datapipe_t devicelock_state_pipe;
extern datapipe_t touch_detected_pipe;
extern datapipe_t touch_grab_wanted_pipe;
extern datapipe_t touch_grab_active_pipe;
extern datapipe_t keypad_grab_wanted_pipe;
extern datapipe_t keypad_grab_active_pipe;
extern datapipe_t music_playback_ongoing_pipe;
extern datapipe_t fpd_service_state_pipe;
extern datapipe_t fpstate_pipe;
extern datapipe_t enroll_in_progress_pipe;

#endif /* _DATAPIPE_H_ */