Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / libraries / preferences / Preferences-aos4.c
blobb4a20dfc0fecaa02aea0aac1a87ad087ed8ba973
1 // Preferences-aos4.c
2 // $Date$
3 // $Revision$
6 #include <exec/interfaces.h>
7 #include <exec/emulation.h>
8 #include <exec/exectags.h>
9 #include <exec/resident.h>
11 #include <proto/exec.h>
12 #include <interfaces/preferences.h>
14 #include <stdarg.h>
16 #include "Preferences_base.h"
17 #include "Preferences.h"
19 #include <defs.h>
21 int _start(void)
23 return -1;
26 static struct Library *Initlib(struct Library *libbase, BPTR seglist, struct ExecIFace *pIExec);
27 static BPTR Expungelib(struct LibraryManagerInterface *Self);
28 static struct LibraryHeader *Openlib(struct LibraryManagerInterface *Self, ULONG version);
29 static BPTR Closelib(struct LibraryManagerInterface *Self);
30 static ULONG Obtainlib(struct LibraryManagerInterface *Self);
31 static ULONG Releaselib(struct LibraryManagerInterface *Self);
33 extern const CONST_APTR VecTable68K[];
35 /* OS4.0 Library */
37 /* ------------------- OS4 Manager Interface ------------------------ */
38 static const APTR managerfunctable[] =
40 (APTR)Obtainlib,
41 (APTR)Releaselib,
42 (APTR)NULL,
43 (APTR)NULL,
44 (APTR)Openlib,
45 (APTR)Closelib,
46 (APTR)Expungelib,
47 (APTR)NULL,
48 (APTR)-1
51 static const struct TagItem managertags[] =
53 {MIT_Name, (ULONG)"__library"},
54 {MIT_VectorTable, (ULONG)managerfunctable},
55 {MIT_Version, 1},
56 {TAG_DONE, 0}
59 /* ---------------------- OS4 Main Interface ------------------------ */
60 static APTR functable[] =
62 Obtainlib,
63 Releaselib,
64 NULL,
65 NULL,
66 LIBAllocPrefsHandle,
67 LIBFreePrefsHandle,
68 LIBSetPreferences,
69 LIBGetPreferences,
70 LIBReadPrefsHandle,
71 LIBWritePrefsHandle,
72 LIBFindPreferences,
73 LIBSetEntry,
74 LIBGetEntry,
75 LIBRemEntry,
76 (APTR) -1
79 static const struct TagItem maintags[] =
81 {MIT_Name, (ULONG)"main"},
82 {MIT_VectorTable, (ULONG)functable},
83 {MIT_Version, 1},
84 {TAG_DONE, 0}
87 /* Init table used in library initialization. */
88 static const ULONG interfaces[] =
90 (ULONG)managertags,
91 (ULONG)maintags,
92 (ULONG)0
95 static const struct TagItem inittab[] =
97 {CLT_DataSize, (ULONG)sizeof(struct PreferencesBase)},
98 {CLT_Interfaces, (ULONG) interfaces},
99 {CLT_Vector68K, (ULONG)VecTable68K},
100 {CLT_InitFunc, (ULONG) Initlib},
101 {TAG_DONE, 0}
105 /* The ROM tag */
106 struct Resident ALIGNED romtag =
108 RTC_MATCHWORD,
109 &romtag,
110 &romtag + 1,
111 RTF_NATIVE | RTF_AUTOINIT,
112 LIB_VERSION,
113 NT_LIBRARY,
115 (STRPTR)libName,
116 (STRPTR)libIdString,
117 (struct TagItem *)inittab
120 /* ------------------- OS4 Manager Functions ------------------------ */
121 static struct Library * Initlib(struct Library *libbase, BPTR seglist, struct ExecIFace *pIExec)
123 struct PreferencesBase *PrefsLibBase = (struct PreferencesBase *) libbase;
124 struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)libbase + libbase->lib_PosSize);
125 struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary;
127 SysBase = (struct ExecBase *)pIExec->Data.LibBase;
128 IExec = pIExec;
129 PrefsLibBase->prb_LibNode.lib_Revision = LIB_REVISION;
130 PrefsLibBase->prb_SegList = (struct SegList *)seglist;
132 d1(kprintf(__FILE__ "/%s/%ld: \n", __FUNC__, __LINE__));
134 if (!PreferencesInit(PrefsLibBase))
136 Expungelib(Self);
137 PrefsLibBase = NULL;
140 d1(kprintf(__FILE__ "/%s/%ld: PrefsLibBase=%08lx\n", __FUNC__, __LINE__, PrefsLibBase));
142 return PrefsLibBase ? &PrefsLibBase->prb_LibNode : NULL;
145 static BPTR Expungelib(struct LibraryManagerInterface *Self)
147 struct PreferencesBase *PrefsLibBase = (struct PreferencesBase *) Self->Data.LibBase;
149 if (0 == PrefsLibBase->prb_LibNode.lib_OpenCnt)
151 struct SegList *libseglist = PrefsLibBase->prb_SegList;
153 d1(kprintf(__FILE__ "/%s/%ld: \n", __FUNC__, __LINE__));
155 Remove((struct Node *) PrefsLibBase);
156 PreferencesCleanup(PrefsLibBase);
157 DeleteLibrary((struct Library *)PrefsLibBase);
159 return (BPTR)libseglist;
162 PrefsLibBase->prb_LibNode.lib_Flags |= LIBF_DELEXP;
164 return (BPTR)NULL;
167 static struct LibraryHeader *Openlib(struct LibraryManagerInterface *Self, ULONG version)
169 struct PreferencesBase *PrefsLibBase = (struct PreferencesBase *) Self->Data.LibBase;
171 PrefsLibBase->prb_LibNode.lib_OpenCnt++;
172 PrefsLibBase->prb_LibNode.lib_Flags &= ~LIBF_DELEXP;
174 d1(kprintf(__FILE__ "/%s/%ld: OpenCnt=%ld\n", __FUNC__, __LINE__, PrefsLibBase->prb_LibNode.lib_OpenCnt));
176 if (!PrefsLibBase->prb_Initialized)
178 if (!PreferencesOpen(PrefsLibBase))
180 d1(kprintf(__FILE__ "/%s/%ld: Initialization failed\n", __FUNC__, __LINE__));
182 Closelib(Self);
183 return NULL;
186 PrefsLibBase->prb_Initialized = TRUE;
189 d1(kprintf(__FILE__ "/%s/%ld: Initialization succeeded\n", __FUNC__, __LINE__));
191 return (struct LibraryHeader *)&PrefsLibBase->prb_LibNode;
194 static BPTR Closelib(struct LibraryManagerInterface *Self)
196 struct PreferencesBase *PrefsLibBase = (struct PreferencesBase *) Self->Data.LibBase;
198 PrefsLibBase->prb_LibNode.lib_OpenCnt--;
200 d1(kprintf(__FILE__ "/%s/%ld: OpenCnt=%ld\n", __FUNC__, __LINE__, PrefsLibBase->prb_LibNode.lib_OpenCnt));
202 if (0 == PrefsLibBase->prb_LibNode.lib_OpenCnt)
204 if (PrefsLibBase->prb_LibNode.lib_Flags & LIBF_DELEXP)
206 return Expungelib(Self);
210 return (BPTR)NULL;
213 static ULONG Obtainlib(struct LibraryManagerInterface *Self)
215 return(Self->Data.RefCount++);
218 static ULONG Releaselib(struct LibraryManagerInterface *Self)
220 return(Self->Data.RefCount--);