Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle all the kmod init where all the modules are handled
We had the reference to the kmod ctx in usb-moded.c, now instead all is in the module
handling code. Which enables us to plug in libusbg / USB gadget fs later in a
cleaner way.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Aug 5, 2014
1 parent 098b51e commit 535e6ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/usb_moded-modules.c
Expand Up @@ -42,9 +42,23 @@
#include "usb_moded-modesetting.h"
#include "usb_moded-modes.h"

/* kmod context - initialized at start in usb_moded_init */
/* kmod context - initialized at start in usb_moded_init by ctx_init()
and cleaned up by ctx_cleanup() functions */
struct kmod_ctx *ctx;

/* kmod module init */
void usb_moded_module_ctx_init(void)
{
ctx = kmod_new(NULL, NULL);
kmod_load_resources(ctx);
}

/* kmod module cleanup */
void usb_moded_module_ctx_cleanup(void)
{
kmod_unref(ctx);
}

/** load module
*
* @param module Name of the module to load
Expand Down
6 changes: 6 additions & 0 deletions src/usb_moded-modules.h
Expand Up @@ -33,6 +33,12 @@
#define MODULE_DEVELOPER "g_ether"
#define MODULE_MTP "g_ffs"

/* module loading init */
void usb_moded_module_ctx_init(void);

/* module loading context cleanup */
void usb_moded_module_ctx_cleanup(void);

/* load module */
int usb_moded_load_module(const char *module);

Expand Down
9 changes: 2 additions & 7 deletions src/usb_moded.c
Expand Up @@ -535,8 +535,6 @@ inline struct mode_list_elem * get_usb_mode_data(void)
/* set default values for usb_moded */
static void usb_moded_init(void)
{
extern struct kmod_ctx *ctx;

current_mode.connected = FALSE;
current_mode.mounted = FALSE;
current_mode.mode = strdup(MODE_UNDEFINED);
Expand Down Expand Up @@ -571,8 +569,7 @@ static void usb_moded_init(void)
}

/* kmod init */
ctx = kmod_new(NULL, NULL);
kmod_load_resources(ctx);
usb_moded_module_ctx_init();

/* Android specific stuff */
if(android_settings())
Expand Down Expand Up @@ -607,8 +604,6 @@ static gboolean charging_fallback(gpointer data)

static void handle_exit(void)
{
extern struct kmod_ctx *ctx;

/* exiting and clean-up when mainloop ended */
appsync_stop();
hwal_cleanup();
Expand All @@ -618,7 +613,7 @@ static void handle_exit(void)
#endif /* MEEGOLOCK */

free_mode_list(modelist);
kmod_unref(ctx);
usb_moded_module_ctx_cleanup();

#ifdef APP_SYNC
free_appsync_list();
Expand Down

0 comments on commit 535e6ec

Please sign in to comment.