1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
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-async-notify.h"
23 * SECTION: anjuta-async-notify
24 * @short_description: Mechanism used by interfaces that run asynchronously to
25 * notify clients of finished tasks and to report errors.
27 * #AnjutaAsyncNotify is a way to allow Anjuta interfaces that run
28 * asynchronously, such as #IAnjutaVCS, to notify clients that a method has
29 * completed. #AnjutaAsyncNotify also reports errors to the user.
31 * All clients need to do is create an instance of #AnjutaAsyncNotify, connect
32 * to the finished signal, and pass it in to the interface method to be called.
43 static guint async_notify_signals
[LAST_SIGNAL
] = { 0 };
45 struct _AnjutaAsyncNotifyPriv
50 G_DEFINE_TYPE (AnjutaAsyncNotify
, anjuta_async_notify
, G_TYPE_OBJECT
);
53 anjuta_async_notify_init (AnjutaAsyncNotify
*self
)
55 self
->priv
= g_new0 (AnjutaAsyncNotifyPriv
, 1);
59 anjuta_async_notify_finalize (GObject
*object
)
61 AnjutaAsyncNotify
*self
;
63 self
= ANJUTA_ASYNC_NOTIFY (object
);
65 g_error_free (self
->priv
->error
);
68 G_OBJECT_CLASS (anjuta_async_notify_parent_class
)->finalize (object
);
72 anjuta_async_notify_finished (AnjutaAsyncNotify
*self
)
78 anjuta_async_notify_class_init (AnjutaAsyncNotifyClass
*klass
)
80 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
82 object_class
->finalize
= anjuta_async_notify_finalize
;
84 klass
->finished
= anjuta_async_notify_finished
;
87 * AnjutaAsyncNotify::finished:
88 * @notify: AnjutaAsyncNotify object.
90 * Notifies clients that the requested task has finished.
92 async_notify_signals
[FINISHED
] =
93 g_signal_new ("finished",
94 G_OBJECT_CLASS_TYPE (klass
),
96 G_STRUCT_OFFSET (AnjutaAsyncNotifyClass
, finished
),
98 g_cclosure_marshal_VOID__VOID
,
104 * anjuta_async_notify_new:
106 * Creates a new #AnjutaAsyncNotify object.
108 * Return value: a new #AnjutaAsyncNotify instance
111 anjuta_async_notify_new (void)
113 return g_object_new (ANJUTA_TYPE_ASYNC_NOTIFY
, NULL
);
117 * anjuta_async_notify_get_error:
118 * @self: An #AnjutaAsyncNotify object
119 * @error: Return location for the error set by the called interface to which
120 * this object was passed. If no error is set, @error is set to NULL.
122 * Gets the error set on @self.
125 anjuta_async_notify_get_error (AnjutaAsyncNotify
*self
, GError
**error
)
127 if (self
->priv
->error
)
128 *error
= g_error_copy (self
->priv
->error
);
132 * anjuta_async_notify_set_error:
133 * @self: An #AnjutaAsyncNotify object
134 * @error: Error to set
136 * Sets the error for an interface call. This method should only be used by
137 * interface implementations themselves, not by clients.
140 anjuta_async_notify_set_error (AnjutaAsyncNotify
*self
, GError
*error
)
142 if (self
->priv
->error
)
143 g_error_free (self
->priv
->error
);
145 self
->priv
->error
= g_error_copy (error
);
149 * anjuta_async_notify_notify_finished:
150 * @self: An #AnjutaAsyncNotify object
152 * Emits the finished signal. This method should only be used by
153 * interface methods themselves, not by clients.
156 anjuta_async_notify_notify_finished (AnjutaAsyncNotify
*self
)
158 g_signal_emit_by_name (self
, "finished", NULL
);