+libcaptive/io/create.c
[captive.git] / src / libcaptive / io / create.c
1 /* $Id$
2  * reactos I/O streams management of libcaptive
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 "reactos/ddk/iofuncs.h"        /* self */
23 #include <glib/gmessages.h>
24 #include <glib/ghash.h>
25
26
27 /* map: (FILE_OBJECT *) -> GINT_TO_POINTER(1) */
28 static GHashTable *captive_stream_file_object_hash;
29
30 /* initialize 'captive_stream_file_object_hash' */
31 static void captive_stream_file_object_hash_init(void)
32 {
33         if (captive_stream_file_object_hash)
34                 return;
35         captive_stream_file_object_hash=g_hash_table_new(g_direct_hash,g_direct_equal);
36 }
37
38
39 BOOLEAN IoCreateStreamFileObjectLite_is_owner(FILE_OBJECT *FileObject)
40 {
41         g_return_val_if_fail(FileObject!=NULL,FALSE);
42
43         return !!g_hash_table_lookup(captive_stream_file_object_hash,FileObject);
44 }
45
46
47 void IoCreateStreamFileObjectLite_remove(FILE_OBJECT *FileObject)
48 {
49 gboolean errbool;
50
51         g_return_if_fail(FileObject!=NULL);
52
53         errbool=g_hash_table_remove(captive_stream_file_object_hash,FileObject);
54         g_assert(errbool==TRUE);
55 }
56
57
58 PFILE_OBJECT IoCreateStreamFileObjectLite(IN PFILE_OBJECT FileObject OPTIONAL,IN PDEVICE_OBJECT DeviceObject OPTIONAL)
59 {
60 FILE_OBJECT *r;
61
62         captive_stream_file_object_hash_init();
63
64         r=IoCreateStreamFileObject(FileObject,DeviceObject);
65         g_return_val_if_fail(r!=NULL,NULL);
66
67         g_assert(NULL==g_hash_table_lookup(captive_stream_file_object_hash,r)); /* paranoia sanity */
68
69         g_hash_table_insert(captive_stream_file_object_hash,r,GINT_TO_POINTER(1));
70
71         return r;
72 }