4 #include <gphoto2/gphoto2-camera.h>
8 static GPPortInfoList *portinfolist = NULL;
9 static CameraAbilitiesList *abilities = NULL;
12 * This detects all currently attached cameras and returns
13 * them in a list. It avoids the generic usb: entry.
15 * This function does not open nor initialize the cameras yet.
18 sample_autodetect (CameraList *list, GPContext *context) {
20 CameraList *xlist = NULL;
22 ret = gp_list_new (&xlist);
23 if (ret < GP_OK) goto out;
25 /* Load all the port drivers we have... */
26 ret = gp_port_info_list_new (&portinfolist);
27 if (ret < GP_OK) goto out;
28 ret = gp_port_info_list_load (portinfolist);
29 if (ret < 0) goto out;
30 ret = gp_port_info_list_count (portinfolist);
31 if (ret < 0) goto out;
33 /* Load all the camera drivers we have... */
34 ret = gp_abilities_list_new (&abilities);
35 if (ret < GP_OK) goto out;
36 ret = gp_abilities_list_load (abilities, context);
37 if (ret < GP_OK) goto out;
39 /* ... and autodetect the currently attached cameras. */
40 ret = gp_abilities_list_detect (abilities, portinfolist, xlist, context);
41 if (ret < GP_OK) goto out;
43 /* Filter out the "usb:" entry */
44 ret = gp_list_count (xlist);
45 if (ret < GP_OK) goto out;
47 const char *name, *value;
49 gp_list_get_name (xlist, i, &name);
50 gp_list_get_value (xlist, i, &value);
51 if (!strcmp ("usb:",value)) continue;
52 gp_list_append (list, name, value);
56 return gp_list_count(list);
60 * This function opens a camera depending on the specified model and port.
63 sample_open_camera (Camera ** camera, const char *model, const char *port) {
68 ret = gp_camera_new (camera);
69 if (ret < GP_OK) return ret;
71 /* First lookup the model / driver */
72 m = gp_abilities_list_lookup_model (abilities, model);
73 if (m < GP_OK) return ret;
74 ret = gp_abilities_list_get_abilities (abilities, m, &a);
75 if (ret < GP_OK) return ret;
76 ret = gp_camera_set_abilities (*camera, a);
77 if (ret < GP_OK) return ret;
79 /* Then associate the camera with the specified port */
80 p = gp_port_info_list_lookup_path (portinfolist, port);
81 if (ret < GP_OK) return ret;
83 case GP_ERROR_UNKNOWN_PORT:
84 fprintf (stderr, "The port you specified "
85 "('%s') can not be found. Please "
86 "specify one of the ports found by "
87 "'gphoto2 --list-ports' and make "
88 "sure the spelling is correct "
89 "(i.e. with prefix 'serial:' or 'usb:').",
95 if (ret < GP_OK) return ret;
96 ret = gp_port_info_list_get_info (portinfolist, p, &pi);
97 if (ret < GP_OK) return ret;
98 ret = gp_camera_set_port_info (*camera, pi);
99 if (ret < GP_OK) return ret;