Copyright clean-up (part 1):
[AROS.git] / arch / all-mingw32 / hidd / wingdi / gdi_hostlib.c
blobc9fe687a6ce2325b02fa972693dffb9d7851a849
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/config.h>
8 #include "gdi.h"
10 #include <aros/symbolsets.h>
12 #include <proto/hostlib.h>
14 #include LC_LIBDEFS_FILE
16 #define DEBUG 0
17 #include <aros/debug.h>
19 void *gdi_handle = NULL;
20 void *user_handle = NULL;
21 void *native_handle = NULL;
23 struct gdi_func *gdi_func;
24 struct user_func *user_func;
25 struct native_func *native_func;
27 static const char *gdi_func_names[] = {
28 "CreateDCA",
29 "CreateCompatibleDC",
30 "DeleteDC",
31 "GetDeviceCaps",
32 "CreateBitmapIndirect",
33 "CreateCompatibleBitmap",
34 "CreateSolidBrush",
35 "DeleteObject",
36 "SelectObject",
37 "SetBkColor",
38 "SetTextColor",
39 "SetROP2",
40 "BitBlt",
41 "PatBlt",
42 "GetPixel",
43 "SetPixel",
44 "GetDIBits",
45 "StretchDIBits",
46 NULL
49 static const char *user_func_names[] = {
50 "CreateIconIndirect",
51 "DestroyIcon",
52 "SetCursor",
53 "SetWindowPos",
54 "RedrawWindow",
55 NULL
58 static const char *native_func_names[] = {
59 "GDI_Init",
60 "GDI_Shutdown",
61 "GDI_PutMsg",
62 "GDI_KbdAck",
63 "GDI_MouseAck",
64 NULL
67 void *KernelBase;
68 void *HostLibBase;
70 APTR *gdi_hostlib_load_so(const char *sofile, const char **names, void **handle)
72 APTR *funcptr;
73 ULONG i;
75 D(bug("[gdi] loading functions from %s\n", sofile));
77 if ((*handle = HostLib_Open(sofile, NULL)) == NULL) {
78 D(kprintf("[gdi] couldn't open '%s'\n", sofile));
79 return NULL;
82 funcptr = HostLib_GetInterface(*handle, names, &i);
83 if (funcptr)
85 if (!i)
87 D(bug("[gdi] done\n"));
88 return funcptr;
90 D(kprintf("[gdi] couldn't get %lu symbols from '%s'\n", i, sofile));
91 HostLib_DropInterface(funcptr);
93 HostLib_Close(*handle, NULL);
94 return NULL;
97 static int gdi_hostlib_init(LIBBASETYPEPTR LIBBASE) {
98 D(bug("[gdi] hostlib init\n"));
100 if ((KernelBase = OpenResource("kernel.resource")) == NULL) {
101 kprintf("[gdi] couldn't open kernel.resource");
102 return FALSE;
104 if ((HostLibBase = OpenResource("hostlib.resource")) == NULL) {
105 kprintf("[gdi] couldn't open hostlib.resource");
106 return FALSE;
109 gdi_func = (struct gdi_func *)gdi_hostlib_load_so(GDI_SOFILE, gdi_func_names, &gdi_handle);
110 if (!gdi_func)
111 return FALSE;
112 user_func = (struct user_func *)gdi_hostlib_load_so(USER_SOFILE, user_func_names, &user_handle);
113 if (user_func) {
114 native_func = (struct native_func *)gdi_hostlib_load_so(NATIVE_SOFILE, native_func_names, &native_handle);
115 if (native_func)
116 return TRUE;
117 HostLib_DropInterface((APTR *)user_func);
118 HostLib_Close(user_handle, NULL);
120 HostLib_DropInterface((APTR *)gdi_func);
121 HostLib_Close(gdi_handle, NULL);
122 return FALSE;
125 static int gdi_hostlib_expunge(LIBBASETYPEPTR LIBBASE) {
126 D(bug("[gdi] hostlib expunge\n"));
128 if (gdi_func != NULL)
129 HostLib_DropInterface((APTR *)gdi_func);
130 if (gdi_handle != NULL)
131 HostLib_Close(gdi_handle, NULL);
133 if (native_func != NULL)
134 HostLib_DropInterface((APTR *)native_func);
135 if (native_handle != NULL)
136 HostLib_Close(native_handle, NULL);
138 return TRUE;
141 ADD2INITLIB(gdi_hostlib_init, 0)
142 ADD2EXPUNGELIB(gdi_hostlib_expunge, 0)