gphoto2-camera.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /** \file
  2. *
  3. * \brief Implement Camera object representing a camera attached to the system.
  4. *
  5. * \author Copyright 2000 Scott Fritzinger
  6. *
  7. * \note
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * \note
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * \note
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the
  22. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301 USA
  24. */
  25. #ifndef __GPHOTO2_CAMERA_H__
  26. #define __GPHOTO2_CAMERA_H__
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif /* __cplusplus */
  30. /**
  31. * \brief Object representing a camera attached to the system.
  32. *
  33. * A Camera object represents a specific instance of a (physical of
  34. * virtual) camera attached to the system.
  35. *
  36. * The abilities of this type of camera are stored in a CameraAbility
  37. * object.
  38. *
  39. * The details of the Camera object are internal.
  40. */
  41. typedef struct _Camera Camera;
  42. #ifdef __cplusplus
  43. }
  44. #endif /* __cplusplus */
  45. #include <gphoto2/gphoto2-abilities-list.h>
  46. #include <gphoto2/gphoto2-port.h>
  47. #include <gphoto2/gphoto2-widget.h>
  48. #include <gphoto2/gphoto2-filesys.h>
  49. #include <gphoto2/gphoto2-result.h>
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif /* __cplusplus */
  53. /**
  54. * \brief CameraText structure used in various functions.
  55. *
  56. * A text structure containing translated text returned
  57. * by various functions (about, manual, summary). You should
  58. * not assume a size.
  59. */
  60. typedef struct {
  61. char text [32 * 1024]; /**< \brief Character string containing the translated text. */
  62. } CameraText;
  63. /**
  64. * \brief A structure created by the capture operation.
  65. *
  66. * A structure containing the folder and filename of an object
  67. * after a successful capture and is passed as reference to the
  68. * gp_camera_capture() function.
  69. */
  70. typedef struct {
  71. char name [128]; /**< \brief Name of the captured file. */
  72. char folder [1024]; /**< \brief Name of the folder of the captured file. */
  73. } CameraFilePath;
  74. /**
  75. * \brief Type of the capture to do.
  76. *
  77. * Specifies the type of capture the user wants to do with the
  78. * gp_camera_capture() function.
  79. */
  80. typedef enum {
  81. GP_CAPTURE_IMAGE, /**< \brief Capture an image. */
  82. GP_CAPTURE_MOVIE, /**< \brief Capture a movie. */
  83. GP_CAPTURE_SOUND /**< \brief Capture audio. */
  84. } CameraCaptureType;
  85. /**
  86. * \brief Specify what event we received from the camera.
  87. *
  88. * Used by gp_camera_wait_for_event() to specify what
  89. * event happened on the camera.
  90. * This functionality is still in development and might change.
  91. *
  92. */
  93. typedef enum {
  94. GP_EVENT_UNKNOWN, /**< unknown and unhandled event */
  95. GP_EVENT_TIMEOUT, /**< timeout, no arguments */
  96. GP_EVENT_FILE_ADDED, /**< CameraFilePath* = file path on camfs */
  97. GP_EVENT_FOLDER_ADDED, /**< CameraFilePath* = folder on camfs */
  98. GP_EVENT_CAPTURE_COMPLETE /**< last capture is complete */
  99. } CameraEventType;
  100. /**
  101. * \name Camera object member functions
  102. *
  103. * These functions must be implemented by a camlib and the camlib's
  104. * camera_init() function will add them to a Camera object.
  105. *
  106. * @{
  107. */
  108. /**
  109. * \brief The camera exit function
  110. *
  111. * \param camera the current camera
  112. * \param context a #GPContext
  113. *
  114. * This functions is called in the camera driver for closing the camera
  115. * connection. It should do the necessary cleanups of the internal camera
  116. * state, free allocated private structures and similar.
  117. *
  118. * The driver does not need to close the #GPPort, this is done by libgphoto2
  119. * itself.
  120. *
  121. * Implement this function if you need to any of this stuff, otherwise leave
  122. * it out.
  123. *
  124. * \returns a gphoto error code
  125. */
  126. typedef int (*CameraExitFunc) (Camera *camera, GPContext *context);
  127. /**
  128. * \brief Get a configuration tree for the camera and its driver
  129. *
  130. * \param camera the current camera
  131. * \param widget pointer to store the toplevel widget of the tree
  132. * \param context the active #GPContext
  133. *
  134. * A camera driver can support configuration of either its own behaviour
  135. * or the camera device itself. To allow a flexible driver framework,
  136. * the camera driver provides a generic configuration widget tree to the
  137. * frontend, which then renders it, allows user input and sends it back
  138. * via the #CameraSetConfigFunc function to have the driver configure itself
  139. * or the camera.
  140. *
  141. * If you do not have configuration ability, there is no need to specify this
  142. * function.
  143. *
  144. * \returns a gphoto error code
  145. */
  146. typedef int (*CameraGetConfigFunc) (Camera *camera, CameraWidget **widget,
  147. GPContext *context);
  148. /**
  149. * \brief Set the configuration in the camera
  150. *
  151. * \param camera the current camera
  152. * \param widget the configuration widget tree that was changed
  153. * \param context the active #GPContext
  154. *
  155. * This function is called in the driver after the configuration is set.
  156. * It is called directly after setting the value and might called multiple
  157. * times (or never) after just one #CameraGetConfigFunc.
  158. *
  159. * \returns a gphoto error code
  160. */
  161. typedef int (*CameraSetConfigFunc) (Camera *camera, CameraWidget *widget,
  162. GPContext *context);
  163. typedef int (*CameraCaptureFunc) (Camera *camera, CameraCaptureType type,
  164. CameraFilePath *path, GPContext *context);
  165. typedef int (*CameraTriggerCaptureFunc) (Camera *camera, GPContext *context);
  166. typedef int (*CameraCapturePreviewFunc) (Camera *camera, CameraFile *file,
  167. GPContext *context);
  168. typedef int (*CameraSummaryFunc) (Camera *camera, CameraText *text,
  169. GPContext *context);
  170. typedef int (*CameraManualFunc) (Camera *camera, CameraText *text,
  171. GPContext *context);
  172. typedef int (*CameraAboutFunc) (Camera *camera, CameraText *text,
  173. GPContext *context);
  174. typedef int (*CameraWaitForEvent) (Camera *camera, int timeout,
  175. CameraEventType *eventtype, void **eventdata,
  176. GPContext *context);
  177. /**@}*/
  178. /**
  179. * \param camera a \ref Camera object
  180. * \param context a \ref GPContext object
  181. * \return a gphoto2 error code
  182. *
  183. * Implement this function in the camera driver if the camera needs to
  184. * be initialized before or reset the after each access from
  185. * libgphoto2.
  186. *
  187. * For example, you would probably set the speed to the highest one
  188. * right before downloading an image, and reset it to the default speed
  189. * afterwards so that other programs will not be affected by this speed
  190. * change.
  191. */
  192. typedef int (*CameraPrePostFunc) (Camera *camera, GPContext *context);
  193. /**
  194. * \brief Various camera specific functions.
  195. *
  196. * This structure contains various pointers to functions that apply to
  197. * the camera itself, and not the filesystem (which is handled by the
  198. * filesystem functions). Set the ones you want to provide, leave the rest
  199. * unset.
  200. *
  201. * This structure should only used by the driver itself, the frontend
  202. * should use the gp_camera_xxx wrapper functions for it, who handle
  203. * opening and locking around those hooks.
  204. */
  205. typedef struct _CameraFunctions {
  206. CameraPrePostFunc pre_func; /**< \brief Function called before each camera operation. */
  207. CameraPrePostFunc post_func; /**< \brief Function called after each camera operation. */
  208. CameraExitFunc exit; /**< \brief Function called on closing the camera. */
  209. /* Configuration */
  210. CameraGetConfigFunc get_config; /**< \brief Called for requesting the configuration widgets. */
  211. CameraSetConfigFunc set_config; /**< \brief Called after a configuration was changed */
  212. /* Capturing */
  213. CameraCaptureFunc capture; /**< \brief Remote control the camera to capture */
  214. CameraTriggerCaptureFunc trigger_capture;/**< \brief Remote control the camera to trigger capture */
  215. CameraCapturePreviewFunc capture_preview;/**< \brief Preview viewfinder content. */
  216. /* Textual information */
  217. CameraSummaryFunc summary; /**< \brief Give a summary about the current camera status, translated. */
  218. CameraManualFunc manual; /**< \brief Give a brief manual about any specific items a user has to know, translated. */
  219. CameraAboutFunc about; /**< \brief A little About text, including authors and credits. */
  220. /* Event Interface */
  221. CameraWaitForEvent wait_for_event; /**< \brief Wait for a specific event from the camera */
  222. /* Reserved space to use in the future without changing the struct size */
  223. void *reserved1; /**< \brief reserved for future use */
  224. void *reserved2; /**< \brief reserved for future use */
  225. void *reserved3; /**< \brief reserved for future use */
  226. void *reserved4; /**< \brief reserved for future use */
  227. void *reserved5; /**< \brief reserved for future use */
  228. void *reserved6; /**< \brief reserved for future use */
  229. void *reserved7; /**< \brief reserved for future use */
  230. void *reserved8; /**< \brief reserved for future use */
  231. } CameraFunctions;
  232. typedef struct _CameraPrivateLibrary CameraPrivateLibrary;
  233. typedef struct _CameraPrivateCore CameraPrivateCore;
  234. struct _Camera {
  235. /** \name Those should be accessed only by the camera driver.
  236. * @{ */
  237. GPPort *port;
  238. CameraFilesystem *fs;
  239. CameraFunctions *functions;
  240. /**@}*/
  241. CameraPrivateLibrary *pl; /**< Private data of camera libraries. */
  242. CameraPrivateCore *pc; /**< Private data of the core of gphoto2. */
  243. };
  244. /** Create a new camera device. */
  245. int gp_camera_new (Camera **camera);
  246. /** \name Preparing initialization
  247. * @{
  248. */
  249. int gp_camera_set_abilities (Camera *camera, CameraAbilities abilities);
  250. int gp_camera_get_abilities (Camera *camera, CameraAbilities *abilities);
  251. int gp_camera_set_port_info (Camera *camera, GPPortInfo info);
  252. int gp_camera_get_port_info (Camera *camera, GPPortInfo *info);
  253. /**@}*/
  254. /**
  255. * \name camera speed
  256. *
  257. * You normally don't use that. If you do, you prevent the camera driver
  258. * from selecting the optimal speed.
  259. *
  260. * @{
  261. */
  262. int gp_camera_set_port_speed (Camera *camera, int speed);
  263. int gp_camera_get_port_speed (Camera *camera);
  264. /**@}*/
  265. /** \name Initialization
  266. * @{
  267. */
  268. int gp_camera_autodetect (CameraList *list, GPContext *context);
  269. int gp_camera_init (Camera *camera, GPContext *context);
  270. int gp_camera_exit (Camera *camera, GPContext *context);
  271. /**@}*/
  272. /** \name Operations on cameras
  273. * @{
  274. */
  275. int gp_camera_ref (Camera *camera);
  276. int gp_camera_unref (Camera *camera);
  277. int gp_camera_free (Camera *camera);
  278. int gp_camera_get_config (Camera *camera, CameraWidget **window,
  279. GPContext *context);
  280. int gp_camera_set_config (Camera *camera, CameraWidget *window,
  281. GPContext *context);
  282. int gp_camera_get_summary (Camera *camera, CameraText *summary,
  283. GPContext *context);
  284. int gp_camera_get_manual (Camera *camera, CameraText *manual,
  285. GPContext *context);
  286. int gp_camera_get_about (Camera *camera, CameraText *about,
  287. GPContext *context);
  288. int gp_camera_capture (Camera *camera, CameraCaptureType type,
  289. CameraFilePath *path, GPContext *context);
  290. int gp_camera_trigger_capture (Camera *camera, GPContext *context);
  291. int gp_camera_capture_preview (Camera *camera, CameraFile *file,
  292. GPContext *context);
  293. int gp_camera_wait_for_event (Camera *camera, int timeout,
  294. CameraEventType *eventtype, void **eventdata,
  295. GPContext *context);
  296. int gp_camera_get_storageinfo (Camera *camera, CameraStorageInformation**,
  297. int *, GPContext *context);
  298. /**@}*/
  299. /** \name Operations on folders
  300. * @{
  301. */
  302. int gp_camera_folder_list_files (Camera *camera, const char *folder,
  303. CameraList *list, GPContext *context);
  304. int gp_camera_folder_list_folders (Camera *camera, const char *folder,
  305. CameraList *list, GPContext *context);
  306. int gp_camera_folder_delete_all (Camera *camera, const char *folder,
  307. GPContext *context);
  308. int gp_camera_folder_put_file (Camera *camera,
  309. const char *folder, const char *filename,
  310. CameraFileType type,
  311. CameraFile *file, GPContext *context);
  312. int gp_camera_folder_make_dir (Camera *camera, const char *folder,
  313. const char *name, GPContext *context);
  314. int gp_camera_folder_remove_dir (Camera *camera, const char *folder,
  315. const char *name, GPContext *context);
  316. /**@}*/
  317. /** \name Operations on files
  318. * @{
  319. */
  320. int gp_camera_file_get_info (Camera *camera, const char *folder,
  321. const char *file, CameraFileInfo *info,
  322. GPContext *context);
  323. int gp_camera_file_set_info (Camera *camera, const char *folder,
  324. const char *file, CameraFileInfo info,
  325. GPContext *context);
  326. int gp_camera_file_get (Camera *camera, const char *folder,
  327. const char *file, CameraFileType type,
  328. CameraFile *camera_file, GPContext *context);
  329. int gp_camera_file_read (Camera *camera, const char *folder, const char *file,
  330. CameraFileType type,
  331. uint64_t offset, char *buf, uint64_t *size,
  332. GPContext *context);
  333. int gp_camera_file_delete (Camera *camera, const char *folder,
  334. const char *file, GPContext *context);
  335. /**@}*/
  336. /**
  337. * \name Some cameras need 'keep-alive-messages'.
  338. * @{
  339. */
  340. typedef int (* CameraTimeoutFunc) (Camera *camera,
  341. GPContext *context);
  342. typedef unsigned int (* CameraTimeoutStartFunc) (Camera *camera,
  343. unsigned int timeout,
  344. CameraTimeoutFunc func,
  345. void *data);
  346. typedef void (* CameraTimeoutStopFunc) (Camera *camera,
  347. unsigned int id, void *data);
  348. void gp_camera_set_timeout_funcs (Camera *camera,
  349. CameraTimeoutStartFunc start_func,
  350. CameraTimeoutStopFunc stop_func,
  351. void *data);
  352. int gp_camera_start_timeout (Camera *camera, unsigned int timeout,
  353. CameraTimeoutFunc func);
  354. void gp_camera_stop_timeout (Camera *camera, unsigned int id);
  355. /**@}*/
  356. #ifdef __cplusplus
  357. }
  358. #endif /* __cplusplus */
  359. #endif /* __GPHOTO2_CAMERA_H__ */