Commit 1ae9b0b8 authored by spiiroin's avatar spiiroin

[usb-moded] Add usbmoded_get_modedata() function

Iterating mode lists is cumbersome and might not be safe when done from
the worker thread.

As an enabler for removing custom list iterators, implement common
usbmoded_get_modedata() function for locating mode data by name.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent ac5a4dc5
......@@ -106,28 +106,29 @@
* USBMODED
* ------------------------------------------------------------------------- */
GList *usbmoded_get_modelist (void);
void usbmoded_load_modelist (void);
void usbmoded_free_modelist (void);
bool usbmoded_get_rescue_mode (void);
void usbmoded_set_rescue_mode (bool rescue_mode);
bool usbmoded_get_diag_mode (void);
void usbmoded_set_diag_mode (bool diag_mode);
void usbmoded_set_cable_connection_delay(int delay_ms);
int usbmoded_get_cable_connection_delay(void);
static gboolean usbmoded_allow_suspend_timer_cb (gpointer aptr);
void usbmoded_allow_suspend (void);
void usbmoded_delay_suspend (void);
bool usbmoded_can_export (void);
bool usbmoded_init_done_p (void);
void usbmoded_set_init_done (bool reached);
void usbmoded_probe_init_done (void);
void usbmoded_exit_mainloop (int exitcode);
void usbmoded_handle_signal (int signum);
static bool usbmoded_init (void);
static void usbmoded_cleanup (void);
static void usbmoded_usage (void);
static void usbmoded_parse_options (int argc, char *argv[]);
GList *usbmoded_get_modelist (void);
void usbmoded_load_modelist (void);
void usbmoded_free_modelist (void);
const modedata_t *usbmoded_get_modedata (const char *modename);
bool usbmoded_get_rescue_mode (void);
void usbmoded_set_rescue_mode (bool rescue_mode);
bool usbmoded_get_diag_mode (void);
void usbmoded_set_diag_mode (bool diag_mode);
void usbmoded_set_cable_connection_delay(int delay_ms);
int usbmoded_get_cable_connection_delay(void);
static gboolean usbmoded_allow_suspend_timer_cb (gpointer aptr);
void usbmoded_allow_suspend (void);
void usbmoded_delay_suspend (void);
bool usbmoded_can_export (void);
bool usbmoded_init_done_p (void);
void usbmoded_set_init_done (bool reached);
void usbmoded_probe_init_done (void);
void usbmoded_exit_mainloop (int exitcode);
void usbmoded_handle_signal (int signum);
static bool usbmoded_init (void);
static void usbmoded_cleanup (void);
static void usbmoded_usage (void);
static void usbmoded_parse_options (int argc, char *argv[]);
/* ------------------------------------------------------------------------- *
* MAIN
......@@ -189,6 +190,21 @@ usbmoded_free_modelist(void)
}
}
const modedata_t *
usbmoded_get_modedata(const char *modename)
{
modedata_t *modedata = 0;
for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) ) {
modedata_t *data = iter->data;
if( !g_strcmp0(data->mode_name, modename) ) {
modedata = data;
break;
}
}
return modedata;
}
/* ------------------------------------------------------------------------- *
* RESCUE_MODE
* ------------------------------------------------------------------------- */
......
......@@ -32,6 +32,8 @@
# include "../config.h" // NOTRIM
# endif
# include "usb_moded-dyn-config.h"
# include <stdbool.h>
# include <stdio.h>
......@@ -64,23 +66,24 @@
* USBMODED
* ------------------------------------------------------------------------- */
GList *usbmoded_get_modelist (void);
void usbmoded_load_modelist (void);
void usbmoded_free_modelist (void);
bool usbmoded_get_rescue_mode (void);
void usbmoded_set_rescue_mode (bool rescue_mode);
bool usbmoded_get_diag_mode (void);
void usbmoded_set_diag_mode (bool diag_mode);
void usbmoded_set_cable_connection_delay(int delay_ms);
int usbmoded_get_cable_connection_delay(void);
void usbmoded_allow_suspend (void);
void usbmoded_delay_suspend (void);
bool usbmoded_can_export (void);
bool usbmoded_init_done_p (void);
void usbmoded_set_init_done (bool reached);
void usbmoded_probe_init_done (void);
void usbmoded_exit_mainloop (int exitcode);
void usbmoded_handle_signal (int signum);
GList *usbmoded_get_modelist (void);
void usbmoded_load_modelist (void);
void usbmoded_free_modelist (void);
const modedata_t *usbmoded_get_modedata (const char *modename);
bool usbmoded_get_rescue_mode (void);
void usbmoded_set_rescue_mode (bool rescue_mode);
bool usbmoded_get_diag_mode (void);
void usbmoded_set_diag_mode (bool diag_mode);
void usbmoded_set_cable_connection_delay(int delay_ms);
int usbmoded_get_cable_connection_delay(void);
void usbmoded_allow_suspend (void);
void usbmoded_delay_suspend (void);
bool usbmoded_can_export (void);
bool usbmoded_init_done_p (void);
void usbmoded_set_init_done (bool reached);
void usbmoded_probe_init_done (void);
void usbmoded_exit_mainloop (int exitcode);
void usbmoded_handle_signal (int signum);
/* ------------------------------------------------------------------------- *
* MAIN
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment