Commit 97107d13 authored by spiiroin's avatar spiiroin

[usb-moded] Normalize backend startup/cleanup functionality

Use backend_init() and backend_quit() functions for settings up and
cleaning up all backends.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 9ae49bb2
......@@ -42,7 +42,8 @@
bool android_in_use (void);
static bool android_probe (void);
gchar *android_get_serial (void);
bool android_init_values (void);
bool android_init (void);
void android_quit (void);
bool android_set_enabled (bool enable);
bool android_set_charging_mode(void);
bool android_set_function (const char *function);
......@@ -161,9 +162,11 @@ EXIT:
}
/** initialize the basic android values
*
* @return true if android usb backend is ready for use, false otherwise
*/
bool
android_init_values(void)
android_init(void)
{
LOG_REGISTER_CONTEXT;
......@@ -224,6 +227,14 @@ EXIT:
return android_in_use();
}
/** Cleanup resources allocated by android usb backend
*/
void
android_quit(void)
{
/* For now this exists for symmetry with other backends only */
}
bool
android_set_enabled(bool enable)
{
......
......@@ -48,7 +48,8 @@
bool android_in_use (void);
gchar *android_get_serial (void);
bool android_init_values (void);
bool android_init (void);
void android_quit (void);
bool android_set_enabled (bool enable);
bool android_set_charging_mode(void);
bool android_set_function (const char *function);
......
......@@ -88,7 +88,8 @@ static bool configfs_write_file (const char *path, const char
static bool configfs_read_file (const char *path, char *buff, size_t size);
static bool configfs_write_udc (const char *text);
bool configfs_set_udc (bool enable);
bool configfs_init_values (void);
bool configfs_init (void);
void configfs_quit (void);
bool configfs_set_charging_mode (void);
bool configfs_set_productid (const char *id);
bool configfs_set_vendorid (const char *id);
......@@ -740,9 +741,11 @@ configfs_set_udc(bool enable)
}
/** initialize the basic configfs values
*
* @return true if configfs backend is ready for use, false otherwise
*/
bool
configfs_init_values(void)
configfs_init(void)
{
LOG_REGISTER_CONTEXT;
......@@ -802,6 +805,44 @@ EXIT:
return configfs_in_use();
}
/** Cleanup resources allocated by configfs backend
*/
void
configfs_quit(void)
{
g_free(GADGET_BASE_DIRECTORY),
GADGET_BASE_DIRECTORY = 0;
g_free(GADGET_FUNC_DIRECTORY),
GADGET_FUNC_DIRECTORY = 0;
g_free(GADGET_CONF_DIRECTORY),
GADGET_CONF_DIRECTORY = 0;
g_free(GADGET_CTRL_UDC),
GADGET_CTRL_UDC = 0;
g_free(GADGET_CTRL_ID_VENDOR),
GADGET_CTRL_ID_VENDOR= 0;
g_free(GADGET_CTRL_ID_PRODUCT),
GADGET_CTRL_ID_PRODUCT= 0;
g_free(GADGET_CTRL_MANUFACTURER),
GADGET_CTRL_MANUFACTURER= 0;
g_free(GADGET_CTRL_PRODUCT),
GADGET_CTRL_PRODUCT = 0;
g_free(GADGET_CTRL_SERIAL),
GADGET_CTRL_SERIAL = 0;
g_free(FUNCTION_MASS_STORAGE),
FUNCTION_MASS_STORAGE = 0;
g_free(FUNCTION_RNDIS),
FUNCTION_RNDIS = 0;
g_free(FUNCTION_MTP),
FUNCTION_MTP = 0;
g_free(RNDIS_CTRL_WCEIS),
RNDIS_CTRL_WCEIS = 0;
g_free(RNDIS_CTRL_ETHADDR),
RNDIS_CTRL_ETHADDR= 0;
}
/* Set a charging mode for the configfs gadget
*
* @return true if successful, false on failure
......
......@@ -33,7 +33,8 @@
bool configfs_in_use (void);
bool configfs_set_udc (bool enable);
bool configfs_init_values (void);
bool configfs_init (void);
void configfs_quit (void);
bool configfs_set_charging_mode (void);
bool configfs_set_productid (const char *id);
bool configfs_set_vendorid (const char *id);
......
......@@ -135,7 +135,10 @@ static bool modules_probe(void)
return modules_in_use();
}
/* kmod module init */
/** kmod module init
*
* @return true if modules backend is ready for use, false otherwise
*/
bool modules_init(void)
{
LOG_REGISTER_CONTEXT;
......
......@@ -48,7 +48,7 @@
/* -- modules -- */
bool modules_in_use (void);
bool modules_in_use (void);
bool modules_init (void);
void modules_quit (void);
int modules_load_module (const char *module);
......
......@@ -566,10 +566,10 @@ static bool usbmoded_init(void)
* while waiting.
*/
for( int i = 10; ; ) {
if( configfs_init_values() )
if( configfs_init() )
break;
if( android_init_values() )
if( android_init() )
break;
/* Must probe / poll since we're not yet running mainloop */
......@@ -680,8 +680,10 @@ static void usbmoded_cleanup(void)
/* Stop udev listener */
umudev_quit();
/* Undo modules_init() */
/* Do backend specific cleanup */
modules_quit();
android_quit();
configfs_quit();
/* Undo trigger_init() */
trigger_stop();
......
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