## ExoSimpleJob ExoSimpleJob — Simple interface to execute functions asynchronously |

## Synopsis

    #include <exo/exo.h>

                        ExoSimpleJob;
    gboolean            (*ExoSimpleJobFunc)                 (ExoJob *job,
                                                             GValueArray *param_values,
                                                             GError **error);
    ExoJob *            exo_simple_job_launch               (ExoSimpleJobFunc func,
                                                             guint n_param_values,
                                                             ...);

## Object Hierarchy

      GObject
       +----ExoJob
             +----ExoSimpleJob

## Description

ExoSimpleJob can be used to execute functions asynchronously in an ExoJob wrapper object. It is easier to use than the GThread system and provides basic signals to follow the progress of an operation.

## Details

### ExoSimpleJob

    typedef struct _ExoSimpleJob ExoSimpleJob;

The ExoSimpleJob struct contains only private fields and should not be directly accessed.

### ExoSimpleJobFunc ()

    gboolean            (*ExoSimpleJobFunc)                 (ExoJob *job,
                                                             GValueArray *param_values,
                                                             GError **error);

Used by the ExoSimpleJob to process the `job`. See `exo_simple_job_launch()` for further details.

`job` : | an ExoJob.
`param_values` : | a GValueArray of the GValues passed to `exo_simple_job_launch()`.
`error` : | return location for errors.
Returns : | `TRUE` on success, `FALSE` in case of an error.

### exo_simple_job_launch ()

    ExoJob *            exo_simple_job_launch               (ExoSimpleJobFunc func,
                                                             guint n_param_values,
                                                             ...);

Allocates a new ExoJob which executes the specified `func` with the specified parameters.

An example could be:

    static gboolean
    list_directory (ExoJob      *job,
                    GValueArray *param_values,
                    GError     **error)
    {
      GFileEnumerator *enumerator;
      GFileInfo       *info;
      GError          *err = NULL;
      GFile           *directory;

      if (exo_job_set_error_if_cancelled (EXO_JOB (job), error))
        return FALSE;

      directory = g_value_get_object (g_value_array_get_nth (param_values, 0));

      enumerator = g_file_enumerate_children (directory,
                                              "standard::display-name",
                                              G_FILE_QUERY_INFO_NONE,
                                              exo_job_get_cancellable (job),
                                              &err);

      if (err != NULL)
        {
          g_propagate_error (error, err);
          return FALSE;
        }

      while (TRUE)
        {
          info = g_file_enumerator_next_file (enumerator,
                                              exo_job_get_cancellable (job),
                                              &err);

          if (info == NULL)
            break;

          exo_job_info_message (job, _("Child: %s"),
                                g_file_info_get_display_name (info));

          g_object_unref (info);
        }

      g_object_unref (enumerator);

      if (err != NULL)
        {
          g_propagate_error (error, err);
          return FALSE;
        }
      else
        {
          return TRUE;
        }
    }

    ...

    GFile *file = g_file_new_for_path ("/home/user");
    ExoJob *job = exo_simple_job_launch (list_directory, 1, G_TYPE_FILE, file);
    g_signal_connect (job, "info-message", G_CALLBACK (update_some_widget), widget);
    g_signal_connect (job, "finished", G_CALLBACK (unref_the_job_object), NULL);

The caller is responsible to release the returned ExoJob object using `g_object_unref()` when no longer needed.

`func` : | the ExoSimpleJobFunc to execute the job.
`n_param_values` : | the number of parameters to pass to the `func`.
`...` : | a list of GType and parameter pairs (exactly `n_param_values` pairs) that are passed to `func`.
Returns : | the launched ExoJob.

## See Also

ExoJob