summaryrefslogtreecommitdiff
path: root/tests/test-gphoto2.c
blob: d74ae47b05aad215f45b7b0e6c1e365f367e651a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <gphoto2-camera.h>

#include <stdio.h>
#ifdef _GNU_SOURCE
#include <mcheck.h>
#endif

#define CHECK(f) {int res = f; if (res < 0) {printf ("ERROR: %s\n", gp_result_as_string (res)); return (1);}}

int
main (int argc, char *argv [])
{
	CameraText text;
	Camera *camera;
	CameraAbilitiesList *al;
	CameraAbilities abilities;
	int m;

#ifdef _GNU_SOURCE
	mtrace();
#endif

	/*
	 * You'll probably want to access your camera. You will first have
	 * to create a camera (that is, allocating the memory).
	 */
	printf ("Creating camera...\n");
	CHECK (gp_camera_new (&camera));

	/*
	 * Before you initialize the camera, set the model so that
	 * gphoto2 knows which library to use.
	 */
	printf ("Setting model...\n");
	CHECK (gp_abilities_list_new (&al));
	CHECK (gp_abilities_list_load (al));
	CHECK (m = gp_abilities_list_lookup_model (al, "Directory Browse"));
	CHECK (gp_abilities_list_get_abilities (al, m, &abilities));
	CHECK (gp_abilities_list_free (al));
	CHECK (gp_camera_set_abilities (camera, abilities));

	/*
	 * Now, initialize the camera (establish a connection).
	 */
	printf ("Initializing camera...\n");
	CHECK (gp_camera_init (camera));

	/*
	 * At this point, you can do whatever you want.
	 * You could get files, capture images...
	 */
	printf ("Getting information about the driver...\n");
	CHECK (gp_camera_get_about (camera, &text));
	printf ("%s\n", text.text);

	/*
	 * Don't forget to clean up when you don't need the camera any
	 * more. Please use unref instead of destroy - you'll never know
	 * if some part of the program still needs the camera.
	 */
	printf ("Unrefing camera...\n");
	CHECK (gp_camera_unref (camera));

#ifdef _GNU_SOURCE
	muntrace();
#endif

	return (0);
}

/*
 * Local variables:
 *  compile-command: "gcc -pedantic -Wstrict-prototypes -O2 -g test-gphoto2.c -o test-gphoto2 `gphoto2-config --cflags --libs` && export MALLOC_TRACE=test-gphoto2.log && ./test-gphoto2 && mtrace ./test-gphoto2 test-gphoto2.log"
 * End:
 */