/gio2/ext/gio2/gfileinputstream.c

https://github.com/geoffyoungs/ruby-gnome2 · C · 90 lines · 57 code · 14 blank · 19 comment · 4 complexity · 20d3177cbb484f6b71e45f4f3dc5dbbf MD5 · raw file

  1. /* -*- c-file-style: "ruby" -*- */
  2. /*
  3. * Ruby/GIO: a Ruby binding of gio-2.0.x.
  4. * Copyright (C) 2008-2009 Ruby-GNOME2 Project Team
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include "gio2.h"
  21. #define _SELF(value) G_FILE_INPUT_STREAM(RVAL2GOBJ(value))
  22. static VALUE
  23. fileinputstream_query_info(int argc, VALUE *argv, VALUE self)
  24. {
  25. VALUE attributes, cancellable;
  26. GError *error = NULL;
  27. GFileInfo *info;
  28. rb_scan_args(argc, argv, "02", &attributes, &cancellable);
  29. info = g_file_input_stream_query_info(_SELF(self),
  30. RVAL2ATTRIBUTESDEFAULT(attributes),
  31. RVAL2GCANCELLABLE(cancellable),
  32. &error);
  33. if (info == NULL)
  34. rbgio_raise_error(error);
  35. return GOBJ2RVAL_UNREF(info);
  36. }
  37. static VALUE
  38. fileinputstream_query_info_async(int argc, VALUE *argv, VALUE self)
  39. {
  40. VALUE rbattributes, rbio_priority, rbcancellable, block;
  41. const char *attributes;
  42. int io_priority;
  43. GCancellable *cancellable;
  44. rb_scan_args(argc, argv, "03&", &rbattributes, &rbio_priority, &rbcancellable, &block);
  45. attributes = RVAL2ATTRIBUTESDEFAULT(rbattributes);
  46. io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
  47. cancellable = RVAL2GCANCELLABLE(rbcancellable);
  48. SAVE_BLOCK(block);
  49. g_file_input_stream_query_info_async(_SELF(self),
  50. attributes,
  51. io_priority,
  52. cancellable,
  53. rbgio_async_ready_callback,
  54. (gpointer)block);
  55. return self;
  56. }
  57. static VALUE
  58. fileinputstream_query_info_finish(VALUE self, VALUE result)
  59. {
  60. GError *error = NULL;
  61. GFileInfo *info;
  62. info = g_file_input_stream_query_info_finish(_SELF(self),
  63. RVAL2GASYNCRESULT(result),
  64. &error);
  65. if (info == NULL)
  66. rbgio_raise_error(error);
  67. return GOBJ2RVAL_UNREF(info);
  68. }
  69. void
  70. Init_gfileinputstream(VALUE glib)
  71. {
  72. VALUE fileinputstream = G_DEF_CLASS(G_TYPE_FILE_INPUT_STREAM, "FileInputStream", glib);
  73. rb_define_method(fileinputstream, "query_info", fileinputstream_query_info, -1);
  74. rb_define_method(fileinputstream, "query_info_async", fileinputstream_query_info_async, -1);
  75. rb_define_method(fileinputstream, "query_info_finish", fileinputstream_query_info_finish, 1);
  76. }