TnyDevice

TnyDevice — A type that defines a device

Synopsis




#define             TNY_TYPE_DEVICE_SIGNAL
                    TnyDevice;
                    TnyDeviceIface;
gboolean            tny_device_is_online                (TnyDevice *self);
void                tny_device_force_online             (TnyDevice *self);
void                tny_device_force_offline            (TnyDevice *self);
void                tny_device_reset                    (TnyDevice *self);

Object Hierarchy


  GInterface
   +----TnyDevice

Prerequisites

TnyDevice requires GObject.

Signals


  "connection-changed"                             : Run First

Description

A abstract type that defines a few device specific things like the online/offline status.

Details

TNY_TYPE_DEVICE_SIGNAL

#define TNY_TYPE_DEVICE_SIGNAL (tny_device_signal_get_type())


TnyDevice

typedef struct _TnyDevice TnyDevice;


TnyDeviceIface

typedef struct {
	GTypeInterface parent;

	gboolean (*is_online_func) (TnyDevice *self);

	void (*force_online_func) (TnyDevice *self);
	void (*force_offline_func) (TnyDevice *self);
	void (*reset_func) (TnyDevice *self);

	/* Signals */
	void (*connection_changed) (TnyDevice *self, gboolean online);
} TnyDeviceIface;


tny_device_is_online ()

gboolean            tny_device_is_online                (TnyDevice *self);

Example:

static void
connection_changed (TnyDevice *device, gboolean online, gpointer user_data)
{
     if (!online && tny_device_is_online (device))
          g_print ("Something is wrong\n");
}
TnyDevice *device = ...
g_signal_connect (G_OBJECT (device), "connection_changed",
      G_CALLBACK (connection_changed), self);

self : a TnyDevice object
Returns : Whether the device is online

tny_device_force_online ()

void                tny_device_force_online             (TnyDevice *self);

Force online status, so that tny_device_is_online() returns TRUE, regardless of whether there is an actual network connection. The connection_changed signal will be emitted if the online status is changed by this function, but note if a real network connection is made or lost later, the connection_changed signal will not be emitted again, and tny_device_is_online() will continue to return TRUE;

This might be used on platforms that cannot detect whether a network connection exists.

This will usually not attempt to make a real network connection.

See also tny_device_force_offline() and tny_device_reset().

self : a TnyDevice object

tny_device_force_offline ()

void                tny_device_force_offline            (TnyDevice *self);

Force offline status, so that tny_device_is_online() returns FALSE, regardless of whether there is an actual network connection. The connection_changed signal will be emitted if the online status is changed by this function, but note if a real network connection is made or lost later, the connection_changed signal will not be emitted again, and tny_device_is_online() will continue to return FALSE;

This might be used to mark a device as offline if the connection is partly unusable due to some specific error, such as a failure to access a server or to use a particular port, or if the user specifically chose "offline mode". It might also be used on platforms that cannot detect whether a network connection exists.

This will usually not attempt to disconnect a real network connection.

Example:

TnyDevice *device = ...
tny_device_force_offline (device);
if (tny_device_is_online (device))
     g_print ("Something is wrong\n");
tny_device_reset (device);

See also tny_device_force_online() and tny_device_reset().

self : a TnyDevice object

tny_device_reset ()

void                tny_device_reset                    (TnyDevice *self);

Reset the status (unforce the status).

This reverses the effects of tny_device_force_online() or tny_device_force_offline(), so that future changes of connection status will cause the connection_changed signal to be emitted, and tny_device_is_online() will return a correct value.

The connection_changed signal will be emitted if this tny_device_is_online() to return a different value than before, for instance if the network connection has actually become available or unavailable while the status was forced.

self : a TnyDevice object

Signal Details

The "connection-changed" signal

void                user_function                      (TnyDevice *self,
                                                        gboolean   arg1,
                                                        gpointer   user_data)      : Run First

Emitted when the connection status of a device changes. This signal will not be emitted in response to actual connection changes while the status is forced with tny_device_force_online() or tny_device_force_offline().

Implementors must make sure that the emissions of this signal always happen in the mainloop.

self : the object on which the signal is emitted
arg1 : Whether or not the device is now online
user_data : user data set when the signal handler was connected.
user_data : user data set when the signal handler was connected.

See Also

TnyDeviceSignal