libanjuta: bgo #696984 - Fix function argument name typos in documentation comments
[anjuta.git] / libanjuta / anjuta-command-queue.c
blob74885fd5b9b6359f3e161c15d433bb77c22689dd
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2009 <jrliggett@cox.net>
5 *
6 * anjuta is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * anjuta is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "anjuta-command-queue.h"
22 enum
24 FINISHED,
26 LAST_SIGNAL
29 static guint anjuta_command_queue_signals[LAST_SIGNAL] = { 0 };
31 /**
32 * SECTION: anjuta-command-queue
33 * @short_description: #AnjutaCommandQueue is used to queue commands
34 * @include: libanjuta/anjuta-async-command.h
36 * #AnjutaCommandQueue always starts the next command in the queue when
37 * the previous command finishes. That also works for asyncronous commands
40 struct _AnjutaCommandQueuePriv
42 GQueue *queue;
43 gboolean busy;
44 AnjutaCommandQueueExecuteMode mode;
47 G_DEFINE_TYPE (AnjutaCommandQueue, anjuta_command_queue, G_TYPE_OBJECT);
49 static void
50 anjuta_command_queue_init (AnjutaCommandQueue *self)
52 self->priv = g_new0 (AnjutaCommandQueuePriv, 1);
54 self->priv->queue = g_queue_new ();
57 static void
58 anjuta_command_queue_finalize (GObject *object)
60 AnjutaCommandQueue *self;
61 GList *current_command;
63 self = ANJUTA_COMMAND_QUEUE (object);
65 current_command = self->priv->queue->head;
67 while (current_command)
69 g_object_unref (current_command->data);
70 current_command = g_list_next (current_command);
73 g_queue_free (self->priv->queue);
74 g_free (self->priv);
76 G_OBJECT_CLASS (anjuta_command_queue_parent_class)->finalize (object);
79 static void
80 finished (AnjutaCommandQueue *queue)
85 static void
86 anjuta_command_queue_class_init (AnjutaCommandQueueClass *klass)
88 GObjectClass* object_class = G_OBJECT_CLASS (klass);
90 object_class->finalize = anjuta_command_queue_finalize;
91 klass->finished = finished;
93 anjuta_command_queue_signals[FINISHED] = g_signal_new ("finished",
94 G_OBJECT_CLASS_TYPE (klass),
95 G_SIGNAL_RUN_FIRST,
96 G_STRUCT_OFFSET (AnjutaCommandQueueClass, finished),
97 NULL,
98 NULL,
99 g_cclosure_marshal_VOID__VOID,
100 G_TYPE_NONE,
105 static void
106 on_command_finished (AnjutaCommand *command, guint return_code,
107 AnjutaCommandQueue *self)
109 AnjutaCommand *next_command;
111 next_command = g_queue_pop_head (self->priv->queue);
113 if (next_command)
115 g_signal_connect (G_OBJECT (next_command), "command-finished",
116 G_CALLBACK (on_command_finished),
117 self);
119 anjuta_command_start (next_command);
121 g_object_unref (next_command);
123 else
125 self->priv->busy = FALSE;
127 if (self->priv->mode == ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL)
128 g_signal_emit_by_name (self, "finished");
132 AnjutaCommandQueue *
133 anjuta_command_queue_new (AnjutaCommandQueueExecuteMode mode)
135 AnjutaCommandQueue *self;
137 self = g_object_new (ANJUTA_TYPE_COMMAND_QUEUE, NULL);
139 self->priv->mode = mode;
141 return self;
145 * anjuta_command_queue_push:
146 * @self: AnjutaCommandQueue object
147 * @command: The command to add
149 * Adds a command to the Queue and starts it if there are no other commands
150 * waiting
153 void
154 anjuta_command_queue_push (AnjutaCommandQueue *self, AnjutaCommand *command)
156 if (self->priv->mode == ANJUTA_COMMAND_QUEUE_EXECUTE_AUTOMATIC)
158 if (!self->priv->busy)
160 g_signal_connect (G_OBJECT (command), "command-finished",
161 G_CALLBACK (on_command_finished),
162 self);
164 if (self->priv->mode == ANJUTA_COMMAND_QUEUE_EXECUTE_AUTOMATIC)
166 self->priv->busy = TRUE;
167 anjuta_command_start (command);
170 else
171 g_queue_push_tail (self->priv->queue, g_object_ref (command));
173 else
174 g_queue_push_tail (self->priv->queue, g_object_ref (command));
177 gboolean
178 anjuta_command_queue_start (AnjutaCommandQueue *self)
180 gboolean ret;
181 AnjutaCommand *first_command;
183 ret = FALSE;
185 if ((self->priv->mode == ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL) &&
186 (!self->priv->busy))
188 first_command = g_queue_pop_head (self->priv->queue);
190 if (first_command)
192 g_signal_connect (G_OBJECT (first_command), "command-finished",
193 G_CALLBACK (on_command_finished),
194 self);
196 self->priv->busy = TRUE;
197 ret = TRUE;
199 anjuta_command_start (first_command);
203 return ret;