disable debug
[AROS.git] / workbench / tools / SysExplorer / sysexp_library.c
blob2c3eadc96e05e97efa9af4743fd73d6782fec019
1 /*
2 Copyright (C) 2013-2019, The AROS Development Team.
3 $Id: main.c 54142 2017-03-16 01:57:58Z NicJA $
4 */
6 #include <aros/debug.h>
8 #define MUIMASTER_YES_INLINE_STDARG
10 #include <exec/memory.h>
11 #include <hidd/hidd.h>
12 #include <hidd/system.h>
13 #include <hidd/gfx.h>
14 #include <hidd/storage.h>
15 #include <libraries/asl.h>
16 #include <mui/NListtree_mcc.h>
17 #include <mui/NListview_mcc.h>
18 #include <utility/tagitem.h>
19 #include <utility/hooks.h>
21 #include <proto/sysexp.h>
23 #include <proto/alib.h>
24 #include <proto/dos.h>
25 #include <proto/exec.h>
26 #include <proto/muimaster.h>
27 #include <proto/oop.h>
28 #include <proto/utility.h>
29 #include <proto/intuition.h>
31 #include <ctype.h>
32 #include <stdio.h>
33 #include <stdlib.h>
35 #include "locale.h"
36 #include "classes.h"
38 #include "enums.h"
40 extern void hwEnum(OOP_Object *obj, struct MUI_NListtree_TreeNode *tn);
42 CONST_STRPTR hwenumfunc_name = "HWEnum.Func";
43 CONST_STRPTR devicepageclass_name = "DevicePage.Class";
44 CONST_STRPTR genericwindowclass_name = "GenericWindow.Class";
45 CONST_STRPTR computerwindowclass_name = "ComputerWindow.Class";
47 BOOL ClassNameMatches(const char *classA, const char *classB)
49 if ((!strncmp(classA, classB, strlen(classB))) &&
50 (strlen(classA) == strlen(classB)))
52 return TRUE;
54 return FALSE;
57 /** Null function **/
59 AROS_LH0(void, Null,
60 struct SysexpBase *, SysexpBase, 0, LIB)
62 AROS_LIBFUNC_INIT
64 return;
66 AROS_LIBFUNC_EXIT
69 /** Library API functions **/
71 AROS_LH2(void, RegisterModule,
72 AROS_LHA(struct SysexpModule *, Module, A0),
73 AROS_LHA(APTR, ModBase, A1),
74 struct SysexpBase *, SysexpBase, 5, Sysexp)
76 AROS_LIBFUNC_INIT
78 D(bug("[sysexp.library] %s()\n", __func__));
80 if (Module)
82 struct SysexpIntModule *IntModule = AllocMem(sizeof(struct SysexpIntModule), MEMF_ANY);
83 CopyMem(Module, IntModule, sizeof(struct SysexpModule));
84 IntModule->seim_ModuleBase = ModBase;
85 Enqueue(&SysexpBase->sesb_Modules, &IntModule->seim_Module.sem_Node);
87 return;
89 AROS_LIBFUNC_EXIT
92 AROS_LH2(void, RegisterBase,
93 AROS_LHA(CONST_STRPTR, BaseID, A0),
94 AROS_LHA(APTR, Base, A1),
95 struct SysexpBase *, SysexpBase, 6, Sysexp)
97 AROS_LIBFUNC_INIT
99 D(bug("[sysexp.library] %s()\n", __func__));
101 struct SysexpIntBase *IntBase = AllocMem(sizeof(struct SysexpIntBase), MEMF_ANY);
102 IntBase->seib_Node.ln_Name = (char *)BaseID;
103 IntBase->seib_Base = Base;
104 AddTail(&SysexpBase->sesb_GenericBases, &IntBase->seib_Node);
106 return;
108 AROS_LIBFUNC_EXIT
111 AROS_LH1(APTR, GetBase,
112 AROS_LHA(CONST_STRPTR, BaseID, A0),
113 struct SysexpBase *, SysexpBase, 7, Sysexp)
115 AROS_LIBFUNC_INIT
116 struct SysexpIntModule *IntModule;
117 struct SysexpIntBase *IntBase;
119 D(bug("[sysexp.library] %s()\n", __func__));
121 ForeachNode(&SysexpBase->sesb_GenericBases, IntBase)
123 if (!strcmp(IntBase->seib_Node.ln_Name, BaseID))
124 return IntBase->seib_Base;
126 ForeachNode(&SysexpBase->sesb_Modules, IntModule)
128 if (!strcmp(IntModule->seim_Module.sem_Node.ln_Name, BaseID))
129 return IntModule->seim_ModuleBase;
132 return NULL;
134 AROS_LIBFUNC_EXIT
137 AROS_LH5(BOOL, RegisterClassHandler,
138 AROS_LHA(CONST_STRPTR, classid, A0),
139 AROS_LHA(BYTE, pri, D0),
140 AROS_LHA(struct MUI_CustomClass *, customwinclass, A1),
141 AROS_LHA(CLASS_ENUMFUNC, enumfunc, A2),
142 AROS_LHA(CLASS_VALIDFUNC, validfunc, A3),
143 struct SysexpBase *, SysexpBase, 9, Sysexp)
145 AROS_LIBFUNC_INIT
147 struct ClassHandlerNode *newClass;
148 BOOL add = TRUE;
149 if ((newClass = FindClassHandler(classid, &SysexpBase->sesb_ClassHandlers)))
151 if (newClass->enumFunc != hwEnum)
152 return FALSE;
154 D(bug("[sysexp.library] %s: Updating '%s'..\n", __func__, classid));
155 add = FALSE;
158 if (add)
160 D(bug("[sysexp.library] %s: Registering '%s'..\n", __func__, classid));
161 newClass = AllocMem(sizeof(struct ClassHandlerNode), MEMF_CLEAR);
164 if (newClass)
166 newClass->ch_Node.ln_Name = (char *)classid;
167 newClass->ch_Node.ln_Pri = pri;
168 newClass->muiClass = customwinclass;
169 newClass->enumFunc = enumfunc;
170 newClass->validFunc = validfunc;
172 if (add)
173 Enqueue(&SysexpBase->sesb_ClassHandlers, &newClass->ch_Node);
175 return TRUE;
177 return FALSE;
179 AROS_LIBFUNC_EXIT
182 AROS_LH2(struct ClassHandlerNode *, FindClassHandler,
183 AROS_LHA(CONST_STRPTR, classid, A0),
184 AROS_LHA(struct List *, _handlers, A1),
185 struct SysexpBase *, SysexpBase, 10, Sysexp)
187 AROS_LIBFUNC_INIT
189 struct ClassHandlerNode *curHandler;
191 ForeachNode(_handlers, curHandler)
193 if (ClassNameMatches(classid, curHandler->ch_Node.ln_Name))
195 D(bug("[sysexp.library] %s: Returning class '%s'\n", __func__, curHandler->ch_Node.ln_Name));
196 return curHandler;
199 return NULL;
201 AROS_LIBFUNC_EXIT
204 AROS_LH2(struct ClassHandlerNode *, FindObjectHandler,
205 AROS_LHA(OOP_Object *, obj, A0),
206 AROS_LHA(struct List *, _handlers, A1),
207 struct SysexpBase *, SysexpBase, 11, Sysexp)
209 AROS_LIBFUNC_INIT
211 struct ClassHandlerNode *curHandler;
213 D(bug("[sysexp.library] %s: Finding Handler for Object @ 0x%p\n", __func__, obj));
215 ForeachNode(_handlers, curHandler)
217 OOP_Class *cl;
218 D(bug("[sysexp.library] %s: Checking match with '%s'\n", __func__, curHandler->ch_Node.ln_Name));
220 for (cl = OOP_OCLASS(obj); cl ; cl = cl->superclass)
222 D(bug("[sysexp.library] %s: Object Class -> '%s'\n", __func__, cl->ClassNode.ln_Name));
223 if (ClassNameMatches(cl->ClassNode.ln_Name, curHandler->ch_Node.ln_Name))
225 D(bug("[sysexp.library] %s: Returning obj class '%s'\n", __func__, curHandler->ch_Node.ln_Name));
226 return curHandler;
230 return NULL;
232 AROS_LIBFUNC_EXIT
235 /** Library Initialization **/
237 void *SysexpLibrary_funcTable[] = {
238 AROS_SLIB_ENTRY(Null, LIB, 0), /* Open() */
239 AROS_SLIB_ENTRY(Null, LIB, 0),
240 AROS_SLIB_ENTRY(Null, LIB, 0), /* Expunge() */
241 AROS_SLIB_ENTRY(Null, LIB, 0), /* Reserved() */
242 AROS_SLIB_ENTRY(RegisterModule, Sysexp, 5),
243 AROS_SLIB_ENTRY(RegisterBase, Sysexp, 6),
244 AROS_SLIB_ENTRY(GetBase, Sysexp, 7),
245 AROS_SLIB_ENTRY(Null, LIB, 0),
246 AROS_SLIB_ENTRY(RegisterClassHandler, Sysexp, 9),
247 AROS_SLIB_ENTRY(FindClassHandler, Sysexp, 10),
248 AROS_SLIB_ENTRY(FindObjectHandler, Sysexp, 11),
250 (void *)-1
253 void sysexp_initlib(struct SysexpBase **SysexpBasePtr)
255 struct SysexpBase *SysexpBase = NULL;
257 D(bug("[SysExplorer] %s()\n", __func__));
258 SysexpBase = (struct SysexpBase *)MakeLibrary(SysexpLibrary_funcTable,
259 NULL,
260 NULL,
261 sizeof(struct SysexpBase),
262 BNULL);
264 D(bug("[SysExplorer] %s: SysexpBase @ %p\n", __func__, SysexpBase));
266 if (SysexpBase)
268 NEWLIST(&SysexpBase->sesb_GenericBases);
269 NEWLIST(&SysexpBase->sesb_Modules);
270 NEWLIST(&SysexpBase->sesb_ClassHandlers);
272 RegisterBase(hwenumfunc_name, hwEnum);
273 RegisterBase(devicepageclass_name, DevicePage_CLASS);
274 RegisterBase(genericwindowclass_name, GenericWindow_CLASS);
275 RegisterBase(computerwindowclass_name, ComputerWindow_CLASS);
277 RegisterClassHandler(CLID_Hidd_Storage, 90, NULL, hwEnum, NULL);
278 RegisterClassHandler(CLID_Hidd_Gfx, 60, NULL, hwEnum, NULL);
279 RegisterClassHandler(CLID_Hidd_System, 30, NULL, hwEnum, NULL);
280 RegisterClassHandler(CLID_HW_Root, 0, ComputerWindow_CLASS, hwEnum, NULL);
281 RegisterClassHandler(CLID_HW, -30, NULL, hwEnum, NULL);
282 RegisterClassHandler(CLID_Hidd, -60, GenericWindow_CLASS, NULL, NULL);
284 *SysexpBasePtr = SysexpBase;