1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 
3 /*
4  *  File-Roller
5  *
6  *  Copyright (C) 2001, 2003, 2008 Free Software Foundation, Inc.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program 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
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef FR_PROCESS_H
23 #define FR_PROCESS_H
24 
25 #include <glib.h>
26 #include <gio/gio.h>
27 #include <sys/types.h>
28 #include "fr-error.h"
29 #include "typedefs.h"
30 
31 #define FR_TYPE_PROCESS            (fr_process_get_type ())
32 #define FR_PROCESS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), FR_TYPE_PROCESS, FrProcess))
33 #define FR_PROCESS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), FR_TYPE_PROCESS, FrProcessClass))
34 #define FR_IS_PROCESS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FR_TYPE_PROCESS))
35 #define FR_IS_PROCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FR_TYPE_PROCESS))
36 #define FR_PROCESS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), FR_TYPE_PROCESS, FrProcessClass))
37 
38 typedef struct _FrProcess        FrProcess;
39 typedef struct _FrProcessClass   FrProcessClass;
40 typedef struct _FrProcessPrivate FrProcessPrivate;
41 
42 typedef void     (*ProcFunc)     (gpointer data);
43 typedef gboolean (*ContinueFunc) (FrError **error, gpointer data);
44 typedef void     (*LineFunc)     (char *line, gpointer data);
45 
46 typedef struct {
47 	GIOChannel *source;
48 	GList      *raw;
49 	LineFunc    line_func;
50 	gpointer    line_data;
51 	GIOStatus   status;
52 	GError     *error;
53 } FrChannelData;
54 
55 struct _FrProcess {
56 	GObject  __parent;
57 
58 	FrChannelData     out;
59 	FrChannelData     err;
60 	gboolean          restart;       /* whether to restart the process
61 			  		  * after an error. */
62 	FrProcessPrivate *priv;
63 };
64 
65 struct _FrProcessClass {
66 	GObjectClass __parent_class;
67 
68 	/* -- Signals -- */
69 
70 	void (* sticky_only) (FrProcess *fr_proc);
71 };
72 
73 GType       fr_process_get_type             (void);
74 FrProcess * fr_process_new                  (void);
75 void        fr_process_clear                (FrProcess            *fr_proc);
76 void        fr_process_begin_command        (FrProcess            *fr_proc,
77 					     const char           *arg);
78 void        fr_process_begin_command_at     (FrProcess            *fr_proc,
79 					     const char           *arg,
80 					     int                   index);
81 void        fr_process_add_arg              (FrProcess            *fr_proc,
82 					     const char           *arg);
83 void        fr_process_add_arg_concat       (FrProcess            *fr_proc,
84 					     const char           *arg,
85 					     ...) G_GNUC_NULL_TERMINATED;
86 void        fr_process_add_arg_printf       (FrProcess            *fr_proc,
87 					     const char           *format,
88 					     ...) G_GNUC_PRINTF (2, 3);
89 void        fr_process_add_arg_file         (FrProcess            *process,
90 					     GFile                *file);
91 void        fr_process_set_arg_at           (FrProcess            *fr_proc,
92 					     int                   n_comm,
93 					     int                   n_arg,
94 					     const char           *arg);
95 void        fr_process_set_begin_func       (FrProcess            *fr_proc,
96 					     ProcFunc              func,
97 					     gpointer              func_data);
98 void        fr_process_set_end_func         (FrProcess            *fr_proc,
99 					     ProcFunc              func,
100 					     gpointer              func_data);
101 void        fr_process_set_continue_func    (FrProcess            *fr_proc,
102 					     ContinueFunc          func,
103 					     gpointer              func_data);
104 void        fr_process_end_command          (FrProcess            *fr_proc);
105 void        fr_process_set_working_dir      (FrProcess            *fr_proc,
106 					     const char           *arg);
107 void        fr_process_set_working_dir_file (FrProcess            *fr_proc,
108 					     GFile                *folder);
109 void        fr_process_set_sticky           (FrProcess            *fr_proc,
110 					     gboolean              sticky);
111 void        fr_process_set_ignore_error     (FrProcess            *fr_proc,
112 					     gboolean              ignore_error);
113 void        fr_process_use_standard_locale  (FrProcess            *fr_proc,
114 					     gboolean              use_stand_locale);
115 void        fr_process_set_out_line_func    (FrProcess            *fr_proc,
116 					     LineFunc              func,
117 					     gpointer              func_data);
118 void        fr_process_set_err_line_func    (FrProcess            *fr_proc,
119 					     LineFunc              func,
120 					     gpointer              func_data);
121 void        fr_process_execute              (FrProcess            *process,
122 					     GCancellable         *cancellable,
123 					     GAsyncReadyCallback   callback,
124 					     gpointer              user_data);
125 gboolean    fr_process_execute_finish       (FrProcess            *process,
126 					     GAsyncResult         *result,
127 					     FrError             **error);
128 void        fr_process_restart              (FrProcess            *process);
129 void        fr_process_cancel               (FrProcess            *process);
130 
131 #endif /* FR_PROCESS_H */
132