New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / libs / prometheus / prometheus_init.c
blob42858b5001a3cb60dc9df884ad1ce1fcab301d61
1 /*
2 Copyright (C)©2005 Neil Cafferkey.
3 $Id$
5 Desc: Prometheus initialisation code.
6 Lang: English.
7 */
9 #include <exec/types.h>
10 #include <exec/resident.h>
11 #include <utility/utility.h>
13 #include <proto/exec.h>
14 #include <proto/oop.h>
15 #include <proto/alib.h>
17 #include LC_LIBDEFS_FILE
18 #include "prometheus_intern.h"
19 #include <aros/symbolsets.h>
22 struct HookContext
24 LIBBASETYPE *library;
25 BOOL success;
29 /* Private prototypes */
31 AROS_UFP3(static VOID, EnumHook, AROS_UFPA(struct Hook *, hook, A0),
32 AROS_UFPA(OOP_Object *, aros_board, A2), AROS_UFPA(APTR, message, A1));
33 static int DeleteLibrary(LIBBASETYPE *base);
36 /* Constants */
38 static const TEXT oop_name[] = AROSOOP_NAME;
39 static const TEXT utility_name[] = UTILITYNAME;
42 static int LibInit(LIBBASETYPEPTR base)
44 BOOL success = TRUE;
45 struct Hook *hook;
46 struct HookContext *hook_context;
48 /* Open HIDDs */
50 NewList((APTR)&base->boards);
52 base->pci_hidd = OOP_NewObject(NULL, CLID_Hidd_PCI, NULL);
53 base->irq_hidd = OOP_NewObject(NULL, CLID_Hidd_IRQ, NULL);
54 base->pcidevice_attr_base = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
55 if(base->pci_hidd == NULL || base->irq_hidd == NULL
56 || base->pcidevice_attr_base == 0)
57 success = FALSE;
59 /* Make a list of all boards in the system */
61 hook = AllocMem(sizeof(struct Hook), MEMF_PUBLIC | MEMF_CLEAR);
62 hook_context = AllocMem(sizeof(struct HookContext),
63 MEMF_PUBLIC | MEMF_CLEAR);
64 if(hook == NULL || hook_context == NULL)
65 success = FALSE;
67 if(success)
69 hook->h_Entry = (APTR)EnumHook;
70 hook->h_Data = hook_context;
71 hook_context->library = base;
72 hook_context->success = TRUE;
74 HIDD_PCI_EnumDevices(base->pci_hidd, hook, NULL);
76 success = hook_context->success;
79 if(hook != NULL)
80 FreeMem(hook, sizeof(struct Hook));
81 if(hook_context != NULL)
82 FreeMem(hook_context, sizeof(struct HookContext));
84 if(!success)
85 DeleteLibrary(base);
87 return success;
92 AROS_UFH3(static VOID, EnumHook, AROS_UFHA(struct Hook *, hook, A0),
93 AROS_UFHA(OOP_Object *, aros_board, A2), AROS_UFHA(APTR, message, A1))
95 AROS_USERFUNC_INIT
97 LIBBASETYPE *base;
98 struct PCIBoard *board;
99 struct HookContext *context;
100 OOP_AttrBase HiddPCIDeviceAttrBase;
102 /* Add board to our list */
104 context = hook->h_Data;
105 base = context->library;
106 HiddPCIDeviceAttrBase = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
108 if(HiddPCIDeviceAttrBase != 0)
110 board = AllocMem(sizeof(struct PCIBoard), MEMF_PUBLIC | MEMF_CLEAR);
111 if(board != NULL)
113 board->aros_board = aros_board;
114 AddTail((APTR)&base->boards, (APTR)board);
116 else
117 context->success = FALSE;
118 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice);
121 return;
123 AROS_USERFUNC_EXIT
128 static int DeleteLibrary(LIBBASETYPE *base)
130 struct PCIBoard *board;
132 /* Free the list of boards */
134 while((board = (APTR)RemTail((struct List *)&base->boards)) != NULL)
135 FreeMem(board, sizeof(struct PCIBoard));
137 /* Close HIDDs */
139 if(base->pcidevice_attr_base != 0)
140 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice);
141 if(base->irq_hidd != NULL)
142 OOP_DisposeObject(base->irq_hidd);
143 if(base->pci_hidd != NULL)
144 OOP_DisposeObject(base->pci_hidd);
146 return TRUE;
151 ADD2INITLIB(LibInit, 0);
152 ADD2EXPUNGELIB(DeleteLibrary, 0);
153 ADD2LIBS("irq.hidd", 0, static struct Library *, __irqhidd);