UDisksThreadedJob

UDisksThreadedJob — Job that runs in a thread

Functions

Properties

gpointer job-func Read / Write / Construct Only
gpointer user-data Read / Write / Construct Only
gpointer user-data-free-func Read / Write / Construct Only

Signals

Types and Values

Object Hierarchy

    GObject
    ╰── GDBusInterfaceSkeleton
        ╰── UDisksJobSkeleton
            ╰── UDisksBaseJob
                ╰── UDisksThreadedJob

Implemented Interfaces

UDisksThreadedJob implements GDBusInterface and UDisksJob.

Description

This type provides an implementation of the UDisksJob interface for jobs that run in a thread.

Functions

UDisksThreadedJobFunc ()

gboolean
(*UDisksThreadedJobFunc) (UDisksThreadedJob *job,
                          GCancellable *cancellable,
                          gpointer user_data,
                          GError **error);

Job function that runs in a separate thread.

Long-running jobs should periodically check cancellable to see if they have been cancelled.

Parameters

job

A UDisksThreadedJob.

 

cancellable

A GCancellable (never NULL).

 

user_data

User data passed when creating job .

 

error

Return location for error (never NULL).

 

Returns

TRUE if the job succeeded, FALSE if error is set.


udisks_threaded_job_new ()

UDisksThreadedJob *
udisks_threaded_job_new (UDisksThreadedJobFunc job_func,
                         gpointer user_data,
                         GDestroyNotify user_data_free_func,
                         UDisksDaemon *daemon,
                         GCancellable *cancellable);

Creates a new UDisksThreadedJob instance.

The job is not started automatically! Use udisks_threaded_job_start() to start the job after “threaded-job-completed” or “completed” signals are connected (to get notified when the job is done). This is to prevent a race condition with the job_func finishing before the signals are connected in which case the signal handlers are never triggered.

Parameters

job_func

The function to run in another thread.

 

user_data

User data to pass to job_func .

 

user_data_free_func

Function to free user_data with or NULL.

 

daemon

A UDisksDaemon.

 

cancellable

A GCancellable or NULL.

 

Returns

A new UDisksThreadedJob. Free with g_object_unref().


udisks_threaded_job_start ()

void
udisks_threaded_job_start (UDisksThreadedJob *job);

Start the job . Connect to the “threaded-job-completed” or “completed” signals to get notified when the job is done.

*/ void udisks_threaded_job_start (UDisksThreadedJob *job) { GTask *task;

task = g_task_new (job, udisks_base_job_get_cancellable (UDISKS_BASE_JOB (job)), job_complete_cb, NULL);

/* Only spawn the completed callback once the job func has finished, we don't support early return as there still might be some undergoing I/O. */ g_task_set_return_on_cancel (task, FALSE); g_task_run_in_thread (task, run_task_job); g_object_unref (task); }

/** udisks_threaded_job_run_sync: job : the job to run error : The GError set in case of failure

Run the job synchronously.

Connect to the “threaded-job-completed” or “completed” signals to get notified when the job is done.

Parameters

job

the job to start

 

Returns

TRUE if the job succeeded, FALSE in case of failure with error being set.


udisks_threaded_job_run_sync ()

gboolean
udisks_threaded_job_run_sync (UDisksThreadedJob *job,
                              GError **error);

udisks_threaded_job_get_user_data ()

gpointer
udisks_threaded_job_get_user_data (UDisksThreadedJob *job);

Gets the user_data parameter that job was constructed with.

Parameters

job

A UDisksThreadedJob.

 

Returns

A gpointer owned by job .

Types and Values

UDisksThreadedJob

typedef struct _UDisksThreadedJob UDisksThreadedJob;

The UDisksThreadedJob structure contains only private data and should only be accessed using the provided API.

Property Details

The “job-func” property

  “job-func”                 gpointer

The UDisksThreadedJobFunc to use.

Owner: UDisksThreadedJob

Flags: Read / Write / Construct Only


The “user-data” property

  “user-data”                gpointer

User data for the UDisksThreadedJobFunc.

Owner: UDisksThreadedJob

Flags: Read / Write / Construct Only


The “user-data-free-func” property

  “user-data-free-func”      gpointer

Free function for user data for the UDisksThreadedJobFunc.

Owner: UDisksThreadedJob

Flags: Read / Write / Construct Only

Signal Details

The “threaded-job-completed” signal

gboolean
user_function (UDisksThreadedJob *job,
               gboolean           result,
               GError            *error,
               gpointer           user_data)

Emitted when the threaded job is complete.

The default implementation simply emits the “completed” signal with success set to TRUE if, and only if, error is NULL. Otherwise, message on that signal is set to a string describing error . You can avoid the default implementation by returning TRUE from your signal handler.

This signal is emitted in the

thread-default main loop

of the thread that job was created in.

Parameters

job

The UDisksThreadedJob emitting the signal.

 

result

The gboolean returned by the UDisksThreadedJobFunc.

 

error

The GError set by the UDisksThreadedJobFunc.

 

user_data

user data set when the signal handler was connected.

 

Returns

TRUE if the signal was handled, FALSE to let other handlers run.

Flags: Run Last