Copyright clean-up (part 1):
[AROS.git] / arch / all-hosted / hidd / x11 / x11_hostlib.c
blobb2225d46049ff61b174a710a7a0a12c4445bed58
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/config.h>
8 #include "x11gfx_intern.h"
9 #include "x11.h"
11 #include <aros/symbolsets.h>
13 #include <proto/hostlib.h>
15 #include LC_LIBDEFS_FILE
17 #define DEBUG 0
18 #include <aros/debug.h>
20 void *x11_handle = NULL;
21 void *libc_handle = NULL;
22 void *xf86vm_handle = NULL;
24 struct x11_func x11_func;
25 struct libc_func libc_func;
26 struct xf86vm_func xf86vm_func;
28 static const char *xf86vm_func_names[] = {
29 "XF86VidModeGetAllModeLines",
30 "XF86VidModeSwitchToMode",
31 "XF86VidModeSetViewPort",
32 "XF86VidModeQueryVersion",
33 "XF86VidModeQueryExtension"
36 #define XF86VM_NUM_FUNCS (5)
38 static const char *x11_func_names[] = {
39 "XCreateImage",
40 "XInitImage",
41 "XGetImage",
42 "XOpenDisplay",
43 "XDisplayName",
44 "XInternAtom",
45 "XCreateColormap",
46 "XCreatePixmapCursor",
47 "XCreateFontCursor",
48 "XCreateGC",
49 "XCreatePixmap",
50 "XCreateSimpleWindow",
51 "XCreateWindow",
52 "XLookupKeysym",
53 "XMaxRequestSize",
54 "XVisualIDFromVisual",
55 "XSetErrorHandler",
56 "XSetIOErrorHandler",
57 "XSetWMHints",
58 "XSetWMNormalHints",
59 "XSetWMProtocols",
60 "XAutoRepeatOff",
61 "XAutoRepeatOn",
62 "XChangeGC",
63 "XChangeProperty",
64 "XChangeWindowAttributes",
65 "XClearArea",
66 "XCloseDisplay",
67 "XConfigureWindow",
68 "XConvertSelection",
69 "XCopyArea",
70 "XCopyPlane",
71 "XDefineCursor",
72 "XDeleteProperty",
73 "XDestroyWindow",
74 "XDrawArc",
75 "XDrawLine",
76 "XDrawPoint",
77 "XDrawString",
78 "XEventsQueued",
79 "XFillRectangle",
80 "XFlush",
81 "XFree",
82 "XFreeColormap",
83 "XFreeGC",
84 "XFreePixmap",
85 "XGetErrorText",
86 "XGetVisualInfo",
87 "XGetWindowProperty",
88 "XGetWindowAttributes",
89 "XGrabKeyboard",
90 "XGrabPointer",
91 "XMapRaised",
92 "XMapWindow",
93 "XNextEvent",
94 "XParseGeometry",
95 "XPending",
96 "XPutImage",
97 "XRecolorCursor",
98 "XRefreshKeyboardMapping",
99 "XSelectInput",
100 "XSendEvent",
101 "XSetBackground",
102 "XSetClipMask",
103 "XSetClipRectangles",
104 "XSetFillStyle",
105 "XSetForeground",
106 "XSetFunction",
107 "XSetIconName",
108 "XSetSelectionOwner",
109 "XStoreColor",
110 "XStoreName",
111 "XSync",
112 "XAllocColor",
113 "XLookupString",
114 "XQueryExtension",
115 "XDefaultScreen",
116 "XRootWindow",
117 "XAllocClassHint",
118 "XSetClassHint"
119 #if DEBUG_X11_SYNCHRON
120 , "XSynchronize"
121 #endif
124 #if DEBUG_X11_SYNCHRON
125 #define X11_NUM_FUNCS (81)
126 #else
127 #define X11_NUM_FUNCS (80)
128 #endif
131 static const char *libc_func_names[] = {
132 #if USE_XSHM
133 "ftok",
134 "shmctl",
135 "shmget",
136 "shmat",
137 "shmdt",
138 #endif
139 "raise"
142 #if USE_XSHM
143 #define LIBC_NUM_FUNCS (6)
144 #else
145 #define LIBC_NUM_FUNCS (1)
146 #endif
148 void *HostLibBase;
150 void *x11_hostlib_load_so(const char *sofile, const char **names, int nfuncs, void **funcptr) {
151 void *handle;
152 char *err;
153 int i;
155 D(bug("[x11] loading %d functions from %s\n", nfuncs, sofile));
157 if ((handle = HostLib_Open(sofile, &err)) == NULL) {
158 kprintf("[x11] couldn't open '%s': %s\n", sofile, err);
159 return NULL;
162 for (i = 0; i < nfuncs; i++) {
163 funcptr[i] = HostLib_GetPointer(handle, names[i], &err);
164 D(bug("%s(%x)\n", names[i], funcptr[i]));
165 if (err != NULL) {
166 kprintf("[x11] couldn't get symbol '%s' from '%s': %s\n", names[i], sofile, err);
167 HostLib_Close(handle, NULL);
168 return NULL;
172 D(bug("[x11] done\n"));
174 return handle;
177 static int x11_hostlib_init(LIBBASETYPEPTR LIBBASE) {
178 D(bug("[x11] hostlib init\n"));
180 if ((HostLibBase = OpenResource("hostlib.resource")) == NULL) {
181 kprintf("[x11] couldn't open hostlib.resource\n");
182 return FALSE;
184 if ((xf86vm_handle = x11_hostlib_load_so(XF86VM_SOFILE, xf86vm_func_names, XF86VM_NUM_FUNCS, (void **) &xf86vm_func)) == NULL)
185 return FALSE;
187 if ((x11_handle = x11_hostlib_load_so(X11_SOFILE, x11_func_names, X11_NUM_FUNCS, (void **) &x11_func)) == NULL)
188 return FALSE;
190 if ((libc_handle = x11_hostlib_load_so(LIBC_SOFILE, libc_func_names, LIBC_NUM_FUNCS, (void **) &libc_func)) == NULL) {
191 HostLib_Close(x11_handle, NULL);
192 return FALSE;
195 return TRUE;
198 static int x11_hostlib_expunge(LIBBASETYPEPTR LIBBASE) {
199 D(bug("[x11] hostlib expunge\n"));
201 if (xf86vm_handle != NULL)
202 HostLib_Close(xf86vm_handle, NULL);
204 if (x11_handle != NULL)
205 HostLib_Close(x11_handle, NULL);
207 if (libc_handle != NULL)
208 HostLib_Close(libc_handle, NULL);
210 return TRUE;
213 ADD2INITLIB(x11_hostlib_init, 0)
214 ADD2EXPUNGELIB(x11_hostlib_expunge, 0)