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