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 
25 #ifndef __GPHOTO2_CONTEXT_H__
26 #define __GPHOTO2_CONTEXT_H__
27 
28 #include <stdarg.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33 
34 /**
35  * \brief The gphoto context structure.
36  *
37  * This structure allows callback handling, passing error contexts back,
38  * progress handling and download cancellation and similar things.
39  * It is usually passed around the functions.
40  */
41 typedef struct _GPContext GPContext;
42 
43 GPContext *gp_context_new (void);
44 
45 void gp_context_ref   (GPContext *context);
46 void gp_context_unref (GPContext *context);
47 
48 /**
49  * \brief Return codes that can be returned by progress handling.
50  *
51  * An application can return special values back to the libgphoto2
52  * progress callback handling functions. If "Cancel" is selected,
53  * libgphoto2 and the camera driver will try to cancel transfer.
54  */
55 typedef enum _GPContextFeedback {
56 	GP_CONTEXT_FEEDBACK_OK,		/**< Everything ok... proceed. */
57 	GP_CONTEXT_FEEDBACK_CANCEL	/**< Please cancel the current transfer if possible. */
58 } GPContextFeedback;
59 
60 /* Functions */
61 typedef void (* GPContextIdleFunc)     (GPContext *context, void *data);
62 typedef void (* GPContextErrorFunc)    (GPContext *context, const char *text, void *data);
63 typedef void (* GPContextStatusFunc)   (GPContext *context, const char *text, void *data);
64 typedef void (* GPContextMessageFunc)  (GPContext *context, const char *text, void *data);
65 typedef GPContextFeedback (* GPContextQuestionFunc) (GPContext *context,
66 						     const char *text, void *data);
67 typedef GPContextFeedback (* GPContextCancelFunc)   (GPContext *context,
68 						     void *data);
69 typedef unsigned int (* GPContextProgressStartFunc)  (GPContext *context,
70 						      float target,
71 						      const char *text,
72 						      void *data);
73 typedef void         (* GPContextProgressUpdateFunc) (GPContext *context,
74 						      unsigned int id,
75 						      float current,
76 						      void *data);
77 typedef void         (* GPContextProgressStopFunc)   (GPContext *context,
78 						      unsigned int id,
79 						      void *data);
80 
81 /* Setting those functions (frontends) */
82 void gp_context_set_idle_func      (GPContext *context,
83 			            GPContextIdleFunc func,     void *data);
84 void gp_context_set_progress_funcs (GPContext *context,
85 				    GPContextProgressStartFunc  start_func,
86 				    GPContextProgressUpdateFunc update_func,
87 				    GPContextProgressStopFunc   stop_func,
88 				    void *data);
89 void gp_context_set_error_func     (GPContext *context,
90 				    GPContextErrorFunc func,    void *data);
91 void gp_context_set_status_func    (GPContext *context,
92 				    GPContextStatusFunc func,   void *data);
93 void gp_context_set_question_func  (GPContext *context,
94 				    GPContextQuestionFunc func, void *data);
95 void gp_context_set_cancel_func    (GPContext *context,
96 				    GPContextCancelFunc func,   void *data);
97 void gp_context_set_message_func   (GPContext *context,
98 				    GPContextMessageFunc func,  void *data);
99 
100 /* Calling those functions (backends) */
101 void gp_context_idle     (GPContext *context);
102 void gp_context_error    (GPContext *context, const char *format, ...)
103 #ifdef __GNUC__
104 	__attribute__((__format__(printf,2,3)))
105 #endif
106 ;
107 void gp_context_status   (GPContext *context, const char *format, ...)
108 #ifdef __GNUC__
109 	__attribute__((__format__(printf,2,3)))
110 #endif
111 ;
112 void gp_context_message  (GPContext *context, const char *format, ...)
113 #ifdef __GNUC__
114 	__attribute__((__format__(printf,2,3)))
115 #endif
116 ;
117 GPContextFeedback gp_context_question (GPContext *context, const char *format,
118 				       ...)
119 #ifdef __GNUC__
120 	__attribute__((__format__(printf,2,3)))
121 #endif
122 ;
123 GPContextFeedback gp_context_cancel   (GPContext *context);
124 unsigned int gp_context_progress_start  (GPContext *context, float target,
125 					 const char *format, ...)
126 #ifdef __GNUC__
127 	__attribute__((__format__(printf,3,4)))
128 #endif
129 ;
130 void         gp_context_progress_update (GPContext *context, unsigned int id,
131 					 float current);
132 void         gp_context_progress_stop   (GPContext *context, unsigned int id);
133 
134 #ifdef __cplusplus
135 }
136 #endif /* __cplusplus */
137 
138 #endif /* __GPHOTO2_CONTEXT_H__ */
139