1/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2/* vim:set et sts=4: */
3/* ibus - The Input Bus
4 * Copyright (C) 2008-2015 Peng Huang <shawn.p.huang@gmail.com>
5 * Copyright (C) 2008-2015 Red Hat, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20 * USA
21 */
22
23#if !defined (__IBUS_H_INSIDE__) && !defined (IBUS_COMPILATION)
24#error "Only <ibus.h> can be included directly"
25#endif
26
27#ifndef __IBUS_SERVICE_H_
28#define __IBUS_SERVICE_H_
29
30/**
31 * SECTION: ibusservice
32 * @short_description: IBus service back-end.
33 * @stability: Stable
34 *
35 * An IBusService is a base class for services.
36 */
37
38#include <gio/gio.h>
39#include "ibusobject.h"
40
41/*
42 * Type macros.
43 */
44
45/* define GOBJECT macros */
46#define IBUS_TYPE_SERVICE \
47 (ibus_service_get_type ())
48#define IBUS_SERVICE(obj) \
49 (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_SERVICE, IBusService))
50#define IBUS_SERVICE_CLASS(klass) \
51 (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_SERVICE, IBusServiceClass))
52#define IBUS_IS_SERVICE(obj) \
53 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_SERVICE))
54#define IBUS_IS_SERVICE_CLASS(klass) \
55 (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_SERVICE))
56#define IBUS_SERVICE_GET_CLASS(obj) \
57 (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_SERVICE, IBusServiceClass))
58
59G_BEGIN_DECLS
60
61typedef struct _IBusService IBusService;
62typedef struct _IBusServiceClass IBusServiceClass;
63typedef struct _IBusServicePrivate IBusServicePrivate;
64
65/**
66 * IBusService:
67 *
68 * An opaque data type representing an IBusService.
69 */
70struct _IBusService {
71 /*< private >*/
72 IBusObject parent;
73 IBusServicePrivate *priv;
74};
75
76struct _IBusServiceClass {
77 /*< private >*/
78 IBusObjectClass parent;
79
80 /*< public >*/
81 /* virtual functions */
82 /**
83 * IBusServiceClass::service_method_call:
84 * @service: An #IBusService.
85 * @connection: A dbus connection.
86 * @sender: A sender.
87 * @object_path: An object path.
88 * @interface_name: An interface name.
89 * @method_name: A method name.
90 * @parameters: A parameters.
91 * @invocation: A dbus method invocation.
92 *
93 * The ::service_method_call class method is to connect
94 * GDBusInterfaceMethodCallFunc().
95 */
96 void (* service_method_call)
97 (IBusService *service,
98 GDBusConnection *connection,
99 const gchar *sender,
100 const gchar *object_path,
101 const gchar *interface_name,
102 const gchar *method_name,
103 GVariant *parameters,
104 GDBusMethodInvocation
105 *invocation);
106 /**
107 * IBusServiceClass::service_get_property:
108 * @service: An #IBusService.
109 * @connection: A dbus connection.
110 * @sender: A sender.
111 * @object_path: An object path.
112 * @interface_name: An interface name.
113 * @property_name: A property name.
114 * @error: Return location for error or %NULL.
115 *
116 * The ::service_get_property class method is to connect
117 * GDBusInterfaceGetPropertyFunc().
118 *
119 * Returns: (nullable) (transfer full): A variant.
120 */
121 GVariant * (* service_get_property)
122 (IBusService *service,
123 GDBusConnection *connection,
124 const gchar *sender,
125 const gchar *object_path,
126 const gchar *interface_name,
127 const gchar *property_name,
128 GError **error);
129 /**
130 * IBusServiceClass::service_set_property:
131 * @service: An #IBusService.
132 * @connection: A dbus connection.
133 * @sender: A sender.
134 * @object_path: An object path.
135 * @interface_name: An interface name.
136 * @property_name: An property name.
137 * @value: An property value.
138 * @error: Return location for error or %NULL.
139 *
140 * The ::service_set_property class method is to connect
141 * GDBusInterfaceSetPropertyFunc().
142 *
143 * Returns: %TRUE if set the value else %FALSE.
144 */
145 gboolean (* service_set_property)
146 (IBusService *service,
147 GDBusConnection *connection,
148 const gchar *sender,
149 const gchar *object_path,
150 const gchar *interface_name,
151 const gchar *property_name,
152 GVariant *value,
153 GError **error);
154 /*< private >*/
155 GArray *interfaces;
156
157 /* padding */
158 gpointer pdummy[4];
159};
160
161
162GType ibus_service_get_type (void);
163
164/**
165 * ibus_service_new:
166 * @connection: A GDBusConnection.
167 * @path: Object path.
168 *
169 * Creantes a new #IBusService.
170 *
171 * Returns: A newly allocated #IBusService
172 */
173IBusService *ibus_service_new (GDBusConnection *connection,
174 const gchar *path);
175/**
176 * ibus_service_get_object_path:
177 * @service: An IBusService.
178 *
179 * Gets the object path of an IBusService.
180 *
181 * Returns: The object path of @service
182 */
183const gchar *ibus_service_get_object_path (IBusService *service);
184
185/**
186 * ibus_service_get_connection:
187 * @service: An IBusService.
188 *
189 * Gets a connections.
190 *
191 * Returns: (transfer none): A #GDBusConnection of an #IBusService instance.
192 */
193GDBusConnection *ibus_service_get_connection (IBusService *service);
194
195/**
196 * ibus_service_register:
197 * @service: An IBusService.
198 * @connection: A GDBusConnection the service will be registered to.
199 * @error: Return location for error or NULL.
200 *
201 * Registers service to a connection.
202 *
203 * Returns: %TRUE if the service was registered, %FALSE otherwise.
204 */
205gboolean ibus_service_register (IBusService *service,
206 GDBusConnection *connection,
207 GError **error);
208/**
209 * ibus_service_unregister:
210 * @service: An IBusService.
211 * @connection: A GDBusConnection the service was registered with.
212 *
213 * Unregisters service from a connection.
214 */
215void ibus_service_unregister (IBusService *service,
216 GDBusConnection *connection);
217
218
219
220/**
221 * ibus_service_send_signal:
222 * @service: An IBusService.
223 * @interface: The interface the signal is emitted from.
224 * @name: Name of the signal.
225 * @first_arg_type: Type of first argument.
226 * @...: Rest of arguments, NULL to mark the end.
227 *
228 * Sends signal to all the #IBusConnections of an #IBusService.
229 *
230 * Returns: %TRUE if succeed; %FALSE otherwise.
231 *
232 * see_also: g_dbus_connection_emit_signal()
233 */
234gboolean ibus_service_emit_signal (IBusService *service,
235 const gchar *dest_bus_name,
236 const gchar *interface_name,
237 const gchar *signal_name,
238 GVariant *parameters,
239 GError **error);
240/**
241 * ibus_service_class_add_interfaces:
242 * @klass: An IBusServiceClass.
243 * @xml_data: The introspection xml data.
244 *
245 * Set the interface introspection information with the service class.
246 *
247 * Returns: %TRUE if @xml_data is valid and succeeded to be added;
248 * %FALSE otherwise.
249 */
250gboolean ibus_service_class_add_interfaces
251 (IBusServiceClass *klass,
252 const gchar *xml_data);
253
254
255G_END_DECLS
256#endif
257
258