2 Copyright 1995-2010, The AROS Development Team. All rights reserved.
5 Desc: Code that loads and initializes necessary HIDDs.
11 #include <aros/debug.h>
12 #include <dos/dosextens.h>
13 #include <workbench/icon.h>
14 #include <proto/alib.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
17 #include <proto/icon.h>
22 #define MONITORS_DIR "DEVS:Monitors"
24 /************************************************************************/
26 /* This code does almost the same thing as C:LoadMonDrvs does on other systems.
27 However, additionally we support priority-based sorting for display drivers.
28 This is needed in order to make monitor ID assignment more predictable */
36 static BYTE
checkIcon(STRPTR name
, struct Library
*IconBase
)
39 struct DiskObject
*dobj
= GetDiskObject(name
);
44 if ((dobj
->do_Type
== WBTOOL
) || (dobj
->do_Type
== WBPROJECT
))
46 const STRPTR
*toolarray
= (const STRPTR
*)dobj
->do_ToolTypes
;
49 if ((s
= FindToolType(toolarray
, "STARTPRI")))
62 static BOOL
findMonitors(struct List
*monitorsList
, struct DosLibrary
*DOSBase
, struct Library
*IconBase
, APTR poolmem
)
66 struct AnchorPath
*ap
= AllocPooled(poolmem
, sizeof(struct AnchorPath
));
68 DB2(bug("[LoadMonDrvs] AnchorPath 0x%p\n", ap
));
71 /* Initialize important fields in AnchorPath, especially
72 ap_Strlen (prevents memory trashing) */
77 error
= MatchFirst("~(#?.info)", ap
);
80 struct MonitorNode
*newnode
;
82 DB2(bug("[LoadMonDrvs] Found monitor name %s\n", ap
->ap_Info
.fib_FileName
));
84 newnode
= AllocPooled(poolmem
, sizeof(struct MonitorNode
) + strlen(ap
->ap_Info
.fib_FileName
));
85 DB2(bug("[LoadMonDrvs] Monitor node 0x%p\n", newnode
));
86 if (newnode
== NULL
) {
91 strcpy(newnode
->Name
, ap
->ap_Info
.fib_FileName
);
93 newnode
->n
.ln_Pri
= checkIcon(ap
->ap_Info
.fib_FileName
, IconBase
);
95 newnode
->n
.ln_Pri
= 0;
96 Enqueue(monitorsList
, &newnode
->n
);
98 error
= MatchNext(ap
);
100 if (error
!= ERROR_NO_MORE_ENTRIES
)
113 static void loadMonitors(struct List
*monitorsList
, struct DosLibrary
*DOSBase
)
115 struct MonitorNode
*node
;
117 D(bug("[LoadMonDrvs] Loading monitor drivers...\n"));
118 D(bug(" Pri Name\n"));
120 ForeachNode(monitorsList
, node
)
122 D(bug("%4d %s\n", node
->n
.ln_Pri
, node
->Name
));
123 Execute(node
->Name
, BNULL
, BNULL
);
126 D(bug("--------------------------\n"));
129 __startup BOOL
_main(void)
132 struct Library
*IconBase
;
137 DOSBase
= OpenLibrary("dos.library", 0);
139 return ERROR_INVALID_RESIDENT_LIBRARY
;
142 dir
= Lock(MONITORS_DIR
, SHARED_LOCK
);
143 D(bug("[LoadMonDrvs] Monitors directory 0x%p\n", dir
));
145 olddir
= CurrentDir(dir
);
147 pool
= CreatePool(MEMF_ANY
, sizeof(struct MonitorNode
) * 10, sizeof(struct MonitorNode
) * 5);
148 DB2(bug("[LoadMonDrvs] Created pool 0x%p\n", pool
));
150 struct List MonitorsList
;
152 NewList(&MonitorsList
);
153 IconBase
= OpenLibrary("icon.library", 0);
155 findMonitors(&MonitorsList
, DOSBase
, IconBase
, pool
);
156 loadMonitors(&MonitorsList
, DOSBase
);
157 CloseLibrary(IconBase
);
167 CloseLibrary(DOSBase
);