The gphoto2 source

On my system, I get to the source for gphoto2 by:

cd /archive/gphoto2-2.4.4/gphoto2
ls -l
-rw-r--r-- 1 tom wheel  36486 Feb 10 17:08 Makefile
-rw-r--r-- 1 tom wheel   1293 Jul 26  2007 Makefile.am
-rw-r--r-- 1 tom wheel  40107 Jan 21 16:04 Makefile.in
-rw-r--r-- 1 tom wheel  42276 Oct 18 01:08 actions.c
-rw-r--r-- 1 tom wheel   3531 Jul 26  2007 actions.h
-rw-r--r-- 1 tom wheel  10234 Jul 26  2007 foreach.c
-rw-r--r-- 1 tom wheel   1310 Jul 26  2007 foreach.h
-rw-r--r-- 1 tom wheel    243 Jul 26  2007 globals.h
-rw-r--r-- 1 tom wheel  14596 Jul 26  2007 gp-params.c
-rw-r--r-- 1 tom wheel   2496 Jul 26  2007 gp-params.h
-rw-r--r-- 1 tom wheel   5358 Jul 26  2007 gphoto2-cmd-capture.c
-rw-r--r-- 1 tom wheel   1149 Jul 26  2007 gphoto2-cmd-capture.h
-rw-r--r-- 1 tom wheel  14697 Jul 26  2007 gphoto2-cmd-config.c
-rw-r--r-- 1 tom wheel   1110 Jul 26  2007 gphoto2-cmd-config.h
-rw-r--r-- 1 tom wheel   1547 Jul 26  2007 i18n.h
-rw-r--r-- 1 tom wheel  57622 Dec  4 01:19 main.c
-rw-r--r-- 1 tom wheel   1665 Jun 22  2008 main.h
-rw-r--r-- 1 tom wheel   6462 Jul 26  2007 range.c
-rw-r--r-- 1 tom wheel   1082 Jul 26  2007 range.h
-rw-r--r-- 1 tom wheel  23184 Jun 22  2008 shell.c
-rw-r--r-- 1 tom wheel   1035 Jul 26  2007 shell.h
-rw-r--r-- 1 tom wheel   3589 Jul 26  2007 spawntest.c
-rw-r--r-- 1 tom wheel   2428 Jul 26  2007 spawnve.c
-rw-r--r-- 1 tom wheel   1087 Jul 26  2007 spawnve.h
-rwxr-xr-x 1 tom wheel   1229 Jul 26  2007 test-hook.sh
-rw-r--r-- 1 tom wheel   2697 Mar 28  2008 version.c
-rw-r--r-- 1 tom wheel   1183 Jul 26  2007 version.h
The two big files are actions.c and main.c. All of the popt action happens in main.c and this file holds the loop around poptGetNextOpt.

As a concrete example, consider:

gphoto2 --summary
This is handled by the popt table line:
{"summary", '\0', POPT_ARG_NONE, NULL, ARG_SUMMARY,
                 N_("Show summary"), NULL},
And eventually the line:
case ARG_SUMMARY:
	params->p.r = action_camera_summary (&gp_params);
	break;
This handler (not surprisingly) is in action.c and looks like:
int
action_camera_summary (GPParams *params)
{
    CameraText text;

    CR (gp_camera_get_summary (params->camera, &text, params->context));

    printf (_("Camera summary:"));
    printf ("\n%s\n", _(text.text));

    return (GP_OK);
}
CR is a macro like so:
#define CR(result)       {int r=(result); if (r<0) return r;}
This call to gp_camera_get_summary looks like the point where we leave gphoto2 and jump into libgphoto2.
cd /archive/libgphoto2-2.4.4/libgphoto2
ls -l
-rw-r--r-- 1 tom wheel 36352 Feb 10 16:50 Makefile
-rw-r--r-- 1 tom wheel  1566 Oct 18 03:24 Makefile.am
-rw-r--r-- 1 tom wheel 36879 Jan 21 14:23 Makefile.in
-rw-r--r-- 1 tom wheel    76 Feb 10 16:50 _stdint.h
-rw-r--r-- 1 tom wheel 20882 Oct 18 03:29 ahd_bayer.c
-rw-r--r-- 1 tom wheel  9982 Jul 26  2007 bayer.c
-rw-r--r-- 1 tom wheel  2550 Oct 18 03:25 bayer.h
-rw-r--r-- 1 tom wheel 18535 Jul 26  2007 exif.c
-rw-r--r-- 1 tom wheel  6739 Jul 26  2007 exif.h
-rw-r--r-- 1 tom wheel  2324 Jul 26  2007 gamma.c
-rw-r--r-- 1 tom wheel  1082 Jul 26  2007 gamma.h
-rw-r--r-- 1 tom wheel 17536 Mar 31  2008 gphoto2-abilities-list.c
-rw-r--r-- 1 tom wheel 38740 Jul 26  2007 gphoto2-camera.c
-rw-r--r-- 1 tom wheel  8918 Jul 26  2007 gphoto2-context.c
-rw-r--r-- 1 tom wheel  4610 Feb 10 16:50 gphoto2-endian.h
-rw-r--r-- 1 tom wheel 24127 Jul 26  2007 gphoto2-file.c
-rw-r--r-- 1 tom wheel 70166 Jan 19 15:09 gphoto2-filesys.c
-rw-r--r-- 1 tom wheel  2998 Jul 26  2007 gphoto2-library.c
-rw-r--r-- 1 tom wheel 11357 Jul 26  2007 gphoto2-list.c
-rw-r--r-- 1 tom wheel  2785 Jul 26  2007 gphoto2-result.c
-rw-r--r-- 1 tom wheel  6650 Jul 26  2007 gphoto2-setting.c
-rw-r--r-- 1 tom wheel  1914 Jul 26  2007 gphoto2-version.c
-rw-r--r-- 1 tom wheel 17262 Jul 26  2007 gphoto2-widget.c
-rw-r--r-- 1 tom wheel 12814 Jul 26  2007 jpeg.c
-rw-r--r-- 1 tom wheel  2868 Jul 26  2007 jpeg.h
In particular, the function gp_camera_get_summary is in gphoto2-camera.c.

This will (if needed, and it certainly is the first time through) call the function gp_camera_init, which will load a bunch of function pointers, including one called camera->functions->summary if such a thing is possible for the camera that was found and initialized.

gp_camera_init

This routine (in gphoto2-camera.c) is where things get interesting. After poking around and finding a camera, this routine will try to load the support library for it (via lt_dlopenext). Given that works, it will call that camera libraries init_func in that specific camera support library to initialize the set of function pointers (including the pointer to the summary function) in the camera structure.

The Canon camera support library

cd /archive/libgphoto2-2.4.4/camlibs/canon
ls -l
-rw-r--r-- 1 tom wheel  39443 Oct  4 11:20 ChangeLog
-rw-r--r-- 1 tom wheel    954 Oct 19 05:06 Makefile-files
-rw-r--r-- 1 tom wheel  10252 Jul 13  2008 README.canon
-rw-r--r-- 1 tom wheel   3496 Jul 26  2007 TODO
-rw-r--r-- 1 tom wheel 158516 Jan 18 10:03 canon.c
-rw-r--r-- 1 tom wheel  22016 Jun 22  2008 canon.h
-rw-r--r-- 1 tom wheel  12627 Jun 22  2008 crc.c
-rw-r--r-- 1 tom wheel    188 Jun 22  2008 crc.h
drwxr-xr-x 2 tom wheel   4096 Feb 10 16:50 doc
-rw-r--r-- 1 tom wheel  69918 Oct 18 03:01 library.c
-rw-r--r-- 1 tom wheel   1143 Jun 22  2008 library.h
-rw-r--r-- 1 tom wheel  41914 Jun 22  2008 serial.c
-rw-r--r-- 1 tom wheel   8129 Jun 22  2008 serial.h
-rwxr-xr-x 1 tom wheel  21468 Jul 26  2007 urb-interpret
-rw-r--r-- 1 tom wheel 108456 Aug  8  2008 usb.c
-rw-r--r-- 1 tom wheel  12948 Jun 22  2008 usb.h
-rw-r--r-- 1 tom wheel   5652 Jun 22  2008 util.c
-rw-r--r-- 1 tom wheel   1140 Jun 22  2008 util.h
The functions camera_init and camera_summary are in library.c
Feedback? Questions? Drop me a line!

Tom's Digital Photography Info / tom@mmto.org