static gboolean enumerate_usb_cb(gpointer data)
{
  (void)data;
  enumerate_usb_id = 0;
  log_debug("handling enumeration timeout");
  enumerate_usb();
  /* return false to stop the timer from repeating */
  return FALSE;
}
int mark_active(const gchar *name, int post)
{
  int ret = -1; // assume name not found
  int missing = 0;

  GList *iter;

  log_debug("%s-enum-app %s is started\n", post ? "post" : "pre", name);

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

    if(!strcmp(data->name, name))
    {
      /* TODO: do we need to worry about duplicate names in the list? */
      ret = (data->state != APP_STATE_ACTIVE);
      data->state = APP_STATE_ACTIVE;

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

      /* updated + missing -> not going to enumerate */
      if( ret != -1 ) break;
    }
  }
  if( !post && !missing )
  {
    log_debug("All pre-enum-apps active. Let's enumerate\n");
    enumerate_usb();
  }
  
  /* -1=not found, 0=already active, 1=activated now */
  return ret; 
}
Example #3
0
int mark_active(const gchar *name)
{
  int ret = -1; // assume name not found
  int missing = 0;

  GList *iter;

  log_debug("App %s notified it is ready\n", name);

  for( iter = sync_list; iter; iter = g_list_next(iter) )
  {
    struct list_elem *data = iter->data;
    if(!strcmp(data->name, name))
    {
      /* TODO: do we need to worry about duplicate names in the list? */
      ret = !data->active;
      data->active = 1;

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

      /* updated + missing -> not going to enumerate */
      if( ret != -1 ) break;
    }
  }
  if( !missing )
  {
    log_debug("All apps active. Let's enumerate\n");
    enumerate_usb(NULL);
  }
  
  /* -1=not found, 0=already active, 1=activated now */
  return ret; 
}
Example #4
0
/* @return 0 on succes, 1 if there is a failure */
int activate_sync(const char *mode)
{
  GList *iter;
  int count = 0, count2 = 0;

  log_debug("activate sync");

  /* Bump tag, see enumerate_usb() */
  ++sync_tag; gettimeofday(&sync_tv, 0);

  if( sync_list == 0 )
  {
    log_debug("No sync list! Enumerating\n");
    enumerate_usb(NULL);
    return 0;
  }

  /* set list to inactive, mark other modes as active already */
  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;
    else
    {
	count2++;
	data->active = 1;
    }
  }

  /* if the number of active modes is equal to the number of existing modes
     we enumerate immediately */
  if(count == count2)
  {
      log_debug("Nothing to launch.\n");
      enumerate_usb(NULL);
      return(0);
   }

#ifdef APP_SYNC_DBUS
  /* check dbus initialisation, skip dbus activated services if this fails */
  if(!usb_moded_app_sync_init())
  {
      log_debug("dbus setup failed => skipping dbus launched apps \n");
      no_dbus = 1;
   }
#endif /* APP_SYNC_DBUS */

  /* start timer */
  log_debug("Starting appsync timer\n");
  g_timeout_add_seconds(2, enumerate_usb, NULL);

  /* go through list and launch apps */
  for( iter = sync_list; iter; iter = g_list_next(iter) )
  {
    struct list_elem *data = iter->data;
    if(!strcmp(mode, data->mode))
    {
      /* launch items marked as post, will be launched after usb is up */
      if(data->post)
      {
	mark_active(data->name);
	continue;
      }
      log_debug("launching app %s\n", data->name);
      if(data->systemd)
      {
        if(!systemd_control_service(data->name, SYSTEMD_START))
		mark_active(data->name);
	else
		goto error;
      }
#ifdef UPSTART
      else if(data->upstart)
      {
	if(!upstart_control_job(data->name, UPSTART_START))	
		mark_active(data->name);
	else
		goto error;
      }
#endif /* UPSTART */
      else if(data->launch)
      {
		/* skipping if dbus session bus is not available,
		   or not compiled in */
		if(no_dbus)
			mark_active(data->name);
#ifdef APP_SYNC_DBUS
		else
			if(!usb_moded_dbus_app_launch(data->launch))
				mark_active(data->name);
			else
				goto error;
#endif /* APP_SYNC_DBUS */
      }
    }
  }

  return(0);

error:
  log_warning("Error launching a service!\n");
  return(1);
}
Example #5
0
int activate_sync(const char *mode)
{
  GList *iter;
  int count = 0, count2 = 0;

  log_debug("activate sync");

  /* Bump tag, see enumerate_usb() */
  ++sync_tag; gettimeofday(&sync_tv, 0);

  if( sync_list == 0 )
  {
    enumerate_usb(NULL);
    return 0;
  }

  /* set list to inactive, mark other modes as active already */
  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;
    else
    {
	count2++;
	data->active = 1;
    }
  }

  /* if the number of active modes is equal to the number of existing modes
     we enumerate immediately */
  if(count == count2)
  {
      log_debug("Nothing to launch.\n");
      enumerate_usb(NULL);
      return(1);
   }

  /* add dbus filter. Use session bus for ready method call? */
  if(!usb_moded_app_sync_init())
  {
      log_debug("dbus setup failed => activate immediately \n");
      enumerate_usb(NULL);
      return(1);
   }

  /* start timer */
  log_debug("Starting appsync timer\n");
  g_timeout_add_seconds(2, enumerate_usb, NULL);

  /* go through list and launch apps */
  for( iter = sync_list; iter; iter = g_list_next(iter) )
  {
    struct list_elem *data = iter->data;
    if(!strcmp(mode, data->mode))
    {
      log_debug("launching app %s\n", data->launch);
#ifdef UPSTART
      if(data->upstart)
      {
	if(!upstart_control_job(data->name, UPSTART_START))	
		mark_active(data->name);
      }
      else
#endif /* UPSTART */
      	usb_moded_dbus_app_launch(data->launch);
    }
  }

  return(0);
}
/* @return 0 on succes, 1 if there is a failure */
int activate_sync(const char *mode)
{
  GList *iter;
  int count = 0;

  log_debug("activate sync");

  /* Get start of activation timestamp */
  gettimeofday(&sync_tv, 0);

  if( sync_list == 0 )
  {
    log_debug("No sync list! Enumerating\n");
    enumerate_usb();
    return 0;
  }

  /* 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;

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

  /* If there is nothing to activate, enumerate immediately */
  if(count <= 0)
  {
      log_debug("Nothing to launch.\n");
      enumerate_usb();
      return(0);
   }

#ifdef APP_SYNC_DBUS
  /* check dbus initialisation, skip dbus activated services if this fails */
  if(!usb_moded_app_sync_init())
  {
      log_debug("dbus setup failed => skipping dbus launched apps \n");
      no_dbus = 1;
   }
#endif /* APP_SYNC_DBUS */

  /* start timer */
  start_enumerate_usb_timer();

  /* go through list and launch apps */
  for( iter = sync_list; iter; iter = g_list_next(iter) )
  {
    struct list_elem *data = iter->data;
    if(!strcmp(mode, data->mode))
    {
      /* do not launch items marked as post, will be launched after usb is up */
      if(data->post)
      {
	continue;
      }
      log_debug("launching pre-enum-app %s\n", data->name);
      if(data->systemd)
      {
        if(!systemd_control_service(data->name, SYSTEMD_START))
		mark_active(data->name, 0);
	else
		goto error;
      }
      else if(data->launch)
      {
		/* skipping if dbus session bus is not available,
		   or not compiled in */
		if(no_dbus)
			mark_active(data->name, 0);
#ifdef APP_SYNC_DBUS
		else
			if(!usb_moded_dbus_app_launch(data->launch))
				mark_active(data->name, 0);
			else
				goto error;
#endif /* APP_SYNC_DBUS */
      }
    }
  }

  return(0);

error:
  log_warning("Error launching a service!\n");
  return(1);
}