![]() |
![]() |
![]() |
Libfm Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Signals |
struct FmJob; gpointer (*FmJobCallMainThreadFunc) (FmJob *job
,gpointer user_data
); struct FmJobClass; enum FmJobErrorAction; enum FmJobErrorSeverity; gint fm_job_ask (FmJob *job
,const char *question
,...
); gint fm_job_ask_valist (FmJob *job
,const char *question
,va_list options
); gint fm_job_askv (FmJob *job
,const char *question
,gchar * const *options
); gpointer fm_job_call_main_thread (FmJob *job
,FmJobCallMainThreadFunc func
,gpointer user_data
); void fm_job_cancel (FmJob *job
); FmJobErrorAction fm_job_emit_error (FmJob *job
,GError *err
,FmJobErrorSeverity severity
); void fm_job_finish (FmJob *job
); GCancellable * fm_job_get_cancellable (FmJob *job
); void fm_job_init_cancellable (FmJob *job
); gboolean fm_job_is_cancelled (FmJob *job
); gboolean fm_job_is_running (FmJob *job
); gboolean fm_job_run_async (FmJob *job
); gboolean fm_job_run_sync (FmJob *job
); gboolean fm_job_run_sync_with_mainloop (FmJob *job
); void fm_job_set_cancellable (FmJob *job
,GCancellable *cancellable
);
GObject +----FmJob +----FmDeepCountJob +----FmDirListJob +----FmFileInfoJob +----FmFileOpsJob
include
: libfm/fm-job.h
The FmJob can be used to create asynchronous jobs performing some
time-consuming tasks in another worker thread.
To run a FmJob in another thread you simply call
fm_job_run_async()
, and then the task will be done in another
worker thread. Later, when the job is finished, "finished" signal is
emitted. When the job is still running, it's possible to cancel it
from main thread by calling fm_job_cancel()
. Then, "cancelled" signal
will be emitted before emitting "finished" signal. You can also run
the job in blocking fashion instead of running it asynchronously by
calling fm_job_run_sync()
.
struct FmJobClass { GObjectClass parent_class; /* the class closures for signals */ void (*finished)(FmJob* job); guint (*error)(FmJob* job, GError* err, guint severity); /* guint above are: FmJobErrorAction and FmJobErrorSeverity */ void (*cancelled)(FmJob* job); gint (*ask)(FmJob* job, const gchar* question, gchar* const *options); /* routines used by methods */ gboolean (*run_async)(FmJob* job); /* for fm_job_run_async() */ gboolean (*run)(FmJob* job); /* for any fm_job_run_*() */ void (*cancel)(FmJob* job); /* for fm_job_cancel() */ };
the parent class | |
the class closure for the "finished" signal. | |
the class closure for the "error" signal. | |
the class closure for the "cancelled" signal. | |
the class closure for the "ask" signal. | |
the run_async function called to create a thread for
job execution. Returns TRUE if thread was created successfully.
The most probably should be not overridden by any derived class. |
|
the run function is called to perform actual job actions.
Returns value that will be returned from call fm_job_run_sync() .
Should be set by any class derived from FmJob. |
|
the cancel function is called when the job is cancelled.
It can perform some class-specific operations then. |
typedef enum { FM_JOB_CONTINUE, FM_JOB_RETRY, FM_JOB_ABORT } FmJobErrorAction;
The action that should be performed after error happened. Usually chosen by user.
typedef enum { FM_JOB_ERROR_WARNING, FM_JOB_ERROR_MILD, FM_JOB_ERROR_MODERATE, FM_JOB_ERROR_SEVERE, FM_JOB_ERROR_CRITICAL } FmJobErrorSeverity;
not an error, just a warning | |
no big deal, can be ignored most of the time | |
moderate errors | |
severe errors, whether to abort operation depends on error handlers | |
critical errors, the operation is aborted |
gint fm_job_ask (FmJob *job
,const char *question
,...
);
Asks the user for some interactions. The user will have a list of available options and should make a choice.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
This function should be called from working thread only.
|
the job that calls main thread |
|
the text to ask the user |
|
list of choices to give the user |
Returns : |
user's choice. |
Since 0.1.0
gint fm_job_ask_valist (FmJob *job
,const char *question
,va_list options
);
Asks the user for some interactions. The user will have a list of available options and should make a choice.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
This function should be called from working thread only.
|
the job that calls main thread |
|
the text to ask the user |
|
list of choices to give the user |
Returns : |
user's choice. |
Since 0.1.0
gint fm_job_askv (FmJob *job
,const char *question
,gchar * const *options
);
Asks the user for some interactions. The user will have a list of available options and should make a choice.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
This function should be called from working thread only.
|
the job that calls main thread |
|
the text to ask the user |
|
list of choices to give the user |
Returns : |
user's choice. |
Since 0.1.0
gpointer fm_job_call_main_thread (FmJob *job
,FmJobCallMainThreadFunc func
,gpointer user_data
);
Stops calling thread, waits main thread for idle, passes user_data
to callback func
in main thread, gathers result of callback, and
returns it to caller.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
This function should be called from working thread only.
|
the job that calls main thread |
|
callback to run from main thread |
|
user data for the callback |
Returns : |
return value from running func . |
Since 0.1.0
void fm_job_cancel (FmJob *job
);
Cancels the job
.
|
a job to cancel |
Since 0.1.0
FmJobErrorAction fm_job_emit_error (FmJob *job
,GError *err
,FmJobErrorSeverity severity
);
Emits an "error" signal in the main thread to notify it when an
error occurs.
The return value of this function is the return value returned by
the connected signal handlers.
If severity
is FM_JOB_ERROR_CRITICAL, the returned value is ignored and
fm_job_cancel()
is called to abort the job. Otherwise, the signal
handler of this error can return FM_JOB_RETRY to ask for retrying the
failed operation, return FM_JOB_CONTINUE to ignore the error and
continue the remaining job, or return FM_JOB_ABORT to abort the job.
If FM_JOB_ABORT is returned by the signal handler, fm_job_cancel()
will be called in fm_job_emit_error()
.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
This function should be called from working thread only.
|
a job that emitted the signal |
|
an error descriptor |
|
severity of the error |
Returns : |
action that should be performed on that error. |
Since 0.1.0
void fm_job_finish (FmJob *job
);
Schedules the finishing of job. Once this function is called the
job
becomes invalid for the caller and should be not used anymore.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
This function should be called from working thread only.
|
the job that was finished |
Since 0.1.0
GCancellable * fm_job_get_cancellable (FmJob *job
);
Get an existing GCancellable object from job
for use with gio in
another job by calling fm_job_set_cancellable()
.
This can be used when you wish to share a cancellable object
among different jobs.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
|
the job to inspect |
Returns : |
a GCancellable object if it was initialized for job . |
Since 0.1.9
void fm_job_init_cancellable (FmJob *job
);
Used by derived classes to implement FmJobClass:run()
using gio inside.
This API tries to initialize a GCancellable object for use with gio and
should only be called once in the constructor of derived classes which
require the use of GCancellable.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
|
the job to init |
Since 0.1.0
gboolean fm_job_is_cancelled (FmJob *job
);
Checks if the job is already cancelled.
|
the job to inspect |
Returns : |
TRUE if the job is already cancelled. |
Since 0.1.9
gboolean fm_job_is_running (FmJob *job
);
Checks if the job is still running.
|
the job to inspect |
Returns : |
TRUE if the job is still running. |
Since 0.1.9
gboolean fm_job_run_async (FmJob *job
);
Starts the job
asyncronously creating new thread. If job starts
successfully then the "finished" signal will be emitted when
job
is either succeeded or was cancelled. If job
could not be
started then "cancelled" signal is emitted before return from
this function.
|
a job to run |
Returns : |
TRUE if job started successfully. |
Since 0.1.0
gboolean fm_job_run_sync (FmJob *job
);
Runs the job
in current thread in a blocking fashion. The job will
emit either "cancelled" signal if job was cancelled
or "finished" signal if it finished successfully.
|
a job to run |
Returns : |
TRUE if job ran successfully. |
Since 0.1.0
gboolean fm_job_run_sync_with_mainloop (FmJob *job
);
Runs the job
in current thread in a blocking fashion and an additional
mainloop being created to prevent blocking of user interface. If job
started successfully then "finished" signal is emitted when job
is either succeeded or was cancelled.
|
a job to run |
Returns : |
TRUE if job started successfully. |
Since 0.1.1
void fm_job_set_cancellable (FmJob *job
,GCancellable *cancellable
);
Lets the job to use an existing cancellable
object.
This can be used when you wish to share a cancellable object
among different jobs.
This should only be called before the job
is launched.
This APIs is private to FmJob and should only be used in the implementation of classes derived from FmJob.
|
the job to set |
|
a shared cancellable object. [allow-none] |
Since 0.1.0
"ask"
signalgint user_function (FmJob *job,
gpointer question,
gpointer options,
gpointer user_data) : Run Last
The "ask" signal is emitted when the job asks for some
user interactions. The user then will have a list of available
options
. If there is more than one handler connected to the
signal then only one of them will receive it.
|
a job that emitted the signal |
|
(const gchar *) a question to ask user |
|
(gchar* const *) list of choices to ask user |
|
user data set when the signal handler was connected. |
Returns : |
user's choice. |
Since 0.1.0
"cancelled"
signalvoid user_function (FmJob *job,
gpointer user_data) : Run First
The "cancelled" signal is emitted when the job is cancelled or aborted due to critical errors.
|
a job that emitted the signal |
|
user data set when the signal handler was connected. |
Since 0.1.0
"error"
signalguint user_function (FmJob *job,
GError *error,
guint severity,
gpointer user_data) : Run Last
The "error" signal is emitted when errors happen. A case if more than one handler is connected to this signal is ambiguous.
|
a job that emitted the signal |
|
an error descriptor |
|
FmJobErrorSeverity of the error |
|
user data set when the signal handler was connected. |
Returns : |
FmJobErrorAction that should be performed on that error. |
Since 0.1.0
"finished"
signalvoid user_function (FmJob *job,
gpointer user_data) : Run First
The "finished" signal is emitted after the job is finished.
The signal is never emitted if the fm_job_run_XXX function
returned FALSE
, in that case the "cancelled" signal will be
emitted instead.
|
a job that emitted the signal |
|
user data set when the signal handler was connected. |
Since 0.1.0