Skip to content

Commit

Permalink
[appsync] Start/stop only applications relevant to mode. JB#35683
Browse files Browse the repository at this point in the history
The boolean state data for tracking active/inactive applications makes
it difficult to separate applications that are not relevant to the mode
and as a result an attempt to stop also those irrelevant apps that were
not started is made when exiting the mode.

Switch from boolean to inactive|active|dontcare state tracking.

When starting appsync, mark apps relevant to the mode as inactive and
the rest as dontcare.

When stopping appsync, stop only those applications that have been
activated by usb-moded.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jul 7, 2016
1 parent df105a6 commit 206c957
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
32 changes: 17 additions & 15 deletions src/usb_moded-appsync.c
Expand Up @@ -172,6 +172,7 @@ static struct list_elem *read_file(const gchar *filename, int diag)
list_item->systemd = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_SYSTEMD_KEY, NULL);
log_debug("Systemd control = %d\n", list_item->systemd);
list_item->post = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_POST, NULL);
list_item->state = APP_STATE_DONTCARE;

cleanup:

Expand All @@ -194,7 +195,7 @@ static struct list_elem *read_file(const gchar *filename, int diag)
int activate_sync(const char *mode)
{
GList *iter;
int count = 0, count2 = 0;
int count = 0;

log_debug("activate sync");

Expand All @@ -208,24 +209,25 @@ int activate_sync(const char *mode)
return 0;
}

/* set list to inactive, mark other modes as active already */
/* Count apps that need to be activated for this mode and
* mark them as currently inactive */
for( iter = sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;

count++;
if(!strcmp(data->mode, mode))
data->active = 0;
{
++count;
data->state = APP_STATE_INACTIVE;
}
else
{
count2++;
data->active = 1;
data->state = APP_STATE_DONTCARE;
}
}

/* if the number of active modes is equal to the number of existing modes
we enumerate immediately */
if(count == count2)
/* If there is nothing to activate, enumerate immediately */
if(count <= 0)
{
log_debug("Nothing to launch.\n");
enumerate_usb();
Expand Down Expand Up @@ -362,13 +364,13 @@ int mark_active(const gchar *name, int post)
if(!strcmp(data->name, name))
{
/* TODO: do we need to worry about duplicate names in the list? */
ret = !data->active;
data->active = 1;
ret = (data->state != APP_STATE_ACTIVE);
data->state = APP_STATE_ACTIVE;

/* updated + missing -> not going to enumerate */
if( missing ) break;
}
else if( data->active == 0 && data->post == post )
else if( data->state == APP_STATE_INACTIVE && data->post == post )
{
missing = 1;

Expand Down Expand Up @@ -454,12 +456,12 @@ static void appsync_stop_apps(int post)
{
struct list_elem *data = iter->data;

if(data->systemd && data->active && data->post == post)
if(data->systemd && data->state == APP_STATE_ACTIVE && data->post == post)
{
log_debug("stopping %s-enum-app %s", post ? "post" : "pre", data->name);
if(systemd_control_service(data->name, SYSTEMD_STOP))
log_debug("Failed to stop %s\n", data->name);
data->active = 0;
data->state = APP_STATE_DONTCARE;
}
}
}
Expand All @@ -476,7 +478,7 @@ int appsync_stop(int force)
for( iter = sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
data->active = 1;
data->state = APP_STATE_ACTIVE;
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/usb_moded-appsync.h
Expand Up @@ -29,6 +29,15 @@
#define APP_INFO_SYSTEMD_KEY "systemd"
#define APP_INFO_POST "post"

typedef enum {
/** Application is not relevant for the current mode */
APP_STATE_DONTCARE = 0,
/** Application should be started */
APP_STATE_INACTIVE = 1,
/** Application should be stopped when exiting the mode */
APP_STATE_ACTIVE = 2,
} app_state_t;

/**
* keep all the needed info together for launching an app
*/
Expand All @@ -38,7 +47,7 @@ typedef struct list_elem
char *name; /* name of the app to launch */
char *mode; /* mode in which to launch the app */
char *launch; /* dbus launch command/address */
int active; /* marker to check if the app has started sucessfully */
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 */
/*@}*/
Expand Down

0 comments on commit 206c957

Please sign in to comment.