Skip to content
Permalink
Browse files
[dyn-config] Align config parsing for readability
Long member and key names, and interleaved debug logging makes the config
parsing code difficult to read.

Add whitespace to increase ease visual inspection. Move debug logging
to occur after each configuration block has been parsed.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Aug 24, 2018
1 parent ec49a62 commit 9dd551478decb34b9579c8011e5e2fe939e61a4a
Showing with 45 additions and 29 deletions.
  1. +2 −2 src/usb_moded-appsync.h
  2. +29 −22 src/usb_moded-dyn-config.c
  3. +14 −5 src/usb_moded-dyn-config.h
@@ -37,8 +37,8 @@
# define APP_INFO_MODE_KEY "mode"
# define APP_INFO_NAME_KEY "name"
# define APP_INFO_LAUNCH_KEY "launch"
# define APP_INFO_SYSTEMD_KEY "systemd"
# define APP_INFO_POST "post"
# define APP_INFO_SYSTEMD_KEY "systemd" // integer
# define APP_INFO_POST "post" // integer

/* ========================================================================= *
* Types
@@ -144,37 +144,44 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename)
return(NULL);
}
list_item = malloc(sizeof(struct mode_list_elem));
list_item->mode_name = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_NAME_KEY, NULL);

// [MODE_ENTRY = "mode"]
list_item->mode_name = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_NAME_KEY, NULL);
list_item->mode_module = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_MODULE_KEY, NULL);

log_debug("Dynamic mode name = %s\n", list_item->mode_name);
list_item->mode_module = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_MODULE_KEY, NULL);
log_debug("Dynamic mode module = %s\n", list_item->mode_module);
list_item->appsync = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_NEEDS_APPSYNC_KEY, NULL);
list_item->mass_storage = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_MASS_STORAGE, NULL);
list_item->network = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_NETWORK_KEY, NULL);

list_item->appsync = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_NEEDS_APPSYNC_KEY, NULL);
list_item->mass_storage = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_MASS_STORAGE_KEY, NULL);
list_item->network = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_NETWORK_KEY, NULL);
list_item->network_interface = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_NETWORK_INTERFACE_KEY, NULL);
list_item->sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_PATH, NULL);
//log_debug("Dynamic mode sysfs path = %s\n", list_item->sysfs_path);
list_item->sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_VALUE, NULL);
//log_debug("Dynamic mode sysfs value = %s\n", list_item->sysfs_value);
list_item->sysfs_reset_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_RESET_VALUE, NULL);
list_item->android_extra_sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH, NULL);
list_item->android_extra_sysfs_path2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH2, NULL);
list_item->android_extra_sysfs_path3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH3, NULL);
list_item->android_extra_sysfs_path4 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH4, NULL);
//log_debug("Android extra mode sysfs path2 = %s\n", list_item->android_extra_sysfs_path2);
list_item->android_extra_sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE, NULL);

// [MODE_OPTIONS_ENTRY = "options"]
list_item->sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_PATH, NULL);
list_item->sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_VALUE, NULL);
list_item->sysfs_reset_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_RESET_VALUE, NULL);
list_item->android_extra_sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH, NULL);
list_item->android_extra_sysfs_path2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH2, NULL);
list_item->android_extra_sysfs_path3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH3, NULL);
list_item->android_extra_sysfs_path4 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH4, NULL);
list_item->android_extra_sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE, NULL);
list_item->android_extra_sysfs_value2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE2, NULL);
list_item->android_extra_sysfs_value3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE3, NULL);
list_item->android_extra_sysfs_value4 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE4, NULL);
//log_debug("Android extra value2 = %s\n", list_item->android_extra_sysfs_value2);
list_item->idProduct = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDPRODUCT, NULL);
list_item->idVendorOverride = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDVENDOROVERRIDE, NULL);
list_item->nat = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_NAT, NULL);
list_item->dhcp_server = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_DHCP_SERVER, NULL);
list_item->idProduct = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDPRODUCT, NULL);
list_item->idVendorOverride = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDVENDOROVERRIDE, NULL);
list_item->nat = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_NAT, NULL);
list_item->dhcp_server = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_DHCP_SERVER, NULL);
#ifdef CONNMAN
list_item->connman_tethering = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_CONNMAN_TETHERING, NULL);
list_item->connman_tethering = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_CONNMAN_TETHERING, NULL);
#endif

//log_debug("Dynamic mode sysfs path = %s\n", list_item->sysfs_path);
//log_debug("Dynamic mode sysfs value = %s\n", list_item->sysfs_value);
//log_debug("Android extra mode sysfs path2 = %s\n", list_item->android_extra_sysfs_path2);
//log_debug("Android extra value2 = %s\n", list_item->android_extra_sysfs_value2);

g_key_file_free(settingsfile);
if(list_item->mode_name == NULL || list_item->mode_module == NULL)
{
@@ -37,13 +37,22 @@
# define MODE_DIR_PATH "/etc/usb-moded/dyn-modes"
# define DIAG_DIR_PATH "/etc/usb-moded/diag"

/* - - - - - - - - - - - - - - - - - - - *
* [mode] ini-file block
* - - - - - - - - - - - - - - - - - - - */

# define MODE_ENTRY "mode"
# define MODE_NAME_KEY "name"
# define MODE_MODULE_KEY "module"
# define MODE_NEEDS_APPSYNC_KEY "appsync"
# define MODE_NETWORK_KEY "network"
# define MODE_MASS_STORAGE "mass_storage"
# define MODE_NEEDS_APPSYNC_KEY "appsync" // integer
# define MODE_NETWORK_KEY "network" // integer
# define MODE_MASS_STORAGE_KEY "mass_storage" // integer
# define MODE_NETWORK_INTERFACE_KEY "network_interface"

/* - - - - - - - - - - - - - - - - - - - *
* [options] ini-file block
* - - - - - - - - - - - - - - - - - - - */

# define MODE_OPTIONS_ENTRY "options"
# define MODE_SYSFS_PATH "sysfs_path"

@@ -68,8 +77,8 @@
/* For windows different modes/usb profiles need their own idProduct */
# define MODE_IDPRODUCT "idProduct"
# define MODE_IDVENDOROVERRIDE "idVendorOverride"
# define MODE_HAS_NAT "nat"
# define MODE_HAS_DHCP_SERVER "dhcp_server"
# define MODE_HAS_NAT "nat" // integer
# define MODE_HAS_DHCP_SERVER "dhcp_server" // integer

# ifdef CONNMAN
# define MODE_CONNMAN_TETHERING "connman_tethering"

0 comments on commit 9dd5514

Please sign in to comment.