From 1101b617c3dfd3c5cdbb4b1669e16c5501c8bee7 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Sat, 24 Sep 2016 12:12:09 +0200 Subject: [PATCH] add a sample program for using AFL without the gphoto2 commandline tool overhead --- examples/Makefile.am | 2 + examples/sample-afl.c | 114 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 examples/sample-afl.c diff --git a/examples/Makefile.am b/examples/Makefile.am index 2474cf662..409f28458 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -28,9 +28,11 @@ noinst_PROGRAMS += \ sample-owner \ sample-preview \ sample-tether \ + sample-afl \ best-iso \ sample-capture sample-trigger-capture sample-justfocus +sample_afl_SOURCES = sample-afl.c samples.h context.c sample_autodetect_SOURCES = sample-autodetect.c samples.h context.c config.c sample_owner_SOURCES = sample-owner.c samples.h context.c config.c sample_multi_detect_SOURCES = sample-multi-detect.c samples.h autodetect.c context.c config.c diff --git a/examples/sample-afl.c b/examples/sample-afl.c new file mode 100644 index 000000000..c56176544 --- /dev/null +++ b/examples/sample-afl.c @@ -0,0 +1,114 @@ +#include +#include +#include + +#include + +#include "samples.h" + +/* Sample for AFL usage. + * + */ + +int main(int argc, char **argv) { + Camera *camera = NULL; + int ret; + GPContext *context; + CameraWidget *rootwidget; + GPPortInfo pi; + char buf[200]; + GPPortInfoList *portinfolist = NULL; + CameraAbilitiesList *abilities = NULL; + CameraAbilities a; + CameraText summary; + + context = sample_create_context (); /* see context.c */ + + ret = gp_port_info_list_new (&portinfolist); + if (ret < GP_OK) { + fprintf(stderr,"no portlist allocated.\n"); + goto out; + } + ret = gp_port_info_list_load (portinfolist); + if (ret < GP_OK) { + fprintf(stderr,"no portlist loaded.\n"); + goto out; + } + gp_camera_new (&camera); + strcpy(buf,"usb:"); + if (argc > 1) + strcat (buf, argv[1]); + + ret = gp_port_info_list_lookup_path (portinfolist, buf); + if (ret < GP_OK) { + fprintf(stderr,"path %s not found.\n", buf); + goto out; + } + ret = gp_port_info_list_get_info (portinfolist, ret, &pi); + if (ret < GP_OK) { + fprintf(stderr,"port info not gotten.\n"); + goto out; + } + ret = gp_camera_set_port_info (camera, pi); + if (ret < GP_OK) { + fprintf(stderr,"port info not set in camera.\n"); + goto out; + } + + /* First lookup the model / driver */ + + /* Load all the camera drivers we have... */ + ret = gp_abilities_list_new (&abilities); + if (ret < GP_OK) { + fprintf(stderr,"Abilitylist not allocated.\n"); + goto out; + } + ret = gp_abilities_list_load (abilities, context); + if (ret < GP_OK) { + fprintf(stderr,"Abilitylist not loaded.\n"); + goto out; + } + + ret = gp_abilities_list_lookup_model (abilities, "USB PTP Class Camera"); + if (ret < GP_OK) { + fprintf(stderr,"Camera not found.\n"); + } + ret = gp_abilities_list_get_abilities (abilities, ret, &a); + if (ret < GP_OK) { + fprintf(stderr,"Abilities not gotten.\n"); + } + ret = gp_camera_set_abilities (camera, a); + if (ret < GP_OK) { + fprintf(stderr,"Abilities not set in camera.\n"); + } + + ret = gp_camera_init (camera, context); + if (ret < GP_OK) { + fprintf(stderr,"No camera auto detected.\n"); + goto out; + } + + /* AFL PART STARTS HERE */ + ret = gp_camera_get_summary (camera, &summary, context); + if (ret < GP_OK) { + printf ("Could not get summary.\n"); + goto out; + } + +#if 0 + ret = gp_camera_get_config (camera, &rootwidget, context); + if (ret < GP_OK) { + fprintf (stderr,"Could not get config.\n"); + goto out; + } +#endif + printf ("OK, %s\n", summary.text); + + /* AFL PART ENDS HERE */ +out: + gp_abilities_list_free (abilities); + gp_port_info_list_free (portinfolist); + gp_camera_exit (camera, context); + gp_camera_free (camera); + return 0; +}