revert between 56095 -> 55830 in arch
[AROS.git] / workbench / classes / datatypes / wav / init.c
blob015b88b163c4af930384049a23b8227aa2deb4d8
1 /*
2 * wave.datatype
3 * (c) Fredrik Wikstrom
4 */
6 #define LIBNAME "wave.datatype"
8 #include "wave.datatype_rev.h"
9 #include "wave_class.h"
11 const char
12 #ifdef __GNUC__
13 __attribute__((used))
14 #endif
15 verstag[] = VERSTAG;
17 ULONG libObtain (struct LibraryManagerInterface *Self);
18 ULONG libRelease (struct LibraryManagerInterface *Self);
19 struct ClassBase *libOpen (struct LibraryManagerInterface *Self, ULONG version);
20 BPTR libClose (struct LibraryManagerInterface *Self);
21 BPTR libExpunge (struct LibraryManagerInterface *Self);
23 static CONST_APTR lib_manager_vectors[] = {
24 (APTR)libObtain,
25 (APTR)libRelease,
26 NULL,
27 NULL,
28 (APTR)libOpen,
29 (APTR)libClose,
30 (APTR)libExpunge,
31 NULL,
32 (APTR)-1,
35 static const struct TagItem lib_managerTags[] = {
36 { MIT_Name, (ULONG)"__library" },
37 { MIT_VectorTable, (ULONG)lib_manager_vectors },
38 { MIT_Version, 1 },
39 { TAG_END }
42 ULONG dtObtain (struct DTClassIFace *Self);
43 ULONG dtRelease (struct DTClassIFace *Self);
44 Class * dtObtainEngine (struct DTClassIFace *Self);
46 static CONST_APTR lib_main_vectors[] = {
47 (APTR)dtObtain,
48 (APTR)dtRelease,
49 NULL,
50 NULL,
51 (APTR)dtObtainEngine,
52 (APTR)-1
55 static const struct TagItem lib_mainTags[] = {
56 { MIT_Name, (ULONG)"main" },
57 { MIT_VectorTable, (ULONG)lib_main_vectors },
58 { MIT_Version, 1 },
59 { TAG_END }
62 static CONST_APTR libInterfaces[] = {
63 lib_managerTags,
64 lib_mainTags,
65 NULL
68 struct ClassBase * libInit (struct ClassBase *libBase, BPTR seglist, struct ExecIFace *ISys);
70 static const struct TagItem libCreateTags[] = {
71 { CLT_DataSize, (ULONG)sizeof(struct ClassBase) },
72 { CLT_InitFunc, (ULONG)libInit },
73 { CLT_Interfaces, (ULONG)libInterfaces },
74 { TAG_END }
77 const struct Resident lib_res
78 #ifdef __GNUC__
79 __attribute__((used))
80 #endif
83 RTC_MATCHWORD,
84 (struct Resident *)&lib_res,
85 (APTR)(&lib_res + 1),
86 RTF_NATIVE|RTF_AUTOINIT, /* Add RTF_COLDSTART if you want to be resident */
87 VERSION,
88 NT_LIBRARY, /* Make this NT_DEVICE if needed */
89 0, /* PRI, usually not needed unless you're resident */
90 LIBNAME,
91 VSTRING,
92 (APTR)libCreateTags
95 void _start () {
98 static int openDTLibs (struct ClassBase *libBase);
99 static void closeDTLibs (struct ClassBase *libBase);
101 struct ClassBase *libInit (struct ClassBase *libBase, BPTR seglist, struct ExecIFace *ISys) {
103 libBase->libNode.lib_Node.ln_Type = NT_LIBRARY;
104 libBase->libNode.lib_Node.ln_Pri = 0;
105 libBase->libNode.lib_Node.ln_Name = LIBNAME;
106 libBase->libNode.lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
107 libBase->libNode.lib_Version = VERSION;
108 libBase->libNode.lib_Revision = REVISION;
109 libBase->libNode.lib_IdString = VSTRING;
112 libBase->SegList = seglist;
113 if (openDTLibs(libBase)) {
114 if (libBase->DTClass = initDTClass(libBase)) {
115 return libBase;
118 closeDTLibs(libBase);
120 return NULL;
123 ULONG libObtain (struct LibraryManagerInterface *Self) {
124 return Self->Data.RefCount++;
127 ULONG libRelease (struct LibraryManagerInterface *Self) {
128 return Self->Data.RefCount--;
131 struct ClassBase *libOpen (struct LibraryManagerInterface *Self, ULONG version) {
132 struct ClassBase *libBase;
134 libBase = (struct ClassBase *)Self->Data.LibBase;
136 libBase->libNode.lib_OpenCnt++;
137 libBase->libNode.lib_Flags &= ~LIBF_DELEXP;
139 return libBase;
142 BPTR libClose (struct LibraryManagerInterface *Self) {
143 struct ClassBase *libBase;
145 libBase = (struct ClassBase *)Self->Data.LibBase;
147 libBase->libNode.lib_OpenCnt--;
149 if (libBase->libNode.lib_OpenCnt) {
150 return 0;
153 if (libBase->libNode.lib_Flags & LIBF_DELEXP) {
154 return (BPTR)Self->LibExpunge();
155 } else {
156 return 0;
160 BPTR libExpunge (struct LibraryManagerInterface *Self) {
161 struct ClassBase *libBase;
162 BPTR result = 0;
164 libBase = (struct ClassBase *)Self->Data.LibBase;
166 if (libBase->libNode.lib_OpenCnt == 0) {
167 Remove(&libBase->libNode.lib_Node);
169 result = libBase->SegList;
171 freeDTClass(libBase, libBase->DTClass);
172 libBase->DTClass = NULL;
174 closeDTLibs(libBase);
176 Remove(&libBase->libNode.lib_Node);
177 DeleteLibrary(&libBase->libNode);
178 } else {
179 libBase->libNode.lib_Flags |= LIBF_DELEXP;
182 return result;
185 ULONG dtObtain (struct DTClassIFace *Self) {
186 return(Self->Data.RefCount++);
189 ULONG dtRelease (struct DTClassIFace *Self) {
190 return(Self->Data.RefCount--);
193 Class * dtObtainEngine (struct DTClassIFace *Self) {
194 struct ClassBase *libBase;
195 libBase = (struct ClassBase *)Self->Data.LibBase;
196 return libBase->DTClass;
200 static int openDTLibs (struct ClassBase *libBase) {
201 DOSBase = OpenLibrary("dos.library", 50);
202 if (!DOSBase) return FALSE;
204 IntuitionBase = OpenLibrary("intuition.library", 50);
205 if (!IntuitionBase) return FALSE;
207 UtilityBase = OpenLibrary("utility.library", 50);
208 if (!UtilityBase) return FALSE;
210 DataTypesBase = OpenLibrary("datatypes.library", 50);
211 if (!DataTypesBase) return FALSE;
213 return TRUE;
216 static void closeDTLibs (struct ClassBase *libBase) {
217 if (DataTypesBase) CloseLibrary(DataTypesBase);
219 if (UtilityBase) CloseLibrary(UtilityBase);
221 if (IntuitionBase) CloseLibrary(IntuitionBase);
223 if (DOSBase) CloseLibrary(DOSBase);