Commit 478ac654 authored by spiiroin's avatar spiiroin

[usb_moded] Use accessor functions for pc cable connect delay

Makes it easier to differentiate between value use and value modify.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 781067b9
......@@ -243,8 +243,8 @@ static void umudev_cable_state_from_udev(cable_state_t curr)
gint delay = 100;
if( curr == CABLE_STATE_PC_CONNECTED && prev != CABLE_STATE_UNKNOWN ) {
if( delay < usbmoded_cable_connection_delay )
delay = usbmoded_cable_connection_delay;
if( delay < usbmoded_get_cable_connection_delay() )
delay = usbmoded_get_cable_connection_delay();
}
umudev_cable_state_start_timer(delay);
......
......@@ -104,19 +104,21 @@
/* -- usbmoded -- */
static void usbmoded_set_cable_connection_delay(int delay_ms);
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);
bool usbmoded_can_export (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[]);
/* ========================================================================= *
* Data
......@@ -132,10 +134,6 @@ static bool usbmoded_hw_fallback = false;
static bool usbmoded_systemd_notify = false;
#endif
/** Currently allowed cable detection delay
*/
int usbmoded_cable_connection_delay = CABLE_CONNECTION_DELAY_DEFAULT;
/* ========================================================================= *
* Functions
* ========================================================================= */
......@@ -144,21 +142,43 @@ int usbmoded_cable_connection_delay = CABLE_CONNECTION_DELAY_DEFAULT;
* CABLE_CONNECT_DELAY
* ------------------------------------------------------------------------- */
/** PC connection delay
*
* Slow cable insert / similar physical issues can lead to a charger
* getting initially recognized as a pc connection. This defines how
* long we should wait and see if pc connection gets corrected to a
* charger kind.
*/
static int usbmoded_cable_connection_delay = CABLE_CONNECTION_DELAY_DEFAULT;
/** Helper for setting allowed cable detection delay
*
* Used for implementing --max-cable-delay=<ms> option.
*/
static void usbmoded_set_cable_connection_delay(int delay_ms)
void
usbmoded_set_cable_connection_delay(int delay_ms)
{
if( delay_ms < CABLE_CONNECTION_DELAY_MAXIMUM )
if( delay_ms > CABLE_CONNECTION_DELAY_MAXIMUM )
delay_ms = CABLE_CONNECTION_DELAY_MAXIMUM;
if( delay_ms < 0 )
delay_ms = 0;
if( usbmoded_cable_connection_delay != delay_ms ) {
log_info("cable_connection_delay: %d -> %d",
usbmoded_cable_connection_delay,
delay_ms);
usbmoded_cable_connection_delay = delay_ms;
else {
usbmoded_cable_connection_delay = CABLE_CONNECTION_DELAY_MAXIMUM;
log_warning("using maximum connection delay: %d ms",
usbmoded_cable_connection_delay);
}
}
/** Helper for getting allowed cable detection delay
*/
int
usbmoded_get_cable_connection_delay(void)
{
return usbmoded_cable_connection_delay;
}
/* ------------------------------------------------------------------------- *
* SUSPEND_BLOCKING
* ------------------------------------------------------------------------- */
......
......@@ -60,15 +60,6 @@
* Data
* ========================================================================= */
/** PC connection delay (FIXME: is defunct now)
*
* Slow cable insert / similar physical issues can lead to a charger
* getting initially recognized as a pc connection. This defines how
* long we should wait and see if pc connection gets corrected to a
* charger kind.
*/
extern int usbmoded_cable_connection_delay;
/** Rescue mode flag
*
* When enabled, usb-moded allows developer_mode etc when device is
......@@ -85,15 +76,15 @@ extern GList *usbmoded_modelist;
* Functions
* ========================================================================= */
/* -- usbmoded -- */
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);
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_init_done_p (void);
void usbmoded_set_init_done (bool reached);
void usbmoded_probe_init_done (void);
bool usbmoded_can_export (void);
void usbmoded_exit_mainloop (int exitcode);
void usbmoded_handle_signal (int signum);
#endif /* USB_MODED_H_ */
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