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 protected override void setStruct(GObject* obj) 72 { 73 gDBusMethodInvocation = cast(GDBusMethodInvocation*)obj; 74 super.setStruct(obj); 75 } 76 77 /** 78 * Sets our main struct and passes it to the parent class. 79 */ 80 public this (GDBusMethodInvocation* gDBusMethodInvocation, bool ownedRef = false) 81 { 82 this.gDBusMethodInvocation = gDBusMethodInvocation; 83 super(cast(GObject*)gDBusMethodInvocation, ownedRef); 84 } 85 86 87 /** */ 88 public static GType getType() 89 { 90 return g_dbus_method_invocation_get_type(); 91 } 92 93 /** 94 * Gets the #GDBusConnection the method was invoked on. 95 * 96 * Returns: A #GDBusConnection. Do not free, it is owned by @invocation. 97 * 98 * Since: 2.26 99 */ 100 public DBusConnection getConnection() 101 { 102 auto p = g_dbus_method_invocation_get_connection(gDBusMethodInvocation); 103 104 if(p is null) 105 { 106 return null; 107 } 108 109 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p); 110 } 111 112 /** 113 * Gets the name of the D-Bus interface the method was invoked on. 114 * 115 * If this method call is a property Get, Set or GetAll call that has 116 * been redirected to the method call handler then 117 * "org.freedesktop.DBus.Properties" will be returned. See 118 * #GDBusInterfaceVTable for more information. 119 * 120 * Returns: A string. Do not free, it is owned by @invocation. 121 * 122 * Since: 2.26 123 */ 124 public string getInterfaceName() 125 { 126 return Str.toString(g_dbus_method_invocation_get_interface_name(gDBusMethodInvocation)); 127 } 128 129 /** 130 * Gets the #GDBusMessage for the method invocation. This is useful if 131 * you need to use low-level protocol features, such as UNIX file 132 * descriptor passing, that cannot be properly expressed in the 133 * #GVariant API. 134 * 135 * See this [server][gdbus-server] and [client][gdbus-unix-fd-client] 136 * for an example of how to use this low-level API to send and receive 137 * UNIX file descriptors. 138 * 139 * Returns: #GDBusMessage. Do not free, it is owned by @invocation. 140 * 141 * Since: 2.26 142 */ 143 public DBusMessage getMessage() 144 { 145 auto p = g_dbus_method_invocation_get_message(gDBusMethodInvocation); 146 147 if(p is null) 148 { 149 return null; 150 } 151 152 return ObjectG.getDObject!(DBusMessage)(cast(GDBusMessage*) p); 153 } 154 155 /** 156 * Gets information about the method call, if any. 157 * 158 * If this method invocation is a property Get, Set or GetAll call that 159 * has been redirected to the method call handler then %NULL will be 160 * returned. See g_dbus_method_invocation_get_property_info() and 161 * #GDBusInterfaceVTable for more information. 162 * 163 * Returns: A #GDBusMethodInfo or %NULL. Do not free, it is owned by @invocation. 164 * 165 * Since: 2.26 166 */ 167 public DBusMethodInfo getMethodInfo() 168 { 169 auto p = g_dbus_method_invocation_get_method_info(gDBusMethodInvocation); 170 171 if(p is null) 172 { 173 return null; 174 } 175 176 return ObjectG.getDObject!(DBusMethodInfo)(cast(GDBusMethodInfo*) p); 177 } 178 179 /** 180 * Gets the name of the method that was invoked. 181 * 182 * Returns: A string. Do not free, it is owned by @invocation. 183 * 184 * Since: 2.26 185 */ 186 public string getMethodName() 187 { 188 return Str.toString(g_dbus_method_invocation_get_method_name(gDBusMethodInvocation)); 189 } 190 191 /** 192 * Gets the object path the method was invoked on. 193 * 194 * Returns: A string. Do not free, it is owned by @invocation. 195 * 196 * Since: 2.26 197 */ 198 public string getObjectPath() 199 { 200 return Str.toString(g_dbus_method_invocation_get_object_path(gDBusMethodInvocation)); 201 } 202 203 /** 204 * Gets the parameters of the method invocation. If there are no input 205 * parameters then this will return a GVariant with 0 children rather than NULL. 206 * 207 * Returns: A #GVariant tuple. Do not unref this because it is owned by @invocation. 208 * 209 * Since: 2.26 210 */ 211 public Variant getParameters() 212 { 213 auto p = g_dbus_method_invocation_get_parameters(gDBusMethodInvocation); 214 215 if(p is null) 216 { 217 return null; 218 } 219 220 return new Variant(cast(GVariant*) p); 221 } 222 223 /** 224 * Gets information about the property that this method call is for, if 225 * any. 226 * 227 * This will only be set in the case of an invocation in response to a 228 * property Get or Set call that has been directed to the method call 229 * handler for an object on account of its property_get() or 230 * property_set() vtable pointers being unset. 231 * 232 * See #GDBusInterfaceVTable for more information. 233 * 234 * If the call was GetAll, %NULL will be returned. 235 * 236 * Returns: a #GDBusPropertyInfo or %NULL 237 * 238 * Since: 2.38 239 */ 240 public DBusPropertyInfo getPropertyInfo() 241 { 242 auto p = g_dbus_method_invocation_get_property_info(gDBusMethodInvocation); 243 244 if(p is null) 245 { 246 return null; 247 } 248 249 return ObjectG.getDObject!(DBusPropertyInfo)(cast(GDBusPropertyInfo*) p); 250 } 251 252 /** 253 * Gets the bus name that invoked the method. 254 * 255 * Returns: A string. Do not free, it is owned by @invocation. 256 * 257 * Since: 2.26 258 */ 259 public string getSender() 260 { 261 return Str.toString(g_dbus_method_invocation_get_sender(gDBusMethodInvocation)); 262 } 263 264 /** 265 * Gets the @user_data #gpointer passed to g_dbus_connection_register_object(). 266 * 267 * Returns: A #gpointer. 268 * 269 * Since: 2.26 270 */ 271 public void* getUserData() 272 { 273 return g_dbus_method_invocation_get_user_data(gDBusMethodInvocation); 274 } 275 276 /** 277 * Finishes handling a D-Bus method call by returning an error. 278 * 279 * This method will take ownership of @invocation. See 280 * #GDBusInterfaceVTable for more information about the ownership of 281 * @invocation. 282 * 283 * Params: 284 * errorName = A valid D-Bus error name. 285 * errorMessage = A valid D-Bus error message. 286 * 287 * Since: 2.26 288 */ 289 public void returnDbusError(string errorName, string errorMessage) 290 { 291 g_dbus_method_invocation_return_dbus_error(gDBusMethodInvocation, Str.toStringz(errorName), Str.toStringz(errorMessage)); 292 } 293 294 /** 295 * Like g_dbus_method_invocation_return_error() but without printf()-style formatting. 296 * 297 * This method will take ownership of @invocation. See 298 * #GDBusInterfaceVTable for more information about the ownership of 299 * @invocation. 300 * 301 * Params: 302 * domain = A #GQuark for the #GError error domain. 303 * code = The error code. 304 * message = The error message. 305 * 306 * Since: 2.26 307 */ 308 public void returnErrorLiteral(GQuark domain, int code, string message) 309 { 310 g_dbus_method_invocation_return_error_literal(gDBusMethodInvocation, domain, code, Str.toStringz(message)); 311 } 312 313 /** 314 * Like g_dbus_method_invocation_return_error() but intended for 315 * language bindings. 316 * 317 * This method will take ownership of @invocation. See 318 * #GDBusInterfaceVTable for more information about the ownership of 319 * @invocation. 320 * 321 * Params: 322 * domain = A #GQuark for the #GError error domain. 323 * code = The error code. 324 * format = printf()-style format. 325 * varArgs = #va_list of parameters for @format. 326 * 327 * Since: 2.26 328 */ 329 public void returnErrorValist(GQuark domain, int code, string format, void* varArgs) 330 { 331 g_dbus_method_invocation_return_error_valist(gDBusMethodInvocation, domain, code, Str.toStringz(format), varArgs); 332 } 333 334 /** 335 * Like g_dbus_method_invocation_return_error() but takes a #GError 336 * instead of the error domain, error code and message. 337 * 338 * This method will take ownership of @invocation. See 339 * #GDBusInterfaceVTable for more information about the ownership of 340 * @invocation. 341 * 342 * Params: 343 * error = A #GError. 344 * 345 * Since: 2.26 346 */ 347 public void returnGerror(ErrorG error) 348 { 349 g_dbus_method_invocation_return_gerror(gDBusMethodInvocation, (error is null) ? null : error.getErrorGStruct()); 350 } 351 352 /** 353 * Finishes handling a D-Bus method call by returning @parameters. 354 * If the @parameters GVariant is floating, it is consumed. 355 * 356 * It is an error if @parameters is not of the right format: it must be a tuple 357 * containing the out-parameters of the D-Bus method. Even if the method has a 358 * single out-parameter, it must be contained in a tuple. If the method has no 359 * out-parameters, @parameters may be %NULL or an empty tuple. 360 * 361 * |[<!-- language="C" --> 362 * GDBusMethodInvocation *invocation = some_invocation; 363 * g_autofree gchar *result_string = NULL; 364 * g_autoptr (GError) error = NULL; 365 * 366 * result_string = calculate_result (&error); 367 * 368 * if (error != NULL) 369 * g_dbus_method_invocation_return_gerror (invocation, error); 370 * else 371 * g_dbus_method_invocation_return_value (invocation, 372 * g_variant_new ("(s)", result_string)); 373 * 374 * /<!-- -->* Do not free @invocation here; returning a value does that *<!-- -->/ 375 * ]| 376 * 377 * This method will take ownership of @invocation. See 378 * #GDBusInterfaceVTable for more information about the ownership of 379 * @invocation. 380 * 381 * Since 2.48, if the method call requested for a reply not to be sent 382 * then this call will sink @parameters and free @invocation, but 383 * otherwise do nothing (as per the recommendations of the D-Bus 384 * specification). 385 * 386 * Params: 387 * parameters = A #GVariant tuple with out parameters for the method or %NULL if not passing any parameters. 388 * 389 * Since: 2.26 390 */ 391 public void returnValue(Variant parameters) 392 { 393 g_dbus_method_invocation_return_value(gDBusMethodInvocation, (parameters is null) ? null : parameters.getVariantStruct()); 394 } 395 396 /** 397 * Like g_dbus_method_invocation_return_value() but also takes a #GUnixFDList. 398 * 399 * This method is only available on UNIX. 400 * 401 * This method will take ownership of @invocation. See 402 * #GDBusInterfaceVTable for more information about the ownership of 403 * @invocation. 404 * 405 * Params: 406 * parameters = A #GVariant tuple with out parameters for the method or %NULL if not passing any parameters. 407 * fdList = A #GUnixFDList or %NULL. 408 * 409 * Since: 2.30 410 */ 411 public void returnValueWithUnixFdList(Variant parameters, UnixFDList fdList) 412 { 413 g_dbus_method_invocation_return_value_with_unix_fd_list(gDBusMethodInvocation, (parameters is null) ? null : parameters.getVariantStruct(), (fdList is null) ? null : fdList.getUnixFDListStruct()); 414 } 415 416 /** 417 * Like g_dbus_method_invocation_return_gerror() but takes ownership 418 * of @error so the caller does not need to free it. 419 * 420 * This method will take ownership of @invocation. See 421 * #GDBusInterfaceVTable for more information about the ownership of 422 * @invocation. 423 * 424 * Params: 425 * error = A #GError. 426 * 427 * Since: 2.30 428 */ 429 public void takeError(ErrorG error) 430 { 431 g_dbus_method_invocation_take_error(gDBusMethodInvocation, (error is null) ? null : error.getErrorGStruct(true)); 432 } 433 }