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); }
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; }
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); }
bool photo_camera_list::lookupPortInfo( const std::string port_name, GPPortInfo* port_info ) { int list_index = 0; // Find the port in the list of ports and return the index list_index = gp_port_info_list_lookup_path( port_info_list_, port_name.c_str() ); if( list_index < GP_OK ) { photo_reporter::error( "gp_port_info_list_lookup_path()" ); if( list_index == GP_ERROR_UNKNOWN_PORT ) { std::cerr << "The specified port (" << port_name << ") cannot be found. Use 'gphoto2 --list-ports' to display available ports. The prefix 'serial:' or 'usb:' is required." << std::endl; } return false; } // Get the port information from from the information list if( gp_port_info_list_get_info( port_info_list_, list_index, port_info ) != GP_OK ) { photo_reporter::error( "gp_port_info_list_get_info()" ); return false; } return true; }
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; }
gboolean _camera_initialize(const dt_camctl_t *c, dt_camera_t *cam) { dt_camctl_t *camctl=(dt_camctl_t *)c; CameraAbilities a; GPPortInfo pi; if( cam->gpcam==NULL ) { gp_camera_new(&cam->gpcam); int m = gp_abilities_list_lookup_model( c->gpcams, cam->model ); gp_abilities_list_get_abilities (c->gpcams, m, &a); gp_camera_set_abilities (cam->gpcam, a); int p = gp_port_info_list_lookup_path (c->gpports, cam->port); gp_port_info_list_get_info (c->gpports, p, &pi); gp_camera_set_port_info (cam->gpcam , pi); // Check for abilities if( (a.operations&GP_OPERATION_CAPTURE_IMAGE) ) cam->can_tether=TRUE; if( (a.operations&GP_OPERATION_CAPTURE_PREVIEW) ) cam->can_live_view=TRUE; if( cam->can_tether && (a.operations&GP_OPERATION_CONFIG) ) cam->can_config=TRUE; if( !(a.file_operations&GP_FILE_OPERATION_NONE) ) cam->can_import=TRUE; if( gp_camera_init( cam->gpcam , camctl->gpcontext) != GP_OK ) { dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to initialize camera %s on port %s\n", cam->model,cam->port); return FALSE; } // read a full copy of config to configuration cache gp_camera_get_config( cam->gpcam, &cam->configuration, c->gpcontext ); // TODO: find a more robust way for this, once we find out how to do it with non-EOS cameras if(cam->can_live_view && dt_camctl_camera_property_exists(camctl, cam, "eoszoomposition")) cam->can_live_view_advanced = TRUE; // initialize timeout callbacks eg. keep alive, some cameras needs it. cam->gpcontext = camctl->gpcontext; gp_camera_set_timeout_funcs(cam->gpcam, (CameraTimeoutStartFunc)_camera_start_timeout_func, (CameraTimeoutStopFunc)_camera_stop_timeout_func, cam); dt_pthread_mutex_init(&cam->jobqueue_lock, NULL); dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s initialized\n", cam->model,cam->port); } else dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s already initialized\n", cam->model,cam->port); return TRUE; }
/** * Connects to selected device. */ bool DigitalCameraCapture::open(int index) { const char * model = 0, *path = 0; int m, p; GPPortInfo portInfo; if (isOpened()) { close(); } try { CR(gp_camera_new(&camera)); CR(gp_list_get_name(allDevices, index, &model)); CR(gp_list_get_value(allDevices, index, &path)); // Set model abilities. CR(m = gp_abilities_list_lookup_model(abilitiesList, model)); CR(gp_abilities_list_get_abilities(abilitiesList, m, &cameraAbilities)); CR(gp_camera_set_abilities(camera, cameraAbilities)); // Set port CR(p = gp_port_info_list_lookup_path(capablePorts, path)); CR(gp_port_info_list_get_info(capablePorts, p, &portInfo)); CR(gp_camera_set_port_info(camera, portInfo)); // Initialize connection to the camera. CR(gp_camera_init(camera, context)); message(STATUS, "connected camera", model); message(STATUS, "connected using", path); // State initialization firstCapturedFrameTime = 0; capturedFrames = 0; preview = false; reloadOnChange = false; collectMsgs = false; reloadConfig(); opened = true; return true; } catch (GPhoto2Exception & e) { message(WARNING, "opening device failed", e); return false; } }
bool Image_GPhoto::initCamera(GPhotoCamera& camera) { lock_guard<recursive_mutex> lock(_gpMutex); if (camera.cam == nullptr) { gp_camera_new(&camera.cam); int m = gp_abilities_list_lookup_model(_gpCams, camera.model.c_str()); CameraAbilities abilities{}; gp_abilities_list_get_abilities(_gpCams, m, &abilities); gp_camera_set_abilities(camera.cam, abilities); int p = gp_port_info_list_lookup_path(_gpPorts, camera.port.c_str()); GPPortInfo portInfo; gp_port_info_list_get_info(_gpPorts, p, &portInfo); gp_camera_set_port_info(camera.cam, portInfo); if (abilities.operations & GP_OPERATION_CAPTURE_IMAGE) { camera.canTether = true; if (abilities.operations & GP_OPERATION_CONFIG) camera.canConfig = true; } if (!(abilities.file_operations & GP_FILE_OPERATION_NONE)) camera.canImport = true; if (gp_camera_init(camera.cam, _gpContext) != GP_OK) return false; gp_camera_get_config(camera.cam, &camera.configuration, _gpContext); // Get the available shutterspeeds initCameraProperty(camera, "shutterspeed", camera.shutterspeeds); initCameraProperty(camera, "aperture", camera.apertures); initCameraProperty(camera, "iso", camera.isos); return true; } else { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Camera " << camera.model << " already initialized" << Log::endl; return false; } }
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); }
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 */ }
static TW_UINT16 GPHOTO2_OpenDS( pTW_IDENTITY pOrigin, pTW_IDENTITY self) { int ret, m, p, count, i; CameraAbilities a; GPPortInfo info; const char *model, *port; if (TWRC_SUCCESS != gphoto2_auto_detect()) return TWRC_FAILURE; if (lstrcmpA(self->ProductFamily,"GPhoto2 Camera")) { FIXME("identity passed is not a gphoto camera, but %s!?!\n", self->ProductFamily); return TWRC_FAILURE; } count = gp_list_count (detected_cameras); if (!count) { ERR("No camera found by autodetection. Returning failure.\n"); return TWRC_FAILURE; } if (!lstrcmpA (self->ProductName, "GPhoto2 Camera")) { TRACE("Potential undetected camera. Just using the first autodetected one.\n"); i = 0; } else { for (i=0;i<count;i++) { const char *cname, *pname; TW_STR32 name; gp_list_get_name (detected_cameras, i, &cname); gp_list_get_value (detected_cameras, i, &pname); if (!lstrcmpA(self->ProductName,cname)) break; snprintf(name, sizeof(name), "%s", cname); if (!lstrcmpA(self->ProductName,name)) break; snprintf(name, sizeof(name), "%s@%s", cname, pname); if (!lstrcmpA(self->ProductName,name)) break; } if (i == count) { TRACE("Camera %s not found in autodetected list. Using first entry.\n", self->ProductName); i=0; } } gp_list_get_name (detected_cameras, i, &model); gp_list_get_value (detected_cameras, i, &port); TRACE("model %s, port %s\n", model, port); ret = gp_camera_new (&activeDS.camera); if (ret < GP_OK) { ERR("gp_camera_new: %d\n", ret); return TWRC_FAILURE; } m = gp_abilities_list_lookup_model (abilities_list, model); if (m < GP_OK) { FIXME("Model %s not found, %d!\n", model, m); return TWRC_FAILURE; } ret = gp_abilities_list_get_abilities (abilities_list, m, &a); if (ret < GP_OK) { FIXME("gp_camera_list_get_abilities failed? %d\n", ret); return TWRC_FAILURE; } ret = gp_camera_set_abilities (activeDS.camera, a); if (ret < GP_OK) { FIXME("gp_camera_set_abilities failed? %d\n", ret); return TWRC_FAILURE; } p = gp_port_info_list_lookup_path (port_list, port); if (p < GP_OK) { FIXME("port %s not in portlist?\n", port); return TWRC_FAILURE; } ret = gp_port_info_list_get_info (port_list, p, &info); if (ret < GP_OK) { FIXME("could not get portinfo for port %s?\n", port); return TWRC_FAILURE; } ret = gp_camera_set_port_info (activeDS.camera, info); if (ret < GP_OK) { FIXME("could not set portinfo for port %s to camera?\n", port); return TWRC_FAILURE; } list_init( &(activeDS.files) ); activeDS.currentState = 4; activeDS.twCC = TWRC_SUCCESS; activeDS.pixelflavor = TWPF_CHOCOLATE; activeDS.pixeltype = TWPT_RGB; activeDS.capXferMech = TWSX_MEMORY; TRACE("OK!\n"); return TWRC_SUCCESS; }
/** * \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); }
bool GPCamera::doConnect() { #ifdef HAVE_GPHOTO2 int errorCode; // -- first step - setup the camera -------------------- if (d->camera) { gp_camera_unref(d->camera); d->camera = 0; } CameraAbilitiesList* abilList = 0; GPPortInfoList* infoList = 0; GPPortInfo info; gp_camera_new(&d->camera); delete d->status; d->status = 0; d->status = new GPStatus(); gp_abilities_list_new(&abilList); gp_abilities_list_load(abilList, d->status->context); gp_port_info_list_new(&infoList); gp_port_info_list_load(infoList); int modelNum = gp_abilities_list_lookup_model(abilList, m_model.toLatin1().constData()); int portNum = gp_port_info_list_lookup_path(infoList, m_port.toLatin1().constData()); gp_abilities_list_get_abilities(abilList, modelNum, &d->cameraAbilities); errorCode = gp_camera_set_abilities(d->camera, d->cameraAbilities); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to set camera Abilities!"; printGphotoErrorDescription(errorCode); gp_camera_unref(d->camera); d->camera = 0; gp_abilities_list_free(abilList); gp_port_info_list_free(infoList); return false; } if (m_model != QLatin1String("Directory Browse")) { gp_port_info_list_get_info(infoList, portNum, &info); errorCode = gp_camera_set_port_info(d->camera, info); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to set camera port!"; printGphotoErrorDescription(errorCode); gp_camera_unref(d->camera); d->camera = 0; gp_abilities_list_free(abilList); gp_port_info_list_free(infoList); return false; } } gp_abilities_list_free(abilList); gp_port_info_list_free(infoList); if (d->cameraAbilities.file_operations & GP_FILE_OPERATION_PREVIEW) { m_thumbnailSupport = true; } if (d->cameraAbilities.file_operations & GP_FILE_OPERATION_DELETE) { m_deleteSupport = true; } if (d->cameraAbilities.folder_operations & GP_FOLDER_OPERATION_PUT_FILE) { m_uploadSupport = true; } if (d->cameraAbilities.folder_operations & GP_FOLDER_OPERATION_MAKE_DIR) { m_mkDirSupport = true; } if (d->cameraAbilities.folder_operations & GP_FOLDER_OPERATION_REMOVE_DIR) { m_delDirSupport = true; } if (d->cameraAbilities.operations & GP_OPERATION_CAPTURE_IMAGE) { m_captureImageSupport = true; } if (d->cameraAbilities.operations & GP_OPERATION_CAPTURE_PREVIEW) { m_captureImagePreviewSupport = true; } // -- Try and initialize the camera to see if its connected ----------------- errorCode = gp_camera_init(d->camera, d->status->context); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to initialize camera!"; printGphotoErrorDescription(errorCode); gp_camera_unref(d->camera); d->camera = 0; return false; } d->cameraInitialized = true; return true; #else return false; #endif /* HAVE_GPHOTO2 */ }
int input_run(int id) { int res, i; global->in[id].buf = malloc(256 * 1024); if(global->in[id].buf == NULL) { IPRINT(INPUT_PLUGIN_NAME " - could not allocate memory\n"); exit(EXIT_FAILURE); } plugin_id = id; // auto-detect algorithm CameraAbilitiesList* al; GPPortInfoList* il; CameraList* list; const char* model; const char* port; context = gp_context_new(); gp_abilities_list_new(&al); gp_abilities_list_load(al, context); gp_port_info_list_new(&il); gp_port_info_list_load(il); gp_list_new(&list); gp_abilities_list_detect(al, il, list, context); int count = gp_list_count(list); IPRINT(INPUT_PLUGIN_NAME " - Detected %d camera(s)\n", count); if(count == 0) { IPRINT(INPUT_PLUGIN_NAME " - No cameras detected.\n"); return 0; } GPPortInfo info; CameraAbilities a; int m, p; camera = NULL; for(i = 0; i < count; i++) { res = gp_list_get_name(list, i, &model); CAMERA_CHECK_GP(res, "gp_list_get_name"); m = gp_abilities_list_lookup_model(al, model); if(m < 0) { IPRINT(INPUT_PLUGIN_NAME " - Gphoto abilities_list_lookup_model Code: %d - %s\n", m, gp_result_as_string(m)); return 0; } res = gp_abilities_list_get_abilities(al, m, &a); CAMERA_CHECK_GP(res, "gp_abilities_list_get_abilities"); res = gp_list_get_value(list, i, &port); CAMERA_CHECK_GP(res, "gp_list_get_value"); DBG("Model: %s; port: %s.\n", model, port); if(selected_port != NULL && strcmp(selected_port, port) != 0) continue; p = gp_port_info_list_lookup_path(il, port); if(p < 0) { IPRINT(INPUT_PLUGIN_NAME " - Gphoto port_info_list_lookup_path Code: %d - %s\n", m, gp_result_as_string(m)); return 0; } res = gp_port_info_list_get_info(il, p, &info); CAMERA_CHECK_GP(res, "gp_port_info_list_get_info"); res = gp_camera_new(&camera); CAMERA_CHECK_GP(res, "gp_camera_new"); res = gp_camera_set_abilities(camera, a); CAMERA_CHECK_GP(res, "gp_camera_set_abilities"); res = gp_camera_set_port_info(camera, info); CAMERA_CHECK_GP(res, "gp_camera_set_port_info"); } if(camera == NULL) { IPRINT("Camera %s not found, exiting.\n", selected_port); exit(EXIT_FAILURE); } // cleanup gp_list_unref(list); gp_port_info_list_free(il); gp_abilities_list_free(al); // open camera and set capture on int value = 1; res = gp_camera_init(camera, context); CAMERA_CHECK_GP(res, "gp_camera_init"); camera_set("capture", &value); // starting thread if(pthread_create(&thread, 0, capture, NULL) != 0) { free(global->in[id].buf); IPRINT("could not start worker thread\n"); exit(EXIT_FAILURE); } pthread_detach(thread); return 0; }
/** * 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 (GP_LOG_DEBUG, "gphoto2-camera", "Initializing camera..."); CHECK_NULL (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; GPPortInfo pinfo; GPPortInfoList *il; int m, p; GPPortInfo info; CameraList *list; result = gp_list_new (&list); if (result < GP_OK) return result; result = gp_port_get_info (camera->port, &pinfo); if (result < GP_OK) return result; gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.type %d", pinfo.type); gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.path %s", pinfo.path); gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.name %s", pinfo.name); gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Neither " "port nor model set. Trying auto-detection..."); /* Call auto-detect and choose the first camera */ gp_abilities_list_new (&al); gp_abilities_list_load (al, context); gp_port_info_list_new (&il); gp_port_info_list_load (il); gp_abilities_list_detect (al, il, list, context); 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; /* if the port was set before, then use that entry. but not if it is "usb:" */ if ( (pinfo.type == GP_PORT_USB) && strlen(pinfo.path) && strcmp(pinfo.path,"usb:") ) { for (p = gp_list_count (list);p--;) { const char *xp; gp_list_get_value (list, p, &xp); if (!strcmp (xp, pinfo.path)) break; } if (p<0) { gp_context_error (context, _("Could not detect any camera at port %s"), pinfo.path); return (GP_ERROR_FILE_NOT_FOUND); } } gp_list_get_name (list, p, &model); m = gp_abilities_list_lookup_model (al, model); gp_abilities_list_get_abilities (al, m, &a); 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); gp_port_info_list_get_info (il, p, &info); gp_port_info_list_free (il); CRSL (camera, gp_camera_set_port_info (camera, info), context, list); 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 (GP_LOG_DEBUG, "gphoto2-camera", "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); }
static GtkamCamera * gtkam_chooser_get_camera (GtkamChooser *chooser) { GtkWidget *dialog, *status; GPPortInfo info; Camera *camera; CameraAbilities abilities; const gchar *model, *port, *speed; gchar *port_path, *right, *tmp; int m, p, r; gboolean multi; GtkamCamera *c; model = gtk_entry_get_text (chooser->priv->entry_model); port = gtk_entry_get_text (chooser->priv->entry_port); speed = gtk_entry_get_text (chooser->priv->entry_speed); multi = GTK_TOGGLE_BUTTON (chooser->priv->check_multi)->active; if (!port || !*port) port_path = g_strdup (_("None")); else { port_path = g_strdup (port); right = strrchr (port_path, ')'); *right = '\0'; tmp = g_strdup (strrchr (port_path, '(') + 1); g_free (port_path); port_path = tmp; } gp_camera_new (&camera); #ifdef HAVE_GP_CAMERA_SET_TIMEOUT_FUNCS gp_camera_set_timeout_funcs (camera, start_timeout_func, stop_timeout_func, NULL); #endif /* Model? */ m = gp_abilities_list_lookup_model (chooser->priv->al, model); gp_abilities_list_get_abilities (chooser->priv->al, m, &abilities); gp_camera_set_abilities (camera, abilities); /* Port? */ if (strcmp (port_path, _("None"))) { p = gp_port_info_list_lookup_path (chooser->priv->il, port_path); gp_port_info_list_get_info (chooser->priv->il, p, &info); gp_camera_set_port_info (camera, info); } /* Speed? */ if (strcmp (speed, _("Best"))) gp_camera_set_port_speed (camera, atoi (speed)); /* * Initialize the camera to check if it is really there. Exit * afterwards because other applications could need the camera, too. */ status = gtkam_status_new (_("Initializing camera...")); gtkam_dialog_add_status (GTKAM_DIALOG (chooser), status); r = gp_camera_init (camera, GTKAM_STATUS (status)->context->context); if (multi) gp_camera_exit (camera, NULL); switch (r) { case GP_OK: break; case GP_ERROR_CANCEL: g_free (port_path); break; default: g_free (port_path); dialog = gtkam_error_new (r, GTKAM_STATUS (status)->context, NULL, _("Could not initialize camera.")); gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (chooser)); gtk_widget_show (dialog); gp_camera_unref (camera); camera = NULL; } gtk_object_destroy (GTK_OBJECT (status)); c = gtkam_camera_new (camera, multi); gp_camera_unref (camera); return (c); }
static GnoCamCamera * gnocam_main_get_camera (GnoCamMain *gm, const gchar *model, const gchar *port, CORBA_Environment *ev) { Camera *camera; GnoCamCamera *gc = NULL; g_message ("Trying to get a camera for model '%s' (port '%s')...", model, port); g_return_val_if_fail (GNOCAM_IS_MAIN (gm), NULL); gc = gnocam_cache_lookup (gm->priv->cache, model, port); if (gc) { bonobo_object_ref (gc); return gc; } CR (gp_camera_new (&camera), ev); if (BONOBO_EX (ev)) return (CORBA_OBJECT_NIL); if (model && strlen (model)) { CameraAbilities a; CameraAbilitiesList *al = NULL; int m; memset (&a, 0, sizeof (CameraAbilities)); gp_abilities_list_new (&al); gp_abilities_list_load (al, NULL); m = gp_abilities_list_lookup_model (al, model); gp_abilities_list_get_abilities (al, m, &a); gp_abilities_list_free (al); CR (gp_camera_set_abilities (camera, a), ev); if (BONOBO_EX (ev)) { gp_camera_unref (camera); return NULL; } } if (port && strlen (port)) { GPPortInfo info; GPPortInfoList *il = NULL; int p; memset (&info, 0, sizeof (GPPortInfo)); gp_port_info_list_new (&il); gp_port_info_list_load (il); p = gp_port_info_list_lookup_name (il, port); if (p < 0) p = gp_port_info_list_lookup_path (il, port); gp_port_info_list_get_info (il, p, &info); gp_port_info_list_free (il); CR (gp_camera_set_port_info (camera, info), ev); if (BONOBO_EX (ev)) { gp_camera_unref (camera); return (CORBA_OBJECT_NIL); } } CR (gp_camera_init (camera, NULL), ev); if (BONOBO_EX (ev)) { gp_camera_unref (camera); return NULL; } gc = gnocam_camera_new (camera, ev); gp_camera_unref (camera); if (BONOBO_EX (ev)) return NULL; gnocam_cache_add (gm->priv->cache, gc); g_message ("Successfully created a camera."); return gc; }
bool GPCamera::findConnectedUsbCamera(int vendorId, int productId, QString& model, QString& port) { #ifdef HAVE_GPHOTO2 CameraAbilitiesList* abilList = 0; GPPortInfoList* list = 0; GPContext* context = 0; CameraList* camList = 0; bool success = false; // get name and port of detected camera const char* model_str = 0; const char* port_str = 0; context = gp_context_new(); // get list of all ports gp_port_info_list_new(&list); gp_port_info_list_load(list); gp_abilities_list_new(&abilList); // get list of all supported cameras gp_abilities_list_load(abilList, context); // autodetect all cameras, then match the list to the passed in USB ids gp_list_new (&camList); gp_abilities_list_detect(abilList, list, camList, context); gp_context_unref(context); int count = gp_list_count(camList); int cnt = 0; for (int i = 0 ; i < count ; i++) { const char* xmodel = 0; gp_list_get_name(camList, i, &xmodel); int model = gp_abilities_list_lookup_model (abilList, xmodel); CameraAbilities ab; gp_abilities_list_get_abilities(abilList, model, &ab); if (ab.port != GP_PORT_USB) continue; /* KDE provides us USB Vendor and Product, but we might just * have covered this via a class match. Check class matched * cameras also for matchingo USB vendor/product id */ if (ab.usb_vendor == 0) { int ret; GPPortInfo info; const char* xport = 0; GPPort* gpport = 0; /* get the port path so we only look at this bus position */ gp_list_get_value(camList, i, &xport); ret = gp_port_info_list_lookup_path (list, xport); if (ret < GP_OK) /* should not happen */ continue; /* get the lowlevel port info for the path */ gp_port_info_list_get_info(list, ret, &info); /* open lowlevel driver interface briefly to search */ gp_port_new(&gpport); gp_port_set_info(gpport, info); /* And now call into the lowlevel usb driver to see if the bus position * has that specific vendor/product id */ if (gp_port_usb_find_device(gpport, vendorId, productId) == GP_OK) { ab.usb_vendor = vendorId; ab.usb_product = productId; } gp_port_free (gpport); } if (ab.usb_vendor != vendorId) continue; if (ab.usb_product != productId) continue; /* keep it, and continue iterating, in case we find another one */ gp_list_get_name (camList, i, &model_str); gp_list_get_value(camList, i, &port_str); cnt++; } gp_port_info_list_free(list); gp_abilities_list_free(abilList); if (cnt > 0) { if (cnt > 1) { qCWarning(DIGIKAM_IMPORTUI_LOG) << "More than one camera detected on port " << port << ". Due to restrictions in the GPhoto2 API, " << "only the first camera is used."; } model = QString::fromLatin1(model_str); port = QString::fromLatin1(port_str); success = true; } else { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get information for the listed camera"; } gp_list_free(camList); return success; #else Q_UNUSED(vendorId); Q_UNUSED(productId); Q_UNUSED(model); Q_UNUSED(port); return false; #endif /* HAVE_GPHOTO2 */ }