GumDisposable

GumDisposable — timer-based auto disposable object

Synopsis

#include <gum/common/gum-disposable.h>

struct              GumDisposable;
struct              GumDisposableClass;
void                gum_disposable_delete_later         (GumDisposable *self);
gboolean            gum_disposable_get_auto_dispose     (GumDisposable *self);
void                gum_disposable_set_auto_dispose     (GumDisposable *self,
                                                         gboolean dispose);
void                gum_disposable_set_timeout          (GumDisposable *self,
                                                         guint timeout);

Object Hierarchy

  GObject
   +----GumDisposable

Properties

  "auto-dispose"             gboolean              : Read / Write
  "delete-later"             gboolean              : Read
  "timeout"                  guint                 : Read / Write

Signals

  "disposing"                                      : Action

Description

GumDisposable is used to dispose the object when the timer expires with the specified timeout value provided auto-dispose is enabled. A GObject which needs to be auto-disposable should derive itself from GumDisposable and can set the timeout value (at the time of object construction e.g.). One such example, which can make use of GumDisposable, is a DBus object as it may be required to destory after some period of inactivity.

Usage

Following code snippet demonstrates how to derive and use GumDisposable:


//gum-test-object.h
struct _GumTestObject
{
    GumDisposable parent;
};

struct _GumTestObjectClass
{
    GumDisposableClass parent_class;
};

//gum-test-object.c
GumTestObject *
gum_test_object_new ()
{
   GumTestObject *obj = g_object_new (GUM_TYPE_TEST_OBJECT, NULL);

   // ... other code

   // GumTestobject will be disposed after 5 seconds unless auto-dispose
   // is disabled by calling gum_disposable_set_auto_dispose (obj, FALSE)
   gint timeout = 5;
   gum_disposable_set_timeout (GUM_DISPOSABLE (obj), timeout);

   // ... other code
}

Details

struct GumDisposable

struct GumDisposable;

Opaque structure for the object.


struct GumDisposableClass

struct GumDisposableClass {
    GObjectClass parent_class;
};

Opaque structure for the class.

GObjectClass parent_class;

parent class object

gum_disposable_delete_later ()

void                gum_disposable_delete_later         (GumDisposable *self);

Sets the object to be deleted later. Once delete later is requested, the object should not be used.

self :

an instance of GumDisposable. [transfer none]

gum_disposable_get_auto_dispose ()

gboolean            gum_disposable_get_auto_dispose     (GumDisposable *self);

Gets the auto-dispose value.

self :

an instance of GumDisposable. [transfer none]

Returns :

the auto-dispose value of the object.

gum_disposable_set_auto_dispose ()

void                gum_disposable_set_auto_dispose     (GumDisposable *self,
                                                         gboolean dispose);

Sets the auto-dispose flag, and sets up the timer if needed.

self :

an instance of GumDisposable. [transfer none]

dispose :

dispose flag

gum_disposable_set_timeout ()

void                gum_disposable_set_timeout          (GumDisposable *self,
                                                         guint timeout);

Sets the timeout value and sets up the timer if needed. If timeout value is set to 0, the object is never disposed.

self :

an instance of GumDisposable. [transfer none]

timeout :

timeout value in seconds

Property Details

The "auto-dispose" property

  "auto-dispose"             gboolean              : Read / Write

This property holds the value of auto-dispose to be TRUE or FALSE. Default value is FALSE. If auto-dispose is TRUE, then object is auto-disposed otherwise not.

Default value: TRUE


The "delete-later" property

  "delete-later"             gboolean              : Read

This property is used when the object is asked to be deleted later. The object should not be used once gum_disposable_delete_later is requested for the object.

Default value: FALSE


The "timeout" property

  "timeout"                  guint                 : Read / Write

This property holds the value of timeout in seconds. Default value is 0. If timeout value is 0, the object never auto-dispose.

Default value: 0

Signal Details

The "disposing" signal

void                user_function                      (GumDisposable *object,
                                                        gpointer       user_data)      : Action

This signal is emitted when the object is about to be disposed.

object :

the object which emits the signal

user_data :

user data set when the signal handler was connected.