Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dyn-config] Group functions by type
Move functions of the same type close to each other.

No functional changes.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Apr 9, 2019
1 parent b234f7f commit 390ccad
Showing 1 changed file with 67 additions and 63 deletions.
130 changes: 67 additions & 63 deletions src/usb_moded-dyn-config.c
Expand Up @@ -52,7 +52,7 @@ void modelist_free(GList *modelist);
GList *modelist_load(int diag);

/* ========================================================================= *
* Functions
* MODEDATA
* ========================================================================= */

/** Relase modedata_t object
Expand Down Expand Up @@ -88,23 +88,6 @@ modedata_free(modedata_t *list_item)
}
}

/** Release mode list
*
* @param modelist List pointer, or NULL
*/
void
modelist_free(GList *modelist)
{
LOG_REGISTER_CONTEXT;

if(modelist)
{
g_list_foreach(modelist, (GFunc) modedata_free, NULL);
g_list_free(modelist);
modelist = 0;
}
}

/** Callback for sorting mode list alphabetically
*
* For use with g_list_sort()
Expand All @@ -125,51 +108,6 @@ modedata_sort_cb(gconstpointer a, gconstpointer b)
return g_strcmp0(aa->mode_name, bb->mode_name);
}

/** Load mode data files from configuration directory
*
* @param diag true to load diagnostic modes, false for normal modes
*
* @return List of mode data objects, or NULL
*/
GList *
modelist_load(int diag)
{
LOG_REGISTER_CONTEXT;

GDir *confdir;
GList *modelist = NULL;
const gchar *dirname;
modedata_t *list_item;
gchar *full_filename = NULL;

if(diag)
confdir = g_dir_open(DIAG_DIR_PATH, 0, NULL);
else
confdir = g_dir_open(MODE_DIR_PATH, 0, NULL);
if(confdir)
{
while((dirname = g_dir_read_name(confdir)) != NULL)
{
log_debug("Read file %s\n", dirname);
if(diag)
full_filename = g_strconcat(DIAG_DIR_PATH, "/", dirname, NULL);
else
full_filename = g_strconcat(MODE_DIR_PATH, "/", dirname, NULL);
list_item = modedata_load(full_filename);
/* free full_filename immediately as we do not use it anymore */
free(full_filename);
if(list_item)
modelist = g_list_append(modelist, list_item);
}
g_dir_close(confdir);
}
else
log_debug("Mode confdir open failed or file is incomplete/invalid.\n");

modelist = g_list_sort (modelist, modedata_sort_cb);
return modelist;
}

/** Load mode data from file
*
* @param filename Path to file from which to read
Expand Down Expand Up @@ -268,3 +206,69 @@ modedata_load(const gchar *filename)

return list_item;
}

/* ========================================================================= *
* MODELIST
* ========================================================================= */

/** Release mode list
*
* @param modelist List pointer, or NULL
*/
void
modelist_free(GList *modelist)
{
LOG_REGISTER_CONTEXT;

if(modelist)
{
g_list_foreach(modelist, (GFunc) modedata_free, NULL);
g_list_free(modelist);
modelist = 0;
}
}

/** Load mode data files from configuration directory
*
* @param diag true to load diagnostic modes, false for normal modes
*
* @return List of mode data objects, or NULL
*/
GList *
modelist_load(int diag)
{
LOG_REGISTER_CONTEXT;

GDir *confdir;
GList *modelist = NULL;
const gchar *dirname;
modedata_t *list_item;
gchar *full_filename = NULL;

if(diag)
confdir = g_dir_open(DIAG_DIR_PATH, 0, NULL);
else
confdir = g_dir_open(MODE_DIR_PATH, 0, NULL);
if(confdir)
{
while((dirname = g_dir_read_name(confdir)) != NULL)
{
log_debug("Read file %s\n", dirname);
if(diag)
full_filename = g_strconcat(DIAG_DIR_PATH, "/", dirname, NULL);
else
full_filename = g_strconcat(MODE_DIR_PATH, "/", dirname, NULL);
list_item = modedata_load(full_filename);
/* free full_filename immediately as we do not use it anymore */
free(full_filename);
if(list_item)
modelist = g_list_append(modelist, list_item);
}
g_dir_close(confdir);
}
else
log_debug("Mode confdir open failed or file is incomplete/invalid.\n");

modelist = g_list_sort (modelist, modedata_sort_cb);
return modelist;
}

0 comments on commit 390ccad

Please sign in to comment.