gphoto2-context.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /** \file
  2. * \brief Context callback operation functions.
  3. *
  4. * \author Copyright 2001 Lutz Mueller <lutz@users.sourceforge.net>
  5. *
  6. * \note
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * \note
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * \note
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA
  23. */
  24. #ifndef __GPHOTO2_CONTEXT_H__
  25. #define __GPHOTO2_CONTEXT_H__
  26. #include <stdarg.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif /* __cplusplus */
  30. /**
  31. * \brief The gphoto context structure.
  32. *
  33. * This structure allows callback handling, passing error contexts back,
  34. * progress handling and download cancellation and similar things.
  35. * It is usually passed around the functions.
  36. */
  37. typedef struct _GPContext GPContext;
  38. GPContext *gp_context_new (void);
  39. void gp_context_ref (GPContext *context);
  40. void gp_context_unref (GPContext *context);
  41. /**
  42. * \brief Return codes that can be returned by progress handling.
  43. *
  44. * An application can return special values back to the libgphoto2
  45. * progress callback handling functions. If "Cancel" is selected,
  46. * libgphoto2 and the camera driver will try to cancel transfer.
  47. */
  48. typedef enum _GPContextFeedback {
  49. GP_CONTEXT_FEEDBACK_OK, /**< Everything ok... proceed. */
  50. GP_CONTEXT_FEEDBACK_CANCEL /**< Please cancel the current transfer if possible. */
  51. } GPContextFeedback;
  52. /* Functions */
  53. typedef void (* GPContextIdleFunc) (GPContext *context, void *data);
  54. typedef void (* GPContextErrorFunc) (GPContext *context, const char *text, void *data);
  55. typedef void (* GPContextStatusFunc) (GPContext *context, const char *text, void *data);
  56. typedef void (* GPContextMessageFunc) (GPContext *context, const char *text, void *data);
  57. typedef GPContextFeedback (* GPContextQuestionFunc) (GPContext *context,
  58. const char *text, void *data);
  59. typedef GPContextFeedback (* GPContextCancelFunc) (GPContext *context,
  60. void *data);
  61. typedef unsigned int (* GPContextProgressStartFunc) (GPContext *context,
  62. float target,
  63. const char *text,
  64. void *data);
  65. typedef void (* GPContextProgressUpdateFunc) (GPContext *context,
  66. unsigned int id,
  67. float current,
  68. void *data);
  69. typedef void (* GPContextProgressStopFunc) (GPContext *context,
  70. unsigned int id,
  71. void *data);
  72. /* Setting those functions (frontends) */
  73. void gp_context_set_idle_func (GPContext *context,
  74. GPContextIdleFunc func, void *data);
  75. void gp_context_set_progress_funcs (GPContext *context,
  76. GPContextProgressStartFunc start_func,
  77. GPContextProgressUpdateFunc update_func,
  78. GPContextProgressStopFunc stop_func,
  79. void *data);
  80. void gp_context_set_error_func (GPContext *context,
  81. GPContextErrorFunc func, void *data);
  82. void gp_context_set_status_func (GPContext *context,
  83. GPContextStatusFunc func, void *data);
  84. void gp_context_set_question_func (GPContext *context,
  85. GPContextQuestionFunc func, void *data);
  86. void gp_context_set_cancel_func (GPContext *context,
  87. GPContextCancelFunc func, void *data);
  88. void gp_context_set_message_func (GPContext *context,
  89. GPContextMessageFunc func, void *data);
  90. /* Calling those functions (backends) */
  91. void gp_context_idle (GPContext *context);
  92. void gp_context_error (GPContext *context, const char *format, ...)
  93. #ifdef __GNUC__
  94. __attribute__((__format__(printf,2,3)))
  95. #endif
  96. ;
  97. void gp_context_status (GPContext *context, const char *format, ...)
  98. #ifdef __GNUC__
  99. __attribute__((__format__(printf,2,3)))
  100. #endif
  101. ;
  102. void gp_context_message (GPContext *context, const char *format, ...)
  103. #ifdef __GNUC__
  104. __attribute__((__format__(printf,2,3)))
  105. #endif
  106. ;
  107. GPContextFeedback gp_context_question (GPContext *context, const char *format,
  108. ...)
  109. #ifdef __GNUC__
  110. __attribute__((__format__(printf,2,3)))
  111. #endif
  112. ;
  113. GPContextFeedback gp_context_cancel (GPContext *context);
  114. unsigned int gp_context_progress_start (GPContext *context, float target,
  115. const char *format, ...)
  116. #ifdef __GNUC__
  117. __attribute__((__format__(printf,3,4)))
  118. #endif
  119. ;
  120. void gp_context_progress_update (GPContext *context, unsigned int id,
  121. float current);
  122. void gp_context_progress_stop (GPContext *context, unsigned int id);
  123. #ifdef __cplusplus
  124. }
  125. #endif /* __cplusplus */
  126. #endif /* __GPHOTO2_CONTEXT_H__ */