1 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #include <glibmm/spawn.h>
4 #include <glibmm/private/spawn_p.h>
9 /* Copyright (C) 2002 The gtkmm Development Team
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <glib/gspawn.h>
27 #include <glibmm/exceptionhandler.h>
28 #include <glibmm/utility.h>
37 /* Helper callback to invoke the actual sigc++ slot.
38 * We don't need to worry about (un)referencing, since the
39 * child process gets its own copy of the parent's memory anyway.
41 void child_setup_callback(void* user_data)
45 (*reinterpret_cast<sigc::slot<void>*>(user_data))();
49 Glib::exception_handlers_invoke();
53 void copy_output_buf(std::string* dest, const char* buf)
66 } //anonymous namespace
72 /**** process spawning functions *******************************************/
74 void spawn_async_with_pipes(const std::string& working_directory,
75 const Glib::ArrayHandle<std::string>& argv,
76 const Glib::ArrayHandle<std::string>& envp,
78 const sigc::slot<void>& child_setup,
84 const bool setup_slot = !child_setup.empty();
85 sigc::slot<void> child_setup_ = child_setup;
88 g_spawn_async_with_pipes(
89 working_directory.c_str(),
90 const_cast<char**>(argv.data()),
91 const_cast<char**>(envp.data()),
92 static_cast<GSpawnFlags>(unsigned(flags)),
93 (setup_slot) ? &child_setup_callback : 0,
94 (setup_slot) ? &child_setup_ : 0,
96 standard_input, standard_output, standard_error,
100 Glib::Error::throw_exception(error);
103 void spawn_async_with_pipes(const std::string& working_directory,
104 const Glib::ArrayHandle<std::string>& argv,
106 const sigc::slot<void>& child_setup,
109 int* standard_output,
112 const bool setup_slot = !child_setup.empty();
113 sigc::slot<void> child_setup_ = child_setup;
116 g_spawn_async_with_pipes(
117 working_directory.c_str(),
118 const_cast<char**>(argv.data()), 0,
119 static_cast<GSpawnFlags>(unsigned(flags)),
120 (setup_slot) ? &child_setup_callback : 0,
121 (setup_slot) ? &child_setup_ : 0,
123 standard_input, standard_output, standard_error,
127 Glib::Error::throw_exception(error);
130 void spawn_async(const std::string& working_directory,
131 const Glib::ArrayHandle<std::string>& argv,
132 const Glib::ArrayHandle<std::string>& envp,
134 const sigc::slot<void>& child_setup,
137 const bool setup_slot = !child_setup.empty();
138 sigc::slot<void> child_setup_ = child_setup;
142 working_directory.c_str(),
143 const_cast<char**>(argv.data()),
144 const_cast<char**>(envp.data()),
145 static_cast<GSpawnFlags>(unsigned(flags)),
146 (setup_slot) ? &child_setup_callback : 0,
147 (setup_slot) ? &child_setup_ : 0,
152 Glib::Error::throw_exception(error);
155 void spawn_async(const std::string& working_directory,
156 const Glib::ArrayHandle<std::string>& argv,
158 const sigc::slot<void>& child_setup,
161 const bool setup_slot = !child_setup.empty();
162 sigc::slot<void> child_setup_ = child_setup;
166 working_directory.c_str(),
167 const_cast<char**>(argv.data()), 0,
168 static_cast<GSpawnFlags>(unsigned(flags)),
169 (setup_slot) ? &child_setup_callback : 0,
170 (setup_slot) ? &child_setup_ : 0,
175 Glib::Error::throw_exception(error);
178 void spawn_sync(const std::string& working_directory,
179 const Glib::ArrayHandle<std::string>& argv,
180 const Glib::ArrayHandle<std::string>& envp,
182 const sigc::slot<void>& child_setup,
183 std::string* standard_output,
184 std::string* standard_error,
187 const bool setup_slot = !child_setup.empty();
188 sigc::slot<void> child_setup_ = child_setup;
190 Glib::ScopedPtr<char> buf_standard_output;
191 Glib::ScopedPtr<char> buf_standard_error;
195 working_directory.c_str(),
196 const_cast<char**>(argv.data()),
197 const_cast<char**>(envp.data()),
198 static_cast<GSpawnFlags>(unsigned(flags)),
199 (setup_slot) ? &child_setup_callback : 0,
200 (setup_slot) ? &child_setup_ : 0,
201 (standard_output) ? buf_standard_output.addr() : 0,
202 (standard_error) ? buf_standard_error.addr() : 0,
207 Glib::Error::throw_exception(error);
209 copy_output_buf(standard_output, buf_standard_output.get());
210 copy_output_buf(standard_error, buf_standard_error.get());
213 void spawn_sync(const std::string& working_directory,
214 const Glib::ArrayHandle<std::string>& argv,
216 const sigc::slot<void>& child_setup,
217 std::string* standard_output,
218 std::string* standard_error,
221 const bool setup_slot = !child_setup.empty();
222 sigc::slot<void> child_setup_ = child_setup;
224 Glib::ScopedPtr<char> buf_standard_output;
225 Glib::ScopedPtr<char> buf_standard_error;
229 working_directory.c_str(),
230 const_cast<char**>(argv.data()), 0,
231 static_cast<GSpawnFlags>(unsigned(flags)),
232 (setup_slot) ? &child_setup_callback : 0,
233 (setup_slot) ? &child_setup_ : 0,
234 (standard_output) ? buf_standard_output.addr() : 0,
235 (standard_error) ? buf_standard_error.addr() : 0,
240 Glib::Error::throw_exception(error);
242 copy_output_buf(standard_output, buf_standard_output.get());
243 copy_output_buf(standard_error, buf_standard_error.get());
246 void spawn_command_line_async(const std::string& command_line)
249 g_spawn_command_line_async(command_line.c_str(), &error);
252 Glib::Error::throw_exception(error);
255 void spawn_command_line_sync(const std::string& command_line,
256 std::string* standard_output,
257 std::string* standard_error,
260 Glib::ScopedPtr<char> buf_standard_output;
261 Glib::ScopedPtr<char> buf_standard_error;
264 g_spawn_command_line_sync(
265 command_line.c_str(),
266 (standard_output) ? buf_standard_output.addr() : 0,
267 (standard_error) ? buf_standard_error.addr() : 0,
272 Glib::Error::throw_exception(error);
274 copy_output_buf(standard_output, buf_standard_output.get());
275 copy_output_buf(standard_error, buf_standard_error.get());
278 void spawn_close_pid(Pid pid)
280 g_spawn_close_pid(pid);
288 } // anonymous namespace
291 Glib::SpawnError::SpawnError(Glib::SpawnError::Code error_code, const Glib::ustring& error_message)
293 Glib::Error (G_SPAWN_ERROR, error_code, error_message)
296 Glib::SpawnError::SpawnError(GError* gobject)
298 Glib::Error (gobject)
301 Glib::SpawnError::Code Glib::SpawnError::code() const
303 return static_cast<Code>(Glib::Error::code());
306 void Glib::SpawnError::throw_func(GError* gobject)
308 throw Glib::SpawnError(gobject);