Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / po / shutdownwork.c
1 /* $Id$
2  * reactos PoQueueShutdownWorkItem() implementation by libcaptive
3  * Copyright (C) 2002 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 /* no reactos prototype for PoQueueShutdownWorkItem() */
23 #include "captive/ldr.h"        /* self; for captive_PoQueueShutdownWorkItem_hooklist_invoke() */
24 #include <glib/gmessages.h>
25 #include <glib/ghook.h>
26 #include "reactos/ddk/extypes.h"        /* for WORK_QUEUE_ITEM */
27 #include "captive/macros.h"
28
29
30 static GHookList captive_PoQueueShutdownWorkItem_hooklist;
31
32
33 static void captive_PoQueueShutdownWorkItem_hooklist_init(void)
34 {
35         if (captive_PoQueueShutdownWorkItem_hooklist.is_setup)
36                 return;
37
38         g_hook_list_init(&captive_PoQueueShutdownWorkItem_hooklist,sizeof(GHook));
39 }
40
41
42 void captive_PoQueueShutdownWorkItem_hooklist_invoke(void)
43 {
44         captive_PoQueueShutdownWorkItem_hooklist_init();
45
46         g_hook_list_invoke(&captive_PoQueueShutdownWorkItem_hooklist,
47                         FALSE); /* may_recurse */
48         g_hook_list_clear(&captive_PoQueueShutdownWorkItem_hooklist);
49 }
50
51
52 struct captive_work_queue_item {
53         PWORKER_THREAD_ROUTINE WorkerRoutine;
54         PVOID Parameter;
55         };
56
57 static void PoQueueShutdownWorkItem_func(struct captive_work_queue_item *captive_work_queue_item /* data */)
58 {
59         g_return_if_fail(captive_work_queue_item!=NULL);
60
61         /* typedef VOID CAPTIVE_STDCALL (*PWORKER_THREAD_ROUTINE)(IN PVOID Context); */
62
63         captive_stdcall_call_4((CaptiveStdCallFunc4)captive_work_queue_item->WorkerRoutine,
64                         captive_work_queue_item->Parameter);    /* Context */
65
66         g_free(captive_work_queue_item);
67 }
68
69 NTSTATUS PoQueueShutdownWorkItem(IN PWORK_QUEUE_ITEM WorkItem)
70 {
71 GHook *ghook;
72 struct captive_work_queue_item *captive_work_queue_item;
73
74         g_return_val_if_fail(WorkItem!=NULL,STATUS_INVALID_PARAMETER);
75         g_return_val_if_fail(WorkItem->WorkerRoutine!=NULL,STATUS_INVALID_PARAMETER);
76
77         captive_PoQueueShutdownWorkItem_hooklist_init();
78
79         captive_new(captive_work_queue_item);
80         captive_work_queue_item->WorkerRoutine=WorkItem->WorkerRoutine;
81         captive_work_queue_item->Parameter=WorkItem->Parameter;
82
83         /* FIXME: Should we check for func/data dupes? Are they permitted by W32? */
84
85         ghook=g_hook_alloc(&captive_PoQueueShutdownWorkItem_hooklist);
86         ghook->func=PoQueueShutdownWorkItem_func;
87         ghook->data=captive_work_queue_item;
88         g_hook_append(&captive_PoQueueShutdownWorkItem_hooklist,ghook);
89
90         return STATUS_SUCCESS;
91 }