Commit 1b916294 authored by spiiroin's avatar spiiroin

[usb-moded] Use usbmoded_get_modedata() function

Replace custom mode list iterators with a call to common function.

Also fix compilation warnings resulting from mode data pointers now
being marked as const.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 1ae9b0b8
......@@ -461,24 +461,21 @@ int common_valid_mode(const char *mode)
}
else
{
gchar *whitelist_value = 0;
gchar **whitelist_array = 0;
const modedata_t *data = usbmoded_get_modedata(mode);
if( (whitelist_value = config_get_mode_whitelist()) )
whitelist_array = g_strsplit(whitelist_value, ",", 0);
if( data ) {
gchar *whitelist_value = 0;
gchar **whitelist_array = 0;
for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) ) {
modedata_t *data = iter->data;
if( strcmp(mode, data->mode_name) )
continue;
if( (whitelist_value = config_get_mode_whitelist()) )
whitelist_array = g_strsplit(whitelist_value, ",", 0);
if (!whitelist_array || common_mode_in_list(data->mode_name, whitelist_array))
valid = 0;
break;
}
g_strfreev(whitelist_array);
g_free(whitelist_value);
g_strfreev(whitelist_array);
g_free(whitelist_value);
}
}
return valid;
}
......
......@@ -622,7 +622,6 @@ char * config_get_network_setting(const char *config)
LOG_REGISTER_CONTEXT;
char * ret = 0;
modedata_t *data;
if(!strcmp(config, NETWORK_IP_KEY))
{
......@@ -641,7 +640,7 @@ char * config_get_network_setting(const char *config)
goto end;
/* no interface override specified, let's use the one
* from the mode config */
data = worker_get_usb_mode_data();
const modedata_t *data = worker_get_usb_mode_data();
if(data)
{
if(data->network_interface)
......
......@@ -1034,16 +1034,7 @@ umdbus_append_mode_details(DBusMessage *msg, const char *mode_name)
{
LOG_REGISTER_CONTEXT;
const modedata_t *data = 0;
for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) )
{
const modedata_t *iter_data = iter->data;
if( g_strcmp0(iter_data->mode_name, mode_name) )
continue;
data = iter_data;
break;
}
const modedata_t *data = usbmoded_get_modedata(mode_name);
DBusMessageIter body, dict;
......
......@@ -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 (modedata_t *data);
static int modesetting_leave_mass_storage_mode (modedata_t *data);
static bool modesetting_enter_mass_storage_mode (const modedata_t *data);
static int modesetting_leave_mass_storage_mode (const 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);
......@@ -426,7 +426,7 @@ EXIT:
return *pcount = count, info;
}
static bool modesetting_enter_mass_storage_mode(modedata_t *data)
static bool modesetting_enter_mass_storage_mode(const modedata_t *data)
{
LOG_REGISTER_CONTEXT;
......@@ -564,7 +564,7 @@ EXIT:
return ack;
}
static int modesetting_leave_mass_storage_mode(modedata_t *data)
static int modesetting_leave_mass_storage_mode(const modedata_t *data)
{
LOG_REGISTER_CONTEXT;
......@@ -704,7 +704,7 @@ bool modesetting_enter_dynamic_mode(void)
bool ack = false;
modedata_t *data;
const modedata_t *data;
log_debug("DYNAMIC MODE: SETUP");
......@@ -856,9 +856,7 @@ void modesetting_leave_dynamic_mode(void)
log_debug("DYNAMIC MODE: CLEANUP");
modedata_t *data;
data = worker_get_usb_mode_data();
const modedata_t *data = worker_get_usb_mode_data();
/* - - - - - - - - - - - - - - - - - - - *
* Is a dynamic mode?
......
......@@ -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 (modedata_t *data);
static int network_set_usb_ip_forward (modedata_t *data, ipforward_data_t *ipforward);
static char *network_get_interface (const modedata_t *data);
static int network_set_usb_ip_forward (const 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, modedata_t *data);
int network_set_up_dhcpd (modedata_t *data);
int network_up (modedata_t *data);
int network_down (modedata_t *data);
static int network_write_udhcpd_conf (ipforward_data_t *ipforward, const modedata_t *data);
int network_set_up_dhcpd (const modedata_t *data);
int network_up (const modedata_t *data);
int network_down (const modedata_t *data);
int network_update (void);
/* ------------------------------------------------------------------------- *
......@@ -157,7 +157,7 @@ static int network_check_interface(char *interface)
return ret;
}
static char* network_get_interface(modedata_t *data)
static char *network_get_interface(const modedata_t *data)
{
LOG_REGISTER_CONTEXT;
......@@ -194,7 +194,7 @@ static char* network_get_interface(modedata_t *data)
* Turn on ip forwarding on the usb interface
* @return: 0 on success, 1 on failure
*/
static int network_set_usb_ip_forward(modedata_t *data, ipforward_data_t *ipforward)
static int network_set_usb_ip_forward(const modedata_t *data, ipforward_data_t *ipforward)
{
LOG_REGISTER_CONTEXT;
......@@ -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, modedata_t *data)
static int network_write_udhcpd_conf(ipforward_data_t *ipforward, const modedata_t *data)
{
LOG_REGISTER_CONTEXT;
......@@ -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(modedata_t *data)
int network_set_up_dhcpd(const modedata_t *data)
{
LOG_REGISTER_CONTEXT;
......@@ -1048,7 +1048,7 @@ static int append_variant(DBusMessageIter *iter, const char *property,
* Activate the network interface
*
*/
int network_up(modedata_t *data)
int network_up(const modedata_t *data)
{
LOG_REGISTER_CONTEXT;
......@@ -1216,7 +1216,7 @@ int network_up(modedata_t *data)
* Deactivate the network interface
*
*/
int network_down(modedata_t *data)
int network_down(const modedata_t *data)
{
LOG_REGISTER_CONTEXT;
......@@ -1295,7 +1295,7 @@ int network_update(void)
LOG_REGISTER_CONTEXT;
if( control_get_cable_state() == CABLE_STATE_PC_CONNECTED ) {
modedata_t *data = worker_get_usb_mode_data();
const modedata_t *data = worker_get_usb_mode_data();
if( data && data->network ) {
network_down(data);
network_up(data);
......
......@@ -45,9 +45,9 @@ gboolean connman_set_tethering(const char *path, gboolean on);
* NETWORK
* ------------------------------------------------------------------------- */
int network_set_up_dhcpd(modedata_t *data);
int network_up (modedata_t *data);
int network_down (modedata_t *data);
int network_set_up_dhcpd(const modedata_t *data);
int network_up (const modedata_t *data);
int network_down (const modedata_t *data);
int network_update (void);
#endif /* USB_MODED_NETWORK_H_ */
......@@ -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);
modedata_t *worker_get_usb_mode_data (void);
void worker_set_usb_mode_data (modedata_t *data);
const modedata_t *worker_get_usb_mode_data (void);
void worker_set_usb_mode_data (const 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);
......@@ -391,14 +391,14 @@ void worker_clear_kernel_module(void)
* ------------------------------------------------------------------------- */
/** Contains the mode data */
static modedata_t *worker_mode_data = NULL;
static const modedata_t *worker_mode_data = NULL;
/** get the usb mode data
*
* @return a pointer to the usb mode data
*
*/
modedata_t *worker_get_usb_mode_data(void)
const modedata_t *worker_get_usb_mode_data(void)
{
LOG_REGISTER_CONTEXT;
......@@ -410,7 +410,7 @@ modedata_t *worker_get_usb_mode_data(void)
* @param data mode_list_element pointer
*
*/
void worker_set_usb_mode_data(modedata_t *data)
void worker_set_usb_mode_data(const modedata_t *data)
{
LOG_REGISTER_CONTEXT;
......@@ -585,13 +585,8 @@ worker_switch_to_mode(const char *mode)
goto FAILED;
}
/* go through all the dynamic modes if the modelist exists*/
for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) )
{
modedata_t *data = iter->data;
if( strcmp(mode, data->mode_name) )
continue;
const modedata_t *data = usbmoded_get_modedata(mode);
if( data ) {
log_debug("Matching mode %s found.\n", mode);
/* set data before calling any of the dynamic mode functions
......
......@@ -40,17 +40,17 @@
* WORKER
* ------------------------------------------------------------------------- */
bool worker_bailing_out (void);
const char *worker_get_kernel_module (void);
bool worker_set_kernel_module (const char *module);
void worker_clear_kernel_module (void);
modedata_t *worker_get_usb_mode_data (void);
void worker_set_usb_mode_data (modedata_t *data);
void worker_request_hardware_mode(const char *mode);
void worker_clear_hardware_mode (void);
void worker_switch_to_mode (const char *mode);
bool worker_init (void);
void worker_quit (void);
void worker_wakeup (void);
bool worker_bailing_out (void);
const char *worker_get_kernel_module (void);
bool worker_set_kernel_module (const char *module);
void worker_clear_kernel_module (void);
const modedata_t *worker_get_usb_mode_data (void);
void worker_set_usb_mode_data (const modedata_t *data);
void worker_request_hardware_mode(const char *mode);
void worker_clear_hardware_mode (void);
void worker_switch_to_mode (const char *mode);
bool worker_init (void);
void worker_quit (void);
void worker_wakeup (void);
#endif /* USB_MODED_WORKER_H_ */
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