Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dyn-config] Rename mode_list_elem_t to modedata_t
The important part is that these structures contain mode data, not
that they are also held in lists - make the naming reflect this.

Also rename related functions accordingly.

No functional changes.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Apr 9, 2019
1 parent 73b7210 commit e765c72
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/usb_moded-common.c
Expand Up @@ -468,7 +468,7 @@ int common_valid_mode(const char *mode)
whitelist_array = g_strsplit(whitelist_value, ",", 0);

for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) ) {
mode_list_elem_t *data = iter->data;
modedata_t *data = iter->data;
if( strcmp(mode, data->mode_name) )
continue;

Expand Down Expand Up @@ -525,7 +525,7 @@ gchar *common_get_mode_list(mode_list_type_t type)

for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) )
{
mode_list_elem_t *data = iter->data;
modedata_t *data = iter->data;

/* skip items in the hidden list */
if (common_mode_in_list(data->mode_name, hidden_modes_array))
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-config.c
Expand Up @@ -622,7 +622,7 @@ char * config_get_network_setting(const char *config)
LOG_REGISTER_CONTEXT;

char * ret = 0;
mode_list_elem_t *data;
modedata_t *data;

if(!strcmp(config, NETWORK_IP_KEY))
{
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-control.c
Expand Up @@ -325,7 +325,7 @@ void control_select_usb_mode(void)
log_err("Diagnostic mode is not configured!");
}
else {
mode_list_elem_t *data = iter->data;
modedata_t *data = iter->data;
log_debug("Entering diagnostic mode!");
control_set_usb_mode(data->mode_name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/usb_moded-dbus.c
Expand Up @@ -1034,11 +1034,11 @@ umdbus_append_mode_details(DBusMessage *msg, const char *mode_name)
{
LOG_REGISTER_CONTEXT;

const mode_list_elem_t *data = 0;
const modedata_t *data = 0;

for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) )
{
const mode_list_elem_t *iter_data = iter->data;
const modedata_t *iter_data = iter->data;
if( g_strcmp0(iter_data->mode_name, mode_name) )
continue;
data = iter_data;
Expand Down
43 changes: 24 additions & 19 deletions src/usb_moded-dyn-config.c
Expand Up @@ -37,20 +37,25 @@
* ========================================================================= */

/* ------------------------------------------------------------------------- *
* UTILITY
* MODEDATA
* ------------------------------------------------------------------------- */

void dynconfig_free_list_item(mode_list_elem_t *list_item);
void dynconfig_free_mode_list(GList *modelist);
static gint dynconfig_compare_modes (gconstpointer a, gconstpointer b);
GList *dynconfig_read_mode_list(int diag);
static mode_list_elem_t *dynconfig_read_mode_file(const gchar *filename);
void modedata_free (modedata_t *list_item);
static gint modedata_sort_cb(gconstpointer a, gconstpointer b);
static modedata_t *modedata_load (const gchar *filename);

/* ------------------------------------------------------------------------- *
* MODELIST
* ------------------------------------------------------------------------- */

void modelist_free(GList *modelist);
GList *modelist_load(int diag);

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

void dynconfig_free_list_item(mode_list_elem_t *list_item)
void modedata_free(modedata_t *list_item)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -78,36 +83,36 @@ void dynconfig_free_list_item(mode_list_elem_t *list_item)
}
}

void dynconfig_free_mode_list(GList *modelist)
void modelist_free(GList *modelist)
{
LOG_REGISTER_CONTEXT;

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

static gint dynconfig_compare_modes(gconstpointer a, gconstpointer b)
static gint modedata_sort_cb(gconstpointer a, gconstpointer b)
{
LOG_REGISTER_CONTEXT;

mode_list_elem_t *aa = (mode_list_elem_t *)a;
mode_list_elem_t *bb = (mode_list_elem_t *)b;
modedata_t *aa = (modedata_t *)a;
modedata_t *bb = (modedata_t *)b;

return g_strcmp0(aa->mode_name, bb->mode_name);
}

GList *dynconfig_read_mode_list(int diag)
GList *modelist_load(int diag)
{
LOG_REGISTER_CONTEXT;

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

if(diag)
Expand All @@ -123,7 +128,7 @@ GList *dynconfig_read_mode_list(int diag)
full_filename = g_strconcat(DIAG_DIR_PATH, "/", dirname, NULL);
else
full_filename = g_strconcat(MODE_DIR_PATH, "/", dirname, NULL);
list_item = dynconfig_read_mode_file(full_filename);
list_item = modedata_load(full_filename);
/* free full_filename immediately as we do not use it anymore */
free(full_filename);
if(list_item)
Expand All @@ -134,17 +139,17 @@ GList *dynconfig_read_mode_list(int diag)
else
log_debug("Mode confdir open failed or file is incomplete/invalid.\n");

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

static mode_list_elem_t *dynconfig_read_mode_file(const gchar *filename)
static modedata_t *modedata_load(const gchar *filename)
{
LOG_REGISTER_CONTEXT;

bool success = false;
GKeyFile *settingsfile = g_key_file_new();
mode_list_elem_t *list_item = NULL;
modedata_t *list_item = NULL;

if( !g_key_file_load_from_file(settingsfile, filename, G_KEY_FILE_NONE, NULL) ) {
log_err("%s: can't read mode configuration file", filename);
Expand Down Expand Up @@ -225,7 +230,7 @@ static mode_list_elem_t *dynconfig_read_mode_file(const gchar *filename)
g_key_file_free(settingsfile);

if( !success )
dynconfig_free_list_item(list_item), list_item = 0;
modedata_free(list_item), list_item = 0;

return list_item;
}
17 changes: 11 additions & 6 deletions src/usb_moded-dyn-config.h
Expand Up @@ -93,7 +93,7 @@
/**
* Struct keeping all the data needed for the definition of a dynamic mode
*/
typedef struct mode_list_elem_t
typedef struct modedata_t
{
char *mode_name; /**< Mode name */
char *mode_module; /**< Needed module for given mode */
Expand All @@ -119,18 +119,23 @@ typedef struct mode_list_elem_t
# ifdef CONNMAN
char* connman_tethering; /**< Connman's tethering technology path */
# endif
} mode_list_elem_t;
} modedata_t;

/* ========================================================================= *
* Prototypes
* ========================================================================= */

/* ------------------------------------------------------------------------- *
* UTILITY
* MODEDATA
* ------------------------------------------------------------------------- */

void dynconfig_free_list_item(mode_list_elem_t *list_item);
void dynconfig_free_mode_list(GList *modelist);
GList *dynconfig_read_mode_list(int diag);
void modedata_free(modedata_t *list_item);

/* ------------------------------------------------------------------------- *
* MODELIST
* ------------------------------------------------------------------------- */

void modelist_free(GList *modelist);
GList *modelist_load(int diag);

#endif /* USB_MODED_DYN_CONFIG_H_ */
12 changes: 6 additions & 6 deletions src/usb_moded-modesetting.c
Expand Up @@ -79,8 +79,8 @@ bool modesetting_unmount (const char *mount
static gchar *modesetting_mountdev (const char *mountpoint);
static void modesetting_free_storage_info (storage_info_t *info);
static storage_info_t *modesetting_get_storage_info (size_t *pcount);
static bool modesetting_enter_mass_storage_mode (mode_list_elem_t *data);
static int modesetting_leave_mass_storage_mode (mode_list_elem_t *data);
static bool modesetting_enter_mass_storage_mode (modedata_t *data);
static int modesetting_leave_mass_storage_mode (modedata_t *data);
static void modesetting_report_mass_storage_blocker(const char *mountpoint, int try);
bool modesetting_enter_dynamic_mode (void);
void modesetting_leave_dynamic_mode (void);
Expand Down Expand Up @@ -426,7 +426,7 @@ modesetting_get_storage_info(size_t *pcount)
return *pcount = count, info;
}

static bool modesetting_enter_mass_storage_mode(mode_list_elem_t *data)
static bool modesetting_enter_mass_storage_mode(modedata_t *data)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -564,7 +564,7 @@ static bool modesetting_enter_mass_storage_mode(mode_list_elem_t *data)
return ack;
}

static int modesetting_leave_mass_storage_mode(mode_list_elem_t *data)
static int modesetting_leave_mass_storage_mode(modedata_t *data)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -704,7 +704,7 @@ bool modesetting_enter_dynamic_mode(void)

bool ack = false;

mode_list_elem_t *data;
modedata_t *data;

log_debug("DYNAMIC MODE: SETUP");

Expand Down Expand Up @@ -856,7 +856,7 @@ void modesetting_leave_dynamic_mode(void)

log_debug("DYNAMIC MODE: CLEANUP");

mode_list_elem_t *data;
modedata_t *data;

data = worker_get_usb_mode_data();

Expand Down
26 changes: 13 additions & 13 deletions src/usb_moded-network.c
Expand Up @@ -79,14 +79,14 @@ typedef struct ipforward_data_t

static void network_free_ipforward_data (ipforward_data_t *ipforward);
static int network_check_interface (char *interface);
static char *network_get_interface (mode_list_elem_t *data);
static int network_set_usb_ip_forward (mode_list_elem_t *data, ipforward_data_t *ipforward);
static char *network_get_interface (modedata_t *data);
static int network_set_usb_ip_forward (modedata_t *data, ipforward_data_t *ipforward);
static void network_clean_usb_ip_forward(void);
static int network_checklink (void);
static int network_write_udhcpd_conf (ipforward_data_t *ipforward, mode_list_elem_t *data);
int network_set_up_dhcpd (mode_list_elem_t *data);
int network_up (mode_list_elem_t *data);
int network_down (mode_list_elem_t *data);
static int network_write_udhcpd_conf (ipforward_data_t *ipforward, modedata_t *data);
int network_set_up_dhcpd (modedata_t *data);
int network_up (modedata_t *data);
int network_down (modedata_t *data);
int network_update (void);

/* ------------------------------------------------------------------------- *
Expand Down Expand Up @@ -157,7 +157,7 @@ static int network_check_interface(char *interface)
return ret;
}

static char* network_get_interface(mode_list_elem_t *data)
static char* network_get_interface(modedata_t *data)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -194,7 +194,7 @@ static char* network_get_interface(mode_list_elem_t *data)
* Turn on ip forwarding on the usb interface
* @return: 0 on success, 1 on failure
*/
static int network_set_usb_ip_forward(mode_list_elem_t *data, ipforward_data_t *ipforward)
static int network_set_usb_ip_forward(modedata_t *data, ipforward_data_t *ipforward)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -389,7 +389,7 @@ static int network_checklink(void)
* Write udhcpd.conf
* @ipforward : NULL if we want a simple config, otherwise include dns info etc...
*/
static int network_write_udhcpd_conf(ipforward_data_t *ipforward, mode_list_elem_t *data)
static int network_write_udhcpd_conf(ipforward_data_t *ipforward, modedata_t *data)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -964,7 +964,7 @@ static int connman_reset_state(void)
/**
* Write out /etc/udhcpd.conf conf so the config is available when it gets started
*/
int network_set_up_dhcpd(mode_list_elem_t *data)
int network_set_up_dhcpd(modedata_t *data)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -1048,7 +1048,7 @@ static int append_variant(DBusMessageIter *iter, const char *property,
* Activate the network interface
*
*/
int network_up(mode_list_elem_t *data)
int network_up(modedata_t *data)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -1216,7 +1216,7 @@ int network_up(mode_list_elem_t *data)
* Deactivate the network interface
*
*/
int network_down(mode_list_elem_t *data)
int network_down(modedata_t *data)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -1295,7 +1295,7 @@ int network_update(void)
LOG_REGISTER_CONTEXT;

if( control_get_cable_state() == CABLE_STATE_PC_CONNECTED ) {
mode_list_elem_t *data = worker_get_usb_mode_data();
modedata_t *data = worker_get_usb_mode_data();
if( data && data->network ) {
network_down(data);
network_up(data);
Expand Down
6 changes: 3 additions & 3 deletions src/usb_moded-network.h
Expand Up @@ -45,9 +45,9 @@ gboolean connman_set_tethering(const char *path, gboolean on);
* NETWORK
* ------------------------------------------------------------------------- */

int network_set_up_dhcpd(mode_list_elem_t *data);
int network_up (mode_list_elem_t *data);
int network_down (mode_list_elem_t *data);
int network_set_up_dhcpd(modedata_t *data);
int network_up (modedata_t *data);
int network_down (modedata_t *data);
int network_update (void);

#endif /* USB_MODED_NETWORK_H_ */
14 changes: 7 additions & 7 deletions src/usb_moded-worker.c
Expand Up @@ -60,8 +60,8 @@ static bool worker_switch_to_charging (void);
const char *worker_get_kernel_module (void);
bool worker_set_kernel_module (const char *module);
void worker_clear_kernel_module (void);
mode_list_elem_t *worker_get_usb_mode_data (void);
void worker_set_usb_mode_data (mode_list_elem_t *data);
modedata_t *worker_get_usb_mode_data (void);
void worker_set_usb_mode_data (modedata_t *data);
static const char *worker_get_activated_mode_locked(void);
static bool worker_set_activated_mode_locked(const char *mode);
static const char *worker_get_requested_mode_locked(void);
Expand Down Expand Up @@ -391,26 +391,26 @@ void worker_clear_kernel_module(void)
* ------------------------------------------------------------------------- */

/** Contains the mode data */
static mode_list_elem_t *worker_mode_data = NULL;
static modedata_t *worker_mode_data = NULL;

/** get the usb mode data
*
* @return a pointer to the usb mode data
*
*/
mode_list_elem_t *worker_get_usb_mode_data(void)
modedata_t *worker_get_usb_mode_data(void)
{
LOG_REGISTER_CONTEXT;

return worker_mode_data;
}

/** set the mode_list_elem_t data
/** set the modedata_t data
*
* @param data mode_list_element pointer
*
*/
void worker_set_usb_mode_data(mode_list_elem_t *data)
void worker_set_usb_mode_data(modedata_t *data)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -588,7 +588,7 @@ worker_switch_to_mode(const char *mode)
/* go through all the dynamic modes if the modelist exists*/
for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) )
{
mode_list_elem_t *data = iter->data;
modedata_t *data = iter->data;
if( strcmp(mode, data->mode_name) )
continue;

Expand Down

0 comments on commit e765c72

Please sign in to comment.