Back to index

dbus-test-runner  12.10.0
Classes | Defines | Enumerations | Functions | Variables
task.c File Reference
#include "dbus-test.h"
#include <gio/gio.h>

Go to the source code of this file.

Classes

struct  _DbusTestTaskPrivate

Defines

#define DBUS_TEST_TASK_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUS_TEST_TYPE_TASK, DbusTestTaskPrivate))

Enumerations

enum  { STATE_CHANGED, LAST_SIGNAL }

Functions

static void dbus_test_task_class_init (DbusTestTaskClass *klass)
static void dbus_test_task_init (DbusTestTask *self)
static void dbus_test_task_dispose (GObject *object)
static void dbus_test_task_finalize (GObject *object)
 G_DEFINE_TYPE (DbusTestTask, dbus_test_task, G_TYPE_OBJECT)
DbusTestTask * dbus_test_task_new (void)
void dbus_test_task_set_name (DbusTestTask *task, const gchar *name)
void dbus_test_task_set_name_spacing (DbusTestTask *task, glong chars)
void dbus_test_task_set_wait_for (DbusTestTask *task, const gchar *dbus_name)
void dbus_test_task_set_return (DbusTestTask *task, DbusTestTaskReturn ret)
void dbus_test_task_print (DbusTestTask *task, const gchar *message)
DbusTestTaskState dbus_test_task_get_state (DbusTestTask *task)
DbusTestTaskReturn dbus_test_task_get_return (DbusTestTask *task)
static void wait_for_found (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
void dbus_test_task_run (DbusTestTask *task)
gboolean dbus_test_task_passed (DbusTestTask *task)
const gchar * dbus_test_task_get_name (DbusTestTask *task)
const gchar * dbus_test_task_get_wait_for (DbusTestTask *task)

Variables

static guint signals [LAST_SIGNAL] = {0}

Class Documentation

struct _DbusTestTaskPrivate

Definition at line 27 of file task.c.

Class Members
gboolean been_run
gchar * name
gchar * name_padded
glong padding_cnt
DbusTestTaskReturn return_type
gchar * wait_for
guint wait_task

Define Documentation

#define DBUS_TEST_TASK_GET_PRIVATE (   o)    (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUS_TEST_TYPE_TASK, DbusTestTaskPrivate))

Definition at line 46 of file task.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
STATE_CHANGED 
LAST_SIGNAL 

Definition at line 41 of file task.c.

     {
       STATE_CHANGED,
       LAST_SIGNAL /* Don't touch! */
};

Function Documentation

static void dbus_test_task_class_init ( DbusTestTaskClass *  klass) [static]

Definition at line 59 of file task.c.

{
       GObjectClass *object_class = G_OBJECT_CLASS (klass);

       g_type_class_add_private (klass, sizeof (DbusTestTaskPrivate));

       object_class->dispose = dbus_test_task_dispose;
       object_class->finalize = dbus_test_task_finalize;

       klass->run = NULL;
       klass->get_state = NULL;
       klass->get_passed = NULL;

       signals[STATE_CHANGED]  = g_signal_new(DBUS_TEST_TASK_SIGNAL_STATE_CHANGED,
                                              G_TYPE_FROM_CLASS (klass),
                                              G_SIGNAL_RUN_LAST,
                                              G_STRUCT_OFFSET (DbusTestTaskClass, state_changed),
                                              NULL, NULL,
                                              g_cclosure_marshal_VOID__INT,
                                              G_TYPE_NONE, 1, G_TYPE_INT, G_TYPE_NONE);

       return;
}

Here is the call graph for this function:

static void dbus_test_task_dispose ( GObject *  object) [static]

Definition at line 105 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(object));
       DbusTestTask * self = DBUS_TEST_TASK(object);

       if (self->priv->wait_task != 0) {
              g_bus_unwatch_name(self->priv->wait_task);
              self->priv->wait_task = 0;
       }

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

Here is the caller graph for this function:

static void dbus_test_task_finalize ( GObject *  object) [static]

Definition at line 120 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(object));
       DbusTestTask * self = DBUS_TEST_TASK(object);

       g_free(self->priv->name);
       g_free(self->priv->name_padded);
       g_free(self->priv->wait_for);

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

Here is the caller graph for this function:

const gchar* dbus_test_task_get_name ( DbusTestTask *  task)

Definition at line 335 of file task.c.

{
       g_return_val_if_fail(DBUS_TEST_IS_TASK(task), NULL);

       return task->priv->name;
}

Here is the caller graph for this function:

Definition at line 253 of file task.c.

{
       g_return_val_if_fail(DBUS_TEST_IS_TASK(task), DBUS_TEST_TASK_RETURN_IGNORE);

       return task->priv->return_type;
}

Here is the caller graph for this function:

DbusTestTaskState dbus_test_task_get_state ( DbusTestTask *  task)

Definition at line 232 of file task.c.

{
       g_return_val_if_fail(DBUS_TEST_IS_TASK(task), DBUS_TEST_TASK_STATE_FINISHED);

       if (task->priv->wait_task != 0) {
              return DBUS_TEST_TASK_STATE_WAITING;
       }

       DbusTestTaskClass * klass = DBUS_TEST_TASK_GET_CLASS(task);
       if (klass->get_state != NULL) {
              return klass->get_state(task);
       }

       if (task->priv->been_run) {
              return DBUS_TEST_TASK_STATE_FINISHED;
       } else {
              return DBUS_TEST_TASK_STATE_INIT;
       }
}

Here is the caller graph for this function:

const gchar* dbus_test_task_get_wait_for ( DbusTestTask *  task)

Definition at line 343 of file task.c.

{
       g_return_val_if_fail(DBUS_TEST_IS_TASK(task), NULL);

       return task->priv->wait_for;
}

Here is the caller graph for this function:

static void dbus_test_task_init ( DbusTestTask *  self) [static]

Definition at line 84 of file task.c.

{
       static gint task_count = 0;

       self->priv = DBUS_TEST_TASK_GET_PRIVATE(self);

       self->priv->return_type = DBUS_TEST_TASK_RETURN_NORMAL;

       self->priv->wait_for = NULL;
       self->priv->wait_task = 0;

       self->priv->name = g_strdup_printf("task-%d", task_count++);
       self->priv->name_padded = NULL;
       self->priv->padding_cnt = 0;

       self->priv->been_run = FALSE;

       return;
}
DbusTestTask* dbus_test_task_new ( void  )

Definition at line 134 of file task.c.

{
       DbusTestTask * task = g_object_new(DBUS_TEST_TYPE_TASK,
                                          NULL);

       return task;
}

Here is the caller graph for this function:

gboolean dbus_test_task_passed ( DbusTestTask *  task)

Definition at line 311 of file task.c.

{
       g_return_val_if_fail(DBUS_TEST_IS_TASK(task), FALSE);

       /* If we don't care, we always pass */
       if (task->priv->return_type == DBUS_TEST_TASK_RETURN_IGNORE) {
              return TRUE;
       }

       DbusTestTaskClass * klass = DBUS_TEST_TASK_GET_CLASS(task);
       if (klass->get_passed == NULL) {
              return FALSE;
       }

       gboolean subret = klass->get_passed(task);

       if (task->priv->return_type == DBUS_TEST_TASK_RETURN_INVERT) {
              return !subret;
       }

       return subret;
}
void dbus_test_task_print ( DbusTestTask *  task,
const gchar *  message 
)

Definition at line 216 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(task));
       g_return_if_fail(message != NULL);

       gchar * name = task->priv->name;
       if (task->priv->name_padded != NULL) {
              name = task->priv->name_padded;
       }

       g_print("%s: %s\n", name, message);

       return;
}

Here is the caller graph for this function:

void dbus_test_task_run ( DbusTestTask *  task)

Definition at line 281 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(task));

       /* We're going to process the waiting at this level if we've been
          asked to do so */
       if (task->priv->wait_for != NULL) {
              task->priv->wait_task = g_bus_watch_name(G_BUS_TYPE_SESSION,
                                                       task->priv->wait_for,
                                                       G_BUS_NAME_WATCHER_FLAGS_NONE,
                                                       wait_for_found,
                                                       NULL,
                                                       task,
                                                       NULL);
              g_signal_emit(G_OBJECT(task), signals[STATE_CHANGED], 0, DBUS_TEST_TASK_STATE_WAITING, NULL);
              return;
       }

       DbusTestTaskClass * klass = DBUS_TEST_TASK_GET_CLASS(task);
       if (klass->run != NULL) {
              klass->run(task);
       } else {
              task->priv->been_run = TRUE;
              g_signal_emit(G_OBJECT(task), signals[STATE_CHANGED], 0, DBUS_TEST_TASK_STATE_FINISHED, NULL);
       }

       return;
}

Here is the call graph for this function:

void dbus_test_task_set_name ( DbusTestTask *  task,
const gchar *  name 
)

Definition at line 143 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(task));

       g_free(task->priv->name);
       g_free(task->priv->name_padded);

       task->priv->name = g_strdup(name);
       if (task->priv->padding_cnt != 0 && task->priv->name != NULL) {
              gchar * fillstr = g_strnfill(task->priv->padding_cnt - g_utf8_strlen(task->priv->name, -1), ' ');
              task->priv->name_padded = g_strconcat(task->priv->name, fillstr, NULL);
              g_free(fillstr);
       } else {
              task->priv->name_padded = NULL;
       }

       return;
}

Here is the caller graph for this function:

void dbus_test_task_set_name_spacing ( DbusTestTask *  task,
glong  chars 
)

Definition at line 163 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(task));

       g_free(task->priv->name_padded);
       task->priv->padding_cnt = chars;

       g_return_if_fail(task->priv->padding_cnt >= g_utf8_strlen(task->priv->name, -1));

       if (chars != 0 && task->priv->name != NULL) {
              gchar * fillstr = g_strnfill(task->priv->padding_cnt - g_utf8_strlen(task->priv->name, -1), ' ');
              task->priv->name_padded = g_strconcat(task->priv->name, fillstr, NULL);
              g_free(fillstr);
       } else {
              task->priv->name_padded = NULL;
       }

       return;
}
void dbus_test_task_set_return ( DbusTestTask *  task,
DbusTestTaskReturn  ret 
)

Definition at line 203 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(task));

       if (ret != task->priv->return_type && dbus_test_task_get_state(task) == DBUS_TEST_TASK_STATE_FINISHED) {
              g_warning("Changing return type after the task has finished");
       }

       task->priv->return_type = ret;
       return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dbus_test_task_set_wait_for ( DbusTestTask *  task,
const gchar *  dbus_name 
)

Definition at line 184 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(task));

       if (task->priv->wait_for != NULL) {
              g_free(task->priv->wait_for);
              task->priv->wait_for = NULL;
       }

       if (dbus_name == NULL) {
              return;
       }

       task->priv->wait_for = g_strdup(dbus_name);

       return;
}

Here is the caller graph for this function:

G_DEFINE_TYPE ( DbusTestTask  ,
dbus_test_task  ,
G_TYPE_OBJECT   
)
static void wait_for_found ( GDBusConnection *  connection,
const gchar *  name,
const gchar *  name_owner,
gpointer  user_data 
) [static]

Definition at line 261 of file task.c.

{
       g_return_if_fail(DBUS_TEST_IS_TASK(user_data));
       DbusTestTask * task = DBUS_TEST_TASK(user_data);

       g_bus_unwatch_name(task->priv->wait_task);
       task->priv->wait_task = 0;

       DbusTestTaskClass * klass = DBUS_TEST_TASK_GET_CLASS(task);
       if (klass->run != NULL) {
              klass->run(task);
       } else {
              task->priv->been_run = TRUE;
              g_signal_emit(G_OBJECT(task), signals[STATE_CHANGED], 0, DBUS_TEST_TASK_STATE_FINISHED, NULL);
       }

       return;
}

Here is the caller graph for this function:


Variable Documentation

guint signals[LAST_SIGNAL] = {0} [static]

Definition at line 56 of file task.c.