libgphoto2 photo camera library (libgphoto2) API 2.5.30

template.c File Reference

Documented source code template for a camera driver (camlib). More...

`#include "config.h"`
`#include <string.h>`
`#include <gphoto2/gphoto2-library.h>`
`#include <gphoto2/gphoto2-result.h>`
`#include "libgphoto2/i18n.h"`
Include dependency graph for template.c:

## Functions
Camera object member functions
The prototypes for these functions are defined in gphoto2-camera.h
int | camera_exit (Camera *camera, GPContext *context)
int | camera_config_get (Camera *camera, CameraWidget **window, GPContext *context)
int | camera_config_set (Camera *camera, CameraWidget *window, GPContext *context)
int | camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
int | camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path, GPContext *context)
int | camera_summary (Camera *camera, CameraText *summary, GPContext *context)
int | camera_manual (Camera *camera, CameraText *manual, GPContext *context)
int | camera_about (Camera *camera, CameraText *about, GPContext *context)
CameraFilesystem member functions
int | get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileType type, CameraFile *file, void *data, GPContext *context)
int | put_file_func (CameraFilesystem *fs, const char *folder, const char *name, CameraFileType type, CameraFile *file, void *data, GPContext *context)
int | delete_file_func (CameraFilesystem *fs, const char *folder, const char *filename, void *data, GPContext *context)
int | delete_all_func (CameraFilesystem *fs, const char *folder, void *data, GPContext *context)
int | get_info_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileInfo *info, void *data, GPContext *context)
int | set_info_func (CameraFilesystem *fs, const char *folder, const char *file, CameraFileInfo info, void *data, GPContext *context)
int | folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context)
int | file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context)
int | storage_info_func (CameraFilesystem *fs, CameraStorageInformation **storageinformations, int *nrofstorageinformations, void *data, GPContext *context)

## camlib API functions
CameraFilesystemFuncs | fsfuncs
int | camera_id (CameraText *id)
| Get a unique camera id.
int | camera_abilities (CameraAbilitiesList *list)
| Get a list of abilities of all supported cameras.
int | camera_init (Camera *camera, GPContext *context)

## Detailed Description

Documented source code template for a camera driver (camlib).

Author
  Copyright 2001 Lutz Mueller lutz@.nosp@m.user.nosp@m.s.sou.nosp@m.rcef.nosp@m.orge..nosp@m.net
  Copyright 2005 Hans Ulrich Niedermann gp@n-.nosp@m.dime.nosp@m.nsion.nosp@m.al.d.nosp@m.e

  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# Introduction to camera drivers (camlibs)

Every camlib must implement the following three function groups:

- Camera object member functions
- CameraFilesystem object member functions
- camlib API functions

We implement the camlib API functions last in this file because camera_init() must reference all the object member functions and by making camera_init() the last function in this file, we can avoid the need for forward declarations of the object member functions.

# Note about "static" functions and exporting symbols

The build system uses libtool to explicitly specify the list of exported symbols. Only the three functions of the camlib API (camera_init(), camera_id(), and camera_abilities()) are exported.

Therefore it doesn't matter whether you declare your other functions static or not - regardless of whether they are object member functions or internal camlib functions.

We do not define the object member functions as static in this template in order to have autogenerated documentation about them.

## Function Documentation

## ◆ camera_abilities()

int camera_abilities | ( | CameraAbilitiesList * | list | ) |

Get a list of abilities of all supported cameras.

Fill list with abilities of the cameras supported by this camlib.

For each camera, fill a CameraAbilities structure with data about that camera and append it to the list.

The job of this function is basically to extract data from a camlib specific database and insert it into the libgphoto2 camera database. Due to redundant data and other issues, we may decide to revise that database mechanism and replace it by something more flexible and efficient.

This is a camlib API function.

References CameraAbilities::file_operations, CameraAbilities::folder_operations, gp_abilities_list_append(), GP_CAPTURE_IMAGE, GP_DRIVER_STATUS_PRODUCTION, GP_FILE_OPERATION_DELETE, GP_FILE_OPERATION_PREVIEW, GP_FOLDER_OPERATION_NONE, GP_OK, GP_OPERATION_CAPTURE_PREVIEW, GP_PORT_SERIAL, GP_PORT_USB, CameraAbilities::model, CameraAbilities::operations, CameraAbilities::port, CameraAbilities::speed, and CameraAbilities::status.

## ◆ camera_about()

int camera_about | ( | Camera * | camera,
|  | CameraText * | about,
|  | GPContext * | context
| ) |  |

Return "About" content as textual description. Will be translated.

This function is a method of the Camera object.

References GP_OK, and CameraText::text.

Referenced by camera_init().

## ◆ camera_capture()

int camera_capture | ( | Camera * | camera,
|  | CameraCaptureType | type,
|  | CameraFilePath * | path,
|  | GPContext * | context
| ) |  |

Capture an image and tell libgphoto2 where to find it by filling out the path.

This function is a method of the Camera object.

References GP_OK.

Referenced by camera_init().

## ◆ camera_capture_preview()

int camera_capture_preview | ( | Camera * | camera,
|  | CameraFile * | file,
|  | GPContext * | context
| ) |  |

Capture a preview and return the data in the given file (again, use gp_file_set_data_and_size, gp_file_set_mime_type, etc.). libgphoto2 assumes that previews are NOT stored on the camera's disk. If your camera does, please delete it from the camera.

This function is a method of the Camera object.

References GP_OK.

Referenced by camera_init().

## ◆ camera_config_get()

int camera_config_get | ( | Camera * | camera,
|  | CameraWidget ** | window,
|  | GPContext * | context
| ) |  |

Get the full configuration tree of the camera.

This function is a method of the Camera object.

References GP_OK, gp_widget_new(), and GP_WIDGET_WINDOW.

Referenced by camera_init().

## ◆ camera_config_set()

int camera_config_set | ( | Camera * | camera,
|  | CameraWidget * | window,
|  | GPContext * | context
| ) |  |

Set parts of the configuration tree. Note that you get back the whole tree, but should only set the modified values.

This function is a method of the Camera object.

References GP_OK.

Referenced by camera_init().

## ◆ camera_exit()

int camera_exit | ( | Camera * | camera,
|  | GPContext * | context
| ) |  |

Finish up the camera communication and free private data. You do not need to close the port.

This function is a method of the Camera object.

References GP_OK.

Referenced by camera_init().

## ◆ camera_id()

int camera_id | ( | CameraText * | id | ) |

Get a unique camera id.

Set library ID string.

Probably redundant and to be removed shortly, being replaced by the libtool module name defined in the build system.

This is a camlib API function.

References GP_OK, and CameraText::text.

## ◆ camera_init()

int camera_init | ( | Camera * | camera,
|  | GPContext * | context
| ) |  |

Initialize a Camera object.

Sets up all the proper object function pointers, initialize camlib internal data structures, and probably establish a connection to the camera.

This is a camlib API function.

References _CameraFunctions::about, camera_about(), camera_capture(), camera_capture_preview(), camera_config_get(), camera_config_set(), camera_exit(), camera_manual(), camera_summary(), _CameraFunctions::capture, _CameraFunctions::capture_preview, _CameraFunctions::exit, fsfuncs, _CameraFunctions::get_config, gp_filesystem_set_funcs(), GP_OK, _CameraFunctions::manual, _CameraFunctions::set_config, and _CameraFunctions::summary.

## ◆ camera_manual()

int camera_manual | ( | Camera * | camera,
|  | CameraText * | manual,
|  | GPContext * | context
| ) |  |

Return the camera drivers manual. If you would like to tell the user some information about how to use the camera or the driver, this is the place to do.

This function is a method of the Camera object.

References GP_OK.

Referenced by camera_init().

## ◆ camera_summary()

int camera_summary | ( | Camera * | camera,
|  | CameraText * | summary,
|  | GPContext * | context
| ) |  |

Fill out the summary with textual information about the current state of the camera (like pictures taken, etc.).

This function is a method of the Camera object.

References GP_OK.

Referenced by camera_init().

## ◆ delete_all_func()

int delete_all_func | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | void * | data,
|  | GPContext * | context
| ) |  |

Delete all files from the camera.

This function is a CameraFilesystem method.

References GP_OK.

## ◆ delete_file_func()

int delete_file_func | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | filename,
|  | void * | data,
|  | GPContext * | context
| ) |  |

Delete a file from the camera.

This function is a CameraFilesystem method.

References GP_OK.

## ◆ file_list_func()

int file_list_func | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | CameraList * | list,
|  | void * | data,
|  | GPContext * | context
| ) |  |

List available files in the specified folder.

This function is a CameraFilesystem method.

References GP_OK.

## ◆ folder_list_func()

int folder_list_func | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | CameraList * | list,
|  | void * | data,
|  | GPContext * | context
| ) |  |

List available folders in the specified folder.

This function is a CameraFilesystem method.

References GP_OK.

## ◆ get_file_func()

int get_file_func | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | filename,
|  | CameraFileType | type,
|  | CameraFile * | file,
|  | void * | data,
|  | GPContext * | context
| ) |  |

Get the file from the camera.

This function is a CameraFilesystem method.

References GP_OK.

## ◆ get_info_func()

int get_info_func | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | filename,
|  | CameraFileInfo * | info,
|  | void * | data,
|  | GPContext * | context
| ) |  |

Get the file info here and write it to space provided by caller.

Parameters

  info | Space provided by caller in which file info is written.

This function is a CameraFilesystem method.

References GP_OK.

## ◆ put_file_func()

int put_file_func | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | name,
|  | CameraFileType | type,
|  | CameraFile * | file,
|  | void * | data,
|  | GPContext * | context
| ) |  |

Put a file onto the camera.

This function is a CameraFilesystem method.

References GP_OK.

## ◆ set_info_func()

int set_info_func | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | file,
|  | CameraFileInfo | info,
|  | void * | data,
|  | GPContext * | context
| ) |  |

FIXME.

This function is a CameraFilesystem method.

References GP_OK.

## ◆ storage_info_func()

int storage_info_func | ( | CameraFilesystem * | fs,
|  | CameraStorageInformation ** | storageinformations,
|  | int * | nrofstorageinformations,
|  | void * | data,
|  | GPContext * | context
| ) |  |

Get information on all available storages in the camera.

This function is a CameraFilesystem method.

References GP_ERROR_NOT_SUPPORTED.

## Variable Documentation

## ◆ fsfuncs

CameraFilesystemFuncs fsfuncs

Initial value:
= {
.file_list_func = file_list_func,
.folder_list_func = folder_list_func,
.get_info_func = get_info_func,
.set_info_func = set_info_func,
.get_file_func = get_file_func,
.del_file_func = delete_file_func,
.put_file_func = put_file_func,
.delete_all_func = delete_all_func,
.storage_info_func = storage_info_func
}
folder_list_func
int folder_list_func(CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context)
Definition: template.c:357
storage_info_func
int storage_info_func(CameraFilesystem *fs, CameraStorageInformation **storageinformations, int *nrofstorageinformations, void *data, GPContext *context)
Definition: template.c:398
get_info_func
int get_info_func(CameraFilesystem *fs, const char *folder, const char *filename, CameraFileInfo *info, void *data, GPContext *context)
Definition: template.c:319
put_file_func
int put_file_func(CameraFilesystem *fs, const char *folder, const char *name, CameraFileType type, CameraFile *file, void *data, GPContext *context)
Definition: template.c:252
delete_all_func
int delete_all_func(CameraFilesystem *fs, const char *folder, void *data, GPContext *context)
Definition: template.c:294
get_file_func
int get_file_func(CameraFilesystem *fs, const char *folder, const char *filename, CameraFileType type, CameraFile *file, void *data, GPContext *context)
Definition: template.c:228
file_list_func
int file_list_func(CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context)
Definition: template.c:377
set_info_func
int set_info_func(CameraFilesystem *fs, const char *folder, const char *file, CameraFileInfo info, void *data, GPContext *context)
Definition: template.c:337
delete_file_func
int delete_file_func(CameraFilesystem *fs, const char *folder, const char *filename, void *data, GPContext *context)
Definition: template.c:274

All filesystem accessor functions.

This should contain all filesystem accessor functions available in the camera library. Non-present fields are NULL.

Referenced by camera_init().