コード例 #1
0
ファイル: gtkam-chooser.c プロジェクト: gphoto/gtkam
void
gtkam_chooser_set_camera (GtkamChooser *chooser, GtkamCamera *camera)
{
	CameraAbilities a;
	GPPortInfo info;
	gchar *full_info;
#ifdef HAVE_GP_PORT_INFO_GET_NAME
	char *xname,*xpath;
#endif

	g_return_if_fail (GTKAM_IS_CHOOSER (chooser));
	g_return_if_fail (GTKAM_IS_CAMERA (camera));

	gp_camera_get_abilities (camera->camera, &a);
	gp_camera_get_port_info (camera->camera, &info);
#ifdef HAVE_GP_PORT_INFO_GET_NAME
	gp_port_info_get_name (info, &xname);
	gp_port_info_get_path (info, &xpath);
	full_info = g_strdup_printf ("%s (%s)", xname, xpath);
#else
	full_info = g_strdup_printf ("%s (%s)", info.name, info.path);
#endif
	gtk_entry_set_text (chooser->priv->entry_port, full_info);
	g_free (full_info);

	gtk_entry_set_text (chooser->priv->entry_model, a.model);
	gtk_toggle_button_set_active (
		GTK_TOGGLE_BUTTON (chooser->priv->check_multi), camera->multi);

	chooser->priv->needs_update = FALSE;
	gtk_widget_set_sensitive (chooser->apply_button, FALSE);
}
コード例 #2
0
ファイル: gtkam-chooser.c プロジェクト: gphoto/gtkam
static void
on_port_added (GtkamPort *port, const gchar *path, GtkamChooser *chooser)
{
	int index;
	GPPortInfo info;
	gchar *name;
#ifdef HAVE_GP_PORT_INFO_GET_NAME
	char *xname, *xpath;
#endif

	index = gp_port_info_list_lookup_path (chooser->priv->il, path);
	if (index < 0) {
		g_warning ("Could not look up path?!?");
		return;
	}
	gp_port_info_list_get_info (chooser->priv->il, index, &info);
#ifdef HAVE_GP_PORT_INFO_GET_NAME
	gp_port_info_get_name (info, &xname);
	gp_port_info_get_path (info, &xpath);
	name = g_strdup_printf ("%s (%s)", xname, xpath);
#else
	name = g_strdup_printf ("%s (%s)", info.name, info.path);
#endif
	gtk_entry_set_text (chooser->priv->entry_port, name);
	g_free (name);

	gtkam_chooser_update_for_model (chooser);

	chooser->priv->needs_update = TRUE;
	gtk_widget_set_sensitive (chooser->apply_button, TRUE);
}
コード例 #3
0
ファイル: unix.c プロジェクト: rajbot/gphoto
static int
gp_port_serial_open (GPPort *dev)
{
	int result, max_tries = 5, i;
#ifdef OS2
	int fd;
#endif
	char *port;
	GPPortInfo	info;

	result = gp_port_get_info (dev, &info);
	if (result < GP_OK) return result;
	result = gp_port_info_get_path (info, &port);
	if (result < GP_OK) return result;
	gp_log (GP_LOG_DEBUG, "gp_port_serial_open", "opening %s", port);

	/* Ports are named "serial:/dev/whatever/port" */
	port = strchr (port, ':');
	if (!port)
		return GP_ERROR_UNKNOWN_PORT;
	port++;

	result = gp_port_serial_lock (dev, port);
	if (result != GP_OK) {
		for (i = 0; i < max_tries; i++) {
			result = gp_port_serial_lock (dev, port);
			if (result == GP_OK)
				break;
			gp_log (GP_LOG_DEBUG, "gphoto2-port-serial",
				"Failed to get a lock, trying again...");
			sleep (1);
		}
		CHECK (result);
	}
	dev->pl->fd = -1;

#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
	dev->pl->fd = open (port, O_RDWR | O_NOCTTY | O_NONBLOCK);
#elif OS2
	fd = open (port, O_RDWR | O_BINARY);
	dev->pl->fd = open (port, O_RDWR | O_BINARY);
	close(fd);
#else
	if (dev->pl->fd == -1)
		dev->pl->fd = open (port, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK);
#endif
	if (dev->pl->fd == -1) {
		int saved_errno = errno;
		gp_port_set_error (dev, _("Failed to open '%s' (%s)."),
				   port, strerror(saved_errno));
		dev->pl->fd = 0;
		return GP_ERROR_IO;
	}

	return GP_OK;
}
コード例 #4
0
ファイル: gtkam-chooser.c プロジェクト: gphoto/gtkam
void
gtkam_chooser_set_port_mask (GtkamChooser *chooser, GPPortType types)
{
	GtkWidget *dialog;
	GPPortInfo info;
	int n;
	guint i;
	GList *list = NULL;

	g_return_if_fail (GTKAM_IS_CHOOSER (chooser));

	n = gp_port_info_list_count (chooser->priv->il);
	if (n < 0) {
		dialog = gtkam_error_new (n, NULL, GTK_WIDGET (chooser),
			_("Could not get number of ports."));
		gtk_widget_show (dialog);
		return;
	}

	/* Search for ports that fulfil the criteria */
	for (i = 0; i < n; i++) {
#ifdef HAVE_GP_PORT_INFO_GET_NAME
		GPPortType type;
		char *xname,*xpath;
#endif
		gp_port_info_list_get_info (chooser->priv->il, i, &info);
#ifdef HAVE_GP_PORT_INFO_GET_NAME
		gp_port_info_get_type (info, &type);
		gp_port_info_get_name (info, &xname);
		gp_port_info_get_path (info, &xpath);
		if (type & types)
			list = g_list_append (list, g_strdup_printf ("%s (%s)",
					      xname, xpath));
#else
		if (info.type & types)
			list = g_list_append (list, g_strdup_printf ("%s (%s)",
					      info.name, info.path));
#endif
	}

	gtkam_chooser_set_port_list (chooser, list);
}
コード例 #5
0
ファイル: gphoto2-camera.c プロジェクト: Jay314/libgphoto2
int
gp_camera_set_port_info (Camera *camera, GPPortInfo info)
{
	char	*name, *path;
	C_PARAMS (camera);

	/*
	 * If the camera is currently initialized, terminate that connection.
	 * We don't care if we are successful or not.
	 */
	if (camera->pc->lh)
		gp_camera_exit (camera, NULL);

	gp_port_info_get_name (info, &name);
	gp_port_info_get_path (info, &path);
	GP_LOG_D ("Setting port info for port '%s' at '%s'...", name, path);
	CR (camera, gp_port_set_info (camera->port, info), NULL);

	return (GP_OK);
}
コード例 #6
0
/**
 * \param list a CameraAbilitiesList
 * \param info_list the GPPortInfoList of ports to use for detection
 * \param l a #CameraList that contains the autodetected cameras after the call
 * \param context a #GPContext
 *
 * Tries to detect any camera connected to the computer using the supplied
 * list of supported cameras and the supplied info_list of ports.
 *
 * \return a gphoto2 error code
 */
int
gp_abilities_list_detect (CameraAbilitiesList *list,
			  GPPortInfoList *info_list, CameraList *l,
			  GPContext *context)
{
	GPPortInfo info;
	GPPort *port;
	int i, info_count;

	CHECK_NULL (list && info_list && l);

	gp_list_reset (l);

	CHECK_RESULT (info_count = gp_port_info_list_count (info_list));

	CHECK_RESULT (gp_port_new (&port));
	for (i = 0; i < info_count; i++) {
		int res;
		char *xpath;
		GPPortType	type;

		CHECK_RESULT (gp_port_info_list_get_info (info_list, i, &info));
		CHECK_RESULT (gp_port_set_info (port, info));
		gp_port_info_get_type (info, &type);
		res = gp_port_info_get_path (info, &xpath);
		if (res <GP_OK)
			continue;
		switch (type) {
		case GP_PORT_USB:
		case GP_PORT_USB_SCSI:
		case GP_PORT_USB_DISK_DIRECT: {
			int ability;
			
			res = gp_abilities_list_detect_usb (list, &ability, port);
			if (res == GP_OK) {
				gp_list_append(l,
					list->abilities[ability].model,
					xpath);
			} else if (res < 0)
				gp_port_set_error (port, NULL);

			break;
		}
		case GP_PORT_DISK: {
			char	*s, path[1024];
			struct stat stbuf;
		
			s = strchr (xpath, ':');
			if (!s)
				break;
			s++;
			snprintf (path, sizeof(path), "%s/DCIM", s);
			if (-1 == stat(path, &stbuf)) {
				snprintf (path, sizeof(path), "%s/dcim", s);
				if (-1 == stat(path, &stbuf))
					continue;
			}
			gp_list_append (l, "Mass Storage Camera", xpath);
			break;
		}
		case GP_PORT_PTPIP: {
			char	*s;

			s = strchr (xpath, ':');
			if (!s) break;
			s++;
			if (!strlen(s)) break;
			gp_list_append (l, "PTP/IP Camera", xpath);
			break;
		}
		default:
			/*
			 * We currently cannot detect any cameras on this
			 * port
			 */
			break;
		}
	}

	gp_port_free (port);

	return (GP_OK);
}
コード例 #7
0
ファイル: gphoto2-camera.c プロジェクト: Jay314/libgphoto2
/**
 * Initiate a connection to the \c camera. 
 *
 * @param camera a #Camera
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * Before calling this function, the
 * \c camera should be set up using gp_camera_set_port_path() or
 * gp_camera_set_port_name() and gp_camera_set_abilities(). If that has been
 * omitted, gphoto2 tries to autodetect any cameras and chooses the first one
 * if any cameras are found. It is generally a good idea to call
 * gp_camera_exit() after transactions have been completed in order to give
 * other applications the chance to access the camera, too.
 *
 */
int
gp_camera_init (Camera *camera, GPContext *context)
{
	CameraAbilities a;
	const char *model, *port;
	CameraLibraryInitFunc init_func;
	int result;

	GP_LOG_D ("Initializing camera...");

	C_PARAMS (camera);
	/*
	 * Reset the exit_requested flag. If this flag is set, 
	 * gp_camera_exit will be called as soon as the camera is no
	 * longer in use (used flag).
	 */
	camera->pc->exit_requested = 0;

	/*
	 * If the model hasn't been indicated, try to
	 * figure it out (USB only). Beware of "Directory Browse".
	 */
	if (strcasecmp (camera->pc->a.model, "Directory Browse") &&
	    !strcmp ("", camera->pc->a.model)) {
		CameraAbilitiesList *al;
		GPPortInfoList	*il;
		int		m, p;
		char		*ppath;
		GPPortType	ptype;
		GPPortInfo	info;
        	CameraList	*list;

		result = gp_list_new (&list);
		if (result < GP_OK)
			return result;

		GP_LOG_D ("Neither port nor model set. Trying auto-detection...");

		/* Call auto-detect and choose the first camera */
		CRSL (camera, gp_abilities_list_new (&al), context, list);
		CRSL (camera, gp_abilities_list_load (al, context), context, list);
		CRSL (camera, gp_port_info_list_new (&il), context, list);
		CRSL (camera, gp_port_info_list_load (il), context, list);
		CRSL (camera, gp_abilities_list_detect (al, il, list, context), context, list);
		if (!gp_list_count (list)) {
			gp_abilities_list_free (al);
			gp_port_info_list_free (il);
			gp_context_error (context, _("Could not detect "
					     "any camera"));
			gp_list_free (list);
			return (GP_ERROR_MODEL_NOT_FOUND);
		}
		p = 0;
		CRSL (camera, gp_port_get_info (camera->port, &info), context, list);
		CRSL (camera, gp_port_info_get_path (info, &ppath), context, list);
		CRSL (camera, gp_port_info_get_type (info, &ptype), context, list);
		/* if the port was set before, then use that entry, but not if it is "usb:" */
		if ((ptype == GP_PORT_USB) && strlen(ppath) && strcmp(ppath, "usb:")) {
			for (p = gp_list_count (list);p--;) {
				const char *xp;

				gp_list_get_value (list, p, &xp);
				if (!strcmp (xp, ppath))
					break;
			}
			if (p<0) {
				gp_abilities_list_free (al);
				gp_port_info_list_free (il);
				gp_context_error (context, _("Could not detect any camera at port %s"), ppath);
				gp_list_free (list);
				return (GP_ERROR_FILE_NOT_FOUND);
			}
		}

		CRSL (camera, gp_list_get_name  (list, p, &model), context, list);
		m = gp_abilities_list_lookup_model (al, model);
		CRSL (camera, m, context, list);
		CRSL (camera, gp_abilities_list_get_abilities (al, m, &a), context, list);
		gp_abilities_list_free (al);
		CRSL (camera, gp_camera_set_abilities (camera, a), context, list);
		CRSL (camera, gp_list_get_value (list, p, &port), context, list);
		p = gp_port_info_list_lookup_path (il, port);
		CRSL (camera, p, context, list);
		CRSL (camera, gp_port_info_list_get_info (il, p, &info), context, list);
		CRSL (camera, gp_camera_set_port_info (camera, info), context, list);
		gp_port_info_list_free (il);
		gp_list_free (list);
	}

	if (strcasecmp (camera->pc->a.model, "Directory Browse")) {
		switch (camera->port->type) {
		case GP_PORT_NONE:
			gp_context_error (context, _("You have to set the "
				"port prior to initialization of the camera."));
			return (GP_ERROR_UNKNOWN_PORT);
		case GP_PORT_USB:
			if (gp_port_usb_find_device (camera->port,
					camera->pc->a.usb_vendor,
					camera->pc->a.usb_product) != GP_OK) {
				CRS (camera, gp_port_usb_find_device_by_class
					(camera->port,
					camera->pc->a.usb_class,
					camera->pc->a.usb_subclass,
					camera->pc->a.usb_protocol), context);
					}
			break;
		default:
			break;
		}
	}

	/* Load the library. */
	GP_LOG_D ("Loading '%s'...", camera->pc->a.library);
	lt_dlinit ();
	camera->pc->lh = lt_dlopenext (camera->pc->a.library);
	if (!camera->pc->lh) {
		gp_context_error (context, _("Could not load required "
			"camera driver '%s' (%s)."), camera->pc->a.library,
			lt_dlerror ());
		lt_dlexit ();
		return (GP_ERROR_LIBRARY);
	}

	/* Initialize the camera */
	init_func = lt_dlsym (camera->pc->lh, "camera_init");
	if (!init_func) {
		lt_dlclose (camera->pc->lh);
		lt_dlexit ();
		camera->pc->lh = NULL;
		gp_context_error (context, _("Camera driver '%s' is "
			"missing the 'camera_init' function."), 
			camera->pc->a.library);
		return (GP_ERROR_LIBRARY);
	}

	if (strcasecmp (camera->pc->a.model, "Directory Browse")) {
		result = gp_port_open (camera->port);
		if (result < 0) {
			lt_dlclose (camera->pc->lh);
			lt_dlexit ();
			camera->pc->lh = NULL;
			return (result);
		}
	}

	result = init_func (camera, context);
	if (result < 0) {
		gp_port_close (camera->port);
		lt_dlclose (camera->pc->lh);
		lt_dlexit ();
		camera->pc->lh = NULL;
		memset (camera->functions, 0, sizeof (CameraFunctions));
		return (result);
	}

	/* We don't care if that goes wrong */
#ifdef HAVE_MULTI
	gp_port_close (camera->port);
#endif

	return (GP_OK);
}