/**
* g_type_init:
*
* This function used to initialise the type system. Since GLib 2.36,
* the type system is initialised automatically and this function does
* nothing.
*
* Deprecated: 2.36: the type system is now initialised automatically
*/
void
g_type_init (void)
{
g_assert_type_system_initialized ();
}
一:Client started
//bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
/**
* g_bus_get_sync:
* @bus_type: a #GBusType
* @cancellable: (allow-none): a #GCancellable or %NULL
* @error: return location for error or %NULL
*
* Synchronously connects to the message bus specified by @bus_type.
* Note that the returned object may shared with other callers,
* e.g. if two separate parts of a process calls this function with
* the same @bus_type, they will share the same object.
*
* This is a synchronous failable function. See g_bus_get() and
* g_bus_get_finish() for the asynchronous version.
*
* The returned object is a singleton, that is, shared with other
* callers of g_bus_get() and g_bus_get_sync() for @bus_type. In the
* event that you need a private message bus connection, use
* g_dbus_address_get_for_bus_sync() and
* g_dbus_connection_new_for_address().
*
* Note that the returned #GDBusConnection object will (usually) have
* the #GDBusConnection:exit-on-close property set to %TRUE.
*
* Returns: (transfer full): a #GDBusConnection or %NULL if @error is set.
* Free with g_object_unref().
*
* Since: 2.26
*/
GDBusConnection *
g_bus_get_sync (GBusType bus_type,
GCancellable *cancellable,
GError **error)
{
GDBusConnection *connection;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
connection = get_uninitialized_connection (bus_type, cancellable, error);
if (connection == NULL)
goto out;
if (!g_initable_init (G_INITABLE (connection), cancellable, error))
{
g_object_unref (connection);
connection = NULL;
}
out:
return connection;
}
/**
* GBusType:
* @G_BUS_TYPE_STARTER: An alias for the message bus that activated the process, if any.
* @G_BUS_TYPE_NONE: Not a message bus.
* @G_BUS_TYPE_SYSTEM: The system-wide message bus.
* @G_BUS_TYPE_SESSION: The login session message bus.
*
* An enumeration for well-known message buses.
*
* Since: 2.26
*/
typedef enum
{
G_BUS_TYPE_STARTER = -1,
G_BUS_TYPE_NONE = 0,
G_BUS_TYPE_SYSTEM = 1,
G_BUS_TYPE_SESSION = 2
} GBusType;
二:Connected to dbus.
/**
* _g_freedesktop_dbus_proxy_new_sync:
* @connection: A #GDBusConnection.
* @flags: Flags from the #GDBusProxyFlags enumeration.
* @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
* @object_path: An object path.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL
*
* Synchronously creates a proxy for the D-Bus interface <link linkend="gdbus-interface-org-freedesktop-DBus.top_of_page">org.freedesktop.DBus</link>. See g_dbus_proxy_new_sync() for more details.
*
* The calling thread is blocked until a reply is received.
*
* See _g_freedesktop_dbus_proxy_new() for the asynchronous version of this constructor.
*
* Returns: (transfer full) (type _GFreedesktopDBusProxy): The constructed proxy object or %NULL if @error is set.
*/
_GFreedesktopDBus *
_g_freedesktop_dbus_proxy_new_sync (
GDBusConnection *connection,
GDBusProxyFlags flags,
const gchar *name,
const gchar *object_path,
GCancellable *cancellable,
GError **error)
{
GInitable *ret;
ret = g_initable_new (_G_TYPE_FREEDESKTOP_DBUS_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "org.freedesktop.DBus", NULL);
if (ret != NULL)
return _G_FREEDESKTOP_DBUS (ret);
else
return NULL;
}
/**
* g_initable_new:
* @object_type: a #GType supporting #GInitable.
* @cancellable: optional #GCancellable object, %NULL to ignore.
* @error: a #GError location to store the error occurring, or %NULL to
* ignore.
* @first_property_name: (allow-none): the name of the first property, or %NULL if no
* properties
* @...: the value if the first property, followed by and other property
* value pairs, and ended by %NULL.
*
* Helper function for constructing #GInitable object. This is
* similar to g_object_new() but also initializes the object
* and returns %NULL, setting an error on failure.
*
* Returns: (type GObject.Object) (transfer full): a newly allocated
* #GObject, or %NULL on error
*
* Since: 2.22
*/
gpointer
g_initable_new (GType object_type,
GCancellable *cancellable,
GError **error,
const gchar *first_property_name,
...)
{
GObject *object;
va_list var_args;
va_start (var_args, first_property_name);
object = g_initable_new_valist (object_type,
first_property_name, var_args,
cancellable, error);
va_end (var_args);
return object;
}
/**
* g_main_loop_new:
* @context: (allow-none): a #GMainContext (if %NULL, the default context will be used).
* @is_running: set to %TRUE to indicate that the loop is running. This
* is not very important since calling g_main_loop_run() will set this to
* %TRUE anyway.
*
* Creates a new #GMainLoop structure.
*
* Returns: a new #GMainLoop.
**/
GMainLoop *
g_main_loop_new (GMainContext *context,
gboolean is_running)
{
GMainLoop *loop;
if (!context)
context = g_main_context_default();
g_main_context_ref (context);
loop = g_new0 (GMainLoop, 1);
loop->context = context;
loop->is_running = is_running != FALSE;
loop->ref_count = 1;
return loop;
}
/**
* g_main_loop_run:
* @loop: a #GMainLoop
*
* Runs a main loop until g_main_loop_quit() is called on the loop.
* If this is called for the thread of the loop's #GMainContext,
* it will process events from the loop, otherwise it will
* simply wait.
**/
void g_main_loop_run (GMainLoop *loop)
/**
* g_timeout_add:
* @interval: the time between calls to the function, in milliseconds
* (1/1000ths of a second)
* @function: function to call
* @data: data to pass to @function
*
* Sets a function to be called at regular intervals, with the default
* priority, #G_PRIORITY_DEFAULT. The function is called repeatedly
* until it returns %FALSE, at which point the timeout is automatically
* destroyed and the function will not be called again. The first call
* to the function will be at the end of the first @interval.
*
* Note that timeout functions may be delayed, due to the processing of other
* event sources. Thus they should not be relied on for precise timing.
* After each call to the timeout function, the time of the next
* timeout is recalculated based on the current time and the given interval
* (it does not try to 'catch up' time lost in delays).
*
* If you want to have a timer in the "seconds" range and do not care
* about the exact time of the first call of the timer, use the
* g_timeout_add_seconds() function; this function allows for more
* optimizations and more efficient system power usage.
*
* This internally creates a main loop source using g_timeout_source_new()
* and attaches it to the main loop context using g_source_attach(). You can
* do these steps manually if you need greater control.
*
* The interval given is in terms of monotonic time, not wall clock
* time. See g_get_monotonic_time().
*
* Returns: the ID (greater than 0) of the event source.
**/
guint
g_timeout_add (guint32 interval,
GSourceFunc function,
gpointer data)
{
return g_timeout_add_full (G_PRIORITY_DEFAULT,
interval, function, data, NULL);
}
总结:利用以上几个函数是可以做一个简单的client,再往后就是函数调用了。根据
GSourceFunc function,
这个参数,我们可以添加我们的函数到这里。再接下来就是Application的工作了。
转载于:https://blog.51cto.com/tonkey/1434046