ExoSimpleJob

ExoSimpleJob — Simple interface to execute functions asynchronously

Functions

Types and Values

Object Hierarchy

    GObject
    ╰── ExoJob
        ╰── ExoSimpleJob

Includes

#include <exo/exo.h>

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.

Functions

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.

Parameters

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:

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
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.

Parameters

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.

Types and Values

ExoSimpleJob

typedef struct _ExoSimpleJob ExoSimpleJob;

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

See Also

ExoJob