/** * 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 */voidg_type_init (void) {G_assert_type_system_ini Tialized ();}
one: 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&nBSP; (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;
Two: 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 &Nbsp; **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 */gpointerg_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 () &NBSP;IS&NBSP;CALLED&NBSP;ON&NBSP;THE&NBSp;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. **/guintg_timeout_add (guint32 interval, GSourceFunc function, gpointer data) { return g_timeout_add_full (G_PRIORITY_DEFAULT, interval, function, data, null);}
Summary: Using the above functions can be a simple client, and then the function is called. Under
Gsourcefunc function,
With this parameter, we can add our function here. And then there's the application job.
This article is from the "Technology First" blog, please be sure to keep this source http://tonkey.blog.51cto.com/9114566/1434046