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>
16 #include "Preferences_base.h"
17 #include "Preferences.h"
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
[];
37 /* ------------------- OS4 Manager Interface ------------------------ */
38 static const APTR managerfunctable
[] =
51 static const struct TagItem managertags
[] =
53 {MIT_Name
, (ULONG
)"__library"},
54 {MIT_VectorTable
, (ULONG
)managerfunctable
},
59 /* ---------------------- OS4 Main Interface ------------------------ */
60 static APTR functable
[] =
79 static const struct TagItem maintags
[] =
81 {MIT_Name
, (ULONG
)"main"},
82 {MIT_VectorTable
, (ULONG
)functable
},
87 /* Init table used in library initialization. */
88 static const ULONG interfaces
[] =
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
},
106 struct Resident ALIGNED romtag
=
111 RTF_NATIVE
| RTF_AUTOINIT
,
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
;
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
))
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
;
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__
));
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);
213 static ULONG
Obtainlib(struct LibraryManagerInterface
*Self
)
215 return(Self
->Data
.RefCount
++);
218 static ULONG
Releaselib(struct LibraryManagerInterface
*Self
)
220 return(Self
->Data
.RefCount
--);