| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifdef HAVE_CONFIG_H |
| 19 |
#include "config.h" |
| 20 |
#endif |
| 21 |
|
| 22 |
#include "byzanzqueue.h" |
| 23 |
|
| 24 |
#include "byzanzqueueinputstream.h" |
| 25 |
#include "byzanzqueueoutputstream.h" |
| 26 |
|
| 27 |
enum { |
| 28 |
PROP_0, |
| 29 |
PROP_INPUT, |
| 30 |
PROP_OUTPUT, |
| 31 |
}; |
| 32 |
|
| 33 |
G_DEFINE_TYPE (ByzanzQueue, byzanz_queue, G_TYPE_OBJECT) |
| 34 |
|
| 35 |
static void |
| 36 |
byzanz_queue_get_property (GObject *object, guint param_id, GValue *value, |
| 37 |
GParamSpec * pspec) |
| 38 |
{ |
| 39 |
ByzanzQueue *queue = BYZANZ_QUEUE (object); |
| 40 |
|
| 41 |
switch (param_id) { |
| 42 |
case PROP_INPUT: |
| 43 |
g_value_set_object (value, queue->input); |
| 44 |
break; |
| 45 |
case PROP_OUTPUT: |
| 46 |
g_value_set_object (value, queue->output); |
| 47 |
break; |
| 48 |
default: |
| 49 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
| 50 |
break; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
static void |
| 55 |
byzanz_queue_set_property (GObject *object, guint param_id, const GValue *value, |
| 56 |
GParamSpec * pspec) |
| 57 |
{ |
| 58 |
|
| 59 |
|
| 60 |
switch (param_id) { |
| 61 |
default: |
| 62 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
| 63 |
break; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
static void |
| 68 |
byzanz_queue_dispose (GObject *object) |
| 69 |
{ |
| 70 |
ByzanzQueue *queue = BYZANZ_QUEUE (object); |
| 71 |
|
| 72 |
if (queue->input) |
| 73 |
g_object_unref (queue->input); |
| 74 |
if (queue->output) |
| 75 |
g_object_unref (queue->output); |
| 76 |
|
| 77 |
if (!g_atomic_int_dec_and_test (&queue->shared_count)) { |
| 78 |
g_object_ref (queue); |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
G_OBJECT_CLASS (byzanz_queue_parent_class)->dispose (object); |
| 83 |
} |
| 84 |
|
| 85 |
static void |
| 86 |
byzanz_queue_finalize (GObject *object) |
| 87 |
{ |
| 88 |
ByzanzQueue *queue = BYZANZ_QUEUE (object); |
| 89 |
GFile *file; |
| 90 |
|
| 91 |
while ((file = g_async_queue_try_pop (queue->files))) |
| 92 |
g_file_delete (file, NULL, NULL); |
| 93 |
g_async_queue_unref (queue->files); |
| 94 |
|
| 95 |
G_OBJECT_CLASS (byzanz_queue_parent_class)->dispose (object); |
| 96 |
} |
| 97 |
|
| 98 |
static void |
| 99 |
byzanz_queue_class_init (ByzanzQueueClass *klass) |
| 100 |
{ |
| 101 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 102 |
|
| 103 |
object_class->get_property = byzanz_queue_get_property; |
| 104 |
object_class->set_property = byzanz_queue_set_property; |
| 105 |
object_class->dispose = byzanz_queue_dispose; |
| 106 |
object_class->finalize = byzanz_queue_finalize; |
| 107 |
|
| 108 |
g_object_class_install_property (object_class, PROP_INPUT, |
| 109 |
g_param_spec_object ("inputstream", "input stream", "stream to use for reading from the cache", |
| 110 |
G_TYPE_INPUT_STREAM, G_PARAM_READABLE)); |
| 111 |
g_object_class_install_property (object_class, PROP_OUTPUT, |
| 112 |
g_param_spec_object ("outputstream", "output stream", "stream to use for writing to the cache", |
| 113 |
G_TYPE_OUTPUT_STREAM, G_PARAM_READABLE)); |
| 114 |
} |
| 115 |
|
| 116 |
static void |
| 117 |
byzanz_queue_init (ByzanzQueue *queue) |
| 118 |
{ |
| 119 |
queue->files = g_async_queue_new (); |
| 120 |
|
| 121 |
queue->input = byzanz_queue_input_stream_new (queue); |
| 122 |
queue->output = byzanz_queue_output_stream_new (queue); |
| 123 |
|
| 124 |
queue->shared_count = 3; |
| 125 |
} |
| 126 |
|
| 127 |
ByzanzQueue * |
| 128 |
byzanz_queue_new (void) |
| 129 |
{ |
| 130 |
return g_object_new (BYZANZ_TYPE_QUEUE, NULL); |
| 131 |
} |
| 132 |
|
| 133 |
GOutputStream * |
| 134 |
byzanz_queue_get_output_stream (ByzanzQueue *queue) |
| 135 |
{ |
| 136 |
g_return_val_if_fail (BYZANZ_IS_QUEUE (queue), NULL); |
| 137 |
|
| 138 |
return queue->output; |
| 139 |
} |
| 140 |
|
| 141 |
GInputStream * |
| 142 |
byzanz_queue_get_input_stream (ByzanzQueue *queue) |
| 143 |
{ |
| 144 |
g_return_val_if_fail (BYZANZ_IS_QUEUE (queue), NULL); |
| 145 |
|
| 146 |
return queue->input; |
| 147 |
} |
| 148 |
|