Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[usb-moded] Normalize typedefs
Use named structs / enums in typedefs.

Drop "struct" from code in places where it has been made redundant due to
having a typedef for the structure.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 5, 2018
1 parent a282313 commit e48f26b
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 76 deletions.
24 changes: 12 additions & 12 deletions src/usb_moded-appsync.c
Expand Up @@ -42,12 +42,12 @@

/* -- appsync -- */

static void appsync_free_elem (struct list_elem *elem);
static void appsync_free_elem (list_elem_t *elem);
static void appsync_free_elem_cb (gpointer elem, gpointer user_data);
void appsync_free_appsync_list (void);
static gint appsync_list_sort_func (gconstpointer a, gconstpointer b);
void appsync_read_list (int diag);
static struct list_elem *appsync_read_file (const gchar *filename, int diag);
static list_elem_t *appsync_read_file (const gchar *filename, int diag);
int appsync_activate_sync (const char *mode);
int appsync_activate_sync_post (const char *mode);
int appsync_mark_active (const gchar *name, int post);
Expand Down Expand Up @@ -76,7 +76,7 @@ static int appsync_no_dbus = 0;
* Functions
* ========================================================================= */

static void appsync_free_elem(struct list_elem *elem)
static void appsync_free_elem(list_elem_t *elem)
{
g_free(elem->name);
g_free(elem->launch);
Expand Down Expand Up @@ -112,7 +112,7 @@ void appsync_read_list(int diag)
GDir *confdir = 0;

const gchar *dirname;
struct list_elem *list_item;
list_elem_t *list_item;

appsync_free_appsync_list();

Expand Down Expand Up @@ -154,11 +154,11 @@ void appsync_read_list(int diag)
}
}

static struct list_elem *appsync_read_file(const gchar *filename, int diag)
static list_elem_t *appsync_read_file(const gchar *filename, int diag)
{
gchar *full_filename = NULL;
GKeyFile *settingsfile = NULL;
struct list_elem *list_item = NULL;
list_elem_t *list_item = NULL;

if(diag)
{
Expand Down Expand Up @@ -230,7 +230,7 @@ int appsync_activate_sync(const char *mode)
* mark them as currently inactive */
for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
list_elem_t *data = iter->data;

if(!strcmp(data->mode, mode))
{
Expand Down Expand Up @@ -266,7 +266,7 @@ int appsync_activate_sync(const char *mode)
/* go through list and launch apps */
for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
list_elem_t *data = iter->data;
if(!strcmp(mode, data->mode))
{
/* do not launch items marked as post, will be launched after usb is up */
Expand Down Expand Up @@ -329,7 +329,7 @@ int appsync_activate_sync_post(const char *mode)
/* go through list and launch apps */
for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
list_elem_t *data = iter->data;
if(!strcmp(mode, data->mode))
{
/* launch only items marked as post, others are already running */
Expand Down Expand Up @@ -375,7 +375,7 @@ int appsync_mark_active(const gchar *name, int post)

for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
list_elem_t *data = iter->data;

if(!strcmp(data->name, name))
{
Expand Down Expand Up @@ -455,7 +455,7 @@ void appsync_stop_apps(int post)

for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
list_elem_t *data = iter->data;

if(data->systemd && data->state == APP_STATE_ACTIVE && data->post == post)
{
Expand All @@ -478,7 +478,7 @@ int appsync_stop(gboolean force)

for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
list_elem_t *data = iter->data;
data->state = APP_STATE_ACTIVE;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/usb_moded-appsync.h
Expand Up @@ -48,7 +48,7 @@

/** Application activation state
*/
typedef enum {
typedef enum app_state_t {
/** Application is not relevant for the current mode */
APP_STATE_DONTCARE = 0,
/** Application should be started */
Expand All @@ -60,15 +60,15 @@ typedef enum {
/**
* keep all the needed info together for launching an app
*/
typedef struct list_elem
typedef struct list_elem_t
{
char *name; /**< name of the app to launch */
char *mode; /**< mode in which to launch the app */
char *launch; /**< dbus launch command/address */
app_state_t state; /**< marker to check if the app has started sucessfully */
int systemd; /**< marker to know if we start it with systemd or not */
int post; /**< marker to indicate when to start the app */
} list_elem;
} list_elem_t;

/* ========================================================================= *
* Prototypes
Expand Down
4 changes: 2 additions & 2 deletions src/usb_moded-common.c
Expand Up @@ -417,7 +417,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) ) {
struct mode_list_elem *data = iter->data;
mode_list_elem_t *data = iter->data;
if( strcmp(mode, data->mode_name) )
continue;

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

for( GList *iter = usbmoded_get_modelist(); iter; iter = g_list_next(iter) )
{
struct mode_list_elem *data = iter->data;
mode_list_elem_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 @@ -668,7 +668,7 @@ set_config_result_t config_set_network_setting(const char *config, const char *s
char * config_get_network_setting(const char *config)
{
char * ret = 0;
struct mode_list_elem *data;
mode_list_elem_t *data;

if(!strcmp(config, NETWORK_IP_KEY))
{
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-control.c
Expand Up @@ -245,7 +245,7 @@ void control_select_usb_mode(void)
log_err("Diagnostic mode is not configured!");
}
else {
struct mode_list_elem *data = iter->data;
mode_list_elem_t *data = iter->data;
log_debug("Entering diagnostic mode!");
control_set_usb_mode(data->mode_name);
}
Expand Down
16 changes: 8 additions & 8 deletions src/usb_moded-dyn-config.c
Expand Up @@ -38,17 +38,17 @@

/* -- dynconfig -- */

void dynconfig_free_list_item(mode_list_elem *list_item);
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 struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename);
static mode_list_elem_t *dynconfig_read_mode_file(const gchar *filename);

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

void dynconfig_free_list_item(mode_list_elem *list_item)
void dynconfig_free_list_item(mode_list_elem_t *list_item)
{
if( list_item ) {
free(list_item->mode_name);
Expand Down Expand Up @@ -86,8 +86,8 @@ void dynconfig_free_mode_list(GList *modelist)

static gint dynconfig_compare_modes(gconstpointer a, gconstpointer b)
{
struct mode_list_elem *aa = (struct mode_list_elem *)a;
struct mode_list_elem *bb = (struct mode_list_elem *)b;
mode_list_elem_t *aa = (mode_list_elem_t *)a;
mode_list_elem_t *bb = (mode_list_elem_t *)b;

return g_strcmp0(aa->mode_name, bb->mode_name);
}
Expand All @@ -97,7 +97,7 @@ GList *dynconfig_read_mode_list(int diag)
GDir *confdir;
GList *modelist = NULL;
const gchar *dirname;
struct mode_list_elem *list_item;
mode_list_elem_t *list_item;
gchar *full_filename = NULL;

if(diag)
Expand Down Expand Up @@ -128,11 +128,11 @@ GList *dynconfig_read_mode_list(int diag)
return(modelist);
}

static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename)
static mode_list_elem_t *dynconfig_read_mode_file(const gchar *filename)
{
bool success = false;
GKeyFile *settingsfile = g_key_file_new();
struct mode_list_elem *list_item = NULL;
mode_list_elem_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
6 changes: 3 additions & 3 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
typedef struct mode_list_elem_t
{
char *mode_name; /**< Mode name */
char *mode_module; /**< Needed module for given mode */
Expand All @@ -119,15 +119,15 @@ typedef struct mode_list_elem
# ifdef CONNMAN
char* connman_tethering; /**< Connman's tethering technology path */
# endif
} mode_list_elem;
} mode_list_elem_t;

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

/* -- dynconfig -- */

void dynconfig_free_list_item(mode_list_elem *list_item);
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);

Expand Down
12 changes: 6 additions & 6 deletions src/usb_moded-modesetting.c
Expand Up @@ -64,8 +64,8 @@ int modesetting_write_to_file_real (const char *file, int l

static gboolean modesetting_network_retry_cb (gpointer data);

static bool modesetting_enter_mass_storage_mode (struct mode_list_elem *data);
static int modesetting_leave_mass_storage_mode (struct mode_list_elem *data);
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 void modesetting_report_mass_storage_blocker(const char *mountpoint, int try);

bool modesetting_enter_dynamic_mode (void);
Expand Down Expand Up @@ -415,7 +415,7 @@ modesetting_get_storage_info(size_t *pcount)
return *pcount = count, info;
}

static bool modesetting_enter_mass_storage_mode(struct mode_list_elem *data)
static bool modesetting_enter_mass_storage_mode(mode_list_elem_t *data)
{
bool ack = false;
size_t count = 0;
Expand Down Expand Up @@ -551,7 +551,7 @@ static bool modesetting_enter_mass_storage_mode(struct mode_list_elem *data)
return ack;
}

static int modesetting_leave_mass_storage_mode(struct mode_list_elem *data)
static int modesetting_leave_mass_storage_mode(mode_list_elem_t *data)
{
(void)data;

Expand Down Expand Up @@ -685,7 +685,7 @@ bool modesetting_enter_dynamic_mode(void)
{
bool ack = false;

struct mode_list_elem *data;
mode_list_elem_t *data;
int network = 1;

log_debug("DYNAMIC MODE: SETUP");
Expand Down Expand Up @@ -835,7 +835,7 @@ void modesetting_leave_dynamic_mode(void)
{
log_debug("DYNAMIC MODE: CLEANUP");

struct mode_list_elem *data;
mode_list_elem_t *data;

data = worker_get_usb_mode_data();

Expand Down

0 comments on commit e48f26b

Please sign in to comment.