Exemplo n.º 1
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
        VALUE rbbase_stream, size;
        GInputStream *base_stream, *stream;

        rb_scan_args(argc, argv, "11", &rbbase_stream, &size);
        base_stream = RVAL2GINPUTSTREAM(rbbase_stream);

        stream = NIL_P(size) ?
                g_buffered_input_stream_new(base_stream) :
                g_buffered_input_stream_new_sized(base_stream, RVAL2GSIZE(size));
        G_INITIALIZE(self, stream);

        return Qnil;
}
Exemplo n.º 2
0
/**
 * news_parser_parse_async:
 * @parser: (in): A #NewsParser.
 * @stream: (in): A #GInputStream.
 * @cancellable: (in): A #GCancellable to to cancel the task.
 * @callback: (in): A callback to perform when the operation completes.
 * @user_data: (in): User data for @callback.
 *
 * Requests that @parser parse the feed contained in @stream asynchronously.
 * When the operation completes, @callback will be executed from the
 * main loop. @callback is responsible for calling news_parser_parse_finish()
 * to retrieve the result.
 *
 * Returns: None.
 */
void
news_parser_parse_async (NewsParser          *parser,
                         GInputStream        *stream,
                         GCancellable        *cancellable,
                         GAsyncReadyCallback  callback,
                         gpointer             user_data)
{
   NewsParserPrivate *priv;
   GInputStream *buffered;

   ENTRY;

   g_return_if_fail(NEWS_IS_PARSER(parser));
   g_return_if_fail(G_IS_INPUT_STREAM(stream));
   g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable));
   g_return_if_fail(callback != NULL);
   g_return_if_fail(parser->priv->simple == NULL);

   priv = parser->priv;

   priv->simple = g_simple_async_result_new(G_OBJECT(parser),
                                            callback, user_data,
                                            news_parser_parse_async);

   if (cancellable) {
      priv->cancellable = g_object_ref(cancellable);
   }

   buffered = g_buffered_input_stream_new_sized(stream, 1024);
   g_buffered_input_stream_fill_async(G_BUFFERED_INPUT_STREAM(buffered),
                                      BUFFER_FILL_SIZE,
                                      G_PRIORITY_DEFAULT,
                                      priv->cancellable,
                                      news_parser_buffered_fill_cb,
                                      g_object_ref(parser));
   g_object_unref(buffered);

   EXIT;
}