Classes
The following classes are available globally.
-
The
Action
type acts as an owner of an underlyingGAction
instance. It provides the methods that can operate on this data type throughActionProtocol
conformance. UseAction
as a strong reference or owner of aGAction
instance.GAction
represents a single named action.The main interface to an action is that it can be activated with
g_action_activate()
. This results in the ‘activate’ signal being emitted. An activation has aGVariant
parameter (which may benil
). The correct type for the parameter is determined by a static parameter type (which is given at construction time).An action may optionally have a state, in which case the state may be set with
g_action_change_state()
. This call takes aGVariant
. The correct type for the state is determined by a static state type (which is given at construction time).The state may have a hint associated with it, specifying its valid range.
GAction
is merely the interface to the concept of an action, as described above. Various implementations of actions exist, includingGSimpleAction
.In all cases, the implementing class is responsible for storing the name of the action, the parameter type, the enabled state, the optional state type and the state and emitting the appropriate signals when these change. The implementor is responsible for filtering calls to
g_action_activate()
andg_action_change_state()
for type safety and for the state being enabled.Probably the only useful thing to do with a
See moreGAction
is to put it inside of aGSimpleActionGroup
.Declaration
Swift
open class Action : ActionProtocol
-
The
ActionGroup
type acts as an owner of an underlyingGActionGroup
instance. It provides the methods that can operate on this data type throughActionGroupProtocol
conformance. UseActionGroup
as a strong reference or owner of aGActionGroup
instance.GActionGroup
represents a group of actions. Actions can be used to expose functionality in a structured way, either from one part of a program to another, or to the outside world. Action groups are often used together with aGMenuModel
that provides additional representation data for displaying the actions to the user, e.g. in a menu.The main way to interact with the actions in a GActionGroup is to activate them with
g_action_group_activate_action()
. Activating an action may require aGVariant
parameter. The required type of the parameter can be inquired withg_action_group_get_action_parameter_type()
. Actions may be disabled, seeg_action_group_get_action_enabled()
. Activating a disabled action has no effect.Actions may optionally have a state in the form of a
GVariant
. The current state of an action can be inquired withg_action_group_get_action_state()
. Activating a stateful action may change its state, but it is also possible to set the state by callingg_action_group_change_action_state()
.As typical example, consider a text editing application which has an option to change the current font to ‘bold’. A good way to represent this would be a stateful action, with a boolean state. Activating the action would toggle the state.
Each action in the group has a unique name (which is a string). All method calls, except
g_action_group_list_actions()
take the name of an action as an argument.The
GActionGroup
API is meant to be the ‘public’ API to the action group. The calls here are exactly the interaction that ‘external forces’ (eg: UI, incoming D-Bus messages, etc.) are supposed to have with actions. ‘Internal’ APIs (ie: ones meant only to be accessed by the action group implementation) are found on subclasses. This is why you will find - for example -g_action_group_get_action_enabled()
but not an equivalentset()
call.Signals are emitted on the action group in response to state changes on individual actions.
Implementations of
See moreGActionGroup
should provide implementations for the virtual functionsg_action_group_list_actions()
andg_action_group_query_action()
. The other virtual functions should not be implemented - their “wrappers” are actually implemented with calls tog_action_group_query_action()
.Declaration
Swift
open class ActionGroup : ActionGroupProtocol
-
The
ActionMap
type acts as an owner of an underlyingGActionMap
instance. It provides the methods that can operate on this data type throughActionMapProtocol
conformance. UseActionMap
as a strong reference or owner of aGActionMap
instance.The GActionMap interface is implemented by
GActionGroup
implementations that operate by containing a number of namedGAction
instances, such asGSimpleActionGroup
.One useful application of this interface is to map the names of actions from various action groups to unique, prefixed names (e.g. by prepending “app.” or “win.”). This is the motivation for the ‘Map’ part of the interface name.
See moreDeclaration
Swift
open class ActionMap : ActionMapProtocol
-
The
AppInfo
type acts as an owner of an underlyingGAppInfo
instance. It provides the methods that can operate on this data type throughAppInfoProtocol
conformance. UseAppInfo
as a strong reference or owner of aGAppInfo
instance.GAppInfo
andGAppLaunchContext
are used for describing and launching applications installed on the system.As of GLib 2.20, URIs will always be converted to POSIX paths (using
g_file_get_path()
) when usingg_app_info_launch()
even if the application requested an URI and not a POSIX path. For example for a desktop-file based application with Exec keytotem
U`and a single URI,
sftp://foo/file.avi, then
/home/user/.gvfs/sftp on foo/file.aviwill be passed. This will only work if a set of suitable GIO extensions (such as gvfs 2.26 compiled with FUSE support), is available and operational; if this is not the case, the URI will be passed unmodified to the application. Some URIs, such as
mailto:`, of course cannot be mapped to a POSIX path (in gvfs there’s no FUSE mount for it); such URIs will be passed unmodified to the application.Specifically for gvfs 2.26 and later, the POSIX URI will be mapped back to the GIO URI in the
GFile
constructors (since gvfs implements theGVfs
extension point). As such, if the application needs to examine the URI, it needs to useg_file_get_uri()
or similar onGFile
. In other words, an application cannot assume that the URI passed to e.g.g_file_new_for_commandline_arg()
is equal to the result ofg_file_get_uri()
. The following snippet illustrates this:GFile *f; char *uri; file = g_file_new_for_commandline_arg (uri_from_commandline); uri = g_file_get_uri (file); strcmp (uri, uri_from_commandline) == 0; g_free (uri); if (g_file_has_uri_scheme (file, "cdda")) { // do something special with uri } g_object_unref (file);
This code will work when both
See morecdda://sr0/Track 1.wav
and/home/user/.gvfs/cdda on sr0/Track 1.wav
is passed to the application. It should be noted that it’s generally not safe for applications to rely on the format of a particular URIs. Different launcher applications (e.g. file managers) may have different ideas of what a given URI means.Declaration
Swift
open class AppInfo : AppInfoProtocol
-
The
AsyncInitable
type acts as an owner of an underlyingGAsyncInitable
instance. It provides the methods that can operate on this data type throughAsyncInitableProtocol
conformance. UseAsyncInitable
as a strong reference or owner of aGAsyncInitable
instance.This is the asynchronous version of
GInitable
; it behaves the same in all ways except that initialization is asynchronous. For more details see the descriptions onGInitable
.A class may implement both the
GInitable
andGAsyncInitable
interfaces.Users of objects implementing this are not intended to use the interface method directly; instead it will be used automatically in various ways. For C applications you generally just call
g_async_initable_new_async()
directly, or indirectly via afoo_thing_new_async()
wrapper. This will callg_async_initable_init_async()
under the cover, calling back withnil
and a setGError
on failure.A typical implementation might look something like this:
(C Language Example):
See moreenum { NOT_INITIALIZED, INITIALIZING, INITIALIZED }; static void _foo_ready_cb (Foo *self) { GList *l; self->priv->state = INITIALIZED; for (l = self->priv->init_results; l != NULL; l = l->next) { GTask *task = l->data; if (self->priv->success) g_task_return_boolean (task, TRUE); else g_task_return_new_error (task, ...); g_object_unref (task); } g_list_free (self->priv->init_results); self->priv->init_results = NULL; } static void foo_init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { Foo *self = FOO (initable); GTask *task; task = g_task_new (initable, cancellable, callback, user_data); switch (self->priv->state) { case NOT_INITIALIZED: _foo_get_ready (self); self->priv->init_results = g_list_append (self->priv->init_results, task); self->priv->state = INITIALIZING; break; case INITIALIZING: self->priv->init_results = g_list_append (self->priv->init_results, task); break; case INITIALIZED: if (!self->priv->success) g_task_return_new_error (task, ...); else g_task_return_boolean (task, TRUE); g_object_unref (task); break; } } static gboolean foo_init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) { g_return_val_if_fail (g_task_is_valid (result, initable), FALSE); return g_task_propagate_boolean (G_TASK (result), error); } static void foo_async_initable_iface_init (gpointer g_iface, gpointer data) { GAsyncInitableIface *iface = g_iface; iface->init_async = foo_init_async; iface->init_finish = foo_init_finish; }
Declaration
Swift
open class AsyncInitable : AsyncInitableProtocol
-
The
AsyncResult
type acts as an owner of an underlyingGAsyncResult
instance. It provides the methods that can operate on this data type throughAsyncResultProtocol
conformance. UseAsyncResult
as a strong reference or owner of aGAsyncResult
instance.Provides a base class for implementing asynchronous function results.
Asynchronous operations are broken up into two separate operations which are chained together by a
GAsyncReadyCallback
. To begin an asynchronous operation, provide aGAsyncReadyCallback
to the asynchronous function. This callback will be triggered when the operation has completed, and must be run in a later iteration of the thread-default main context from where the operation was initiated. It will be passed aGAsyncResult
instance filled with the details of the operation’s success or failure, the object the asynchronous function was started for and any error codes returned. The asynchronous callback function is then expected to call the corresponding"_finish()
“ function, passing the object the function was called for, theGAsyncResult
instance, and (optionally) anerror
to grab any error conditions that may have occurred.The
"_finish()
” function for an operation takes the generic result (of typeGAsyncResult
) and returns the specific result that the operation in question yields (e.g. aGFileEnumerator
for a “enumerate children” operation). If the result or error status of the operation is not needed, there is no need to call the"_finish()
“ function; GIO will take care of cleaning up the result and error information after theGAsyncReadyCallback
returns. You can passnil
for theGAsyncReadyCallback
if you don’t need to take any action at all after the operation completes. Applications may also take a reference to theGAsyncResult
and call"_finish()
” later; however, the"_finish()
“ function may be called at most once.Example of a typical asynchronous operation flow: (C Language Example):
void _theoretical_frobnitz_async (Theoretical *t, GCancellable *c, GAsyncReadyCallback cb, gpointer u); gboolean _theoretical_frobnitz_finish (Theoretical *t, GAsyncResult *res, GError **e); static void frobnitz_result_func (GObject *source_object, GAsyncResult *res, gpointer user_data) { gboolean success = FALSE; success = _theoretical_frobnitz_finish (source_object, res, NULL); if (success) g_printf ("Hurray!\n"); else g_printf ("Uh oh!\n"); ... } int main (int argc, void *argv[]) { ... _theoretical_frobnitz_async (theoretical_data, NULL, frobnitz_result_func, NULL); ... }
The callback for an asynchronous operation is called only once, and is always called, even in the case of a cancelled operation. On cancellation the result is a
G_IO_ERROR_CANCELLED
error.I/O Priority #
Many I/O-related asynchronous operations have a priority parameter, which is used in certain cases to determine the order in which operations are executed. They are not used to determine system-wide I/O scheduling. Priorities are integers, with lower numbers indicating higher priority. It is recommended to choose priorities between
See moreG_PRIORITY_LOW
andG_PRIORITY_HIGH
, withG_PRIORITY_DEFAULT
as a default.Declaration
Swift
open class AsyncResult : AsyncResultProtocol
-
The
Converter
type acts as an owner of an underlyingGConverter
instance. It provides the methods that can operate on this data type throughConverterProtocol
conformance. UseConverter
as a strong reference or owner of aGConverter
instance.GConverter
is implemented by objects that convert binary data in various ways. The conversion can be stateful and may fail at any place.Some example conversions are: character set conversion, compression, decompression and regular expression replace.
See moreDeclaration
Swift
open class Converter : ConverterProtocol
-
The
ActionEntry
type acts as an owner of an underlyingGActionEntry
instance. It provides the methods that can operate on this data type throughActionEntryProtocol
conformance. UseActionEntry
as a strong reference or owner of aGActionEntry
instance.This struct defines a single action. It is for use with
g_action_map_add_action_entries()
.The order of the items in the structure are intended to reflect frequency of use. It is permissible to use an incomplete initialiser in order to leave some of the later values as
nil
. All values aftername
are optional. Additional optional fields may be added in the future.See
See moreg_action_map_add_action_entries()
for an example.Declaration
Swift
open class ActionEntry : ActionEntryProtocol
-
The
ActionGroupInterface
type acts as an owner of an underlyingGActionGroupInterface
instance. It provides the methods that can operate on this data type throughActionGroupInterfaceProtocol
conformance. UseActionGroupInterface
as a strong reference or owner of aGActionGroupInterface
instance.The virtual function table for
See moreGActionGroup
.Declaration
Swift
open class ActionGroupInterface : ActionGroupInterfaceProtocol
-
The
ActionInterface
type acts as an owner of an underlyingGActionInterface
instance. It provides the methods that can operate on this data type throughActionInterfaceProtocol
conformance. UseActionInterface
as a strong reference or owner of aGActionInterface
instance.The virtual function table for
See moreGAction
.Declaration
Swift
open class ActionInterface : ActionInterfaceProtocol
-
The
ActionMapInterface
type acts as an owner of an underlyingGActionMapInterface
instance. It provides the methods that can operate on this data type throughActionMapInterfaceProtocol
conformance. UseActionMapInterface
as a strong reference or owner of aGActionMapInterface
instance.The virtual function table for
See moreGActionMap
.Declaration
Swift
open class ActionMapInterface : ActionMapInterfaceProtocol
-
The
AppInfoIface
type acts as an owner of an underlyingGAppInfoIface
instance. It provides the methods that can operate on this data type throughAppInfoIfaceProtocol
conformance. UseAppInfoIface
as a strong reference or owner of aGAppInfoIface
instance.Application Information interface, for operating system portability.
See moreDeclaration
Swift
open class AppInfoIface : AppInfoIfaceProtocol
-
The
See moreAppLaunchContextClass
type acts as an owner of an underlyingGAppLaunchContextClass
instance. It provides the methods that can operate on this data type throughAppLaunchContextClassProtocol
conformance. UseAppLaunchContextClass
as a strong reference or owner of aGAppLaunchContextClass
instance.Declaration
Swift
open class AppLaunchContextClass : AppLaunchContextClassProtocol
-
The
See moreAppLaunchContextPrivate
type acts as an owner of an underlyingGAppLaunchContextPrivate
instance. It provides the methods that can operate on this data type throughAppLaunchContextPrivateProtocol
conformance. UseAppLaunchContextPrivate
as a strong reference or owner of aGAppLaunchContextPrivate
instance.Declaration
Swift
open class AppLaunchContextPrivate : AppLaunchContextPrivateProtocol
-
The
ApplicationClass
type acts as an owner of an underlyingGApplicationClass
instance. It provides the methods that can operate on this data type throughApplicationClassProtocol
conformance. UseApplicationClass
as a strong reference or owner of aGApplicationClass
instance.Virtual function table for
See moreGApplication
.Declaration
Swift
open class ApplicationClass : ApplicationClassProtocol
-
The
ApplicationCommandLineClass
type acts as an owner of an underlyingGApplicationCommandLineClass
instance. It provides the methods that can operate on this data type throughApplicationCommandLineClassProtocol
conformance. UseApplicationCommandLineClass
as a strong reference or owner of aGApplicationCommandLineClass
instance.The
See moreGApplicationCommandLineClass
-struct contains private data only.Declaration
Swift
open class ApplicationCommandLineClass : ApplicationCommandLineClassProtocol
-
The
See moreApplicationCommandLinePrivate
type acts as an owner of an underlyingGApplicationCommandLinePrivate
instance. It provides the methods that can operate on this data type throughApplicationCommandLinePrivateProtocol
conformance. UseApplicationCommandLinePrivate
as a strong reference or owner of aGApplicationCommandLinePrivate
instance.Declaration
Swift
open class ApplicationCommandLinePrivate : ApplicationCommandLinePrivateProtocol
-
The
See moreApplicationPrivate
type acts as an owner of an underlyingGApplicationPrivate
instance. It provides the methods that can operate on this data type throughApplicationPrivateProtocol
conformance. UseApplicationPrivate
as a strong reference or owner of aGApplicationPrivate
instance.Declaration
Swift
open class ApplicationPrivate : ApplicationPrivateProtocol
-
The
AsyncInitableIface
type acts as an owner of an underlyingGAsyncInitableIface
instance. It provides the methods that can operate on this data type throughAsyncInitableIfaceProtocol
conformance. UseAsyncInitableIface
as a strong reference or owner of aGAsyncInitableIface
instance.Provides an interface for asynchronous initializing object such that initialization may fail.
See moreDeclaration
Swift
open class AsyncInitableIface : AsyncInitableIfaceProtocol
-
The
AsyncResultIface
type acts as an owner of an underlyingGAsyncResultIface
instance. It provides the methods that can operate on this data type throughAsyncResultIfaceProtocol
conformance. UseAsyncResultIface
as a strong reference or owner of aGAsyncResultIface
instance.Interface definition for
See moreGAsyncResult
.Declaration
Swift
open class AsyncResultIface : AsyncResultIfaceProtocol
-
The
See moreBufferedInputStreamClass
type acts as an owner of an underlyingGBufferedInputStreamClass
instance. It provides the methods that can operate on this data type throughBufferedInputStreamClassProtocol
conformance. UseBufferedInputStreamClass
as a strong reference or owner of aGBufferedInputStreamClass
instance.Declaration
Swift
open class BufferedInputStreamClass : BufferedInputStreamClassProtocol
-
The
AppInfoMonitor
type acts as a reference-counted owner of an underlyingGAppInfoMonitor
instance. It provides the methods that can operate on this data type throughAppInfoMonitorProtocol
conformance. UseAppInfoMonitor
as a strong reference or owner of aGAppInfoMonitor
instance.GAppInfoMonitor
is a very simple object used for monitoring the app info database for changes (ie: newly installed or removed applications).Call
g_app_info_monitor_get()
to get aGAppInfoMonitor
and connect to the “changed” signal.In the usual case, applications should try to make note of the change (doing things like invalidating caches) but not act on it. In particular, applications should avoid making calls to
See moreGAppInfo
APIs in response to the change signal, deferring these until the time that the data is actually required. The exception to this case is when application information is actually being displayed on the screen (eg: during a search or when the list of all applications is shown). The reason for this is that changes to the list of installed applications often come in groups (like during system updates) and rescanning the list on every change is pointless and expensive.Declaration
Swift
open class AppInfoMonitor : Object, AppInfoMonitorProtocol
-
The
AppLaunchContext
type acts as a reference-counted owner of an underlyingGAppLaunchContext
instance. It provides the methods that can operate on this data type throughAppLaunchContextProtocol
conformance. UseAppLaunchContext
as a strong reference or owner of aGAppLaunchContext
instance.Integrating the launch with the launching application. This is used to handle for instance startup notification and launching the new application on the same screen as the launching window.
See moreDeclaration
Swift
open class AppLaunchContext : Object, AppLaunchContextProtocol
-
The
Application
type acts as a reference-counted owner of an underlyingGApplication
instance. It provides the methods that can operate on this data type throughApplicationProtocol
conformance. UseApplication
as a strong reference or owner of aGApplication
instance.A
GApplication
is the foundation of an application. It wraps some low-level platform-specific services and is intended to act as the foundation for higher-level application classes such asGtkApplication
orMxApplication
. In general, you should not use this class outside of a higher level framework.GApplication provides convenient life cycle management by maintaining a “use count” for the primary application instance. The use count can be changed using
g_application_hold()
andg_application_release()
. If it drops to zero, the application exits. Higher-level classes such asGtkApplication
employ the use count to ensure that the application stays alive as long as it has any opened windows.Another feature that GApplication (optionally) provides is process uniqueness. Applications can make use of this functionality by providing a unique application ID. If given, only one application with this ID can be running at a time per session. The session concept is platform-dependent, but corresponds roughly to a graphical desktop login. When your application is launched again, its arguments are passed through platform communication to the already running program. The already running instance of the program is called the “primary instance”; for non-unique applications this is the always the current instance. On Linux, the D-Bus session bus is used for communication.
The use of
GApplication
differs from some other commonly-used uniqueness libraries (such as libunique) in important ways. The application is not expected to manually register itself and check if it is the primary instance. Instead, themain()
function of aGApplication
should do very little more than instantiating the application instance, possibly connecting signal handlers, then callingg_application_run()
. All checks for uniqueness are done internally. If the application is the primary instance then the startup signal is emitted and the mainloop runs. If the application is not the primary instance then a signal is sent to the primary instance andg_application_run()
promptly returns. See the code examples below.If used, the expected form of an application identifier is the same as that of of a D-Bus well-known bus name. Examples include:
com.example.MyApp
,org.example.internal_apps.Calculator
,org._7_zip.Archiver
. For details on valid application identifiers, seeg_application_id_is_valid()
.On Linux, the application identifier is claimed as a well-known bus name on the user’s session bus. This means that the uniqueness of your application is scoped to the current session. It also means that your application may provide additional services (through registration of other object paths) at that bus name. The registration of these object paths should be done with the shared GDBus session bus. Note that due to the internal architecture of GDBus, method calls can be dispatched at any time (even if a main loop is not running). For this reason, you must ensure that any object paths that you wish to register are registered before
GApplication
attempts to acquire the bus name of your application (which happens ing_application_register()
). Unfortunately, this means that you cannot useg_application_get_is_remote()
to decide if you want to register object paths.GApplication also implements the
GActionGroup
andGActionMap
interfaces and lets you easily export actions by adding them withg_action_map_add_action()
. When invoking an action by callingg_action_group_activate_action()
on the application, it is always invoked in the primary instance. The actions are also exported on the session bus, and GIO provides theGDBusActionGroup
wrapper to conveniently access them remotely. GIO provides aGDBusMenuModel
wrapper for remote access to exportedGMenuModels
.There is a number of different entry points into a GApplication:
via ‘Activate’ (i.e. just starting the application)
via ‘Open’ (i.e. opening some files)
by handling a command-line
via activating an action
The
GApplication::startup
signal lets you handle the application initialization for all of these in a single place.Regardless of which of these entry points is used to start the application, GApplication passes some ‘platform data’ from the launching instance to the primary instance, in the form of a
GVariant
dictionary mapping strings to variants. To use platform data, override thebefore_emit
orafter_emit
virtual functions in yourGApplication
subclass. When dealing withGApplicationCommandLine
objects, the platform data is directly available viag_application_command_line_get_cwd()
,g_application_command_line_get_environ()
andg_application_command_line_get_platform_data()
.As the name indicates, the platform data may vary depending on the operating system, but it always includes the current directory (key “cwd”), and optionally the environment (ie the set of environment variables and their values) of the calling process (key “environ”). The environment is only added to the platform data if the
G_APPLICATION_SEND_ENVIRONMENT
flag is set.GApplication
subclasses can add their own platform data by overriding theadd_platform_data
virtual function. For instance,GtkApplication
adds startup notification data in this way.To parse commandline arguments you may handle the
GApplication::command
-line signal or override thelocal_command_line()
vfunc, to parse them in either the primary instance or the local instance, respectively.For an example of opening files with a GApplication, see gapplication-example-open.c.
For an example of using actions with GApplication, see gapplication-example-actions.c.
For an example of using extra D-Bus hooks with GApplication, see gapplication-example-dbushooks.c.
See moreDeclaration
Swift
open class Application : Object, ApplicationProtocol
-
The
ApplicationCommandLine
type acts as a reference-counted owner of an underlyingGApplicationCommandLine
instance. It provides the methods that can operate on this data type throughApplicationCommandLineProtocol
conformance. UseApplicationCommandLine
as a strong reference or owner of aGApplicationCommandLine
instance.GApplicationCommandLine
represents a command-line invocation of an application. It is created byGApplication
and emitted in theGApplication::command
-line signal and virtual function.The class contains the list of arguments that the program was invoked with. It is also possible to query if the commandline invocation was local (ie: the current process is running in direct response to the invocation) or remote (ie: some other process forwarded the commandline to this process).
The GApplicationCommandLine object can provide the
argc
andargv
parameters for use with theGOptionContext
command-line parsing API, with theg_application_command_line_get_arguments()
function. See gapplication-example-cmdline3.c for an example.The exit status of the originally-invoked process may be set and messages can be printed to stdout or stderr of that process. The lifecycle of the originally-invoked process is tied to the lifecycle of this object (ie: the process exits when the last reference is dropped).
The main use for
GApplicationCommandLine
(and theGApplication::command
-line signal) is ‘Emacs server’ like use cases: You can set theEDITOR
environment variable to have e.g. git use your favourite editor to edit commit messages, and if you already have an instance of the editor running, the editing will happen in the running instance, instead of opening a new one. An important aspect of this use case is that the process that gets started by git does not return until the editing is done.Normally, the commandline is completely handled in the
GApplication::command
-line handler. The launching instance exits once the signal handler in the primary instance has returned, and the return value of the signal handler becomes the exit status of the launching instance. (C Language Example):static int command_line (GApplication *application, GApplicationCommandLine *cmdline) { gchar **argv; gint argc; gint i; argv = g_application_command_line_get_arguments (cmdline, &argc); g_application_command_line_print (cmdline, "This text is written back\n" "to stdout of the caller\n"); for (i = 0; i < argc; i++) g_print ("argument %d: %s\n", i, argv[i]); g_strfreev (argv); return 0; }
The complete example can be found here: gapplication-example-cmdline.c
In more complicated cases, the handling of the comandline can be split between the launcher and the primary instance. (C Language Example):
static gboolean test_local_cmdline (GApplication *application, gchar ***arguments, gint *exit_status) { gint i, j; gchar **argv; argv = *arguments; i = 1; while (argv[i]) { if (g_str_has_prefix (argv[i], "--local-")) { g_print ("handling argument %s locally\n", argv[i]); g_free (argv[i]); for (j = i; argv[j]; j++) argv[j] = argv[j + 1]; } else { g_print ("not handling argument %s locally\n", argv[i]); i++; } } *exit_status = 0; return FALSE; } static void test_application_class_init (TestApplicationClass *class) { G_APPLICATION_CLASS (class)->local_command_line = test_local_cmdline; ... }
In this example of split commandline handling, options that start with
--local-
are handled locally, all other options are passed to theGApplication::command
-line handler which runs in the primary instance.The complete example can be found here: gapplication-example-cmdline2.c
If handling the commandline requires a lot of work, it may be better to defer it. (C Language Example):
static gboolean my_cmdline_handler (gpointer data) { GApplicationCommandLine *cmdline = data; // do the heavy lifting in an idle g_application_command_line_set_exit_status (cmdline, 0); g_object_unref (cmdline); // this releases the application return G_SOURCE_REMOVE; } static int command_line (GApplication *application, GApplicationCommandLine *cmdline) { // keep the application running until we are done with this commandline g_application_hold (application); g_object_set_data_full (G_OBJECT (cmdline), "application", application, (GDestroyNotify)g_application_release); g_object_ref (cmdline); g_idle_add (my_cmdline_handler, cmdline); return 0; }
In this example the commandline is not completely handled before the
GApplication::command
-line handler returns. Instead, we keep a reference to theGApplicationCommandLine
object and handle it later (in this example, in an idle). Note that it is necessary to hold the application until you are done with the commandline.The complete example can be found here: gapplication-example-cmdline3.c
See moreDeclaration
Swift
open class ApplicationCommandLine : Object, ApplicationCommandLineProtocol
-
The
BufferedInputStream
type acts as a reference-counted owner of an underlyingGBufferedInputStream
instance. It provides the methods that can operate on this data type throughBufferedInputStreamProtocol
conformance. UseBufferedInputStream
as a strong reference or owner of aGBufferedInputStream
instance.Buffered input stream implements
GFilterInputStream
and provides for buffered reads.By default,
GBufferedInputStream
‘s buffer size is set at 4 kilobytes.To create a buffered input stream, use
g_buffered_input_stream_new()
, org_buffered_input_stream_new_sized()
to specify the buffer’s size at construction.To get the size of a buffer within a buffered input stream, use
See moreg_buffered_input_stream_get_buffer_size()
. To change the size of a buffered input stream’s buffer, useg_buffered_input_stream_set_buffer_size()
. Note that the buffer’s size cannot be reduced below the size of the data within the buffer.Declaration
Swift
open class BufferedInputStream : FilterInputStream, BufferedInputStreamProtocol
-
The
See moreBufferedInputStreamPrivate
type acts as an owner of an underlyingGBufferedInputStreamPrivate
instance. It provides the methods that can operate on this data type throughBufferedInputStreamPrivateProtocol
conformance. UseBufferedInputStreamPrivate
as a strong reference or owner of aGBufferedInputStreamPrivate
instance.Declaration
Swift
open class BufferedInputStreamPrivate : BufferedInputStreamPrivateProtocol
-
The
See moreBufferedOutputStreamClass
type acts as an owner of an underlyingGBufferedOutputStreamClass
instance. It provides the methods that can operate on this data type throughBufferedOutputStreamClassProtocol
conformance. UseBufferedOutputStreamClass
as a strong reference or owner of aGBufferedOutputStreamClass
instance.Declaration
Swift
open class BufferedOutputStreamClass : BufferedOutputStreamClassProtocol
-
The
See moreBufferedOutputStreamPrivate
type acts as an owner of an underlyingGBufferedOutputStreamPrivate
instance. It provides the methods that can operate on this data type throughBufferedOutputStreamPrivateProtocol
conformance. UseBufferedOutputStreamPrivate
as a strong reference or owner of aGBufferedOutputStreamPrivate
instance.Declaration
Swift
open class BufferedOutputStreamPrivate : BufferedOutputStreamPrivateProtocol
-
The
See moreCancellableClass
type acts as an owner of an underlyingGCancellableClass
instance. It provides the methods that can operate on this data type throughCancellableClassProtocol
conformance. UseCancellableClass
as a strong reference or owner of aGCancellableClass
instance.Declaration
Swift
open class CancellableClass : CancellableClassProtocol
-
The
BufferedOutputStream
type acts as a reference-counted owner of an underlyingGBufferedOutputStream
instance. It provides the methods that can operate on this data type throughBufferedOutputStreamProtocol
conformance. UseBufferedOutputStream
as a strong reference or owner of aGBufferedOutputStream
instance.Buffered output stream implements
GFilterOutputStream
and provides for buffered writes.By default,
GBufferedOutputStream
‘s buffer size is set at 4 kilobytes.To create a buffered output stream, use
g_buffered_output_stream_new()
, org_buffered_output_stream_new_sized()
to specify the buffer’s size at construction.To get the size of a buffer within a buffered input stream, use
See moreg_buffered_output_stream_get_buffer_size()
. To change the size of a buffered output stream’s buffer, useg_buffered_output_stream_set_buffer_size()
. Note that the buffer’s size cannot be reduced below the size of the data within the buffer.Declaration
Swift
open class BufferedOutputStream : FilterOutputStream, BufferedOutputStreamProtocol
-
The
BytesIcon
type acts as a reference-counted owner of an underlyingGBytesIcon
instance. It provides the methods that can operate on this data type throughBytesIconProtocol
conformance. UseBytesIcon
as a strong reference or owner of aGBytesIcon
instance.
See moreGBytesIcon
specifies an image held in memory in a common format (usually png) to be used as icon.Declaration
Swift
open class BytesIcon : Object, BytesIconProtocol
-
The
Cancellable
type acts as a reference-counted owner of an underlyingGCancellable
instance. It provides the methods that can operate on this data type throughCancellableProtocol
conformance. UseCancellable
as a strong reference or owner of aGCancellable
instance.GCancellable is a thread-safe operation cancellation stack used throughout GIO to allow for cancellation of synchronous and asynchronous operations.
See moreDeclaration
Swift
open class Cancellable : Object, CancellableProtocol
-
The
See moreCancellablePrivate
type acts as an owner of an underlyingGCancellablePrivate
instance. It provides the methods that can operate on this data type throughCancellablePrivateProtocol
conformance. UseCancellablePrivate
as a strong reference or owner of aGCancellablePrivate
instance.Declaration
Swift
open class CancellablePrivate : CancellablePrivateProtocol
-
The
See moreCharsetConverterClass
type acts as an owner of an underlyingGCharsetConverterClass
instance. It provides the methods that can operate on this data type throughCharsetConverterClassProtocol
conformance. UseCharsetConverterClass
as a strong reference or owner of aGCharsetConverterClass
instance.Declaration
Swift
open class CharsetConverterClass : CharsetConverterClassProtocol
-
The
ConverterIface
type acts as an owner of an underlyingGConverterIface
instance. It provides the methods that can operate on this data type throughConverterIfaceProtocol
conformance. UseConverterIface
as a strong reference or owner of aGConverterIface
instance.Provides an interface for converting data from one type to another type. The conversion can be stateful and may fail at any place.
See moreDeclaration
Swift
open class ConverterIface : ConverterIfaceProtocol
-
The
See moreConverterInputStreamClass
type acts as an owner of an underlyingGConverterInputStreamClass
instance. It provides the methods that can operate on this data type throughConverterInputStreamClassProtocol
conformance. UseConverterInputStreamClass
as a strong reference or owner of aGConverterInputStreamClass
instance.Declaration
Swift
open class ConverterInputStreamClass : ConverterInputStreamClassProtocol
-
The
See moreConverterInputStreamPrivate
type acts as an owner of an underlyingGConverterInputStreamPrivate
instance. It provides the methods that can operate on this data type throughConverterInputStreamPrivateProtocol
conformance. UseConverterInputStreamPrivate
as a strong reference or owner of aGConverterInputStreamPrivate
instance.Declaration
Swift
open class ConverterInputStreamPrivate : ConverterInputStreamPrivateProtocol
-
The
See moreConverterOutputStreamClass
type acts as an owner of an underlyingGConverterOutputStreamClass
instance. It provides the methods that can operate on this data type throughConverterOutputStreamClassProtocol
conformance. UseConverterOutputStreamClass
as a strong reference or owner of aGConverterOutputStreamClass
instance.Declaration
Swift
open class ConverterOutputStreamClass : ConverterOutputStreamClassProtocol
-
The
See moreConverterOutputStreamPrivate
type acts as an owner of an underlyingGConverterOutputStreamPrivate
instance. It provides the methods that can operate on this data type throughConverterOutputStreamPrivateProtocol
conformance. UseConverterOutputStreamPrivate
as a strong reference or owner of aGConverterOutputStreamPrivate
instance.Declaration
Swift
open class ConverterOutputStreamPrivate : ConverterOutputStreamPrivateProtocol
-
The
CredentialsClass
type acts as an owner of an underlyingGCredentialsClass
instance. It provides the methods that can operate on this data type throughCredentialsClassProtocol
conformance. UseCredentialsClass
as a strong reference or owner of aGCredentialsClass
instance.Class structure for
See moreGCredentials
.Declaration
Swift
open class CredentialsClass : CredentialsClassProtocol
-
The
DBusAnnotationInfo
type acts as a reference-counted owner of an underlyingGDBusAnnotationInfo
instance. It provides the methods that can operate on this data type throughDBusAnnotationInfoProtocol
conformance. UseDBusAnnotationInfo
as a strong reference or owner of aGDBusAnnotationInfo
instance.Information about an annotation.
See moreDeclaration
Swift
open class DBusAnnotationInfo : DBusAnnotationInfoProtocol
-
The
CharsetConverter
type acts as a reference-counted owner of an underlyingGCharsetConverter
instance. It provides the methods that can operate on this data type throughCharsetConverterProtocol
conformance. UseCharsetConverter
as a strong reference or owner of aGCharsetConverter
instance.
See moreGCharsetConverter
is an implementation ofGConverter
based on GIConv.Declaration
Swift
open class CharsetConverter : Object, CharsetConverterProtocol
-
The
ConverterInputStream
type acts as a reference-counted owner of an underlyingGConverterInputStream
instance. It provides the methods that can operate on this data type throughConverterInputStreamProtocol
conformance. UseConverterInputStream
as a strong reference or owner of aGConverterInputStream
instance.Converter input stream implements
GInputStream
and allows conversion of data of various types during reading.As of GLib 2.34,
See moreGConverterInputStream
implementsGPollableInputStream
.Declaration
Swift
open class ConverterInputStream : FilterInputStream, ConverterInputStreamProtocol
-
The
ConverterOutputStream
type acts as a reference-counted owner of an underlyingGConverterOutputStream
instance. It provides the methods that can operate on this data type throughConverterOutputStreamProtocol
conformance. UseConverterOutputStream
as a strong reference or owner of aGConverterOutputStream
instance.Converter output stream implements
GOutputStream
and allows conversion of data of various types during reading.As of GLib 2.34,
See moreGConverterOutputStream
implementsGPollableOutputStream
.Declaration
Swift
open class ConverterOutputStream : FilterOutputStream, ConverterOutputStreamProtocol
-
The
Credentials
type acts as a reference-counted owner of an underlyingGCredentials
instance. It provides the methods that can operate on this data type throughCredentialsProtocol
conformance. UseCredentials
as a strong reference or owner of aGCredentials
instance.The
GCredentials
type is a reference-counted wrapper for native credentials. This information is typically used for identifying, authenticating and authorizing other processes.Some operating systems supports looking up the credentials of the remote peer of a communication endpoint - see e.g.
g_socket_get_credentials()
.Some operating systems supports securely sending and receiving credentials over a Unix Domain Socket, see
GUnixCredentialsMessage
,g_unix_connection_send_credentials()
andg_unix_connection_receive_credentials()
for details.On Linux, the native credential type is a struct ucred - see the
unix(7)
man page for details. This corresponds toG_CREDENTIALS_TYPE_LINUX_UCRED
.On FreeBSD, Debian GNU/kFreeBSD, and GNU/Hurd, the native credential type is a struct cmsgcred. This corresponds to
G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED
.On NetBSD, the native credential type is a struct unpcbid. This corresponds to
G_CREDENTIALS_TYPE_NETBSD_UNPCBID
.On OpenBSD, the native credential type is a struct sockpeercred. This corresponds to
G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED
.On Solaris (including OpenSolaris and its derivatives), the native credential type is a ucred_t. This corresponds to
See moreG_CREDENTIALS_TYPE_SOLARIS_UCRED
.Declaration
Swift
open class Credentials : Object, CredentialsProtocol
-
The
DBusActionGroup
type acts as a reference-counted owner of an underlyingGDBusActionGroup
instance. It provides the methods that can operate on this data type throughDBusActionGroupProtocol
conformance. UseDBusActionGroup
as a strong reference or owner of aGDBusActionGroup
instance.
See moreGDBusActionGroup
is an implementation of theGActionGroup
interface that can be used as a proxy for an action group that is exported over D-Bus withg_dbus_connection_export_action_group()
.Declaration
Swift
open class DBusActionGroup : Object, DBusActionGroupProtocol
-
The
DBusArgInfo
type acts as a reference-counted owner of an underlyingGDBusArgInfo
instance. It provides the methods that can operate on this data type throughDBusArgInfoProtocol
conformance. UseDBusArgInfo
as a strong reference or owner of aGDBusArgInfo
instance.Information about an argument for a method or a signal.
See moreDeclaration
Swift
open class DBusArgInfo : DBusArgInfoProtocol
-
The
DBusErrorEntry
type acts as an owner of an underlyingGDBusErrorEntry
instance. It provides the methods that can operate on this data type throughDBusErrorEntryProtocol
conformance. UseDBusErrorEntry
as a strong reference or owner of aGDBusErrorEntry
instance.Struct used in
See moreg_dbus_error_register_error_domain()
.Declaration
Swift
open class DBusErrorEntry : DBusErrorEntryProtocol
-
The
DBusInterfaceIface
type acts as an owner of an underlyingGDBusInterfaceIface
instance. It provides the methods that can operate on this data type throughDBusInterfaceIfaceProtocol
conformance. UseDBusInterfaceIface
as a strong reference or owner of aGDBusInterfaceIface
instance.Base type for D-Bus interfaces.
See moreDeclaration
Swift
open class DBusInterfaceIface : DBusInterfaceIfaceProtocol
-
The
DBusInterfaceInfo
type acts as a reference-counted owner of an underlyingGDBusInterfaceInfo
instance. It provides the methods that can operate on this data type throughDBusInterfaceInfoProtocol
conformance. UseDBusInterfaceInfo
as a strong reference or owner of aGDBusInterfaceInfo
instance.Information about a D-Bus interface.
See moreDeclaration
Swift
open class DBusInterfaceInfo : DBusInterfaceInfoProtocol
-
The
DBusInterfaceSkeletonClass
type acts as an owner of an underlyingGDBusInterfaceSkeletonClass
instance. It provides the methods that can operate on this data type throughDBusInterfaceSkeletonClassProtocol
conformance. UseDBusInterfaceSkeletonClass
as a strong reference or owner of aGDBusInterfaceSkeletonClass
instance.Class structure for
See moreGDBusInterfaceSkeleton
.Declaration
Swift
open class DBusInterfaceSkeletonClass : DBusInterfaceSkeletonClassProtocol
-
The
See moreDBusInterfaceSkeletonPrivate
type acts as an owner of an underlyingGDBusInterfaceSkeletonPrivate
instance. It provides the methods that can operate on this data type throughDBusInterfaceSkeletonPrivateProtocol
conformance. UseDBusInterfaceSkeletonPrivate
as a strong reference or owner of aGDBusInterfaceSkeletonPrivate
instance.Declaration
Swift
open class DBusInterfaceSkeletonPrivate : DBusInterfaceSkeletonPrivateProtocol
-
The
DBusInterfaceVTable
type acts as an owner of an underlyingGDBusInterfaceVTable
instance. It provides the methods that can operate on this data type throughDBusInterfaceVTableProtocol
conformance. UseDBusInterfaceVTable
as a strong reference or owner of aGDBusInterfaceVTable
instance.Virtual table for handling properties and method calls for a D-Bus interface.
Since 2.38, if you want to handle getting/setting D-Bus properties asynchronously, give
nil
as yourget_property()
orset_property()
function. The D-Bus call will be directed to yourmethod_call
function, with the providedinterface_name
set to “org.freedesktop.DBus.Properties”.Ownership of the
GDBusMethodInvocation
object passed to themethod_call()
function is transferred to your handler; you must call one of the methods ofGDBusMethodInvocation
to return a reply (possibly empty), or an error. These functions also take ownership of the passed-in invocation object, so unless the invocation object has otherwise been referenced, it will be then be freed. Calling one of these functions may be done within yourmethod_call()
implementation but it also can be done at a later point to handle the method asynchronously.The usual checks on the validity of the calls is performed. For
Get
calls, an error is automatically returned if the property does not exist or the permissions do not allow access. The same checks are performed forSet
calls, and the provided value is also checked for being the correct type.For both
Get
andSet
calls, theGDBusMethodInvocation
passed to themethod_call
handler can be queried withg_dbus_method_invocation_get_property_info()
to get a pointer to theGDBusPropertyInfo
of the property.If you have readable properties specified in your interface info, you must ensure that you either provide a non-
nil
get_property
()
function or provide implementations of both theGet
andGetAll
methods on org.freedesktop.DBus.Properties interface in yourmethod_call
function. Note that the required return type of theGet
call is(v)
, not the type of the property.GetAll
expects a return value of typea{sv}
.If you have writable properties specified in your interface info, you must ensure that you either provide a non-
See morenil
set_property
()
function or provide an implementation of theSet
call. If implementing the call, you must return the value of typeG_VARIANT_TYPE_UNIT
.Declaration
Swift
open class DBusInterfaceVTable : DBusInterfaceVTableProtocol
-
The
DBusMethodInfo
type acts as a reference-counted owner of an underlyingGDBusMethodInfo
instance. It provides the methods that can operate on this data type throughDBusMethodInfoProtocol
conformance. UseDBusMethodInfo
as a strong reference or owner of aGDBusMethodInfo
instance.Information about a method on an D-Bus interface.
See moreDeclaration
Swift
open class DBusMethodInfo : DBusMethodInfoProtocol
-
The
DBusNodeInfo
type acts as a reference-counted owner of an underlyingGDBusNodeInfo
instance. It provides the methods that can operate on this data type throughDBusNodeInfoProtocol
conformance. UseDBusNodeInfo
as a strong reference or owner of aGDBusNodeInfo
instance.Information about nodes in a remote object hierarchy.
See moreDeclaration
Swift
open class DBusNodeInfo : DBusNodeInfoProtocol
-
The
DBusObjectIface
type acts as an owner of an underlyingGDBusObjectIface
instance. It provides the methods that can operate on this data type throughDBusObjectIfaceProtocol
conformance. UseDBusObjectIface
as a strong reference or owner of aGDBusObjectIface
instance.Base object type for D-Bus objects.
See moreDeclaration
Swift
open class DBusObjectIface : DBusObjectIfaceProtocol
-
The
DBusObjectManagerClientClass
type acts as an owner of an underlyingGDBusObjectManagerClientClass
instance. It provides the methods that can operate on this data type throughDBusObjectManagerClientClassProtocol
conformance. UseDBusObjectManagerClientClass
as a strong reference or owner of aGDBusObjectManagerClientClass
instance.Class structure for
See moreGDBusObjectManagerClient
.Declaration
Swift
open class DBusObjectManagerClientClass : DBusObjectManagerClientClassProtocol
-
The
See moreDBusObjectManagerClientPrivate
type acts as an owner of an underlyingGDBusObjectManagerClientPrivate
instance. It provides the methods that can operate on this data type throughDBusObjectManagerClientPrivateProtocol
conformance. UseDBusObjectManagerClientPrivate
as a strong reference or owner of aGDBusObjectManagerClientPrivate
instance.Declaration
Swift
open class DBusObjectManagerClientPrivate : DBusObjectManagerClientPrivateProtocol
-
The
DBusObjectManagerIface
type acts as an owner of an underlyingGDBusObjectManagerIface
instance. It provides the methods that can operate on this data type throughDBusObjectManagerIfaceProtocol
conformance. UseDBusObjectManagerIface
as a strong reference or owner of aGDBusObjectManagerIface
instance.Base type for D-Bus object managers.
See moreDeclaration
Swift
open class DBusObjectManagerIface : DBusObjectManagerIfaceProtocol
-
The
DBusObjectManagerServerClass
type acts as an owner of an underlyingGDBusObjectManagerServerClass
instance. It provides the methods that can operate on this data type throughDBusObjectManagerServerClassProtocol
conformance. UseDBusObjectManagerServerClass
as a strong reference or owner of aGDBusObjectManagerServerClass
instance.Class structure for
See moreGDBusObjectManagerServer
.Declaration
Swift
open class DBusObjectManagerServerClass : DBusObjectManagerServerClassProtocol
-
The
See moreDBusObjectManagerServerPrivate
type acts as an owner of an underlyingGDBusObjectManagerServerPrivate
instance. It provides the methods that can operate on this data type throughDBusObjectManagerServerPrivateProtocol
conformance. UseDBusObjectManagerServerPrivate
as a strong reference or owner of aGDBusObjectManagerServerPrivate
instance.Declaration
Swift
open class DBusObjectManagerServerPrivate : DBusObjectManagerServerPrivateProtocol
-
The
DBusObjectProxyClass
type acts as an owner of an underlyingGDBusObjectProxyClass
instance. It provides the methods that can operate on this data type throughDBusObjectProxyClassProtocol
conformance. UseDBusObjectProxyClass
as a strong reference or owner of aGDBusObjectProxyClass
instance.Class structure for
See moreGDBusObjectProxy
.Declaration
Swift
open class DBusObjectProxyClass : DBusObjectProxyClassProtocol
-
The
See moreDBusObjectProxyPrivate
type acts as an owner of an underlyingGDBusObjectProxyPrivate
instance. It provides the methods that can operate on this data type throughDBusObjectProxyPrivateProtocol
conformance. UseDBusObjectProxyPrivate
as a strong reference or owner of aGDBusObjectProxyPrivate
instance.Declaration
Swift
open class DBusObjectProxyPrivate : DBusObjectProxyPrivateProtocol
-
The
DBusObjectSkeletonClass
type acts as an owner of an underlyingGDBusObjectSkeletonClass
instance. It provides the methods that can operate on this data type throughDBusObjectSkeletonClassProtocol
conformance. UseDBusObjectSkeletonClass
as a strong reference or owner of aGDBusObjectSkeletonClass
instance.Class structure for
See moreGDBusObjectSkeleton
.Declaration
Swift
open class DBusObjectSkeletonClass : DBusObjectSkeletonClassProtocol
-
The
See moreDBusObjectSkeletonPrivate
type acts as an owner of an underlyingGDBusObjectSkeletonPrivate
instance. It provides the methods that can operate on this data type throughDBusObjectSkeletonPrivateProtocol
conformance. UseDBusObjectSkeletonPrivate
as a strong reference or owner of aGDBusObjectSkeletonPrivate
instance.Declaration
Swift
open class DBusObjectSkeletonPrivate : DBusObjectSkeletonPrivateProtocol
-
The
DBusPropertyInfo
type acts as a reference-counted owner of an underlyingGDBusPropertyInfo
instance. It provides the methods that can operate on this data type throughDBusPropertyInfoProtocol
conformance. UseDBusPropertyInfo
as a strong reference or owner of aGDBusPropertyInfo
instance.Information about a D-Bus property on a D-Bus interface.
See moreDeclaration
Swift
open class DBusPropertyInfo : DBusPropertyInfoProtocol
-
The
DBusProxyClass
type acts as an owner of an underlyingGDBusProxyClass
instance. It provides the methods that can operate on this data type throughDBusProxyClassProtocol
conformance. UseDBusProxyClass
as a strong reference or owner of aGDBusProxyClass
instance.Class structure for
See moreGDBusProxy
.Declaration
Swift
open class DBusProxyClass : DBusProxyClassProtocol
-
The
See moreDBusProxyPrivate
type acts as an owner of an underlyingGDBusProxyPrivate
instance. It provides the methods that can operate on this data type throughDBusProxyPrivateProtocol
conformance. UseDBusProxyPrivate
as a strong reference or owner of aGDBusProxyPrivate
instance.Declaration
Swift
open class DBusProxyPrivate : DBusProxyPrivateProtocol
-
The
DBusSignalInfo
type acts as a reference-counted owner of an underlyingGDBusSignalInfo
instance. It provides the methods that can operate on this data type throughDBusSignalInfoProtocol
conformance. UseDBusSignalInfo
as a strong reference or owner of aGDBusSignalInfo
instance.Information about a signal on a D-Bus interface.
See moreDeclaration
Swift
open class DBusSignalInfo : DBusSignalInfoProtocol
-
The
DBusSubtreeVTable
type acts as an owner of an underlyingGDBusSubtreeVTable
instance. It provides the methods that can operate on this data type throughDBusSubtreeVTableProtocol
conformance. UseDBusSubtreeVTable
as a strong reference or owner of aGDBusSubtreeVTable
instance.Virtual table for handling subtrees registered with
See moreg_dbus_connection_register_subtree()
.Declaration
Swift
open class DBusSubtreeVTable : DBusSubtreeVTableProtocol
-
The
See moreDataInputStreamClass
type acts as an owner of an underlyingGDataInputStreamClass
instance. It provides the methods that can operate on this data type throughDataInputStreamClassProtocol
conformance. UseDataInputStreamClass
as a strong reference or owner of aGDataInputStreamClass
instance.Declaration
Swift
open class DataInputStreamClass : DataInputStreamClassProtocol
-
The
See moreDataInputStreamPrivate
type acts as an owner of an underlyingGDataInputStreamPrivate
instance. It provides the methods that can operate on this data type throughDataInputStreamPrivateProtocol
conformance. UseDataInputStreamPrivate
as a strong reference or owner of aGDataInputStreamPrivate
instance.Declaration
Swift
open class DataInputStreamPrivate : DataInputStreamPrivateProtocol
-
The
See moreDataOutputStreamClass
type acts as an owner of an underlyingGDataOutputStreamClass
instance. It provides the methods that can operate on this data type throughDataOutputStreamClassProtocol
conformance. UseDataOutputStreamClass
as a strong reference or owner of aGDataOutputStreamClass
instance.Declaration
Swift
open class DataOutputStreamClass : DataOutputStreamClassProtocol
-
The
See moreDataOutputStreamPrivate
type acts as an owner of an underlyingGDataOutputStreamPrivate
instance. It provides the methods that can operate on this data type throughDataOutputStreamPrivateProtocol
conformance. UseDataOutputStreamPrivate
as a strong reference or owner of aGDataOutputStreamPrivate
instance.Declaration
Swift
open class DataOutputStreamPrivate : DataOutputStreamPrivateProtocol
-
The
DatagramBasedInterface
type acts as an owner of an underlyingGDatagramBasedInterface
instance. It provides the methods that can operate on this data type throughDatagramBasedInterfaceProtocol
conformance. UseDatagramBasedInterface
as a strong reference or owner of aGDatagramBasedInterface
instance.Provides an interface for socket-like objects which have datagram semantics, following the Berkeley sockets API. The interface methods are thin wrappers around the corresponding virtual methods, and no pre-processing of inputs is implemented — so implementations of this API must handle all functionality documented in the interface methods.
See moreDeclaration
Swift
open class DatagramBasedInterface : DatagramBasedInterfaceProtocol
-
The
DriveIface
type acts as an owner of an underlyingGDriveIface
instance. It provides the methods that can operate on this data type throughDriveIfaceProtocol
conformance. UseDriveIface
as a strong reference or owner of aGDriveIface
instance.Interface for creating
See moreGDrive
implementations.Declaration
Swift
open class DriveIface : DriveIfaceProtocol
-
The
DtlsClientConnectionInterface
type acts as an owner of an underlyingGDtlsClientConnectionInterface
instance. It provides the methods that can operate on this data type throughDtlsClientConnectionInterfaceProtocol
conformance. UseDtlsClientConnectionInterface
as a strong reference or owner of aGDtlsClientConnectionInterface
instance.vtable for a
See moreGDtlsClientConnection
implementation.Declaration
Swift
open class DtlsClientConnectionInterface : DtlsClientConnectionInterfaceProtocol
-
The
DtlsConnectionInterface
type acts as an owner of an underlyingGDtlsConnectionInterface
instance. It provides the methods that can operate on this data type throughDtlsConnectionInterfaceProtocol
conformance. UseDtlsConnectionInterface
as a strong reference or owner of aGDtlsConnectionInterface
instance.Virtual method table for a
See moreGDtlsConnection
implementation.Declaration
Swift
open class DtlsConnectionInterface : DtlsConnectionInterfaceProtocol
-
The
DtlsServerConnectionInterface
type acts as an owner of an underlyingGDtlsServerConnectionInterface
instance. It provides the methods that can operate on this data type throughDtlsServerConnectionInterfaceProtocol
conformance. UseDtlsServerConnectionInterface
as a strong reference or owner of aGDtlsServerConnectionInterface
instance.vtable for a
See moreGDtlsServerConnection
implementation.Declaration
Swift
open class DtlsServerConnectionInterface : DtlsServerConnectionInterfaceProtocol
-
The
See moreEmblemClass
type acts as an owner of an underlyingGEmblemClass
instance. It provides the methods that can operate on this data type throughEmblemClassProtocol
conformance. UseEmblemClass
as a strong reference or owner of aGEmblemClass
instance.Declaration
Swift
open class EmblemClass : EmblemClassProtocol
-
The
DBusAuthObserver
type acts as a reference-counted owner of an underlyingGDBusAuthObserver
instance. It provides the methods that can operate on this data type throughDBusAuthObserverProtocol
conformance. UseDBusAuthObserver
as a strong reference or owner of aGDBusAuthObserver
instance.The
GDBusAuthObserver
type provides a mechanism for participating in how aGDBusServer
(or aGDBusConnection
) authenticates remote peers. Simply instantiate aGDBusAuthObserver
and connect to the signals you are interested in. Note that new signals may be added in the futureControlling Authentication Mechanisms
By default, a
GDBusServer
or server-sideGDBusConnection
will allow any authentication mechanism to be used. If you only want to allow D-Bus connections with theEXTERNAL
mechanism, which makes use of credentials passing and is the recommended mechanism for modern Unix platforms such as Linux and the BSD family, you would use a signal handler like this:(C Language Example):
static gboolean on_allow_mechanism (GDBusAuthObserver *observer, const gchar *mechanism, gpointer user_data) { if (g_strcmp0 (mechanism, "EXTERNAL") == 0) { return TRUE; } return FALSE; }
Controlling Authorization #
By default, a
GDBusServer
or server-sideGDBusConnection
will accept connections from any successfully authenticated user (but not from anonymous connections using theANONYMOUS
mechanism). If you only want to allow D-Bus connections from processes owned by the same uid as the server, you would use a signal handler like the following:(C Language Example):
See morestatic gboolean on_authorize_authenticated_peer (GDBusAuthObserver *observer, GIOStream *stream, GCredentials *credentials, gpointer user_data) { gboolean authorized; authorized = FALSE; if (credentials != NULL) { GCredentials *own_credentials; own_credentials = g_credentials_new (); if (g_credentials_is_same_user (credentials, own_credentials, NULL)) authorized = TRUE; g_object_unref (own_credentials); } return authorized; }
Declaration
Swift
open class DBusAuthObserver : Object, DBusAuthObserverProtocol
-
The
DBusConnection
type acts as a reference-counted owner of an underlyingGDBusConnection
instance. It provides the methods that can operate on this data type throughDBusConnectionProtocol
conformance. UseDBusConnection
as a strong reference or owner of aGDBusConnection
instance.The
GDBusConnection
type is used for D-Bus connections to remote peers such as a message buses. It is a low-level API that offers a lot of flexibility. For instance, it lets you establish a connection over any transport that can by represented as aGIOStream
.This class is rarely used directly in D-Bus clients. If you are writing a D-Bus client, it is often easier to use the
g_bus_own_name()
,g_bus_watch_name()
org_dbus_proxy_new_for_bus()
APIs.As an exception to the usual GLib rule that a particular object must not be used by two threads at the same time,
GDBusConnection
‘s methods may be called from any thread. This is so thatg_bus_get()
andg_bus_get_sync()
can safely return the sameGDBusConnection
when called from any thread.Most of the ways to obtain a
GDBusConnection
automatically initialize it (i.e. connect to D-Bus): for instance,g_dbus_connection_new()
andg_bus_get()
, and the synchronous versions of those methods, give you an initialized connection. Language bindings for GIO should useg_initable_new()
org_async_initable_new_async()
, which also initialize the connection.If you construct an uninitialized
GDBusConnection
, such as viag_object_new()
, you must initialize it viag_initable_init()
org_async_initable_init_async()
before using its methods or properties. Calling methods or accessing properties on aGDBusConnection
that has not completed initialization successfully is considered to be invalid, and leads to undefined behaviour. In particular, if initialization fails with aGError
, the only valid thing you can do with thatGDBusConnection
is to free it withg_object_unref()
.An example D-Bus server #
Here is an example for a D-Bus server: gdbus-example-server.c
An example for exporting a subtree #
Here is an example for exporting a subtree: gdbus-example-subtree.c
An example for file descriptor passing #
Here is an example for passing UNIX file descriptors: gdbus-unix-fd-client.c
An example for exporting a GObject #
Here is an example for exporting a
See moreGObject:
gdbus-example-export.cDeclaration
Swift
open class DBusConnection : Object, DBusConnectionProtocol
-
The
DBusInterfaceSkeleton
type acts as a reference-counted owner of an underlyingGDBusInterfaceSkeleton
instance. It provides the methods that can operate on this data type throughDBusInterfaceSkeletonProtocol
conformance. UseDBusInterfaceSkeleton
as a strong reference or owner of aGDBusInterfaceSkeleton
instance.Abstract base class for D-Bus interfaces on the service side.
See moreDeclaration
Swift
open class DBusInterfaceSkeleton : Object, DBusInterfaceSkeletonProtocol
-
The
DBusMenuModel
type acts as a reference-counted owner of an underlyingGDBusMenuModel
instance. It provides the methods that can operate on this data type throughDBusMenuModelProtocol
conformance. UseDBusMenuModel
as a strong reference or owner of aGDBusMenuModel
instance.
See moreGDBusMenuModel
is an implementation ofGMenuModel
that can be used as a proxy for a menu model that is exported over D-Bus withg_dbus_connection_export_menu_model()
.Declaration
Swift
open class DBusMenuModel : MenuModel, DBusMenuModelProtocol
-
The
DBusMessage
type acts as a reference-counted owner of an underlyingGDBusMessage
instance. It provides the methods that can operate on this data type throughDBusMessageProtocol
conformance. UseDBusMessage
as a strong reference or owner of aGDBusMessage
instance.A type for representing D-Bus messages that can be sent or received on a
See moreGDBusConnection
.Declaration
Swift
open class DBusMessage : Object, DBusMessageProtocol
-
The
DBusMethodInvocation
type acts as a reference-counted owner of an underlyingGDBusMethodInvocation
instance. It provides the methods that can operate on this data type throughDBusMethodInvocationProtocol
conformance. UseDBusMethodInvocation
as a strong reference or owner of aGDBusMethodInvocation
instance.Instances of the
GDBusMethodInvocation
class are used when handling D-Bus method calls. It provides a way to asynchronously return results and errors.The normal way to obtain a
See moreGDBusMethodInvocation
object is to receive it as an argument to thehandle_method_call()
function in aGDBusInterfaceVTable
that was passed tog_dbus_connection_register_object()
.Declaration
Swift
open class DBusMethodInvocation : Object, DBusMethodInvocationProtocol
-
The
DBusObjectManagerClient
type acts as a reference-counted owner of an underlyingGDBusObjectManagerClient
instance. It provides the methods that can operate on this data type throughDBusObjectManagerClientProtocol
conformance. UseDBusObjectManagerClient
as a strong reference or owner of aGDBusObjectManagerClient
instance.GDBusObjectManagerClient
is used to create, monitor and delete object proxies for remote objects exported by aGDBusObjectManagerServer
(or any code implementing the org.freedesktop.DBus.ObjectManager interface).Once an instance of this type has been created, you can connect to the
GDBusObjectManager::object
-added andGDBusObjectManager::object
-removed signals and inspect theGDBusObjectProxy
objects returned byg_dbus_object_manager_get_objects()
.If the name for a
GDBusObjectManagerClient
is not owned by anyone at object construction time, the default behavior is to request the message bus to launch an owner for the name. This behavior can be disabled using theG_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START
flag. It’s also worth noting that this only works if the name of interest is activatable in the first place. E.g. in some cases it is not possible to launch an owner for the requested name. In this case,GDBusObjectManagerClient
object construction still succeeds but there will be no object proxies (e.g.g_dbus_object_manager_get_objects()
returns the empty list) and theGDBusObjectManagerClient:name
-owner property isnil
.The owner of the requested name can come and go (for example consider a system service being restarted) –
GDBusObjectManagerClient
handles this case too; simply connect to theGObject::notify
signal to watch for changes on theGDBusObjectManagerClient:name
-owner property. When the name owner vanishes, the behavior is thatGDBusObjectManagerClient:name
-owner is set tonil
(this includes emission of theGObject::notify
signal) and thenGDBusObjectManager::object
-removed signals are synthesized for all currently existing object proxies. SinceGDBusObjectManagerClient:name
-owner isnil
when this happens, you can use this information to disambiguate a synthesized signal from a genuine signal caused by object removal on the remoteGDBusObjectManager
. Similarly, when a new name owner appears,GDBusObjectManager::object
-added signals are synthesized whileGDBusObjectManagerClient:name
-owner is stillnil
. Only when all object proxies have been added, theGDBusObjectManagerClient:name
-owner is set to the new name owner (this includes emission of theGObject::notify
signal). Furthermore, you are guaranteed thatGDBusObjectManagerClient:name
-owner will alternate between a name owner (e.g.:1.42
) andnil
even in the case where the name of interest is atomically replacedUltimately,
GDBusObjectManagerClient
is used to obtainGDBusProxy
instances. All signals (including the org.freedesktop.DBus.PropertiesPropertiesChanged
signal) delivered toGDBusProxy
instances are guaranteed to originate from the name owner. This guarantee along with the behavior described above, means that certain race conditions including the “half the proxy is from the old owner and the other half is from the new owner” problem cannot happen.To avoid having the application connect to signals on the returned
GDBusObjectProxy
andGDBusProxy
objects, theGDBusObject::interface
-added,GDBusObject::interface
-removed,GDBusProxy::g
-properties-changed andGDBusProxy::g
-signal signals are also emitted on theGDBusObjectManagerClient
instance managing these objects. The signals emitted areGDBusObjectManager::interface
-added,GDBusObjectManager::interface
-removed,GDBusObjectManagerClient::interface
-proxy-properties-changed andGDBusObjectManagerClient::interface
-proxy-signal.Note that all callbacks and signals are emitted in the thread-default main context that the
See moreGDBusObjectManagerClient
object was constructed in. Additionally, theGDBusObjectProxy
andGDBusProxy
objects originating from theGDBusObjectManagerClient
object will be created in the same context and, consequently, will deliver signals in the same main loop.Declaration
Swift
open class DBusObjectManagerClient : Object, DBusObjectManagerClientProtocol
-
The
DBusObjectManagerServer
type acts as a reference-counted owner of an underlyingGDBusObjectManagerServer
instance. It provides the methods that can operate on this data type throughDBusObjectManagerServerProtocol
conformance. UseDBusObjectManagerServer
as a strong reference or owner of aGDBusObjectManagerServer
instance.GDBusObjectManagerServer
is used to exportGDBusObject
instances using the standardized org.freedesktop.DBus.ObjectManager interface. For example, remote D-Bus clients can get all objects and properties in a single call. Additionally, any change in the object hierarchy is broadcast using signals. This means that D-Bus clients can keep caches up to date by only listening to D-Bus signals.The recommended path to export an object manager at is the path form of the well-known name of a D-Bus service, or below. For example, if a D-Bus service is available at the well-known name
net.example.ExampleService1
, the object manager should typically be exported at/net/example/ExampleService1
, or below (to allow for multiple object managers in a service).It is supported, but not recommended, to export an object manager at the root path,
/
.See
See moreGDBusObjectManagerClient
for the client-side code that is intended to be used withGDBusObjectManagerServer
or any D-Bus object implementing the org.freedesktop.DBus.ObjectManager interface.Declaration
Swift
open class DBusObjectManagerServer : Object, DBusObjectManagerServerProtocol
-
The
DBusObjectProxy
type acts as a reference-counted owner of an underlyingGDBusObjectProxy
instance. It provides the methods that can operate on this data type throughDBusObjectProxyProtocol
conformance. UseDBusObjectProxy
as a strong reference or owner of aGDBusObjectProxy
instance.A
See moreGDBusObjectProxy
is an object used to represent a remote object with one or more D-Bus interfaces. Normally, you don’t instantiate aGDBusObjectProxy
yourself - typicallyGDBusObjectManagerClient
is used to obtain it.Declaration
Swift
open class DBusObjectProxy : Object, DBusObjectProxyProtocol
-
The
DBusObjectSkeleton
type acts as a reference-counted owner of an underlyingGDBusObjectSkeleton
instance. It provides the methods that can operate on this data type throughDBusObjectSkeletonProtocol
conformance. UseDBusObjectSkeleton
as a strong reference or owner of aGDBusObjectSkeleton
instance.A
GDBusObjectSkeleton
instance is essentially a group of D-Bus interfaces. The set of exported interfaces on the object may be dynamic and change at runtime.This type is intended to be used with
See moreGDBusObjectManager
.Declaration
Swift
open class DBusObjectSkeleton : Object, DBusObjectSkeletonProtocol
-
The
DBusProxy
type acts as a reference-counted owner of an underlyingGDBusProxy
instance. It provides the methods that can operate on this data type throughDBusProxyProtocol
conformance. UseDBusProxy
as a strong reference or owner of aGDBusProxy
instance.GDBusProxy
is a base class used for proxies to access a D-Bus interface on a remote object. AGDBusProxy
can be constructed for both well-known and unique names.By default,
GDBusProxy
will cache all properties (and listen to changes) of the remote object, and proxy all signals that get emitted. This behaviour can be changed by passing suitableGDBusProxyFlags
when the proxy is created. If the proxy is for a well-known name, the property cache is flushed when the name owner vanishes and reloaded when a name owner appears.The unique name owner of the proxy’s name is tracked and can be read from
GDBusProxy:g
-name-owner. Connect to theGObject::notify
signal to get notified of changes. Additionally, only signals and property changes emitted from the current name owner are considered and calls are always sent to the current name owner. This avoids a number of race conditions when the name is lost by one owner and claimed by another. However, if no name owner currently exists, then calls will be sent to the well-known name which may result in the message bus launching an owner (unlessG_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START
is set).The generic
GDBusProxy::g
-properties-changed andGDBusProxy::g
-signal signals are not very convenient to work with. Therefore, the recommended way of working with proxies is to subclassGDBusProxy
, and have more natural properties and signals in your derived class. This example shows how this can easily be done using the gdbus-codegen tool.A
GDBusProxy
instance can be used from multiple threads but note that all signals (e.g.GDBusProxy::g
-signal,GDBusProxy::g
-properties-changed andGObject::notify
) are emitted in the thread-default main context of the thread where the instance was constructed.An example using a proxy for a well-known name can be found in gdbus-example-watch-proxy.c
See moreDeclaration
Swift
open class DBusProxy : Object, DBusProxyProtocol
-
The
DBusServer
type acts as a reference-counted owner of an underlyingGDBusServer
instance. It provides the methods that can operate on this data type throughDBusServerProtocol
conformance. UseDBusServer
as a strong reference or owner of aGDBusServer
instance.GDBusServer
is a helper for listening to and accepting D-Bus connections. This can be used to create a new D-Bus server, allowing two peers to use the D-Bus protocol for their own specialized communication. A server instance provided in this way will not perform message routing or implement the org.freedesktop.DBus interface.To just export an object on a well-known name on a message bus, such as the session or system bus, you should instead use
g_bus_own_name()
.An example of peer-to-peer communication with G-DBus can be found in gdbus-example-peer.c.
Note that a minimal
See moreGDBusServer
will accept connections from any peer. In many use-cases it will be necessary to add aGDBusAuthObserver
that only accepts connections that have successfully authenticated as the same user that is running theGDBusServer
.Declaration
Swift
open class DBusServer : Object, DBusServerProtocol
-
The
DataInputStream
type acts as a reference-counted owner of an underlyingGDataInputStream
instance. It provides the methods that can operate on this data type throughDataInputStreamProtocol
conformance. UseDataInputStream
as a strong reference or owner of aGDataInputStream
instance.Data input stream implements
See moreGInputStream
and includes functions for reading structured data directly from a binary input stream.Declaration
Swift
open class DataInputStream : BufferedInputStream, DataInputStreamProtocol
-
The
DataOutputStream
type acts as a reference-counted owner of an underlyingGDataOutputStream
instance. It provides the methods that can operate on this data type throughDataOutputStreamProtocol
conformance. UseDataOutputStream
as a strong reference or owner of aGDataOutputStream
instance.Data output stream implements
See moreGOutputStream
and includes functions for writing data directly to an output stream.Declaration
Swift
open class DataOutputStream : FilterOutputStream, DataOutputStreamProtocol
-
The
Emblem
type acts as a reference-counted owner of an underlyingGEmblem
instance. It provides the methods that can operate on this data type throughEmblemProtocol
conformance. UseEmblem
as a strong reference or owner of aGEmblem
instance.GEmblem
is an implementation ofGIcon
that supports having an emblem, which is an icon with additional properties. It can than be added to aGEmblemedIcon
.Currently, only metainformation about the emblem’s origin is supported. More may be added in the future.
See moreDeclaration
Swift
open class Emblem : Object, EmblemProtocol
-
The
DBusInterface
type acts as an owner of an underlyingGDBusInterface
instance. It provides the methods that can operate on this data type throughDBusInterfaceProtocol
conformance. UseDBusInterface
as a strong reference or owner of aGDBusInterface
instance.The
See moreGDBusInterface
type is the base type for D-Bus interfaces both on the service side (seeGDBusInterfaceSkeleton
) and client side (seeGDBusProxy
).Declaration
Swift
open class DBusInterface : DBusInterfaceProtocol
-
The
DBusObject
type acts as an owner of an underlyingGDBusObject
instance. It provides the methods that can operate on this data type throughDBusObjectProtocol
conformance. UseDBusObject
as a strong reference or owner of aGDBusObject
instance.The
See moreGDBusObject
type is the base type for D-Bus objects on both the service side (seeGDBusObjectSkeleton
) and the client side (seeGDBusObjectProxy
). It is essentially just a container of interfaces.Declaration
Swift
open class DBusObject : DBusObjectProtocol
-
The
DBusObjectManager
type acts as an owner of an underlyingGDBusObjectManager
instance. It provides the methods that can operate on this data type throughDBusObjectManagerProtocol
conformance. UseDBusObjectManager
as a strong reference or owner of aGDBusObjectManager
instance.The
GDBusObjectManager
type is the base type for service- and client-side implementations of the standardized org.freedesktop.DBus.ObjectManager interface.See
See moreGDBusObjectManagerClient
for the client-side implementation andGDBusObjectManagerServer
for the service-side implementation.Declaration
Swift
open class DBusObjectManager : DBusObjectManagerProtocol
-
The
DatagramBased
type acts as an owner of an underlyingGDatagramBased
instance. It provides the methods that can operate on this data type throughDatagramBasedProtocol
conformance. UseDatagramBased
as a strong reference or owner of aGDatagramBased
instance.A
GDatagramBased
is a networking interface for representing datagram-based communications. It is a more or less direct mapping of the core parts of the BSD socket API in a portable GObject interface. It is implemented byGSocket
, which wraps the UNIX socket API on UNIX and winsock2 on Windows.GDatagramBased
is entirely platform independent, and is intended to be used alongside higher-level networking APIs such asGIOStream
.It uses vectored scatter/gather I/O by default, allowing for many messages to be sent or received in a single call. Where possible, implementations of the interface should take advantage of vectored I/O to minimise processing or system calls. For example,
GSocket
usesrecvmmsg()
andsendmmsg()
where possible. Callers should take advantage of scatter/gather I/O (the use of multiple buffers per message) to avoid unnecessary copying of data to assemble or disassemble a message.Each
GDatagramBased
operation has a timeout parameter which may be negative for blocking behaviour, zero for non-blocking behaviour, or positive for timeout behaviour. A blocking operation blocks until finished or there is an error. A non-blocking operation will return immediately with aG_IO_ERROR_WOULD_BLOCK
error if it cannot make progress. A timeout operation will block until the operation is complete or the timeout expires; if the timeout expires it will return what progress it made, orG_IO_ERROR_TIMED_OUT
if no progress was made. To know when a call would successfully run you can callg_datagram_based_condition_check()
org_datagram_based_condition_wait()
. You can also useg_datagram_based_create_source()
and attach it to aGMainContext
to get callbacks when I/O is possible.When running a non-blocking operation applications should always be able to handle getting a
G_IO_ERROR_WOULD_BLOCK
error even when some other function said that I/O was possible. This can easily happen in case of a race condition in the application, but it can also happen for other reasons. For instance, on Windows a socket is always seen as writable until a write returnsG_IO_ERROR_WOULD_BLOCK
.As with
GSocket
,GDatagramBaseds
can be either connection oriented (for example, SCTP) or connectionless (for example, UDP).GDatagramBaseds
must be datagram-based, not stream-based. The interface does not cover connection establishment — use methods on the underlying type to establish a connection before sending and receiving data through theGDatagramBased
API. For connectionless socket types the target/source address is specified or received in each I/O operation.Like most other APIs in GLib,
See moreGDatagramBased
is not inherently thread safe. To use aGDatagramBased
concurrently from multiple threads, you must implement your own locking.Declaration
Swift
open class DatagramBased : DatagramBasedProtocol
-
The
Drive
type acts as an owner of an underlyingGDrive
instance. It provides the methods that can operate on this data type throughDriveProtocol
conformance. UseDrive
as a strong reference or owner of aGDrive
instance.GDrive
- this represent a piece of hardware connected to the machine. It’s generally only created for removable hardware or hardware with removable media.GDrive
is a container class forGVolume
objects that stem from the same piece of media. As such,GDrive
abstracts a drive with (or without) removable media and provides operations for querying whether media is available, determining whether media change is automatically detected and ejecting the media.If the
GDrive
reports that media isn’t automatically detected, one can poll for media; typically one should not do this periodically as a poll for media operation is potententially expensive and may spin up the drive creating noise.GDrive
supports starting and stopping drives with authentication support for the former. This can be used to support a diverse set of use cases including connecting/disconnecting iSCSI devices, powering down external disk enclosures and starting/stopping multi-disk devices such as RAID devices. Note that the actual semantics and side-effects of starting/stopping aGDrive
may vary according to implementation. To choose the correct verbs in e.g. a file manager, useg_drive_get_start_stop_type()
.For porting from GnomeVFS note that there is no equivalent of
See moreGDrive
in that API.Declaration
Swift
open class Drive : DriveProtocol
-
The
DtlsClientConnection
type acts as an owner of an underlyingGDtlsClientConnection
instance. It provides the methods that can operate on this data type throughDtlsClientConnectionProtocol
conformance. UseDtlsClientConnection
as a strong reference or owner of aGDtlsClientConnection
instance.
See moreGDtlsClientConnection
is the client-side subclass ofGDtlsConnection
, representing a client-side DTLS connection.Declaration
Swift
open class DtlsClientConnection : DatagramBased, DtlsClientConnectionProtocol
-
The
DtlsConnection
type acts as an owner of an underlyingGDtlsConnection
instance. It provides the methods that can operate on this data type throughDtlsConnectionProtocol
conformance. UseDtlsConnection
as a strong reference or owner of aGDtlsConnection
instance.GDtlsConnection
is the base DTLS connection class type, which wraps aGDatagramBased
and provides DTLS encryption on top of it. Its subclasses,GDtlsClientConnection
andGDtlsServerConnection
, implement client-side and server-side DTLS, respectively.For TLS support, see
GTlsConnection
.As DTLS is datagram based,
GDtlsConnection
implementsGDatagramBased
, presenting a datagram-socket-like API for the encrypted connection. This operates over a base datagram connection, which is also aGDatagramBased
(GDtlsConnection:base
-socket).To close a DTLS connection, use
g_dtls_connection_close()
.Neither
See moreGDtlsServerConnection
orGDtlsClientConnection
set the peer address on their baseGDatagramBased
if it is aGSocket
— it is up to the caller to do that if they wish. If they do not, andg_socket_close()
is called on the base socket, theGDtlsConnection
will not raise aG_IO_ERROR_NOT_CONNECTED
error on further I/O.Declaration
Swift
open class DtlsConnection : DatagramBased, DtlsConnectionProtocol
-
The
DtlsServerConnection
type acts as an owner of an underlyingGDtlsServerConnection
instance. It provides the methods that can operate on this data type throughDtlsServerConnectionProtocol
conformance. UseDtlsServerConnection
as a strong reference or owner of aGDtlsServerConnection
instance.
See moreGDtlsServerConnection
is the server-side subclass ofGDtlsConnection
, representing a server-side DTLS connection.Declaration
Swift
open class DtlsServerConnection : DatagramBased, DtlsServerConnectionProtocol
-
The
File
type acts as an owner of an underlyingGFile
instance. It provides the methods that can operate on this data type throughFileProtocol
conformance. UseFile
as a strong reference or owner of aGFile
instance.GFile
is a high level abstraction for manipulating files on a virtual file system.GFiles
are lightweight, immutable objects that do no I/O upon creation. It is necessary to understand thatGFile
objects do not represent files, merely an identifier for a file. All file content I/O is implemented as streaming operations (seeGInputStream
andGOutputStream
).To construct a
GFile
, you can use:g_file_new_for_path()
if you have a path.g_file_new_for_uri()
if you have a URI.g_file_new_for_commandline_arg()
for a command line argument.g_file_new_tmp()
to create a temporary file from a template.g_file_parse_name()
from a UTF-8 string gotten fromg_file_get_parse_name()
.g_file_new_build_filename()
to create a file from path elements.
One way to think of a
GFile
is as an abstraction of a pathname. For normal files the system pathname is what is stored internally, but asGFiles
are extensible it could also be something else that corresponds to a pathname in a userspace implementation of a filesystem.GFiles
make up hierarchies of directories and files that correspond to the files on a filesystem. You can move through the file system withGFile
usingg_file_get_parent()
to get an identifier for the parent directory,g_file_get_child()
to get a child within a directory,g_file_resolve_relative_path()
to resolve a relative path between twoGFiles
. There can be multiple hierarchies, so you may not end up at the same root if you repeatedly callg_file_get_parent()
on two different files.All
GFiles
have a basename (get withg_file_get_basename()
). These names are byte strings that are used to identify the file on the filesystem (relative to its parent directory) and there is no guarantees that they have any particular charset encoding or even make any sense at all. If you want to use filenames in a user interface you should use the display name that you can get by requesting theG_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
attribute withg_file_query_info()
. This is guaranteed to be in UTF-8 and can be used in a user interface. But always store the real basename or theGFile
to use to actually access the file, because there is no way to go from a display name to the actual name.Using
GFile
as an identifier has the same weaknesses as using a path in that there may be multiple aliases for the same file. For instance, hard or soft links may cause two differentGFiles
to refer to the same file. Other possible causes for aliases are: case insensitive filesystems, short and long names on FAT/NTFS, or bind mounts in Linux. If you want to check if twoGFiles
point to the same file you can query for theG_FILE_ATTRIBUTE_ID_FILE
attribute. Note thatGFile
does some trivial canonicalization of pathnames passed in, so that trivial differences in the path string used at creation (duplicated slashes, slash at end of path, “.” or “..” path segments, etc) does not create differentGFiles
.Many
GFile
operations have both synchronous and asynchronous versions to suit your application. Asynchronous versions of synchronous functions simply have_async()
appended to their function names. The asynchronous I/O functions call aGAsyncReadyCallback
which is then used to finalize the operation, producing a GAsyncResult which is then passed to the function’s matching_finish()
operation.It is highly recommended to use asynchronous calls when running within a shared main loop, such as in the main thread of an application. This avoids I/O operations blocking other sources on the main loop from being dispatched. Synchronous I/O operations should be performed from worker threads. See the introduction to asynchronous programming section for more.
Some
GFile
operations almost always take a noticeable amount of time, and so do not have synchronous analogs. Notable cases include:g_file_mount_mountable()
to mount a mountable file.g_file_unmount_mountable_with_operation()
to unmount a mountable file.g_file_eject_mountable_with_operation()
to eject a mountable file.
Entity Tags #
One notable feature of
See moreGFiles
are entity tags, or “etags” for short. Entity tags are somewhat like a more abstract version of the traditional mtime, and can be used to quickly determine if the file has been modified from the version on the file system. See the HTTP 1.1 specification for HTTP Etag headers, which are a very similar concept.Declaration
Swift
open class File : FileProtocol
-
The
EmblemedIcon
type acts as a reference-counted owner of an underlyingGEmblemedIcon
instance. It provides the methods that can operate on this data type throughEmblemedIconProtocol
conformance. UseEmblemedIcon
as a strong reference or owner of aGEmblemedIcon
instance.GEmblemedIcon
is an implementation ofGIcon
that supports adding an emblem to an icon. Adding multiple emblems to an icon is ensured viag_emblemed_icon_add_emblem()
.Note that
See moreGEmblemedIcon
allows no control over the position of the emblems. See alsoGEmblem
for more information.Declaration
Swift
open class EmblemedIcon : Object, EmblemedIconProtocol
-
The
FileEnumerator
type acts as a reference-counted owner of an underlyingGFileEnumerator
instance. It provides the methods that can operate on this data type throughFileEnumeratorProtocol
conformance. UseFileEnumerator
as a strong reference or owner of aGFileEnumerator
instance.GFileEnumerator
allows you to operate on a set ofGFiles
, returning aGFileInfo
structure for each file enumerated (e.g.g_file_enumerate_children()
will return aGFileEnumerator
for each of the children within a directory).To get the next file’s information from a
GFileEnumerator
, useg_file_enumerator_next_file()
or its asynchronous version,g_file_enumerator_next_files_async()
. Note that the asynchronous version will return a list ofGFileInfos
, whereas the synchronous will only return the next file in the enumerator.The ordering of returned files is unspecified for non-Unix platforms; for more information, see
g_dir_read_name()
. On Unix, when operating on local files, returned files will be sorted by inode number. Effectively you can assume that the ordering of returned files will be stable between successive calls (and applications) assuming the directory is unchanged.If your application needs a specific ordering, such as by name or modification time, you will have to implement that in your application code.
To close a
See moreGFileEnumerator
, useg_file_enumerator_close()
, or its asynchronous version,g_file_enumerator_close_async()
. Once aGFileEnumerator
is closed, no further actions may be performed on it, and it should be freed withg_object_unref()
.Declaration
Swift
open class FileEnumerator : Object, FileEnumeratorProtocol
-
The
See moreEmblemedIconClass
type acts as an owner of an underlyingGEmblemedIconClass
instance. It provides the methods that can operate on this data type throughEmblemedIconClassProtocol
conformance. UseEmblemedIconClass
as a strong reference or owner of aGEmblemedIconClass
instance.Declaration
Swift
open class EmblemedIconClass : EmblemedIconClassProtocol
-
The
See moreEmblemedIconPrivate
type acts as an owner of an underlyingGEmblemedIconPrivate
instance. It provides the methods that can operate on this data type throughEmblemedIconPrivateProtocol
conformance. UseEmblemedIconPrivate
as a strong reference or owner of aGEmblemedIconPrivate
instance.Declaration
Swift
open class EmblemedIconPrivate : EmblemedIconPrivateProtocol
-
The
FileAttributeInfo
type acts as an owner of an underlyingGFileAttributeInfo
instance. It provides the methods that can operate on this data type throughFileAttributeInfoProtocol
conformance. UseFileAttributeInfo
as a strong reference or owner of aGFileAttributeInfo
instance.Information about a specific attribute.
See moreDeclaration
Swift
open class FileAttributeInfo : FileAttributeInfoProtocol
-
The
FileAttributeInfoList
type acts as a reference-counted owner of an underlyingGFileAttributeInfoList
instance. It provides the methods that can operate on this data type throughFileAttributeInfoListProtocol
conformance. UseFileAttributeInfoList
as a strong reference or owner of aGFileAttributeInfoList
instance.Acts as a lightweight registry for possible valid file attributes. The registry stores Key-Value pair formats as
See moreGFileAttributeInfos
.Declaration
Swift
open class FileAttributeInfoList : FileAttributeInfoListProtocol
-
The
FileAttributeMatcher
type acts as a reference-counted owner of an underlyingGFileAttributeMatcher
instance. It provides the methods that can operate on this data type throughFileAttributeMatcherProtocol
conformance. UseFileAttributeMatcher
as a strong reference or owner of aGFileAttributeMatcher
instance.Determines if a string matches a file attribute.
See moreDeclaration
Swift
open class FileAttributeMatcher : FileAttributeMatcherProtocol
-
The
FileDescriptorBasedIface
type acts as an owner of an underlyingGFileDescriptorBasedIface
instance. It provides the methods that can operate on this data type throughFileDescriptorBasedIfaceProtocol
conformance. UseFileDescriptorBasedIface
as a strong reference or owner of aGFileDescriptorBasedIface
instance.An interface for file descriptor based io objects.
See moreDeclaration
Swift
open class FileDescriptorBasedIface : FileDescriptorBasedIfaceProtocol
-
The
See moreFileEnumeratorClass
type acts as an owner of an underlyingGFileEnumeratorClass
instance. It provides the methods that can operate on this data type throughFileEnumeratorClassProtocol
conformance. UseFileEnumeratorClass
as a strong reference or owner of aGFileEnumeratorClass
instance.Declaration
Swift
open class FileEnumeratorClass : FileEnumeratorClassProtocol
-
The
See moreFileEnumeratorPrivate
type acts as an owner of an underlyingGFileEnumeratorPrivate
instance. It provides the methods that can operate on this data type throughFileEnumeratorPrivateProtocol
conformance. UseFileEnumeratorPrivate
as a strong reference or owner of aGFileEnumeratorPrivate
instance.Declaration
Swift
open class FileEnumeratorPrivate : FileEnumeratorPrivateProtocol
-
The
See moreFileIOStreamClass
type acts as an owner of an underlyingGFileIOStreamClass
instance. It provides the methods that can operate on this data type throughFileIOStreamClassProtocol
conformance. UseFileIOStreamClass
as a strong reference or owner of aGFileIOStreamClass
instance.Declaration
Swift
open class FileIOStreamClass : FileIOStreamClassProtocol
-
The
See moreFileIOStreamPrivate
type acts as an owner of an underlyingGFileIOStreamPrivate
instance. It provides the methods that can operate on this data type throughFileIOStreamPrivateProtocol
conformance. UseFileIOStreamPrivate
as a strong reference or owner of aGFileIOStreamPrivate
instance.Declaration
Swift
open class FileIOStreamPrivate : FileIOStreamPrivateProtocol
-
The
See moreFileIconClass
type acts as an owner of an underlyingGFileIconClass
instance. It provides the methods that can operate on this data type throughFileIconClassProtocol
conformance. UseFileIconClass
as a strong reference or owner of aGFileIconClass
instance.Declaration
Swift
open class FileIconClass : FileIconClassProtocol
-
The
FileIface
type acts as an owner of an underlyingGFileIface
instance. It provides the methods that can operate on this data type throughFileIfaceProtocol
conformance. UseFileIface
as a strong reference or owner of aGFileIface
instance.An interface for writing VFS file handles.
See moreDeclaration
Swift
open class FileIface : FileIfaceProtocol
-
The
See moreFileInfoClass
type acts as an owner of an underlyingGFileInfoClass
instance. It provides the methods that can operate on this data type throughFileInfoClassProtocol
conformance. UseFileInfoClass
as a strong reference or owner of aGFileInfoClass
instance.Declaration
Swift
open class FileInfoClass : FileInfoClassProtocol
-
The
See moreFileInputStreamClass
type acts as an owner of an underlyingGFileInputStreamClass
instance. It provides the methods that can operate on this data type throughFileInputStreamClassProtocol
conformance. UseFileInputStreamClass
as a strong reference or owner of aGFileInputStreamClass
instance.Declaration
Swift
open class FileInputStreamClass : FileInputStreamClassProtocol
-
The
See moreFileInputStreamPrivate
type acts as an owner of an underlyingGFileInputStreamPrivate
instance. It provides the methods that can operate on this data type throughFileInputStreamPrivateProtocol
conformance. UseFileInputStreamPrivate
as a strong reference or owner of aGFileInputStreamPrivate
instance.Declaration
Swift
open class FileInputStreamPrivate : FileInputStreamPrivateProtocol
-
The
See moreFileMonitorClass
type acts as an owner of an underlyingGFileMonitorClass
instance. It provides the methods that can operate on this data type throughFileMonitorClassProtocol
conformance. UseFileMonitorClass
as a strong reference or owner of aGFileMonitorClass
instance.Declaration
Swift
open class FileMonitorClass : FileMonitorClassProtocol
-
The
See moreFileMonitorPrivate
type acts as an owner of an underlyingGFileMonitorPrivate
instance. It provides the methods that can operate on this data type throughFileMonitorPrivateProtocol
conformance. UseFileMonitorPrivate
as a strong reference or owner of aGFileMonitorPrivate
instance.Declaration
Swift
open class FileMonitorPrivate : FileMonitorPrivateProtocol
-
The
See moreFileOutputStreamClass
type acts as an owner of an underlyingGFileOutputStreamClass
instance. It provides the methods that can operate on this data type throughFileOutputStreamClassProtocol
conformance. UseFileOutputStreamClass
as a strong reference or owner of aGFileOutputStreamClass
instance.Declaration
Swift
open class FileOutputStreamClass : FileOutputStreamClassProtocol
-
The
See moreFileOutputStreamPrivate
type acts as an owner of an underlyingGFileOutputStreamPrivate
instance. It provides the methods that can operate on this data type throughFileOutputStreamPrivateProtocol
conformance. UseFileOutputStreamPrivate
as a strong reference or owner of aGFileOutputStreamPrivate
instance.Declaration
Swift
open class FileOutputStreamPrivate : FileOutputStreamPrivateProtocol
-
The
See moreFilenameCompleterClass
type acts as an owner of an underlyingGFilenameCompleterClass
instance. It provides the methods that can operate on this data type throughFilenameCompleterClassProtocol
conformance. UseFilenameCompleterClass
as a strong reference or owner of aGFilenameCompleterClass
instance.Declaration
Swift
open class FilenameCompleterClass : FilenameCompleterClassProtocol
-
The
See moreFilterInputStreamClass
type acts as an owner of an underlyingGFilterInputStreamClass
instance. It provides the methods that can operate on this data type throughFilterInputStreamClassProtocol
conformance. UseFilterInputStreamClass
as a strong reference or owner of aGFilterInputStreamClass
instance.Declaration
Swift
open class FilterInputStreamClass : FilterInputStreamClassProtocol
-
The
See moreFilterOutputStreamClass
type acts as an owner of an underlyingGFilterOutputStreamClass
instance. It provides the methods that can operate on this data type throughFilterOutputStreamClassProtocol
conformance. UseFilterOutputStreamClass
as a strong reference or owner of aGFilterOutputStreamClass
instance.Declaration
Swift
open class FilterOutputStreamClass : FilterOutputStreamClassProtocol
-
The
IOExtension
type acts as an owner of an underlyingGIOExtension
instance. It provides the methods that can operate on this data type throughIOExtensionProtocol
conformance. UseIOExtension
as a strong reference or owner of aGIOExtension
instance.
See moreGIOExtension
is an opaque data structure and can only be accessed using the following functions.Declaration
Swift
open class IOExtension : IOExtensionProtocol
-
The
FileDescriptorBased
type acts as an owner of an underlyingGFileDescriptorBased
instance. It provides the methods that can operate on this data type throughFileDescriptorBasedProtocol
conformance. UseFileDescriptorBased
as a strong reference or owner of aGFileDescriptorBased
instance.GFileDescriptorBased
is implemented by streams (implementations ofGInputStream
orGOutputStream
) that are based on file descriptors.Note that
See more<gio/gfiledescriptorbased.h>
belongs to the UNIX-specific GIO interfaces, thus you have to use thegio-unix-2.0.pc
pkg-config file when using it.Declaration
Swift
open class FileDescriptorBased : FileDescriptorBasedProtocol
-
The
Icon
type acts as an owner of an underlyingGIcon
instance. It provides the methods that can operate on this data type throughIconProtocol
conformance. UseIcon
as a strong reference or owner of aGIcon
instance.GIcon
is a very minimal interface for icons. It provides functions for checking the equality of two icons, hashing of icons and serializing an icon to and from strings.GIcon
does not provide the actual pixmap for the icon as this is out of GIO’s scope, however implementations ofGIcon
may contain the name of an icon (seeGThemedIcon
), or the path to an icon (seeGLoadableIcon
).To obtain a hash of a
GIcon
, seeg_icon_hash()
.To check if two
GIcons
are equal, seeg_icon_equal()
.For serializing a
GIcon
, useg_icon_serialize()
andg_icon_deserialize()
.If you want to consume
GIcon
(for example, in a toolkit) you must be prepared to handle at least the three following cases:GLoadableIcon
,GThemedIcon
andGEmblemedIcon
. It may also make sense to have fast-paths for other cases (like handlingGdkPixbuf
directly, for example) but all compliantGIcon
implementations outside of GIO must implementGLoadableIcon
.If your application or library provides one or more
See moreGIcon
implementations you need to ensure that your new implementation also implementsGLoadableIcon
. Additionally, you must provide an implementation ofg_icon_serialize()
that gives a result that is understood byg_icon_deserialize()
, yielding one of the built-in icon types.Declaration
Swift
open class Icon : IconProtocol
-
The
FileIOStream
type acts as a reference-counted owner of an underlyingGFileIOStream
instance. It provides the methods that can operate on this data type throughFileIOStreamProtocol
conformance. UseFileIOStream
as a strong reference or owner of aGFileIOStream
instance.GFileIOStream provides io streams that both read and write to the same file handle.
GFileIOStream implements
GSeekable
, which allows the io stream to jump to arbitrary positions in the file and to truncate the file, provided the filesystem of the file supports these operations.To find the position of a file io stream, use
g_seekable_tell()
.To find out if a file io stream supports seeking, use
g_seekable_can_seek()
. To position a file io stream, useg_seekable_seek()
. To find out if a file io stream supports truncating, useg_seekable_can_truncate()
. To truncate a file io stream, useg_seekable_truncate()
.The default implementation of all the
See moreGFileIOStream
operations and the implementation ofGSeekable
just call into the same operations on the output stream.Declaration
Swift
open class FileIOStream : IOStream, FileIOStreamProtocol
-
The
FileIcon
type acts as a reference-counted owner of an underlyingGFileIcon
instance. It provides the methods that can operate on this data type throughFileIconProtocol
conformance. UseFileIcon
as a strong reference or owner of aGFileIcon
instance.
See moreGFileIcon
specifies an icon by pointing to an image file to be used as icon.Declaration
Swift
open class FileIcon : Object, FileIconProtocol
-
The
FileInfo
type acts as a reference-counted owner of an underlyingGFileInfo
instance. It provides the methods that can operate on this data type throughFileInfoProtocol
conformance. UseFileInfo
as a strong reference or owner of aGFileInfo
instance.Functionality for manipulating basic metadata for files.
GFileInfo
implements methods for getting information that all files should contain, and allows for manipulation of extended attributes.See GFileAttribute for more information on how GIO handles file attributes.
To obtain a
GFileInfo
for aGFile
, useg_file_query_info()
(or its async variant). To obtain aGFileInfo
for a file input or output stream, useg_file_input_stream_query_info()
org_file_output_stream_query_info()
(or their async variants).To change the actual attributes of a file, you should then set the attribute in the
GFileInfo
and callg_file_set_attributes_from_info()
org_file_set_attributes_async()
on a GFile.However, not all attributes can be changed in the file. For instance, the actual size of a file cannot be changed via
g_file_info_set_size()
. You may callg_file_query_settable_attributes()
andg_file_query_writable_namespaces()
to discover the settable attributes of a particular file at runtime.
See moreGFileAttributeMatcher
allows for searching through aGFileInfo
for attributes.Declaration
Swift
open class FileInfo : Object, FileInfoProtocol
-
The
FileInputStream
type acts as a reference-counted owner of an underlyingGFileInputStream
instance. It provides the methods that can operate on this data type throughFileInputStreamProtocol
conformance. UseFileInputStream
as a strong reference or owner of aGFileInputStream
instance.GFileInputStream provides input streams that take their content from a file.
GFileInputStream implements
See moreGSeekable
, which allows the input stream to jump to arbitrary positions in the file, provided the filesystem of the file allows it. To find the position of a file input stream, useg_seekable_tell()
. To find out if a file input stream supports seeking, useg_seekable_can_seek()
. To position a file input stream, useg_seekable_seek()
.Declaration
Swift
open class FileInputStream : InputStream, FileInputStreamProtocol
-
The
FileMonitor
type acts as a reference-counted owner of an underlyingGFileMonitor
instance. It provides the methods that can operate on this data type throughFileMonitorProtocol
conformance. UseFileMonitor
as a strong reference or owner of aGFileMonitor
instance.Monitors a file or directory for changes.
To obtain a
GFileMonitor
for a file or directory, useg_file_monitor()
,g_file_monitor_file()
, org_file_monitor_directory()
.To get informed about changes to the file or directory you are monitoring, connect to the
See moreGFileMonitor::changed
signal. The signal will be emitted in the thread-default main context of the thread that the monitor was created in (though if the global default main context is blocked, this may cause notifications to be blocked even if the thread-default context is still running).Declaration
Swift
open class FileMonitor : Object, FileMonitorProtocol
-
The
FileOutputStream
type acts as a reference-counted owner of an underlyingGFileOutputStream
instance. It provides the methods that can operate on this data type throughFileOutputStreamProtocol
conformance. UseFileOutputStream
as a strong reference or owner of aGFileOutputStream
instance.GFileOutputStream provides output streams that write their content to a file.
GFileOutputStream implements
GSeekable
, which allows the output stream to jump to arbitrary positions in the file and to truncate the file, provided the filesystem of the file supports these operations.To find the position of a file output stream, use
See moreg_seekable_tell()
. To find out if a file output stream supports seeking, useg_seekable_can_seek()
.To position a file output stream, useg_seekable_seek()
. To find out if a file output stream supports truncating, useg_seekable_can_truncate()
. To truncate a file output stream, useg_seekable_truncate()
.Declaration
Swift
open class FileOutputStream : OutputStream, FileOutputStreamProtocol
-
The
FilenameCompleter
type acts as a reference-counted owner of an underlyingGFilenameCompleter
instance. It provides the methods that can operate on this data type throughFilenameCompleterProtocol
conformance. UseFilenameCompleter
as a strong reference or owner of aGFilenameCompleter
instance.Completes partial file and directory names given a partial string by looking in the file system for clues. Can return a list of possible completion strings for widget implementations.
See moreDeclaration
Swift
open class FilenameCompleter : Object, FilenameCompleterProtocol
-
The
FilterInputStream
type acts as a reference-counted owner of an underlyingGFilterInputStream
instance. It provides the methods that can operate on this data type throughFilterInputStreamProtocol
conformance. UseFilterInputStream
as a strong reference or owner of aGFilterInputStream
instance.Base class for input stream implementations that perform some kind of filtering operation on a base stream. Typical examples of filtering operations are character set conversion, compression and byte order flipping.
See moreDeclaration
Swift
open class FilterInputStream : InputStream, FilterInputStreamProtocol
-
The
FilterOutputStream
type acts as a reference-counted owner of an underlyingGFilterOutputStream
instance. It provides the methods that can operate on this data type throughFilterOutputStreamProtocol
conformance. UseFilterOutputStream
as a strong reference or owner of aGFilterOutputStream
instance.Base class for output stream implementations that perform some kind of filtering operation on a base stream. Typical examples of filtering operations are character set conversion, compression and byte order flipping.
See moreDeclaration
Swift
open class FilterOutputStream : OutputStream, FilterOutputStreamProtocol
-
The
IOModule
type acts as a reference-counted owner of an underlyingGIOModule
instance. It provides the methods that can operate on this data type throughIOModuleProtocol
conformance. UseIOModule
as a strong reference or owner of aGIOModule
instance.Provides an interface and default functions for loading and unloading modules. This is used internally to make GIO extensible, but can also be used by others to implement module loading.
See moreDeclaration
Swift
open class IOModule : TypeModule, IOModuleProtocol
-
The
IOExtensionPoint
type acts as an owner of an underlyingGIOExtensionPoint
instance. It provides the methods that can operate on this data type throughIOExtensionPointProtocol
conformance. UseIOExtensionPoint
as a strong reference or owner of aGIOExtensionPoint
instance.
See moreGIOExtensionPoint
is an opaque data structure and can only be accessed using the following functions.Declaration
Swift
open class IOExtensionPoint : IOExtensionPointProtocol
-
The
See moreIOModuleClass
type acts as an owner of an underlyingGIOModuleClass
instance. It provides the methods that can operate on this data type throughIOModuleClassProtocol
conformance. UseIOModuleClass
as a strong reference or owner of aGIOModuleClass
instance.Declaration
Swift
open class IOModuleClass : IOModuleClassProtocol
-
The
IOModuleScope
type acts as an owner of an underlyingGIOModuleScope
instance. It provides the methods that can operate on this data type throughIOModuleScopeProtocol
conformance. UseIOModuleScope
as a strong reference or owner of aGIOModuleScope
instance.Represents a scope for loading IO modules. A scope can be used for blocking duplicate modules, or blocking a module you don’t want to load.
The scope can be used with
See moreg_io_modules_load_all_in_directory_with_scope()
org_io_modules_scan_all_in_directory_with_scope()
.Declaration
Swift
open class IOModuleScope : IOModuleScopeProtocol
-
The
IOSchedulerJob
type acts as an owner of an underlyingGIOSchedulerJob
instance. It provides the methods that can operate on this data type throughIOSchedulerJobProtocol
conformance. UseIOSchedulerJob
as a strong reference or owner of aGIOSchedulerJob
instance.Opaque class for defining and scheduling IO jobs.
See moreDeclaration
Swift
open class IOSchedulerJob : IOSchedulerJobProtocol
-
The
See moreIOStreamAdapter
type acts as an owner of an underlyingGIOStreamAdapter
instance. It provides the methods that can operate on this data type throughIOStreamAdapterProtocol
conformance. UseIOStreamAdapter
as a strong reference or owner of aGIOStreamAdapter
instance.Declaration
Swift
open class IOStreamAdapter : IOStreamAdapterProtocol
-
The
See moreIOStreamClass
type acts as an owner of an underlyingGIOStreamClass
instance. It provides the methods that can operate on this data type throughIOStreamClassProtocol
conformance. UseIOStreamClass
as a strong reference or owner of aGIOStreamClass
instance.Declaration
Swift
open class IOStreamClass : IOStreamClassProtocol
-
The
See moreIOStreamPrivate
type acts as an owner of an underlyingGIOStreamPrivate
instance. It provides the methods that can operate on this data type throughIOStreamPrivateProtocol
conformance. UseIOStreamPrivate
as a strong reference or owner of aGIOStreamPrivate
instance.Declaration
Swift
open class IOStreamPrivate : IOStreamPrivateProtocol
-
The
IconIface
type acts as an owner of an underlyingGIconIface
instance. It provides the methods that can operate on this data type throughIconIfaceProtocol
conformance. UseIconIface
as a strong reference or owner of aGIconIface
instance.GIconIface is used to implement GIcon types for various different systems. See
See moreGThemedIcon
andGLoadableIcon
for examples of how to implement this interface.Declaration
Swift
open class IconIface : IconIfaceProtocol
-
The
See moreInetAddressClass
type acts as an owner of an underlyingGInetAddressClass
instance. It provides the methods that can operate on this data type throughInetAddressClassProtocol
conformance. UseInetAddressClass
as a strong reference or owner of aGInetAddressClass
instance.Declaration
Swift
open class InetAddressClass : InetAddressClassProtocol
-
The
See moreInetAddressMaskClass
type acts as an owner of an underlyingGInetAddressMaskClass
instance. It provides the methods that can operate on this data type throughInetAddressMaskClassProtocol
conformance. UseInetAddressMaskClass
as a strong reference or owner of aGInetAddressMaskClass
instance.Declaration
Swift
open class InetAddressMaskClass : InetAddressMaskClassProtocol
-
The
See moreInetAddressMaskPrivate
type acts as an owner of an underlyingGInetAddressMaskPrivate
instance. It provides the methods that can operate on this data type throughInetAddressMaskPrivateProtocol
conformance. UseInetAddressMaskPrivate
as a strong reference or owner of aGInetAddressMaskPrivate
instance.Declaration
Swift
open class InetAddressMaskPrivate : InetAddressMaskPrivateProtocol
-
The
See moreInetAddressPrivate
type acts as an owner of an underlyingGInetAddressPrivate
instance. It provides the methods that can operate on this data type throughInetAddressPrivateProtocol
conformance. UseInetAddressPrivate
as a strong reference or owner of aGInetAddressPrivate
instance.Declaration
Swift
open class InetAddressPrivate : InetAddressPrivateProtocol
-
The
See moreInetSocketAddressClass
type acts as an owner of an underlyingGInetSocketAddressClass
instance. It provides the methods that can operate on this data type throughInetSocketAddressClassProtocol
conformance. UseInetSocketAddressClass
as a strong reference or owner of aGInetSocketAddressClass
instance.Declaration
Swift
open class InetSocketAddressClass : InetSocketAddressClassProtocol
-
The
See moreInetSocketAddressPrivate
type acts as an owner of an underlyingGInetSocketAddressPrivate
instance. It provides the methods that can operate on this data type throughInetSocketAddressPrivateProtocol
conformance. UseInetSocketAddressPrivate
as a strong reference or owner of aGInetSocketAddressPrivate
instance.Declaration
Swift
open class InetSocketAddressPrivate : InetSocketAddressPrivateProtocol
-
The
InitableIface
type acts as an owner of an underlyingGInitableIface
instance. It provides the methods that can operate on this data type throughInitableIfaceProtocol
conformance. UseInitableIface
as a strong reference or owner of aGInitableIface
instance.Provides an interface for initializing object such that initialization may fail.
See moreDeclaration
Swift
open class InitableIface : InitableIfaceProtocol
-
The
InputMessage
type acts as an owner of an underlyingGInputMessage
instance. It provides the methods that can operate on this data type throughInputMessageProtocol
conformance. UseInputMessage
as a strong reference or owner of aGInputMessage
instance.Structure used for scatter/gather data input when receiving multiple messages or packets in one go. You generally pass in an array of empty
GInputVectors
and the operation will use all the buffers as if they were one buffer, and will setbytes_received
to the total number of bytes received across allGInputVectors
.This structure closely mirrors
struct mmsghdr
andstruct msghdr
from the POSIX sockets API (seeman 2 recvmmsg
).If
address
is non-nil
then it is set to the source address the message was received from, and the caller must free it afterwards.If
control_messages
is non-nil
then it is set to an array of control messages received with the message (if any), and the caller must free it afterwards.num_control_messages
is set to the number of elements in this array, which may be zero.Flags relevant to this message will be returned in
See moreflags
. For example,MSG_EOR
orMSG_TRUNC
.Declaration
Swift
open class InputMessage : InputMessageProtocol
-
The
See moreInputStreamClass
type acts as an owner of an underlyingGInputStreamClass
instance. It provides the methods that can operate on this data type throughInputStreamClassProtocol
conformance. UseInputStreamClass
as a strong reference or owner of aGInputStreamClass
instance.Declaration
Swift
open class InputStreamClass : InputStreamClassProtocol
-
The
See moreInputStreamPrivate
type acts as an owner of an underlyingGInputStreamPrivate
instance. It provides the methods that can operate on this data type throughInputStreamPrivateProtocol
conformance. UseInputStreamPrivate
as a strong reference or owner of aGInputStreamPrivate
instance.Declaration
Swift
open class InputStreamPrivate : InputStreamPrivateProtocol
-
The
InputVector
type acts as an owner of an underlyingGInputVector
instance. It provides the methods that can operate on this data type throughInputVectorProtocol
conformance. UseInputVector
as a strong reference or owner of aGInputVector
instance.Structure used for scatter/gather data input. You generally pass in an array of
See moreGInputVectors
and the operation will store the read data starting in the first buffer, switching to the next as needed.Declaration
Swift
open class InputVector : InputVectorProtocol
-
The
ListModelInterface
type acts as an owner of an underlyingGListModelInterface
instance. It provides the methods that can operate on this data type throughListModelInterfaceProtocol
conformance. UseListModelInterface
as a strong reference or owner of aGListModelInterface
instance.The virtual function table for
See moreGListModel
.Declaration
Swift
open class ListModelInterface : ListModelInterfaceProtocol
-
The
IOStream
type acts as a reference-counted owner of an underlyingGIOStream
instance. It provides the methods that can operate on this data type throughIOStreamProtocol
conformance. UseIOStream
as a strong reference or owner of aGIOStream
instance.GIOStream represents an object that has both read and write streams. Generally the two streams act as separate input and output streams, but they share some common resources and state. For instance, for seekable streams, both streams may use the same position.
Examples of
GIOStream
objects areGSocketConnection
, which represents a two-way network connection; andGFileIOStream
, which represents a file handle opened in read-write mode.To do the actual reading and writing you need to get the substreams with
g_io_stream_get_input_stream()
andg_io_stream_get_output_stream()
.The
GIOStream
object owns the input and the output streams, not the other way around, so keeping the substreams alive will not keep theGIOStream
object alive. If theGIOStream
object is freed it will be closed, thus closing the substreams, so even if the substreams stay alive they will always returnG_IO_ERROR_CLOSED
for all operations.To close a stream use
g_io_stream_close()
which will close the common stream object and also the individual substreams. You can also close the substreams themselves. In most cases this only marks the substream as closed, so further I/O on it fails but common state in theGIOStream
may still be open. However, some streams may support “half-closed” states where one direction of the stream is actually shut down.Operations on
GIOStreams
cannot be started while another operation on theGIOStream
or its substreams is in progress. Specifically, an application can read from theGInputStream
and write to theGOutputStream
simultaneously (either in separate threads, or as asynchronous operations in the same thread), but an application cannot start anyGIOStream
operation while there is aGIOStream
,GInputStream
orGOutputStream
operation in progress, and an application can’t start anyGInputStream
orGOutputStream
operation while there is aGIOStream
operation in progress.This is a product of individual stream operations being associated with a given
GMainContext
(the thread-default context at the time the operation was started), rather than entire streams being associated with a singleGMainContext
.GIO may run operations on
See moreGIOStreams
from other (worker) threads, and this may be exposed to application code in the behaviour of wrapper streams, such asGBufferedInputStream
orGTlsConnection
. With such wrapper APIs, application code may only run operations on the base (wrapped) stream when the wrapper stream is idle. Note that the semantics of such operations may not be well-defined due to the state the wrapper stream leaves the base stream in (though they are guaranteed not to crash).Declaration
Swift
open class IOStream : Object, IOStreamProtocol
-
The
InetAddress
type acts as a reference-counted owner of an underlyingGInetAddress
instance. It provides the methods that can operate on this data type throughInetAddressProtocol
conformance. UseInetAddress
as a strong reference or owner of aGInetAddress
instance.GInetAddress
represents an IPv4 or IPv6 internet address. Useg_resolver_lookup_by_name()
org_resolver_lookup_by_name_async()
to look up theGInetAddress
for a hostname. Useg_resolver_lookup_by_address()
org_resolver_lookup_by_address_async()
to look up the hostname for aGInetAddress
.To actually connect to a remote host, you will need a
See moreGInetSocketAddress
(which includes aGInetAddress
as well as a port number).Declaration
Swift
open class InetAddress : Object, InetAddressProtocol
-
The
InetAddressMask
type acts as a reference-counted owner of an underlyingGInetAddressMask
instance. It provides the methods that can operate on this data type throughInetAddressMaskProtocol
conformance. UseInetAddressMask
as a strong reference or owner of aGInetAddressMask
instance.
See moreGInetAddressMask
represents a range of IPv4 or IPv6 addresses described by a base address and a length indicating how many bits of the base address are relevant for matching purposes. These are often given in string form. Eg, “<IP_ADDRESS>/8”, or “fe80”/10".Declaration
Swift
open class InetAddressMask : Object, InetAddressMaskProtocol
-
The
InetSocketAddress
type acts as a reference-counted owner of an underlyingGInetSocketAddress
instance. It provides the methods that can operate on this data type throughInetSocketAddressProtocol
conformance. UseInetSocketAddress
as a strong reference or owner of aGInetSocketAddress
instance.An IPv4 or IPv6 socket address; that is, the combination of a
See moreGInetAddress
and a port number.Declaration
Swift
open class InetSocketAddress : SocketAddress, InetSocketAddressProtocol
-
The
InputStream
type acts as a reference-counted owner of an underlyingGInputStream
instance. It provides the methods that can operate on this data type throughInputStreamProtocol
conformance. UseInputStream