| 1 |
/* |
| 2 |
* Copyright (C) 2013 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef __COCKPIT_PIPE_H__ |
| 7 |
#define __COCKPIT_PIPE_H__ |
| 8 |
|
| 9 |
#include <gio/gio.h> |
| 10 |
|
| 11 |
G_BEGIN_DECLS |
| 12 |
|
| 13 |
typedef enum { |
| 14 |
COCKPIT_PIPE_FLAGS_NONE = 0, |
| 15 |
COCKPIT_PIPE_STDERR_TO_STDOUT = 1 << 1, |
| 16 |
COCKPIT_PIPE_STDERR_TO_NULL = 1 << 2, |
| 17 |
COCKPIT_PIPE_STDERR_TO_MEMORY = 1 << 3, |
| 18 |
} CockpitPipeFlags; |
| 19 |
|
| 20 |
#define COCKPIT_TYPE_PIPE (cockpit_pipe_get_type ()) |
| 21 |
G_DECLARE_DERIVABLE_TYPE(CockpitPipe, cockpit_pipe, COCKPIT, PIPE, GObject) |
| 22 |
|
| 23 |
struct _CockpitPipeClass { |
| 24 |
GObjectClass parent_class; |
| 25 |
|
| 26 |
/* signals */ |
| 27 |
|
| 28 |
void (* read) (CockpitPipe *pipe, |
| 29 |
GByteArray *buffer, |
| 30 |
gboolean eof); |
| 31 |
|
| 32 |
void (* close) (CockpitPipe *pipe, |
| 33 |
const gchar *problem); |
| 34 |
}; |
| 35 |
|
| 36 |
CockpitPipe * cockpit_pipe_new (const gchar *name, |
| 37 |
gint in_fd, |
| 38 |
gint out_fd); |
| 39 |
|
| 40 |
CockpitPipe * cockpit_pipe_new_user_fd (const gchar *name, |
| 41 |
gint fd); |
| 42 |
|
| 43 |
CockpitPipe * cockpit_pipe_spawn (const gchar **argv, |
| 44 |
const gchar **env, |
| 45 |
const gchar *directory, |
| 46 |
CockpitPipeFlags flags); |
| 47 |
|
| 48 |
CockpitPipe * cockpit_pipe_connect (const gchar *name, |
| 49 |
GSocketAddress *address); |
| 50 |
|
| 51 |
/* HACK: Trying to debug self->priv->closed assertion */ |
| 52 |
#define cockpit_pipe_write(s, d) (_cockpit_pipe_write (s, d, G_STRFUNC, __LINE__)) |
| 53 |
|
| 54 |
void _cockpit_pipe_write (CockpitPipe *self, |
| 55 |
GBytes *data, |
| 56 |
const gchar *caller, |
| 57 |
gint line); |
| 58 |
|
| 59 |
void cockpit_pipe_close (CockpitPipe *self, |
| 60 |
const gchar *problem); |
| 61 |
|
| 62 |
gint cockpit_pipe_exit_status (CockpitPipe *self); |
| 63 |
|
| 64 |
const gchar * cockpit_pipe_get_name (CockpitPipe *self); |
| 65 |
|
| 66 |
GByteArray * cockpit_pipe_get_buffer (CockpitPipe *self); |
| 67 |
|
| 68 |
GByteArray * cockpit_pipe_get_stderr (CockpitPipe *self); |
| 69 |
|
| 70 |
gchar * cockpit_pipe_take_stderr_as_utf8 (CockpitPipe *self); |
| 71 |
|
| 72 |
gboolean cockpit_pipe_get_pid (CockpitPipe *self, |
| 73 |
GPid *pid); |
| 74 |
|
| 75 |
gboolean cockpit_pipe_is_closed (CockpitPipe *self); |
| 76 |
|
| 77 |
void cockpit_pipe_skip (GByteArray *buffer, |
| 78 |
gsize skip); |
| 79 |
|
| 80 |
GBytes * cockpit_pipe_consume (GByteArray *buffer, |
| 81 |
gsize before, |
| 82 |
gsize length, |
| 83 |
gsize after); |
| 84 |
|
| 85 |
G_END_DECLS |
| 86 |
|
| 87 |
#endif /* __COCKPIT_PIPE_H__ */ |