1 // Generated by gtkmmproc -- DO NOT MODIFY!
4 #include <glibmm/spawn.h>
5 #include <glibmm/private/spawn_p.h>
8 /* $Id: spawn.ccg,v 1.8 2006/05/12 08:08:44 murrayc Exp $ */
10 /* Copyright (C) 2002 The gtkmm Development Team
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <glib/gspawn.h>
28 #include <glibmm/exceptionhandler.h>
29 #include <glibmm/utility.h>
38 /* Helper callback to invoke the actual sigc++ slot.
39 * We don't need to worry about (un)referencing, since the
40 * child process gets its own copy of the parent's memory anyway.
42 static void child_setup_callback(void* user_data)
44 #ifdef GLIBMM_EXCEPTIONS_ENABLED
47 #endif //GLIBMM_EXCEPTIONS_ENABLED
48 (*reinterpret_cast<sigc::slot<void>*>(user_data))();
49 #ifdef GLIBMM_EXCEPTIONS_ENABLED
53 Glib::exception_handlers_invoke();
55 #endif //GLIBMM_EXCEPTIONS_ENABLED
58 static void copy_output_buf(std::string* dest, const char* buf)
71 } //anonymous namespace
77 /**** process spawning functions *******************************************/
79 void spawn_async_with_pipes(const std::string& working_directory,
80 const Glib::ArrayHandle<std::string>& argv,
81 const Glib::ArrayHandle<std::string>& envp,
83 const sigc::slot<void>& child_setup,
89 const bool setup_slot = !child_setup.empty();
90 sigc::slot<void> child_setup_ = child_setup;
93 g_spawn_async_with_pipes(
94 working_directory.c_str(),
95 const_cast<char**>(argv.data()),
96 const_cast<char**>(envp.data()),
97 static_cast<GSpawnFlags>(unsigned(flags)),
98 (setup_slot) ? &child_setup_callback : 0,
99 (setup_slot) ? &child_setup_ : 0,
101 standard_input, standard_output, standard_error,
105 Glib::Error::throw_exception(error);
108 void spawn_async_with_pipes(const std::string& working_directory,
109 const Glib::ArrayHandle<std::string>& argv,
111 const sigc::slot<void>& child_setup,
114 int* standard_output,
117 const bool setup_slot = !child_setup.empty();
118 sigc::slot<void> child_setup_ = child_setup;
121 g_spawn_async_with_pipes(
122 working_directory.c_str(),
123 const_cast<char**>(argv.data()), 0,
124 static_cast<GSpawnFlags>(unsigned(flags)),
125 (setup_slot) ? &child_setup_callback : 0,
126 (setup_slot) ? &child_setup_ : 0,
128 standard_input, standard_output, standard_error,
132 Glib::Error::throw_exception(error);
135 void spawn_async(const std::string& working_directory,
136 const Glib::ArrayHandle<std::string>& argv,
137 const Glib::ArrayHandle<std::string>& envp,
139 const sigc::slot<void>& child_setup,
142 const bool setup_slot = !child_setup.empty();
143 sigc::slot<void> child_setup_ = child_setup;
147 working_directory.c_str(),
148 const_cast<char**>(argv.data()),
149 const_cast<char**>(envp.data()),
150 static_cast<GSpawnFlags>(unsigned(flags)),
151 (setup_slot) ? &child_setup_callback : 0,
152 (setup_slot) ? &child_setup_ : 0,
157 Glib::Error::throw_exception(error);
160 void spawn_async(const std::string& working_directory,
161 const Glib::ArrayHandle<std::string>& argv,
163 const sigc::slot<void>& child_setup,
166 const bool setup_slot = !child_setup.empty();
167 sigc::slot<void> child_setup_ = child_setup;
171 working_directory.c_str(),
172 const_cast<char**>(argv.data()), 0,
173 static_cast<GSpawnFlags>(unsigned(flags)),
174 (setup_slot) ? &child_setup_callback : 0,
175 (setup_slot) ? &child_setup_ : 0,
180 Glib::Error::throw_exception(error);
183 void spawn_sync(const std::string& working_directory,
184 const Glib::ArrayHandle<std::string>& argv,
185 const Glib::ArrayHandle<std::string>& envp,
187 const sigc::slot<void>& child_setup,
188 std::string* standard_output,
189 std::string* standard_error,
192 const bool setup_slot = !child_setup.empty();
193 sigc::slot<void> child_setup_ = child_setup;
195 Glib::ScopedPtr<char> buf_standard_output;
196 Glib::ScopedPtr<char> buf_standard_error;
200 working_directory.c_str(),
201 const_cast<char**>(argv.data()),
202 const_cast<char**>(envp.data()),
203 static_cast<GSpawnFlags>(unsigned(flags)),
204 (setup_slot) ? &child_setup_callback : 0,
205 (setup_slot) ? &child_setup_ : 0,
206 (standard_output) ? buf_standard_output.addr() : 0,
207 (standard_error) ? buf_standard_error.addr() : 0,
212 Glib::Error::throw_exception(error);
214 copy_output_buf(standard_output, buf_standard_output.get());
215 copy_output_buf(standard_error, buf_standard_error.get());
218 void spawn_sync(const std::string& working_directory,
219 const Glib::ArrayHandle<std::string>& argv,
221 const sigc::slot<void>& child_setup,
222 std::string* standard_output,
223 std::string* standard_error,
226 const bool setup_slot = !child_setup.empty();
227 sigc::slot<void> child_setup_ = child_setup;
229 Glib::ScopedPtr<char> buf_standard_output;
230 Glib::ScopedPtr<char> buf_standard_error;
234 working_directory.c_str(),
235 const_cast<char**>(argv.data()), 0,
236 static_cast<GSpawnFlags>(unsigned(flags)),
237 (setup_slot) ? &child_setup_callback : 0,
238 (setup_slot) ? &child_setup_ : 0,
239 (standard_output) ? buf_standard_output.addr() : 0,
240 (standard_error) ? buf_standard_error.addr() : 0,
245 Glib::Error::throw_exception(error);
247 copy_output_buf(standard_output, buf_standard_output.get());
248 copy_output_buf(standard_error, buf_standard_error.get());
251 void spawn_command_line_async(const std::string& command_line)
254 g_spawn_command_line_async(command_line.c_str(), &error);
257 Glib::Error::throw_exception(error);
260 void spawn_command_line_sync(const std::string& command_line,
261 std::string* standard_output,
262 std::string* standard_error,
265 Glib::ScopedPtr<char> buf_standard_output;
266 Glib::ScopedPtr<char> buf_standard_error;
269 g_spawn_command_line_sync(
270 command_line.c_str(),
271 (standard_output) ? buf_standard_output.addr() : 0,
272 (standard_error) ? buf_standard_error.addr() : 0,
277 Glib::Error::throw_exception(error);
279 copy_output_buf(standard_output, buf_standard_output.get());
280 copy_output_buf(standard_error, buf_standard_error.get());
283 void spawn_close_pid(Pid pid)
285 g_spawn_close_pid(pid);
293 } // anonymous namespace
296 Glib::SpawnError::SpawnError(Glib::SpawnError::Code error_code, const Glib::ustring& error_message)
298 Glib::Error (G_SPAWN_ERROR, error_code, error_message)
301 Glib::SpawnError::SpawnError(GError* gobject)
303 Glib::Error (gobject)
306 Glib::SpawnError::Code Glib::SpawnError::code() const
308 return static_cast<Code>(Glib::Error::code());
311 #ifdef GLIBMM_EXCEPTIONS_ENABLED
312 void Glib::SpawnError::throw_func(GError* gobject)
314 throw Glib::SpawnError(gobject);
317 //When not using exceptions, we just pass the Exception object around without throwing it:
318 std::auto_ptr<Glib::Error> Glib::SpawnError::throw_func(GError* gobject)
320 return std::auto_ptr<Glib::Error>(new Glib::SpawnError(gobject));
322 #endif //GLIBMM_EXCEPTIONS_ENABLED