1 /*
2  * Copyright (C) 2000 Alan Robertson <alanr@unix.sh>
3  * This software licensed under the GNU LGPL.
4  *
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21 #ifndef PILS_INTERFACE_H
22 #  define PILS_INTERFACE_H
23 #  ifndef PILS_PLUGIN_H
24 #    include <pils/plugin.h>
25 #  endif
26 
27 /*****************************************************************************
28  *
29  * The most basic interface type is the "IFManager" interface.
30  * Each interface manager registers and deals with interfaces of a given type.
31  *
32  * Such an interface must be loaded before any plugins of it's type can
33  * be loaded.
34  *
35  * In order to register any plugin of type "foo", we must load a interface of
36  * type "Interface" named "foo".  This interface then manages the
37  * registration of all interfaces of type foo.
38  *
39  * To bootstrap, we load a interface of type "Interface" named "Interface"
40  * during the initialization of the plugin system.
41  *
42  * IFManagers will be autoloaded if certain conditions are met...
43  *
44  * If a IFManager is to be autoloaded, there must be one interface manager
45  * per file, and the file must be named according to the type of the
46  * interface it implements, and loaded in the directory named PI_IFMANAGER
47  * ("Interface").
48  *
49  */
50 
51 
52 /*
53  *	I'm unsure exactly which of the following structures
54  *	are needed to write a interface, or a interface manager.
55  *	We'll get that figured out and scope the defintions accordingly...
56  */
57 
58 /*
59  *	PILInterface (AKA struct PILInterface_s) holds the information
60  *	we use to track a single interface manager.
61  */
62 
63 
64 struct PILInterface_s {
65 	unsigned long		MagicNum;
66 	PILInterfaceType*	interfacetype;	/* Parent pointer	*/
67 	char *			interfacename;	/* malloced interface name */
68 	PILInterface*		ifmanager;	/* plugin managing us	*/
69 	void*			exports;	/* Exported Functions	*/
70 						/* for this interface	*/
71 	PILInterfaceFun		if_close;	/* Interface close operation*/
72 	void*			ud_interface;	/* per-interface user data */
73 	int			refcnt;		/* Ref count for plugin	*/
74 	PILPlugin*		loadingpi;	/* Plugin that loaded us */
75 };
76 /*
77  *	PILInterfaceType (AKA struct PILInterfaceType_s) holds the info
78  *	we use to track the set of all interfaces of a single kind.
79  */
80 struct PILInterfaceType_s {
81 	unsigned long		MagicNum;
82 	char*			typename;	/* Our interface type name */
83 	GHashTable*		interfaces;	/* The set of interfaces
84 						 * of our type.  The
85 						 * "values" are all
86 						 * PILInterface * objects
87 						 */
88 	void*			ud_if_type;	/* per-interface-type user
89 						   data*/
90 	PILInterfaceUniv*	universe;	/* Pointer to parent (up) */
91 	PILInterface*		ifmgr_ref;	/* Pointer to our interface
92 						   manager */
93 };
94 
95 /*
96  *	PILInterfaceUniv (AKA struct PILInterfaceUniv_s) holds the information
97  *	for all interfaces of all types.  From our point of view this is
98  *	our universe ;-)
99  */
100 
101 struct PILInterfaceUniv_s{
102 	unsigned long		MagicNum;
103 	GHashTable*		iftypes;	/*
104 						 * Set of Interface Types
105 						 * The values are all
106 						 * PILInterfaceType objects
107 						 */
108 	struct PILPluginUniv_s*	piuniv;		/* parallel universe of
109 						 * plugins
110 						 */
111 };
112 
113 #ifdef ENABLE_PLUGIN_MANAGER_PRIVATE
114 /*
115  * From here to the end is specific to interface managers.
116  * This data is only needed by interface managers, and the interface
117  * management system itself.
118  *
119  */
120 typedef struct PILInterfaceOps_s		PILInterfaceOps;
121 
122 
123 /* Interfaces imported by a IFManager interface */
124 struct PILInterfaceImports_s {
125 
126 		/* Return current reference count */
127 	int (*RefCount)(PILInterface * eifinfo);
128 
129 		/* Incr/Decr reference count */
130 	int (*ModRefCount)(PILInterface*eifinfo, int plusminus);
131 
132 		/* Unregister us as a interface */
133 	void (*ForceUnRegister)(PILInterface *eifinfo);
134 
135 		/* For each client */
136 	void (*ForEachClientDel)(PILInterface* manangerif
137 	,	gboolean(*f)(PILInterface* clientif, void * other)
138 	,	void* other);
139 
140 };
141 
142 /* Interfaces exported by an InterfaceManager interface */
143 struct PILInterfaceOps_s{
144 /*
145  *	These are the interfaces exported by an InterfaceManager to the
146  *	interface management infrastructure.  These are not imported
147  *	by interfaces - only the interface management infrastructure.
148  */
149 
150 	/* RegisterInterface - register this interface */
151  	PIL_rc (*RegisterInterface)(PILInterface* newif
152 		,	void**	imports);
153 
154 	PIL_rc	(*UnRegisterInterface)(PILInterface*ifinfo); /* Unregister IF*/
155 				/* And destroy PILInterface object */
156 };
157 
158 #endif /* ENABLE_PLUGIN_MANAGER_PRIVATE */
159 #endif /* PILS_INTERFACE_H */
160