int activate_sync_post(const char *mode)
{
  GList *iter;

  log_debug("activate post sync");

  if( sync_list == 0 )
  {
    log_debug("No sync list! skipping post sync\n");
    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 */

  /* 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 only items marked as post, others are already running */
      if(!data->post)
	continue;
      log_debug("launching post-enum-app %s\n", data->name);
      if(data->systemd)
      {
        if(systemd_control_service(data->name, SYSTEMD_START))
		goto error;
	mark_active(data->name, 1);
      }
      else if(data->launch)
      {
		/* skipping if dbus session bus is not available,
		   or not compiled in */
		if(no_dbus)
			continue;
#ifdef APP_SYNC_DBUS
		else
			if(usb_moded_dbus_app_launch(data->launch) != 0)
				goto error;
#endif /* APP_SYNC_DBUS */
      }
    }
  }

  return(0);

error:
  log_warning("Error launching a service!\n");
  return(1);
}
/**
 * usb_driver_claim_interface - bind a driver to an interface
 * @driver: the driver to be bound
 * @iface: the interface to which it will be bound; must be in the
 *	usb device's active configuration
 * @priv: driver data associated with that interface
 *
 * This is used by usb device drivers that need to claim more than one
 * interface on a device when probing (audio and acm are current examples).
 * No device driver should directly modify internal usb_interface or
 * usb_device structure members.
 *
 * Few drivers should need to use this routine, since the most natural
 * way to bind to an interface is to return the private data from
 * the driver's probe() method.
 *
 * Callers must own the device lock and the driver model's usb_bus_type.subsys
 * writelock.  So driver probe() entries don't need extra locking,
 * but other call contexts may need to explicitly claim those locks.
 */
int usb_driver_claim_interface(struct usb_driver *driver,
				struct usb_interface *iface, void* priv)
{
	struct device *dev = &iface->dev;

	if (dev->driver)
		return -EBUSY;

	dev->driver = &driver->driver;
	usb_set_intfdata(iface, priv);
	iface->condition = USB_INTERFACE_BOUND;
	mark_active(iface);

	/* if interface was already added, bind now; else let
	 * the future device_add() bind it, bypassing probe()
	 */
	if (device_is_registered(dev))
		device_bind_driver(dev);

	return 0;
}
Esempio n. 3
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);
}
Esempio n. 4
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);
}
static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
{
  DBusHandlerResult   status    = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  int                 type      = dbus_message_get_type(msg);
  const char         *interface = dbus_message_get_interface(msg);
  const char         *member    = dbus_message_get_member(msg);
  const char         *object    = dbus_message_get_path(msg);

  if(!interface || !member || !object) goto IGNORE;

  if( type == DBUS_MESSAGE_TYPE_METHOD_CALL &&
      !strcmp(interface, USB_MODE_INTERFACE) &&
      !strcmp(object, USB_MODE_OBJECT) )

  {
    DBusMessage *reply = 0;

    status = DBUS_HANDLER_RESULT_HANDLED;

    if(!strcmp(member, USB_MODE_APP_STATE))
    {
      char      *use = 0;
      DBusError  err = DBUS_ERROR_INIT;

      if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID))
      {
	// could not parse method call args
	reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
      }
      else if( mark_active(use) < 0 )
      {
	// name could not be marked active
	reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
      }
      else if((reply = dbus_message_new_method_return(msg)))
      {
	// generate normal reply
	dbus_message_append_args (reply, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID);
      }
      dbus_error_free(&err);
    }
    else
    {
      /*unknown methods are handled here */
      reply = dbus_message_new_error(msg, DBUS_ERROR_UNKNOWN_METHOD, member);
    }

    if( !dbus_message_get_no_reply(msg) )
    {
      if( !reply )
      {
	// we failed to generate reply above -> generate one
	reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, member);
      }
      if( !reply || !dbus_connection_send(connection, reply, 0) )
      {
	log_debug("Failed sending reply. Out Of Memory!\n");
      }
    }

    if( reply ) dbus_message_unref(reply);
  }

IGNORE:

  return status;
}
/* @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);
}