Skip to content

Commit

Permalink
[usb_moded] Use accessor functions for pc cable connect delay
Browse files Browse the repository at this point in the history
Makes it easier to differentiate between value use and value modify.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 5, 2018
1 parent 781067b commit 478ac65
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/usb_moded-udev.c
Expand Up @@ -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);
Expand Down
44 changes: 32 additions & 12 deletions src/usb_moded.c
Expand Up @@ -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
Expand All @@ -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
* ========================================================================= */
Expand All @@ -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
* ------------------------------------------------------------------------- */
Expand Down
29 changes: 10 additions & 19 deletions src/usb_moded.h
Expand Up @@ -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
Expand All @@ -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_ */

0 comments on commit 478ac65

Please sign in to comment.