1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /*
3  * Libbrasero-burn
4  * Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
5  *
6  * Libbrasero-burn is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * The Libbrasero-burn authors hereby grant permission for non-GPL compatible
12  * GStreamer plugins to be used and distributed together with GStreamer
13  * and Libbrasero-burn. This permission is above and beyond the permissions granted
14  * by the GPL license by which Libbrasero-burn is covered. If you modify this code
15  * you may extend this exception to your version of the code, but you are not
16  * obligated to do so. If you do not wish to do so, delete this exception
17  * statement from your version.
18  *
19  * Libbrasero-burn is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU Library General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to:
26  * 	The Free Software Foundation, Inc.,
27  * 	51 Franklin Street, Fifth Floor
28  * 	Boston, MA  02110-1301, USA.
29  */
30 
31 #ifndef JOB_H
32 #define JOB_H
33 
34 #include <glib.h>
35 #include <glib-object.h>
36 
37 #include "brasero-track.h"
38 
39 G_BEGIN_DECLS
40 
41 #define BRASERO_TYPE_JOB         (brasero_job_get_type ())
42 #define BRASERO_JOB(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), BRASERO_TYPE_JOB, BraseroJob))
43 #define BRASERO_JOB_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), BRASERO_TYPE_JOB, BraseroJobClass))
44 #define BRASERO_IS_JOB(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), BRASERO_TYPE_JOB))
45 #define BRASERO_IS_JOB_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), BRASERO_TYPE_JOB))
46 #define BRASERO_JOB_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), BRASERO_TYPE_JOB, BraseroJobClass))
47 
48 typedef enum {
49 	BRASERO_JOB_ACTION_NONE		= 0,
50 	BRASERO_JOB_ACTION_SIZE,
51 	BRASERO_JOB_ACTION_IMAGE,
52 	BRASERO_JOB_ACTION_RECORD,
53 	BRASERO_JOB_ACTION_ERASE,
54 	BRASERO_JOB_ACTION_CHECKSUM
55 } BraseroJobAction;
56 
57 typedef struct {
58 	GObject parent;
59 } BraseroJob;
60 
61 typedef struct {
62 	GObjectClass parent_class;
63 
64 	/**
65 	 * Virtual functions to implement in each object deriving from
66 	 * BraseroJob.
67 	 */
68 
69 	/**
70 	 * This function is not compulsory. If not implemented then the library
71 	 * will act as if OK had been returned.
72 	 * returns 	BRASERO_BURN_OK on successful initialization
73 	 *		The job can return BRASERO_BURN_NOT_RUNNING if it should
74 	 *		not be started.
75 	 * 		BRASERO_BURN_ERR otherwise
76 	 */
77 	BraseroBurnResult	(*activate)		(BraseroJob *job,
78 							 GError **error);
79 
80 	/**
81 	 * This function is compulsory.
82 	 * returns 	BRASERO_BURN_OK if a loop should be run afterward
83 	 *		The job can return BRASERO_BURN_NOT_RUNNING if it already
84 	 *		completed successfully the task or don't need to be run. In this
85 	 *		case, it's the whole task that will be skipped.
86 	 *		NOT_SUPPORTED if it can't do the action required. When running
87 	 *		in fake mode (to get size mostly), the job will be "forgiven" and
88 	 *		deactivated.
89 	 *		RETRY if the job is not able to start at the moment but should
90 	 *		be given another chance later.
91 	 * 		ERR otherwise
92 	 */
93 	BraseroBurnResult	(*start)		(BraseroJob *job,
94 							 GError **error);
95 
96 	BraseroBurnResult	(*clock_tick)		(BraseroJob *job);
97 
98 	BraseroBurnResult	(*stop)			(BraseroJob *job,
99 							 GError **error);
100 
101 	/**
102 	 * you should not connect to this signal. It's used internally to
103 	 * "autoconfigure" the backend when an error occurs
104 	 */
105 	BraseroBurnResult	(*error)		(BraseroJob *job,
106 							 BraseroBurnError error);
107 } BraseroJobClass;
108 
109 GType brasero_job_get_type (void);
110 
111 /**
112  * These functions are to be used to get information for running jobs.
113  * They are only available when a job is running.
114  */
115 
116 BraseroBurnResult
117 brasero_job_set_nonblocking (BraseroJob *self,
118 			     GError **error);
119 
120 BraseroBurnResult
121 brasero_job_get_action (BraseroJob *job, BraseroJobAction *action);
122 
123 BraseroBurnResult
124 brasero_job_get_flags (BraseroJob *job, BraseroBurnFlag *flags);
125 
126 BraseroBurnResult
127 brasero_job_get_fd_in (BraseroJob *job, int *fd_in);
128 
129 BraseroBurnResult
130 brasero_job_get_tracks (BraseroJob *job, GSList **tracks);
131 
132 BraseroBurnResult
133 brasero_job_get_done_tracks (BraseroJob *job, GSList **tracks);
134 
135 BraseroBurnResult
136 brasero_job_get_current_track (BraseroJob *job, BraseroTrack **track);
137 
138 BraseroBurnResult
139 brasero_job_get_input_type (BraseroJob *job, BraseroTrackType *type);
140 
141 BraseroBurnResult
142 brasero_job_get_audio_title (BraseroJob *job, gchar **album);
143 
144 BraseroBurnResult
145 brasero_job_get_data_label (BraseroJob *job, gchar **label);
146 
147 BraseroBurnResult
148 brasero_job_get_session_output_size (BraseroJob *job,
149 				     goffset *blocks,
150 				     goffset *bytes);
151 
152 /**
153  * Used to get information of the destination media
154  */
155 
156 BraseroBurnResult
157 brasero_job_get_medium (BraseroJob *job, BraseroMedium **medium);
158 
159 BraseroBurnResult
160 brasero_job_get_bus_target_lun (BraseroJob *job, gchar **BTL);
161 
162 BraseroBurnResult
163 brasero_job_get_device (BraseroJob *job, gchar **device);
164 
165 BraseroBurnResult
166 brasero_job_get_media (BraseroJob *job, BraseroMedia *media);
167 
168 BraseroBurnResult
169 brasero_job_get_last_session_address (BraseroJob *job, goffset *address);
170 
171 BraseroBurnResult
172 brasero_job_get_next_writable_address (BraseroJob *job, goffset *address);
173 
174 BraseroBurnResult
175 brasero_job_get_rate (BraseroJob *job, guint64 *rate);
176 
177 BraseroBurnResult
178 brasero_job_get_speed (BraseroJob *self, guint *speed);
179 
180 BraseroBurnResult
181 brasero_job_get_max_rate (BraseroJob *job, guint64 *rate);
182 
183 BraseroBurnResult
184 brasero_job_get_max_speed (BraseroJob *job, guint *speed);
185 
186 /**
187  * necessary for objects imaging either to another or to a file
188  */
189 
190 BraseroBurnResult
191 brasero_job_get_output_type (BraseroJob *job, BraseroTrackType *type);
192 
193 BraseroBurnResult
194 brasero_job_get_fd_out (BraseroJob *job, int *fd_out);
195 
196 BraseroBurnResult
197 brasero_job_get_image_output (BraseroJob *job,
198 			      gchar **image,
199 			      gchar **toc);
200 BraseroBurnResult
201 brasero_job_get_audio_output (BraseroJob *job,
202 			      gchar **output);
203 
204 /**
205  * get a temporary file that will be deleted once the session is finished
206  */
207 
208 BraseroBurnResult
209 brasero_job_get_tmp_file (BraseroJob *job,
210 			  const gchar *suffix,
211 			  gchar **output,
212 			  GError **error);
213 
214 BraseroBurnResult
215 brasero_job_get_tmp_dir (BraseroJob *job,
216 			 gchar **path,
217 			 GError **error);
218 
219 /**
220  * Each tag can be retrieved by any job
221  */
222 
223 BraseroBurnResult
224 brasero_job_tag_lookup (BraseroJob *job,
225 			const gchar *tag,
226 			GValue **value);
227 
228 BraseroBurnResult
229 brasero_job_tag_add (BraseroJob *job,
230 		     const gchar *tag,
231 		     GValue *value);
232 
233 /**
234  * Used to give job results and tell when a job has finished
235  */
236 
237 BraseroBurnResult
238 brasero_job_add_track (BraseroJob *job,
239 		       BraseroTrack *track);
240 
241 BraseroBurnResult
242 brasero_job_finished_track (BraseroJob *job);
243 
244 BraseroBurnResult
245 brasero_job_finished_session (BraseroJob *job);
246 
247 BraseroBurnResult
248 brasero_job_error (BraseroJob *job,
249 		   GError *error);
250 
251 /**
252  * Used to start progress reporting and starts an internal timer to keep track
253  * of remaining time among other things
254  */
255 
256 BraseroBurnResult
257 brasero_job_start_progress (BraseroJob *job,
258 			    gboolean force);
259 
260 /**
261  * task progress report: you can use only some of these functions
262  */
263 
264 BraseroBurnResult
265 brasero_job_set_rate (BraseroJob *job,
266 		      gint64 rate);
267 BraseroBurnResult
268 brasero_job_set_written_track (BraseroJob *job,
269 			       goffset written);
270 BraseroBurnResult
271 brasero_job_set_written_session (BraseroJob *job,
272 				 goffset written);
273 BraseroBurnResult
274 brasero_job_set_progress (BraseroJob *job,
275 			  gdouble progress);
276 BraseroBurnResult
277 brasero_job_reset_progress (BraseroJob *job);
278 BraseroBurnResult
279 brasero_job_set_current_action (BraseroJob *job,
280 				BraseroBurnAction action,
281 				const gchar *string,
282 				gboolean force);
283 BraseroBurnResult
284 brasero_job_get_current_action (BraseroJob *job,
285 				BraseroBurnAction *action);
286 BraseroBurnResult
287 brasero_job_set_output_size_for_current_track (BraseroJob *job,
288 					       goffset sectors,
289 					       goffset bytes);
290 
291 /**
292  * Used to tell it's (or not) dangerous to interrupt this job
293  */
294 
295 void
296 brasero_job_set_dangerous (BraseroJob *job, gboolean value);
297 
298 /**
299  * This is for apps with a jerky current rate (like cdrdao)
300  */
301 
302 BraseroBurnResult
303 brasero_job_set_use_average_rate (BraseroJob *job,
304 				  gboolean value);
305 
306 /**
307  * logging facilities
308  */
309 
310 void
311 brasero_job_log_message (BraseroJob *job,
312 			 const gchar *location,
313 			 const gchar *format,
314 			 ...);
315 
316 #define BRASERO_JOB_LOG(job, message, ...) 			\
317 {								\
318 	gchar *format;						\
319 	format = g_strdup_printf ("%s %s",			\
320 				  G_OBJECT_TYPE_NAME (job),	\
321 				  message);			\
322 	brasero_job_log_message (BRASERO_JOB (job),		\
323 				 G_STRLOC,			\
324 				 format,		 	\
325 				 ##__VA_ARGS__);		\
326 	g_free (format);					\
327 }
328 #define BRASERO_JOB_LOG_ARG(job, message, ...)			\
329 {								\
330 	gchar *format;						\
331 	format = g_strdup_printf ("\t%s",			\
332 				  (gchar*) message);		\
333 	brasero_job_log_message (BRASERO_JOB (job),		\
334 				 G_STRLOC,			\
335 				 format,			\
336 				 ##__VA_ARGS__);		\
337 	g_free (format);					\
338 }
339 
340 #define BRASERO_JOB_NOT_SUPPORTED(job) 					\
341 	{								\
342 		BRASERO_JOB_LOG (job, "unsupported operation");		\
343 		return BRASERO_BURN_NOT_SUPPORTED;			\
344 	}
345 
346 #define BRASERO_JOB_NOT_READY(job)						\
347 	{									\
348 		BRASERO_JOB_LOG (job, "not ready to operate");	\
349 		return BRASERO_BURN_NOT_READY;					\
350 	}
351 
352 
353 G_END_DECLS
354 
355 #endif /* JOB_H */
356