1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.DBusMethodInvocation; 26 27 private import gio.DBusConnection; 28 private import gio.DBusMessage; 29 private import gio.DBusMethodInfo; 30 private import gio.DBusPropertyInfo; 31 private import gio.UnixFDList; 32 private import gio.c.functions; 33 public import gio.c.types; 34 private import glib.ErrorG; 35 private import glib.Str; 36 private import glib.Variant; 37 private import gobject.ObjectG; 38 public import gtkc.giotypes; 39 40 41 /** 42 * Instances of the #GDBusMethodInvocation class are used when 43 * handling D-Bus method calls. It provides a way to asynchronously 44 * return results and errors. 45 * 46 * The normal way to obtain a #GDBusMethodInvocation object is to receive 47 * it as an argument to the handle_method_call() function in a 48 * #GDBusInterfaceVTable that was passed to g_dbus_connection_register_object(). 49 * 50 * Since: 2.26 51 */ 52 public class DBusMethodInvocation : ObjectG 53 { 54 /** the main Gtk struct */ 55 protected GDBusMethodInvocation* gDBusMethodInvocation; 56 57 /** Get the main Gtk struct */ 58 public GDBusMethodInvocation* getDBusMethodInvocationStruct(bool transferOwnership = false) 59 { 60 if (transferOwnership) 61 ownedRef = false; 62 return gDBusMethodInvocation; 63 } 64 65 /** the main Gtk struct as a void* */ 66 protected override void* getStruct() 67 { 68 return cast(void*)gDBusMethodInvocation; 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GDBusMethodInvocation* gDBusMethodInvocation, bool ownedRef = false) 75 { 76 this.gDBusMethodInvocation = gDBusMethodInvocation; 77 super(cast(GObject*)gDBusMethodInvocation, ownedRef); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return g_dbus_method_invocation_get_type(); 85 } 86 87 /** 88 * Gets the #GDBusConnection the method was invoked on. 89 * 90 * Returns: A #GDBusConnection. Do not free, it is owned by @invocation. 91 * 92 * Since: 2.26 93 */ 94 public DBusConnection getConnection() 95 { 96 auto __p = g_dbus_method_invocation_get_connection(gDBusMethodInvocation); 97 98 if(__p is null) 99 { 100 return null; 101 } 102 103 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) __p); 104 } 105 106 /** 107 * Gets the name of the D-Bus interface the method was invoked on. 108 * 109 * If this method call is a property Get, Set or GetAll call that has 110 * been redirected to the method call handler then 111 * "org.freedesktop.DBus.Properties" will be returned. See 112 * #GDBusInterfaceVTable for more information. 113 * 114 * Returns: A string. Do not free, it is owned by @invocation. 115 * 116 * Since: 2.26 117 */ 118 public string getInterfaceName() 119 { 120 return Str.toString(g_dbus_method_invocation_get_interface_name(gDBusMethodInvocation)); 121 } 122 123 /** 124 * Gets the #GDBusMessage for the method invocation. This is useful if 125 * you need to use low-level protocol features, such as UNIX file 126 * descriptor passing, that cannot be properly expressed in the 127 * #GVariant API. 128 * 129 * See this [server][gdbus-server] and [client][gdbus-unix-fd-client] 130 * for an example of how to use this low-level API to send and receive 131 * UNIX file descriptors. 132 * 133 * Returns: #GDBusMessage. Do not free, it is owned by @invocation. 134 * 135 * Since: 2.26 136 */ 137 public DBusMessage getMessage() 138 { 139 auto __p = g_dbus_method_invocation_get_message(gDBusMethodInvocation); 140 141 if(__p is null) 142 { 143 return null; 144 } 145 146 return ObjectG.getDObject!(DBusMessage)(cast(GDBusMessage*) __p); 147 } 148 149 /** 150 * Gets information about the method call, if any. 151 * 152 * If this method invocation is a property Get, Set or GetAll call that 153 * has been redirected to the method call handler then %NULL will be 154 * returned. See g_dbus_method_invocation_get_property_info() and 155 * #GDBusInterfaceVTable for more information. 156 * 157 * Returns: A #GDBusMethodInfo or %NULL. Do not free, it is owned by @invocation. 158 * 159 * Since: 2.26 160 */ 161 public DBusMethodInfo getMethodInfo() 162 { 163 auto __p = g_dbus_method_invocation_get_method_info(gDBusMethodInvocation); 164 165 if(__p is null) 166 { 167 return null; 168 } 169 170 return ObjectG.getDObject!(DBusMethodInfo)(cast(GDBusMethodInfo*) __p); 171 } 172 173 /** 174 * Gets the name of the method that was invoked. 175 * 176 * Returns: A string. Do not free, it is owned by @invocation. 177 * 178 * Since: 2.26 179 */ 180 public string getMethodName() 181 { 182 return Str.toString(g_dbus_method_invocation_get_method_name(gDBusMethodInvocation)); 183 } 184 185 /** 186 * Gets the object path the method was invoked on. 187 * 188 * Returns: A string. Do not free, it is owned by @invocation. 189 * 190 * Since: 2.26 191 */ 192 public string getObjectPath() 193 { 194 return Str.toString(g_dbus_method_invocation_get_object_path(gDBusMethodInvocation)); 195 } 196 197 /** 198 * Gets the parameters of the method invocation. If there are no input 199 * parameters then this will return a GVariant with 0 children rather than NULL. 200 * 201 * Returns: A #GVariant tuple. Do not unref this because it is owned by @invocation. 202 * 203 * Since: 2.26 204 */ 205 public Variant getParameters() 206 { 207 auto __p = g_dbus_method_invocation_get_parameters(gDBusMethodInvocation); 208 209 if(__p is null) 210 { 211 return null; 212 } 213 214 return new Variant(cast(GVariant*) __p); 215 } 216 217 /** 218 * Gets information about the property that this method call is for, if 219 * any. 220 * 221 * This will only be set in the case of an invocation in response to a 222 * property Get or Set call that has been directed to the method call 223 * handler for an object on account of its property_get() or 224 * property_set() vtable pointers being unset. 225 * 226 * See #GDBusInterfaceVTable for more information. 227 * 228 * If the call was GetAll, %NULL will be returned. 229 * 230 * Returns: a #GDBusPropertyInfo or %NULL 231 * 232 * Since: 2.38 233 */ 234 public DBusPropertyInfo getPropertyInfo() 235 { 236 auto __p = g_dbus_method_invocation_get_property_info(gDBusMethodInvocation); 237 238 if(__p is null) 239 { 240 return null; 241 } 242 243 return ObjectG.getDObject!(DBusPropertyInfo)(cast(GDBusPropertyInfo*) __p); 244 } 245 246 /** 247 * Gets the bus name that invoked the method. 248 * 249 * Returns: A string. Do not free, it is owned by @invocation. 250 * 251 * Since: 2.26 252 */ 253 public string getSender() 254 { 255 return Str.toString(g_dbus_method_invocation_get_sender(gDBusMethodInvocation)); 256 } 257 258 /** 259 * Gets the @user_data #gpointer passed to g_dbus_connection_register_object(). 260 * 261 * Returns: A #gpointer. 262 * 263 * Since: 2.26 264 */ 265 public void* getUserData() 266 { 267 return g_dbus_method_invocation_get_user_data(gDBusMethodInvocation); 268 } 269 270 /** 271 * Finishes handling a D-Bus method call by returning an error. 272 * 273 * This method will take ownership of @invocation. See 274 * #GDBusInterfaceVTable for more information about the ownership of 275 * @invocation. 276 * 277 * Params: 278 * errorName = A valid D-Bus error name. 279 * errorMessage = A valid D-Bus error message. 280 * 281 * Since: 2.26 282 */ 283 public void returnDbusError(string errorName, string errorMessage) 284 { 285 g_dbus_method_invocation_return_dbus_error(gDBusMethodInvocation, Str.toStringz(errorName), Str.toStringz(errorMessage)); 286 } 287 288 /** 289 * Like g_dbus_method_invocation_return_error() but without printf()-style formatting. 290 * 291 * This method will take ownership of @invocation. See 292 * #GDBusInterfaceVTable for more information about the ownership of 293 * @invocation. 294 * 295 * Params: 296 * domain = A #GQuark for the #GError error domain. 297 * code = The error code. 298 * message = The error message. 299 * 300 * Since: 2.26 301 */ 302 public void returnErrorLiteral(GQuark domain, int code, string message) 303 { 304 g_dbus_method_invocation_return_error_literal(gDBusMethodInvocation, domain, code, Str.toStringz(message)); 305 } 306 307 /** 308 * Like g_dbus_method_invocation_return_error() but intended for 309 * language bindings. 310 * 311 * This method will take ownership of @invocation. See 312 * #GDBusInterfaceVTable for more information about the ownership of 313 * @invocation. 314 * 315 * Params: 316 * domain = A #GQuark for the #GError error domain. 317 * code = The error code. 318 * format = printf()-style format. 319 * varArgs = #va_list of parameters for @format. 320 * 321 * Since: 2.26 322 */ 323 public void returnErrorValist(GQuark domain, int code, string format, void* varArgs) 324 { 325 g_dbus_method_invocation_return_error_valist(gDBusMethodInvocation, domain, code, Str.toStringz(format), varArgs); 326 } 327 328 /** 329 * Like g_dbus_method_invocation_return_error() but takes a #GError 330 * instead of the error domain, error code and message. 331 * 332 * This method will take ownership of @invocation. See 333 * #GDBusInterfaceVTable for more information about the ownership of 334 * @invocation. 335 * 336 * Params: 337 * error = A #GError. 338 * 339 * Since: 2.26 340 */ 341 public void returnGerror(ErrorG error) 342 { 343 g_dbus_method_invocation_return_gerror(gDBusMethodInvocation, (error is null) ? null : error.getErrorGStruct()); 344 } 345 346 /** 347 * Finishes handling a D-Bus method call by returning @parameters. 348 * If the @parameters GVariant is floating, it is consumed. 349 * 350 * It is an error if @parameters is not of the right format: it must be a tuple 351 * containing the out-parameters of the D-Bus method. Even if the method has a 352 * single out-parameter, it must be contained in a tuple. If the method has no 353 * out-parameters, @parameters may be %NULL or an empty tuple. 354 * 355 * |[<!-- language="C" --> 356 * GDBusMethodInvocation *invocation = some_invocation; 357 * g_autofree gchar *result_string = NULL; 358 * g_autoptr (GError) error = NULL; 359 * 360 * result_string = calculate_result (&error); 361 * 362 * if (error != NULL) 363 * g_dbus_method_invocation_return_gerror (invocation, error); 364 * else 365 * g_dbus_method_invocation_return_value (invocation, 366 * g_variant_new ("(s)", result_string)); 367 * 368 * // Do not free @invocation here; returning a value does that 369 * ]| 370 * 371 * This method will take ownership of @invocation. See 372 * #GDBusInterfaceVTable for more information about the ownership of 373 * @invocation. 374 * 375 * Since 2.48, if the method call requested for a reply not to be sent 376 * then this call will sink @parameters and free @invocation, but 377 * otherwise do nothing (as per the recommendations of the D-Bus 378 * specification). 379 * 380 * Params: 381 * parameters = A #GVariant tuple with out parameters for the method or %NULL if not passing any parameters. 382 * 383 * Since: 2.26 384 */ 385 public void returnValue(Variant parameters) 386 { 387 g_dbus_method_invocation_return_value(gDBusMethodInvocation, (parameters is null) ? null : parameters.getVariantStruct()); 388 } 389 390 /** 391 * Like g_dbus_method_invocation_return_value() but also takes a #GUnixFDList. 392 * 393 * This method is only available on UNIX. 394 * 395 * This method will take ownership of @invocation. See 396 * #GDBusInterfaceVTable for more information about the ownership of 397 * @invocation. 398 * 399 * Params: 400 * parameters = A #GVariant tuple with out parameters for the method or %NULL if not passing any parameters. 401 * fdList = A #GUnixFDList or %NULL. 402 * 403 * Since: 2.30 404 */ 405 public void returnValueWithUnixFdList(Variant parameters, UnixFDList fdList) 406 { 407 g_dbus_method_invocation_return_value_with_unix_fd_list(gDBusMethodInvocation, (parameters is null) ? null : parameters.getVariantStruct(), (fdList is null) ? null : fdList.getUnixFDListStruct()); 408 } 409 410 /** 411 * Like g_dbus_method_invocation_return_gerror() but takes ownership 412 * of @error so the caller does not need to free it. 413 * 414 * This method will take ownership of @invocation. See 415 * #GDBusInterfaceVTable for more information about the ownership of 416 * @invocation. 417 * 418 * Params: 419 * error = A #GError. 420 * 421 * Since: 2.30 422 */ 423 public void takeError(ErrorG error) 424 { 425 g_dbus_method_invocation_take_error(gDBusMethodInvocation, (error is null) ? null : error.getErrorGStruct(true)); 426 } 427 }