1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 
5 #include <gphoto2/gphoto2-camera.h>
6 
7 #include "samples.h"
8 
9 /* Sample autodetection program.
10  *
11  * This program can autodetect multiple cameras and then calls a
12  * simple function in each of them (summary).
13  */
14 
main(int argc,char ** argv)15 int main(int argc, char **argv) {
16 	CameraList	*list;
17 	Camera		**cams;
18 	int		ret, i, count;
19 	const char	*name, *value;
20 	GPContext	*context;
21 
22 	context = sample_create_context (); /* see context.c */
23 
24 	/* Detect all the cameras that can be autodetected... */
25 	ret = gp_list_new (&list);
26 	if (ret < GP_OK) return 1;
27 	count = sample_autodetect (list, context);
28 	if (count < GP_OK) {
29 		printf("No cameras detected.\n");
30 		return 1;
31 	}
32 
33 	/* Now open all cameras we autodected for usage */
34 	printf("Number of cameras: %d\n", count);
35 	cams = calloc (sizeof (Camera*),count);
36         for (i = 0; i < count; i++) {
37                 gp_list_get_name  (list, i, &name);
38                 gp_list_get_value (list, i, &value);
39 		ret = sample_open_camera (&cams[i], name, value, context);
40 		if (ret < GP_OK) fprintf(stderr,"Camera %s on port %s failed to open\n", name, value);
41         }
42 	/* Now call a simple function in each of those cameras. */
43 	for (i = 0; i < count; i++) {
44 		CameraText	text;
45 		char 		*owner;
46 	        ret = gp_camera_get_summary (cams[i], &text, context);
47 		if (ret < GP_OK) {
48 			fprintf (stderr, "Failed to get summary.\n");
49 			continue;
50 		}
51 
52                 gp_list_get_name  (list, i, &name);
53                 gp_list_get_value (list, i, &value);
54                 printf("%-30s %-16s\n", name, value);
55 		printf("Summary:\n%s\n", text.text);
56 
57 		/* Query a simple string configuration variable. */
58 		ret = get_config_value_string (cams[i], "owner", &owner, context);
59 		if (ret >= GP_OK) {
60 			printf("Owner: %s\n", owner);
61 			free (owner);
62 		} else {
63 			printf("Owner: No owner found.\n");
64 		}
65 
66 	}
67 	return 0;
68 }
69