/usr/include/cutter/gcutter/gcut-process.h is in cutter-glib-support 1.1.7-1.2ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Copyright (C) 2008-2011 Kouhei Sutou <kou@clear-code.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __GCUT_PROCESS_H__
#define __GCUT_PROCESS_H__
#include <glib-object.h>
#include <cutter/cut-features.h>
#include <gcutter/gcut-event-loop.h>
G_BEGIN_DECLS
/**
* SECTION: gcut-process
* @title: External command
* @short_description: Convenience API for using external
* command.
*
* #GCutProcess encapsulates external command execution,
* communication and termination. #GCutProcess reports an error
* as #GError. It can be asserted easily by
* gcut_assert_error().
*
* External command is specified to constructor like
* gcut_process_new(), gcut_process_new_strings() and so
* on. External command isn't run at the
* time. gcut_process_run() runs specified external command.
*
* Standard/Error outputs of external command are passed by
* #GCutProcess::output-received/#GCutProcess::error-received signals
* or #GIOChannel returned by
* gcut_process_get_output()/gcut_process_get_error().
* gcut_process_write() writes a chunk to standard input of
* external command.
*
* To wait external command finished, gcut_process_wait() can be
* used. It accepts timeout to avoid infinite waiting.
*
* e.g.:
* |[
* static GString *output_string;
* static GCutProcess *process;
*
* void
* cut_setup (void)
* {
* output_string = g_string_new(NULL);
* process = NULL;
* }
*
* void
* cut_teardown (void)
* {
* if (output_string)
* g_string_free(output_string, TRUE);
* if (process)
* g_object_unref(process);
* }
*
* static void
* cb_output_received (GCutProcess *process, const gchar *chunk, gsize size,
* gpointer user_data)
* {
* g_string_append_len(output_string, chunk, size);
* }
*
* void
* test_echo (void)
* {
* GError *error = NULL;
*
* process = gcut_process_new("echo", "XXX", NULL);
* g_signal_connect(process, "receive-output",
* G_CALLBACK(cb_output_received), NULL);
*
* gcut_process_run(process, &error);
* gcut_assert_error(error);
*
* gcut_process_wait(process, 1000, &error);
* gcut_assert_error(error);
* cut_assert_equal_string("XXX\n", output_string->str);
* }
* ]|
*
* Since: 1.1.5
*/
#define GCUT_TYPE_PROCESS (gcut_process_get_type ())
#define GCUT_PROCESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCUT_TYPE_PROCESS, GCutProcess))
#define GCUT_PROCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCUT_TYPE_PROCESS, GCutProcessClass))
#define GCUT_IS_PROCESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCUT_TYPE_PROCESS))
#define GCUT_IS_PROCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCUT_TYPE_PROCESS))
#define GCUT_PROCESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCUT_TYPE_PROCESS, GCutProcessClass))
#define GCUT_PROCESS_ERROR (gcut_process_error_quark())
typedef struct _GCutProcess GCutProcess;
typedef struct _GCutProcessClass GCutProcessClass;
struct _GCutProcess
{
GObject object;
};
struct _GCutProcessClass
{
GObjectClass parent_class;
void (*output_received) (GCutProcess *process,
const gchar *chunk,
gsize size);
void (*error_received) (GCutProcess *process,
const gchar *chunk,
gsize size);
void (*reaped) (GCutProcess *process,
gint status);
void (*error) (GCutProcess *process,
GError *error);
};
/**
* GCutProcessError:
* @GCUT_PROCESS_ERROR_COMMAND_LINE: Command line related error.
* @GCUT_PROCESS_ERROR_IO_ERROR: IO error.
* @GCUT_PROCESS_ERROR_ALREADY_RUNNING: External command is already running.
* @GCUT_PROCESS_ERROR_NOT_RUNNING: External command isn't running.
* @GCUT_PROCESS_ERROR_INVALID_OBJECT: Invalid #GCutProcess object is passed.
* @GCUT_PROCESS_ERROR_INVALID_SIGNAL: Invalid signal is passed.
* @GCUT_PROCESS_ERROR_PERMISSION_DENIED: Permission denied.
* @GCUT_PROCESS_ERROR_TIMEOUT: Timeout.
*
* Error codes returned by #GCutProcess related operations.
*
* Since: 1.1.5
*/
typedef enum
{
GCUT_PROCESS_ERROR_COMMAND_LINE,
GCUT_PROCESS_ERROR_IO_ERROR,
GCUT_PROCESS_ERROR_ALREADY_RUNNING,
GCUT_PROCESS_ERROR_NOT_RUNNING,
GCUT_PROCESS_ERROR_INVALID_OBJECT,
GCUT_PROCESS_ERROR_INVALID_SIGNAL,
GCUT_PROCESS_ERROR_PERMISSION_DENIED,
GCUT_PROCESS_ERROR_TIMEOUT
} GCutProcessError;
GQuark gcut_process_error_quark (void);
GType gcut_process_get_type (void) G_GNUC_CONST;
/**
* gcut_process_new:
* @command: the external command name to be ran
* @...: the arguments for @command
*
* Creates a new #GCutProcess object that runs @command.
*
* Returns: a new #GCutProcess.
*
* Since: 1.1.5
*/
GCutProcess *gcut_process_new (const gchar *command,
...) G_GNUC_NULL_TERMINATED;
/**
* gcut_process_new_command_line:
* @command_line: a command line
*
* Creates a new #GCutProcess object that runs @command_line.
*
* Returns: a new #GCutProcess.
*
* Since: 1.1.5
*/
GCutProcess *gcut_process_new_command_line (const gchar *command_line);
/**
* gcut_process_new_va_list:
* @command: the external command name to be ran
* @args: arguments for @command
*
* Creates a new #GCutProcess object that runs @command.
*
* Returns: a new #GCutProcess.
*
* Since: 1.1.5
*/
GCutProcess *gcut_process_new_va_list (const gchar *command,
va_list args);
/**
* gcut_process_new_argv:
* @argc: the number of elements of @argv
* @argv: the external command name to be ran and arguments
* of it.
*
* Creates a new #GCutProcess object that runs @command.
*
* Returns: a new #GCutProcess.
*
* Since: 1.1.5
*/
GCutProcess *gcut_process_new_argv (gint argc,
gchar **argv);
/**
* gcut_process_new_strings:
* @command: the external command name to be ran and
* arguments of it. %NULL-terminated.
*
* Creates a new #GCutProcess object that runs @command.
*
* Returns: a new #GCutProcess.
*
* Since: 1.1.5
*/
GCutProcess *gcut_process_new_strings (const gchar **command);
/**
* gcut_process_new_array:
* @command: the external command name to be ran and
* arguments of it. The #GArray should be zero-terminated.
*
* Creates a new #GCutProcess object that runs @command.
*
* Returns: a new #GCutProcess.
*
* Since: 1.1.5
*/
GCutProcess *gcut_process_new_array (GArray *command);
/**
* gcut_process_set_flags:
* @process: a #GCutProcess
* @flags: the flags to be passed to g_spawn_async_with_pipes().
*
* Sets @flags for spawning.
*
* Since: 1.1.5
*/
void gcut_process_set_flags (GCutProcess *process,
GSpawnFlags flags);
/**
* gcut_process_get_flags:
* @process: a #GCutProcess
*
* Gets @flags for spawning.
*
* Returns: the flags for spawning.
*
* Since: 1.1.5
*/
GSpawnFlags gcut_process_get_flags (GCutProcess *process);
/**
* gcut_process_set_env:
* @process: a #GCutProcess
* @name: the first environment name.
* @...: the value of @name, followed by name and value
* pairs. %NULL-terminated.
*
* Sets environment variable for external command.
*
* Since: 1.1.5
*/
void gcut_process_set_env (GCutProcess *process,
const gchar *name,
...) G_GNUC_NULL_TERMINATED;
/**
* gcut_process_get_env:
* @process: a #GCutProcess
*
* Gets environment variable for external command.
*
* Returns: a newly-allocated %NULL-terminated environment
* variables. ("NAME1=VALUE1", "NAME2=VALUE2",
* ..., %NULL) It should be freed by g_strfreev() when no longer
* needed.
*
* Since: 1.1.5
*/
gchar **gcut_process_get_env (GCutProcess *process);
/**
* gcut_process_run:
* @process: a #GCutProcess
* @error: return location for an error, or %NULL
*
* Runs a new external process.
*
* Returns: %TRUE on success, otherwise %FALSE
*
* Since: 1.1.5
*/
gboolean gcut_process_run (GCutProcess *process,
GError **error);
/**
* gcut_process_get_pid:
* @process: a #GCutProcess
*
* Gets the process ID of running external process. If
* external process isn't running, 0 is returned.
*
* Returns: the process ID of running external process if
* external process is running, otherwise 0.
*
* Since: 1.1.5
*/
GPid gcut_process_get_pid (GCutProcess *process);
/**
* gcut_process_wait:
* @process: a #GCutProcess
* @timeout: the timeout period in milliseconds
* @error: return location for an error, or %NULL
*
* Waits running external process is finished while @timeout
* milliseconds. If external process isn't finished while
* @timeout milliseconds, %GCUT_PROCESS_ERROR_TIMEOUT error is
* set and -1 is returned. If external process isn't
* running, %GCUT_PROCESS_ERROR_NOT_RUNNING error is set and -1
* is returned.
*
* Returns: an exit status of external process on success,
* otherwise -1.
*
* Since: 1.1.5
*/
gint gcut_process_wait (GCutProcess *process,
guint timeout,
GError **error);
/**
* gcut_process_kill:
* @process: a #GCutProcess
* @signal_number: the signal number to be sent to external process
* @error: return location for an error, or %NULL
*
* Sends @signal_number signal to external process.
*
* Returns: %TRUE on success, otherwise %FALSE
*
* Since: 1.1.5
*/
gboolean gcut_process_kill (GCutProcess *process,
gint signal_number,
GError **error);
/**
* gcut_process_write:
* @process: a #GCutProcess
* @chunk: the data to be wrote
* @size: the size of @chunk
* @error: return location for an error, or %NULL
*
* Writes @chunk to external process's standard input.
*
* Returns: %TRUE on success, otherwise %FALSE
*
* Since: 1.1.5
*/
gboolean gcut_process_write (GCutProcess *process,
const gchar *chunk,
gsize size,
GError **error);
/**
* gcut_process_flush:
* @process: a #GCutProcess
* @error: return location for an error, or %NULL
*
* Flush buffered external process's standard input.
*
* Returns: the status of the operation: One of
* %G_IO_STATUS_NORMAL, %G_IO_STATUS_AGAIN, or
* %G_IO_STATUS_ERROR.
*
* Since: 1.1.5
*/
GIOStatus gcut_process_flush (GCutProcess *process,
GError **error);
/**
* gcut_process_get_output_string:
* @process: a #GCutProcess
*
* Returns: a #GString that has all result of standard
* output of external process.
*
* Since: 1.1.5
*/
GString *gcut_process_get_output_string
(GCutProcess *process);
/**
* gcut_process_get_error_string:
* @process: a #GCutProcess
*
* Returns: a #GString that has all result of standard
* error of external process.
*
* Since: 1.1.5
*/
GString *gcut_process_get_error_string
(GCutProcess *process);
/**
* gcut_process_get_input_channel:
* @process: a #GCutProcess
*
* Gets a #GIOChannel connected with standard input of
* external process.
*
* Returns: a #GIOChannel if external process is running,
* otherwise %NULL.
*
* Since: 1.1.5
*/
GIOChannel *gcut_process_get_input_channel (GCutProcess *process);
/**
* gcut_process_get_output_channel:
* @process: a #GCutProcess
*
* Gets a #GIOChannel connected with standard output of
* external process.
*
* Returns: a #GIOChannel if external process is running,
* otherwise %NULL.
*
* Since: 1.1.5
*/
GIOChannel *gcut_process_get_output_channel (GCutProcess *process);
/**
* gcut_process_get_error_channel:
* @process: a #GCutProcess
*
* Gets a #GIOChannel connected with standard error output
* of external process.
*
* Returns: a #GIOChannel if external process is running,
* otherwise %NULL.
*
* Since: 1.1.5
*/
GIOChannel *gcut_process_get_error_channel (GCutProcess *process);
#ifdef CUT_SUPPORT_GIO
#include <gio/gio.h>
/**
* gcut_process_get_output_stream:
* @process: a #GCutProcess
*
* Gets a #GInputStream connected with standard output of
* external process.
*
* Returns: a #GInputStream if external process is running,
* otherwise %NULL.
*
* Since: 1.1.5
*/
GInputStream *gcut_process_get_output_stream (GCutProcess *process);
/**
* gcut_process_get_error_stream:
* @process: a #GCutProcess
*
* Gets a #GInputStream connected with standard error output
* of external process.
*
* Returns: a #GInputStream if external process is running,
* otherwise %NULL.
*
* Since: 1.1.5
*/
GInputStream *gcut_process_get_error_stream (GCutProcess *process);
#endif /* CUT_SUPPORT_GIO */
/**
* gcut_process_get_forced_termination_wait_time:
* @process: a #GCutProcess
*
* Gets a wait time in milliseconds for forced termination
* on dispose.
*
* Returns: a timeout value for waiting forced terminated
* external command on dispose.
*
* Since: 1.1.5
*/
guint gcut_process_get_forced_termination_wait_time
(GCutProcess *process);
/**
* gcut_process_set_forced_termination_wait_time:
* @process: a #GCutProcess
* @timeout: the timeout value in milliseconds
*
* Sets a wait time in milliseconds for forced termination
* on dispose. If @timeout is 0, it doesn't wait
* termination of external process. The default value is 10.
*
* Since: 1.1.5
*/
void gcut_process_set_forced_termination_wait_time
(GCutProcess *process,
guint timeout);
/**
* gcut_process_get_event_loop:
* @process: a #GCutProcess
*
* Gets a event loop using by the @process.
*
* Returns: a #GCutEventLoop.
*
* Since: 1.1.6
*/
GCutEventLoop *gcut_process_get_event_loop
(GCutProcess *process);
/**
* gcut_process_set_event_loop:
* @process: a #GCutProcess
* @loop: the event loop or %NULL
*
* Sets a event loop for the @process. If @loop is %NULL,
* the default GLib event loop will be used.
*
* Since: 1.1.6
*/
void gcut_process_set_event_loop
(GCutProcess *process,
GCutEventLoop *loop);
G_END_DECLS
#endif /* __GCUT_PROCESS_H__ */
/*
vi:ts=4:nowrap:ai:expandtab:sw=4
*/
|