soup-message-queue-item.c 1.57 KB
Newer Older
Carlos Garcia Campos's avatar
Carlos Garcia Campos committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * soup-message-queue-item.c: Message queue item
 *
 * Copyright (C) 2003 Novell, Inc.
 * Copyright (C) 2008 Red Hat, Inc.
 * Copyright (C) 2021 Igalia S.L.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "soup-message-queue-item.h"
#include "soup.h"

SoupMessageQueueItem *
17
18
19
20
soup_message_queue_item_new (SoupSession  *session,
                             SoupMessage  *msg,
                             gboolean      async,
                             GCancellable *cancellable)
Carlos Garcia Campos's avatar
Carlos Garcia Campos committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
        SoupMessageQueueItem *item;

        item = g_atomic_rc_box_new0 (SoupMessageQueueItem);
        item->session = g_object_ref (session);
        item->msg = g_object_ref (msg);
        item->async = async;
        item->cancellable = cancellable ? g_object_ref (cancellable) : g_cancellable_new ();

        return item;
}

SoupMessageQueueItem *
soup_message_queue_item_ref (SoupMessageQueueItem *item)
{
        g_atomic_rc_box_acquire (item);

        return item;
}

static void
soup_message_queue_item_destroy (SoupMessageQueueItem *item)
{
44
        g_warn_if_fail (soup_message_get_connection (item->msg) == NULL);
Carlos Garcia Campos's avatar
Carlos Garcia Campos committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

        g_object_unref (item->session);
        g_object_unref (item->msg);
        g_object_unref (item->cancellable);
        g_clear_error (&item->error);
        g_clear_object (&item->task);
}

void
soup_message_queue_item_unref (SoupMessageQueueItem *item)
{
        g_atomic_rc_box_release_full (item, (GDestroyNotify)soup_message_queue_item_destroy);
}

void
soup_message_queue_item_cancel (SoupMessageQueueItem *item)
{
        g_cancellable_cancel (item->cancellable);
}