+captive_leave() to replace g_idle*() function calls postponing
[captive.git] / src / libcaptive / client / leave.c
1 /* $Id$
2  * Code of leaving libcaptive to be called to cleanup W32 fs state
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "captive/leave.h"      /* self */
23 #include <glib/gtypes.h>
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
26 #include <glib/ghook.h>
27
28
29
30 static GHookList captive_leave_hooklist;
31
32
33 static void captive_leave_hooklist_init(void)
34 {
35         if (captive_leave_hooklist.is_setup)
36                 return;
37
38         g_hook_list_init(&captive_leave_hooklist,sizeof(GHook));
39 }
40
41
42 void captive_leave(void)
43 {
44 GHookList captive_leave_hooklist_local;
45
46         for (;;) {
47                 captive_leave_hooklist_init();
48                 if (!captive_leave_hooklist.hooks)
49                         break;
50
51                 captive_leave_hooklist_local=captive_leave_hooklist;
52                 captive_leave_hooklist.is_setup=FALSE;
53
54                 g_hook_list_invoke(&captive_leave_hooklist_local,
55                                 FALSE); /* may_recurse */
56                 g_hook_list_clear(&captive_leave_hooklist_local);
57                 }
58 }
59
60
61 void captive_leave_register(captive_leave_func func,gpointer data)
62 {
63 GHook *ghook;
64
65         g_return_if_fail(func!=NULL);
66
67         captive_leave_hooklist_init();
68
69         ghook=g_hook_alloc(&captive_leave_hooklist);
70         ghook->func=func;
71         ghook->data=data;
72         g_hook_append(&captive_leave_hooklist,ghook);
73 }