1 #ifndef PILS_GENERIC_H
2 #define PILS_GENERIC_H
3 /*
4  * Copyright (C) 2000 Alan Robertson <alanr@unix.sh>
5  * This software licensed under the GNU LGPL.
6  *
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  *
23  * Generic interface (implementation) manager
24  *
25  * This manager will manage any number of types of interfaces.
26  *
27  * This means that when any implementations of our client interfaces register
28  * or unregister, it is us that makes their interfaces show up in the outside
29  * world.
30  *
31  * And, of course, we have to do this in a very generic way, since we have
32  * no idea about the client programs or interface types, or anything else.
33  *
34  * We do that by getting a parameter passed to us which tell us the names
35  * of the interface types we want to manage, and the address of a GHashTable
36  * for each type that we put the implementation in when they register
37  * themselves.
38  *
39  * So, each type of interface that we manage gets its own private
40  * GHashTable of the implementations of that type that are currently
41  * registered.
42  *
43  * For example, if we manage communication modules, their exported
44  * interfaces will be registered in a hash table.  If we manage
45  * authentication modules, they'll have their (separate) hash table that
46  * their exported interfaces are registered in.
47  *
48  */
49 #include <pils/interface.h>
50 
51 /*
52  * Header defintions for using the generic interface/implementation
53  * manager plugin.
54  */
55 
56 /*
57  *	Notification types for the callback function.
58  */
59 typedef enum {
60 	PIL_REGISTER,	/* Someone has registered an implementation */
61 	PIL_UNREGISTER 	/* Someone has unregistered an implementation */
62 }GenericPILCallbackType;
63 
64 /* A user callback for the generic interface manager */
65 typedef int (*GenericPILCallback)
66 (	GenericPILCallbackType	type	/* Event type */
67 ,	PILPluginUniv*		univ	/* pointer to plugin universe */
68 ,	const char * 		iftype	/* Interface type */
69 ,	const char *		ifname	/* Implementation (interface) name */
70 ,	void *			userptr	/* Whatever you want it to be ;-) */
71 );
72 
73 /*
74  * Structures to declare the set of interface types we're managing.
75  */
76 typedef struct {
77 	const char *	   iftype;	/* What type of interface is this? */
78 	GHashTable**	   ifmap;	/* Table with implementation info */
79 	void*		   importfuns;	/* Functions for interface to import */
80 	GenericPILCallback callback;	/* Function2call when events occur */
81 	void*		   userptr;	/* Passed to Callback function */
82 }PILGenericIfMgmtRqst;
83 /*
84  * What does this look like in practice?
85  *
86  * GHashTable*	authmodules = NULL;
87  * GHashTable*	commmodules = NULL;
88  * PILGenericIfMgmtRqst RegisterRequests[] =
89  * {
90  * 	{"auth",	&authmodules,	&authimports,	NULL,	NULL},
91  * 	{"comm",	&commmodules,	&commimports,	NULL,	NULL},
92  * 	{NULL,		NULL,		NULL,		NULL,	NULL}
93 	// NULL entry must be here
94  * };
95  *
96  * PILPlugin*	PluginUniverse;
97  *
98  * PluginUniverse = NewPILPlugin("/usr/lib/whatever/plugins");
99  *
100  * PILLoadPlugin(PluginUniverse, "InterfaceMgr", "generic", &RegisterRequests);
101  *	// N. B.: Passing RegisterRequests as an argument is essential
102  *
103  * Then, when you load an auth module, its exported interface gets added
104  * to "authmodules". When you unload an auth module, it gets removed
105  * from authmodules.
106  *
107  * Then, when you load a comm module, its exported interfaces gets added
108  * to "commodules".  When you unload a comm module, its exported
109  * interfaces get removed from "commodules"
110  *
111  * If there are simple changes that would be useful for this generic
112  * plugin manager, then "patches are being accepted" :-)
113  *
114  * On the other hand, If you don't like the way this plugin manager works
115  * in a broader way, you're free to write your own  - it's just another
116  * plugin ;-)
117  */
118 #endif
119