Remove generated files
[framework/connectivity/libgphoto2.git] / examples / sample-owner.c
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 static void errordumper(GPLogLevel level, const char *domain, const char *format,
10                  va_list args, void *data) {
11   vfprintf(stdout, format, args);
12   fprintf(stdout, "\n");
13 }
14
15 /* Set the owner of the first camera.
16  *
17  * This program can autodetect a single camera and then sets its
18  * owner to the string passed on the cmdline.
19  *
20  * Same as:
21  *      gphoto2 --get-config ownername
22  *      gphoto2 --set-config ownername="Owner Name"
23  */
24
25 int main(int argc, char **argv) {
26         Camera          *camera;
27         int             ret;
28         char            *owner;
29         GPContext       *context;
30
31         context = sample_create_context (); /* see context.c */
32
33         gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
34
35         gp_camera_new (&camera);
36
37         /* This call will autodetect cameras, take the
38          * first one from the list and use it. It will ignore
39          * any others... See the *multi* examples on how to
40          * detect and use more than the first one.
41          */
42         ret = gp_camera_init (camera, context);
43         if (ret < GP_OK) {
44                 printf("No camera auto detected.\n");
45                 gp_camera_free (camera);
46                 return 0;
47         }
48
49         ret = get_config_value_string (camera, "ownername", &owner, context);
50         if (ret < GP_OK) {
51                 printf ("Could not query owner.\n");
52                 goto out;
53         }
54         printf("Current owner: %s\n", owner);
55         if (argc > 1) {
56                 ret = set_config_value_string (camera, "ownername", argv[1], context);
57                 if (ret < GP_OK) {
58                         fprintf (stderr, "Failed to set camera owner to %s; %d\n", argv[1], ret);
59                 } else 
60                         printf("New owner: %s\n", argv[1]);
61         }
62 out:
63         gp_camera_exit (camera, context);
64         gp_camera_free (camera);
65         return 0;
66 }