first public release of samba4 code
[ira/wip.git] / source / smbd / process_model.c
1 /* 
2    Unix SMB/CIFS implementation.
3    process model manager - main loop
4    Copyright (C) Andrew Tridgell 1992-2003
5    Copyright (C) James J Myers 2003 <myersjj@samba.org>
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24
25 /* the list of currently registered process models */
26 static struct {
27         const char *name;
28         struct model_ops *ops;
29 } *models = NULL;
30 static int num_models;
31
32 /*
33   register a process model. 
34
35   The 'name' can be later used by other backends to find the operations
36   structure for this backend.  
37 */
38 BOOL register_process_model(const char *name, struct model_ops *ops)
39 {
40         if (process_model_byname(name) != NULL) {
41                 /* its already registered! */
42                 DEBUG(2,("process_model '%s' already registered\n", 
43                          name));
44                 return False;
45         }
46
47         models = Realloc(models, sizeof(models[0]) * (num_models+1));
48         if (!models) {
49                 smb_panic("out of memory in register_process_model");
50         }
51
52         models[num_models].name = smb_xstrdup(name);
53         models[num_models].ops = smb_xmemdup(ops, sizeof(*ops));
54
55         num_models++;
56
57         return True;
58 }
59
60 /*
61   return the operations structure for a named backend of the specified type
62 */
63 struct model_ops *process_model_byname(const char *name)
64 {
65         int i;
66
67         for (i=0;i<num_models;i++) {
68                 if (strcmp(models[i].name, name) == 0) {
69                         return models[i].ops;
70                 }
71         }
72
73         return NULL;
74 }
75
76
77 /* initialise the builtin process models */
78 void process_model_init(void)
79 {
80         process_model_standard_init();
81         process_model_single_init();
82 #ifdef WITH_PTHREADS
83         process_model_thread_init();
84 #endif
85 }