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 a single camera and then calls a
12 * simple function in it (summary).
13 */
14
main(int argc,char ** argv)15 int main(int argc, char **argv) {
16 Camera *camera;
17 int ret;
18 char *owner;
19 GPContext *context;
20 CameraText text;
21
22 context = sample_create_context (); /* see context.c */
23 gp_camera_new (&camera);
24
25 /* This call will autodetect cameras, take the
26 * first one from the list and use it. It will ignore
27 * any others... See the *multi* examples on how to
28 * detect and use more than the first one.
29 */
30 ret = gp_camera_init (camera, context);
31 if (ret < GP_OK) {
32 printf("No camera auto detected.\n");
33 gp_camera_free (camera);
34 return 0;
35 }
36
37 /* Simple query the camera summary text */
38 ret = gp_camera_get_summary (camera, &text, context);
39 if (ret < GP_OK) {
40 printf("Camera failed retrieving summary.\n");
41 gp_camera_free (camera);
42 return 0;
43 }
44 printf("Summary:\n%s\n", text.text);
45
46 /* Simple query of a string configuration variable. */
47 ret = get_config_value_string (camera, "owner", &owner, context);
48 if (ret >= GP_OK) {
49 printf("Owner: %s\n", owner);
50 free (owner);
51 }
52 gp_camera_exit (camera, context);
53 gp_camera_free (camera);
54 gp_context_unref (context);
55 return 0;
56 }
57