Back to index

dbus-test-runner  12.10.0
Classes | Defines | Functions
process.c File Reference
#include "dbus-test.h"

Go to the source code of this file.

Classes

struct  _DbusTestProcessPrivate

Defines

#define DBUS_TEST_PROCESS_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUS_TEST_TYPE_PROCESS, DbusTestProcessPrivate))

Functions

static void dbus_test_process_class_init (DbusTestProcessClass *klass)
static void dbus_test_process_init (DbusTestProcess *self)
static void dbus_test_process_dispose (GObject *object)
static void dbus_test_process_finalize (GObject *object)
static void process_run (DbusTestTask *task)
static DbusTestTaskState get_state (DbusTestTask *task)
static gboolean get_passed (DbusTestTask *task)
 G_DEFINE_TYPE (DbusTestProcess, dbus_test_process, DBUS_TEST_TYPE_TASK)
static void proc_watcher (GPid pid, gint status, gpointer data)
static gboolean proc_writes (GIOChannel *channel, GIOCondition condition, gpointer data)
DbusTestProcess * dbus_test_process_new (const gchar *executable)
void dbus_test_process_append_param (DbusTestProcess *process, const gchar *parameter)

Class Documentation

struct _DbusTestProcessPrivate

Definition at line 26 of file process.c.

Class Members
gboolean complete
gchar * executable
guint io_watch
GList * parameters
GPid pid
gint status
guint watcher

Define Documentation

#define DBUS_TEST_PROCESS_GET_PRIVATE (   o)    (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUS_TEST_TYPE_PROCESS, DbusTestProcessPrivate))

Definition at line 38 of file process.c.


Function Documentation

void dbus_test_process_append_param ( DbusTestProcess *  process,
const gchar *  parameter 
)

Definition at line 256 of file process.c.

{
       g_return_if_fail(DBUS_TEST_IS_PROCESS(process));
       g_return_if_fail(parameter != NULL);

       process->priv->parameters = g_list_append(process->priv->parameters, g_strdup(parameter));

       return;
}

Here is the caller graph for this function:

static void dbus_test_process_class_init ( DbusTestProcessClass *  klass) [static]

Definition at line 52 of file process.c.

{
       GObjectClass *object_class = G_OBJECT_CLASS (klass);

       g_type_class_add_private (klass, sizeof (DbusTestProcessPrivate));

       object_class->dispose = dbus_test_process_dispose;
       object_class->finalize = dbus_test_process_finalize;

       DbusTestTaskClass * task_class = DBUS_TEST_TASK_CLASS(klass);

       task_class->run = process_run;
       task_class->get_state = get_state;
       task_class->get_passed = get_passed;

       return;
}

Here is the call graph for this function:

static void dbus_test_process_dispose ( GObject *  object) [static]

Definition at line 82 of file process.c.

{
       g_return_if_fail(DBUS_TEST_IS_PROCESS(object));
       DbusTestProcess * process = DBUS_TEST_PROCESS(object);

       if (process->priv->io_watch != 0) {
              g_source_remove(process->priv->io_watch);
              process->priv->io_watch = 0;
       }

       if (process->priv->watcher != 0) {
              g_source_remove(process->priv->watcher);
              process->priv->watcher = 0;
       }

       if (process->priv->pid != 0) {
              gchar * killstr = g_strdup_printf("kill -9 %d", process->priv->pid);
              g_spawn_command_line_async(killstr, NULL);
              g_free(killstr);

              g_spawn_close_pid(process->priv->pid);
              process->priv->pid = 0;
       }

       G_OBJECT_CLASS (dbus_test_process_parent_class)->dispose (object);
       return;
}

Here is the caller graph for this function:

static void dbus_test_process_finalize ( GObject *  object) [static]

Definition at line 111 of file process.c.

{
       g_return_if_fail(DBUS_TEST_IS_PROCESS(object));
       DbusTestProcess * process = DBUS_TEST_PROCESS(object);

       g_free(process->priv->executable);
       process->priv->executable = NULL;

       g_list_free_full(process->priv->parameters, g_free);
       process->priv->parameters = NULL;

       G_OBJECT_CLASS (dbus_test_process_parent_class)->finalize (object);
       return;
}

Here is the caller graph for this function:

static void dbus_test_process_init ( DbusTestProcess *  self) [static]

Definition at line 71 of file process.c.

{
       self->priv = DBUS_TEST_PROCESS_GET_PRIVATE(self);

       self->priv->executable = NULL;
       self->priv->parameters = NULL;

       return;
}
DbusTestProcess* dbus_test_process_new ( const gchar *  executable)

Definition at line 243 of file process.c.

{
       g_return_val_if_fail(executable != NULL, NULL);

       DbusTestProcess * proc = g_object_new(DBUS_TEST_TYPE_PROCESS,
                                             NULL);

       proc->priv->executable = g_strdup(executable);

       return proc;
}

Here is the caller graph for this function:

G_DEFINE_TYPE ( DbusTestProcess  ,
dbus_test_process  ,
DBUS_TEST_TYPE_TASK   
)
static gboolean get_passed ( DbusTestTask *  task) [static]

Definition at line 284 of file process.c.

{
       g_return_val_if_fail(DBUS_TEST_IS_PROCESS(task), FALSE);
       DbusTestProcess * process = DBUS_TEST_PROCESS(task);

       if (!process->priv->complete) {
              return FALSE;
       }

       if (process->priv->status == 0) {
              return TRUE;
       }

       return FALSE;
}

Here is the caller graph for this function:

static DbusTestTaskState get_state ( DbusTestTask *  task) [static]

Definition at line 267 of file process.c.

{
       g_return_val_if_fail(DBUS_TEST_IS_PROCESS(task), DBUS_TEST_TASK_STATE_FINISHED);
       DbusTestProcess * process = DBUS_TEST_PROCESS(task);

       if (process->priv->complete) {
              return DBUS_TEST_TASK_STATE_FINISHED;
       }

       if (process->priv->pid != 0) {
              return DBUS_TEST_TASK_STATE_RUNNING;
       }

       return DBUS_TEST_TASK_STATE_INIT;
}

Here is the caller graph for this function:

static void proc_watcher ( GPid  pid,
gint  status,
gpointer  data 
) [static]

Definition at line 127 of file process.c.

{
       g_return_if_fail(DBUS_TEST_IS_PROCESS(data));
       DbusTestProcess * process = DBUS_TEST_PROCESS(data);

       if (pid != 0) {
              g_spawn_close_pid(pid);
              process->priv->pid = 0;
       }

       process->priv->complete = TRUE;
       process->priv->status = status;

       g_signal_emit_by_name(G_OBJECT(process), DBUS_TEST_TASK_SIGNAL_STATE_CHANGED, DBUS_TEST_TASK_STATE_FINISHED, NULL);

       return;
}

Here is the caller graph for this function:

static gboolean proc_writes ( GIOChannel *  channel,
GIOCondition  condition,
gpointer  data 
) [static]

Definition at line 146 of file process.c.

{
       g_return_val_if_fail(DBUS_TEST_IS_PROCESS(data), FALSE);
       DbusTestProcess * process = DBUS_TEST_PROCESS(data);

       gchar * line;
       gsize termloc;
       gboolean done = FALSE;

       do {
              GIOStatus status = g_io_channel_read_line (channel, &line, NULL, &termloc, NULL);

              if (status == G_IO_STATUS_EOF) {
                     done = TRUE;
                     continue;
              }

              if (status != G_IO_STATUS_NORMAL) {
                     continue;
              }

              line[termloc] = '\0';

              dbus_test_task_print(DBUS_TEST_TASK(process), line);
              g_free(line);
       } while (G_IO_IN & g_io_channel_get_buffer_condition(channel));

       if (done) {
              process->priv->complete = TRUE;
              process->priv->status = -1;

              g_signal_emit_by_name(G_OBJECT(process), DBUS_TEST_TASK_SIGNAL_STATE_CHANGED, DBUS_TEST_TASK_STATE_FINISHED, NULL);
       }

       return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void process_run ( DbusTestTask *  task) [static]

Definition at line 184 of file process.c.

{
       g_return_if_fail(DBUS_TEST_IS_PROCESS(task));
       DbusTestProcess * process = DBUS_TEST_PROCESS(task);

       gchar ** argv;
       argv = g_new0(gchar *, g_list_length(process->priv->parameters) + 2);

       argv[0] = process->priv->executable;
       int i;
       for (i = 0; i < g_list_length(process->priv->parameters); i++) {
              argv[i + 1] = (gchar *)g_list_nth(process->priv->parameters, i)->data;
       }

       GError * error = NULL;
       gint proc_stdout;
       g_spawn_async_with_pipes(g_get_current_dir(),
                                argv, /* argv */
                                NULL, /* envp */
                                G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, /* flags */
                                NULL, /* child setup func */
                                NULL, /* child setup data */
                                                  &(process->priv->pid), /* PID */
                                NULL, /* stdin */
                                &proc_stdout, /* stdout */
                                NULL, /* stderr */
                                &error); /* error */
       g_free(argv);

       if (error != NULL) {
              g_warning("Unable to start process '%s': %s", process->priv->executable, error->message);
              process->priv->complete = TRUE;
              process->priv->status = -1;
              g_signal_emit_by_name(G_OBJECT(process), DBUS_TEST_TASK_SIGNAL_STATE_CHANGED, DBUS_TEST_TASK_STATE_FINISHED, NULL);
              return;
       }

       if (TRUE) {
              gchar * message = g_strdup_printf("Started with PID: %d", process->priv->pid);
              dbus_test_task_print(task, message);
              g_free(message);
       }

       GIOChannel * iochan = g_io_channel_unix_new(proc_stdout);
       g_io_channel_set_buffer_size(iochan, 10 * 1024 * 1024); /* 10 MB should be enough for anyone */
       process->priv->io_watch = g_io_add_watch(iochan,
                                                G_IO_IN, /* conditions */
                                                proc_writes, /* func */
                                                process); /* func data */
       g_io_channel_unref(iochan);

       process->priv->watcher = g_child_watch_add(process->priv->pid, proc_watcher, process);

       g_signal_emit_by_name(G_OBJECT(process), DBUS_TEST_TASK_SIGNAL_STATE_CHANGED, DBUS_TEST_TASK_STATE_RUNNING, NULL);

       return;
}

Here is the call graph for this function:

Here is the caller graph for this function: