Ejemplo n.º 1
0
static GNOME_GnoCam_PortList *
impl_GNOME_GnoCam_getPortList (PortableServer_Servant servant,
				       CORBA_Environment *ev)
{
	GnoCamMain *gm;
	GNOME_GnoCam_PortList *list;
	GPPortInfoList *il = NULL;
	GPPortInfo info;
	int n, i;

	gm = GNOCAM_MAIN (bonobo_object_from_servant (servant));

	gp_port_info_list_new (&il);
	gp_port_info_list_load (il);
	n = MAX (0, gp_port_info_list_count (il));

	list = GNOME_GnoCam_PortList__alloc ();
	list->_buffer = CORBA_sequence_CORBA_string_allocbuf (n);
	for (i = 0; i < n; i++) {
		if (gp_port_info_list_get_info (il, i, &info) >= 0) {
			list->_buffer[list->_length] =
				CORBA_string_dup (info.name);
			list->_length++;
		}
	}
	CORBA_sequence_set_release (list, TRUE);
	gp_port_info_list_free (il);

	return (list);
}
Ejemplo n.º 2
0
static GNOME_C_Camera
impl_connect (PortableServer_Servant servant, const CORBA_char *manufacturer,
	      const CORBA_char *model, const CORBA_char *port, 
	      CORBA_Environment *ev)
{
	KncCMngr *m = KNC_C_MNGR (bonobo_object (servant));
	KncCCamera *c;
	GPPort *p = NULL;
	GPPortInfo info;
	unsigned int i;

	gp_port_new (&p);
	for (i = 0; i < MAX (gp_port_info_list_count (m->priv->il), 0); i++) {
		gp_port_info_list_get_info (m->priv->il, i, &info);
		if (!strcmp (info.name, port)) {
			gp_port_set_info (p, info);
			c = knc_c_camera_new (manufacturer, model, p, ev);
			if (BONOBO_EX (ev)) return CORBA_OBJECT_NIL;
			return CORBA_Object_duplicate (BONOBO_OBJREF (c), ev);
		}
	}
	gp_port_free (p);
	
	CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_C_Error, NULL);
	return CORBA_OBJECT_NIL;
}
Ejemplo n.º 3
0
bool photo_camera_list::loadPortInfo( ssize_t* port_count )
{
  if( port_info_list_ == NULL )
  {
    // Create a new port info list
    if( gp_port_info_list_new( &port_info_list_ ) != GP_OK )
    {
      photo_reporter::error( "gp_port_info_list_new()" );
      return false;
    }

    // Populate the list
    if( gp_port_info_list_load( port_info_list_ ) != GP_OK )
    {
      photo_reporter::error( "gp_port_info_list_load()" );
      return false;
    }
  }

  // Count the number of ports in the list
  *port_count =  gp_port_info_list_count( port_info_list_ );
  if( *port_count < GP_OK )
  {
    photo_reporter::error( "gp_port_info_list_count()" );
    return false;
  }

  return true;
}
Ejemplo n.º 4
0
int
auto_detect_action (CameraList *list,GPContext *context)
{
	int count, result;
    GPPortInfoList *portinfo_list;
    CameraAbilitiesList *al = NULL;
	if ((result = gp_port_info_list_new (&portinfo_list)) < GP_OK)
		return result;
	result = gp_port_info_list_load (portinfo_list);
	if (result < 0) {
		gp_port_info_list_free (portinfo_list);
		return result;
	}
	count = gp_port_info_list_count (portinfo_list);
	if (count < 0) {
		gp_port_info_list_free (portinfo_list);
		return count;
	}
    gp_abilities_list_new (&al);
    gp_abilities_list_load (al, context);
    gp_abilities_list_detect (al, portinfo_list, list, context);
    gp_abilities_list_free (al);
	count = gp_list_count (list);
    return count > 0 ? GP_OK : GP_ERROR;
}
Ejemplo n.º 5
0
static GNOME_C_Mngr_ManufacturerList *
impl_get_devices (PortableServer_Servant servant, CORBA_Environment *ev)
{
	KncCMngr *m = KNC_C_MNGR (bonobo_object (servant));
	GNOME_C_Mngr_ManufacturerList *l;
	unsigned int i, j, k, n, o;
	GPPortInfo info;
	int c;

	l = GNOME_C_Mngr_ManufacturerList__alloc ();

	/* List all manufacturers */
	l->_buffer = GNOME_C_Mngr_ManufacturerList_allocbuf (
						knc_count_devices ());
	l->_length = 0;
	for (i = 0; i < knc_count_devices (); i++) {
	    for (j = 0; j < l->_length; j++)
		if (!strcmp (l->_buffer[j].manufacturer,
			     knc_get_device_manufacturer (i))) break;
	    if (j == l->_length) {
		l->_length++;
		l->_buffer[j].manufacturer = CORBA_string_dup (
				knc_get_device_manufacturer (i));
		l->_buffer[j].models._length = 0;
		l->_buffer[j].models._buffer =
			GNOME_C_Mngr_ModelList_allocbuf (knc_count_devices ());

		/* List all models */
		for (k = 0; k < knc_count_devices (); k++) {
		    if (strcmp (l->_buffer[j].manufacturer,
			        knc_get_device_manufacturer (k))) continue;
		    n = l->_buffer[j].models._length;
		    l->_buffer[j].models._length++;
		    l->_buffer[j].models._buffer[n].model =
			    CORBA_string_dup (knc_get_device_model (k));

		    /* List all serial ports */
		    c = gp_port_info_list_count (m->priv->il);
		    l->_buffer[j].models._buffer[n].ports._length = 0;
		    l->_buffer[j].models._buffer[n].ports._buffer =
			    CORBA_sequence_CORBA_string_allocbuf (MAX (c, 0));
		    for (o = 0; o < MAX (c, 0); o++) {
			gp_port_info_list_get_info (m->priv->il, o, &info);
			if (info.type == GP_PORT_SERIAL) {
			    l->_buffer[j].models._buffer[n].ports._buffer[
				l->_buffer[j].models._buffer[n].ports._length] =
					CORBA_string_dup (info.name);
			    l->_buffer[j].models._buffer[n].ports._length++;
			}
		    }
		}
	    }
	}
	CORBA_sequence_set_release (l, CORBA_TRUE);

	return l;
}
Ejemplo n.º 6
0
/**
 * Autodetect all detectable camera
 *
 * @param list a #CameraList that receives the autodetected cameras
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * This camera will autodetected all cameras that can be autodetected.
 * This will for instance detect all USB cameras.
 *
 *   CameraList *list;
 *   gp_list_new (&list);
 *   gp_camera_autodetect (list, context);
 *   ... done! ...
 */
int
gp_camera_autodetect (CameraList *list, GPContext *context)
{
	CameraAbilitiesList	*al = NULL;
	GPPortInfoList		*il = NULL;
	int			ret, i;
	CameraList		*xlist = NULL;

	ret = gp_list_new (&xlist);
	if (ret < GP_OK) goto out;
	if (!il) {
		/* Load all the port drivers we have... */
		ret = gp_port_info_list_new (&il);
		if (ret < GP_OK) goto out;
		ret = gp_port_info_list_load (il);
		if (ret < 0) goto out;
		ret = gp_port_info_list_count (il);
		if (ret < 0) goto out;
	}
	/* Load all the camera drivers we have... */
	ret = gp_abilities_list_new (&al);
	if (ret < GP_OK) goto out;
	ret = gp_abilities_list_load (al, context);
	if (ret < GP_OK) goto out;

	/* ... and autodetect the currently attached cameras. */
        ret = gp_abilities_list_detect (al, il, xlist, context);
	if (ret < GP_OK) goto out;

	/* Filter out the "usb:" entry */
        ret = gp_list_count (xlist);
	if (ret < GP_OK) goto out;
	for (i=0;i<ret;i++) {
		const char *name, *value;

		gp_list_get_name (xlist, i, &name);
		gp_list_get_value (xlist, i, &value);
		if (!strcmp ("usb:",value)) continue;
		gp_list_append (list, name, value);
	}
out:
	if (il) gp_port_info_list_free (il);
	if (al) gp_abilities_list_free (al);
	gp_list_free (xlist);
	if (ret < GP_OK)
		return ret;
	return gp_list_count(list);
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
void GPCamera::getSupportedPorts(QStringList& plist)
{
#ifdef HAVE_GPHOTO2
    GPPortInfoList* list = 0;
    GPPortInfo      info;

    plist.clear();

    gp_port_info_list_new(&list);
    gp_port_info_list_load(list);

    int numPorts = gp_port_info_list_count(list);

    if (numPorts < 0)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get list of port!";
        printGphotoErrorDescription(numPorts);
        gp_port_info_list_free(list);
        return;
    }
    else
    {
        for (int i = 0 ; i < numPorts ; i++)
        {
            gp_port_info_list_get_info(list, i, &info);
#ifdef HAVE_GPHOTO25
            char* xpath = 0;
            gp_port_info_get_name (info, &xpath);
            plist.append(QString::fromUtf8(xpath));
#else
            plist.append(info.path);
#endif
        }
    }

    gp_port_info_list_free(list);
#else
    Q_UNUSED(plist);
#endif /* HAVE_GPHOTO2 */
}
Ejemplo n.º 9
0
static TW_UINT16
gphoto2_auto_detect(void) {
    int result, count;

    if (detected_cameras && (gp_list_count (detected_cameras) == 0)) {
	/* Reload if previously no cameras, we might detect new ones. */
	TRACE("Reloading portlist trying to detect cameras.\n");
	if (port_list) {
	    gp_port_info_list_free (port_list);
	    port_list = NULL;
	}
    }
    if (!port_list) {
	TRACE("Auto detecting gphoto cameras.\n");
	TRACE("Loading ports...\n");
	if (gp_port_info_list_new (&port_list) < GP_OK)
	    return TWRC_FAILURE;
	result = gp_port_info_list_load (port_list);
	if (result < 0) {
	    gp_port_info_list_free (port_list);
	    return TWRC_FAILURE;
	}
	count = gp_port_info_list_count (port_list);
	if (count <= 0)
	    return TWRC_FAILURE;
	if (gp_list_new (&detected_cameras) < GP_OK)
	    return TWRC_FAILURE;
	if (!abilities_list) { /* Load only once per program start */
	    gp_abilities_list_new (&abilities_list);
	    TRACE("Loading cameras...\n");
	    gp_abilities_list_load (abilities_list, NULL);
	}
	TRACE("Detecting cameras...\n");
	gp_abilities_list_detect (abilities_list, port_list, detected_cameras, NULL);
        curcamera = 0;
        TRACE("%d cameras detected\n", gp_list_count(detected_cameras));
    }
    return TWRC_SUCCESS;
}
Ejemplo n.º 10
0
void dt_camctl_detect_cameras(const dt_camctl_t *c)
{

  dt_camctl_t *camctl=(dt_camctl_t *)c;
  dt_pthread_mutex_lock(&camctl->lock);

  /* reload portdrivers */
  if (camctl->gpports)
    gp_port_info_list_free (camctl->gpports);

  gp_port_info_list_new( &camctl->gpports );
  gp_port_info_list_load( camctl->gpports );
  dt_print(DT_DEBUG_CAMCTL,"[camera_control] loaded %d port drivers.\n", gp_port_info_list_count( camctl->gpports ) );



  CameraList *available_cameras=NULL;
  gp_list_new( &available_cameras );
  gp_abilities_list_detect (c->gpcams,c->gpports, available_cameras, c->gpcontext );
  dt_print(DT_DEBUG_CAMCTL,"[camera_control] %d cameras connected\n",gp_list_count( available_cameras )>0?gp_list_count( available_cameras ):0);


  for(int i=0; i<gp_list_count( available_cameras ); i++)
  {
    dt_camera_t *camera=g_malloc(sizeof(dt_camera_t));
    memset( camera,0,sizeof(dt_camera_t));
    gp_list_get_name (available_cameras, i, &camera->model);
    gp_list_get_value (available_cameras, i, &camera->port);
    dt_pthread_mutex_init(&camera->config_lock, NULL);
    dt_pthread_mutex_init(&camera->live_view_pixbuf_mutex, NULL);
    dt_pthread_mutex_init(&camera->live_view_synch, NULL);

    // if(strcmp(camera->port,"usb:")==0) { g_free(camera); continue; }
    GList *citem;
    if( (citem=g_list_find_custom(c->cameras,camera,_compare_camera_by_port)) == NULL || strcmp(((dt_camera_t *)citem->data)->model,camera->model)!=0 )
    {
      if(citem==NULL)
      {
        // Newly connected camera
        if(_camera_initialize(c,camera)==FALSE)
        {
          dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to initialize device %s on port %s, probably causes are: locked by another application, no access to udev etc.\n", camera->model,camera->port);
          g_free(camera);
          continue;
        }

        // Check if camera has capabililties for being presented to darktable
        if( camera->can_import==FALSE && camera->can_tether==FALSE )
        {
          dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s doesn't support import or tether, skipping device.\n", camera->model,camera->port);
          g_free(camera);
          continue;
        }

        // Fetch some summary of camera
        if( gp_camera_get_summary(camera->gpcam, &camera->summary, c->gpcontext) == GP_OK )
        {
          // Remove device property summary:
          char *eos=strstr(camera->summary.text,"Device Property Summary:\n");
          if (eos) eos[0]='\0';
        }

        // Add to camera list
        camctl->cameras = g_list_append(camctl->cameras,camera);

        // Notify listeners of connected camera
        _dispatch_camera_connected(camctl,camera);
      }
    }
    else
      g_free(camera);
  }

  /* check c->cameras in available_cameras */
  if( c->cameras && g_list_length(c->cameras)>0)
  {
    GList *citem = c->cameras;
    do
    {
      int index=0;
      dt_camera_t *cam=(dt_camera_t *)citem->data;
      if (gp_list_find_by_name(available_cameras,&index,cam->model)!= GP_OK)
      {
        /* remove camera from cached list.. */
        dt_camctl_t *camctl=(dt_camctl_t *)c;
        dt_camera_t *oldcam = (dt_camera_t *)citem->data;
        camctl->cameras=citem= g_list_delete_link (c->cameras,citem);
        g_free(oldcam);
      }
    }
    while ( citem && (citem=g_list_next(citem))!=NULL);
  }

  dt_pthread_mutex_unlock(&camctl->lock);
}
/**
 * \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);
}