dbus Client 생성 과정에서 몇 가지 유용한 함수
/**
* 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 ();
}
1: 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;
2: 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,
이 매개 변수, 우리는 우리의 함수를 여기에 추가할 수 있습니다.그리고 다음은 응용 프로그램의 일입니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
콜백 함수를 Angular 하위 구성 요소에 전달이 예제는 구성 요소에 함수를 전달하는 것과 관련하여 최근에 직면한 문제를 다룰 것입니다. 국가 목록을 제공하는 콤보 상자 또는 테이블 구성 요소. 지금까지 모든 것이 구성 요소 자체에 캡슐화되었으며 백엔드에 대한 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.