GumDisposable

GumDisposable — timer-based auto disposable object

Functions

Properties

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

Signals

void disposing Action

Object Hierarchy

    GObject
    ╰── GumDisposable

Includes

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

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
}

Functions

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.

Parameters

self

an instance of GumDisposable.

[transfer none]

dispose

dispose flag

 

gum_disposable_get_auto_dispose ()

gboolean
gum_disposable_get_auto_dispose (GumDisposable *self);

Gets the auto-dispose value.

Parameters

self

an instance of GumDisposable.

[transfer none]

Returns

the auto-dispose value of the object.


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.

Parameters

self

an instance of GumDisposable.

[transfer none]

timeout

timeout value in seconds

 

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.

Parameters

self

an instance of GumDisposable.

[transfer none]

Types and Values

Property Details

The “auto-dispose” property

  “auto-dispose”             gboolean

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.

Flags: Read / Write

Default value: TRUE


The “delete-later” property

  “delete-later”             gboolean

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.

Flags: Read

Default value: FALSE


The “timeout” property

  “timeout”                  guint

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

Flags: Read / Write

Default value: 0

Signal Details

The “disposing” signal

void
user_function (GumDisposable *object,
               gpointer       user_data)

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

Parameters

object

the object which emits the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Action