revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-hosted / hidd / x11 / x11_hostlib.c
blobc0c0c0f7633d1d49b9c4ae041dae06aa6ace05a1
1 /*
2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "x11_debug.h"
8 #include <aros/symbolsets.h>
10 #include "x11_types.h"
11 #include LC_LIBDEFS_FILE
12 #include "x11_hostlib.h"
14 void *x11_handle = NULL;
15 void *libc_handle = NULL;
16 void *xf86vm_handle = NULL;
17 #if !X11SOFTMOUSE
18 void *xcursor_handle = NULL;
19 #endif
21 struct x11_func x11_func;
22 struct libc_func libc_func;
23 struct xf86vm_func xf86vm_func;
24 #if !X11SOFTMOUSE
25 struct xcursor_func xcursor_func;
26 #endif
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 "XGetWMHints",
59 "XSetWMNormalHints",
60 "XSetWMProtocols",
61 "XAutoRepeatOff",
62 "XAutoRepeatOn",
63 "XChangeGC",
64 "XChangeProperty",
65 "XChangeWindowAttributes",
66 "XClearArea",
67 "XCloseDisplay",
68 "XConfigureWindow",
69 "XConvertSelection",
70 "XCopyArea",
71 "XCopyPlane",
72 "XDefineCursor",
73 "XDeleteProperty",
74 "XDestroyWindow",
75 "XDrawArc",
76 "XDrawLine",
77 "XDrawPoint",
78 "XDrawString",
79 "XEventsQueued",
80 "XFillRectangle",
81 "XFlush",
82 "XFree",
83 "XFreeColormap",
84 "XFreeGC",
85 "XFreePixmap",
86 "XGetErrorText",
87 "XGetVisualInfo",
88 "XGetWindowProperty",
89 "XGetWindowAttributes",
90 "XGrabKeyboard",
91 "XGrabPointer",
92 "XMapRaised",
93 "XMapWindow",
94 "XNextEvent",
95 "XParseGeometry",
96 "XPending",
97 "XPutImage",
98 "XRecolorCursor",
99 "XRefreshKeyboardMapping",
100 "XSelectInput",
101 "XSendEvent",
102 "XSetBackground",
103 "XSetClipMask",
104 "XSetClipRectangles",
105 "XSetFillStyle",
106 "XSetForeground",
107 "XSetFunction",
108 "XSetIconName",
109 "XSetSelectionOwner",
110 "XStoreColor",
111 "XStoreName",
112 "XSync",
113 "XAllocColor",
114 "XLookupString",
115 "XQueryExtension",
116 "XDefaultScreen",
117 "XRootWindow",
118 "XAllocClassHint",
119 "XSetClassHint",
120 "XSetInputFocus"
121 #if DEBUG_X11_SYNCHRON
122 , "XSynchronize"
123 #endif
126 #if DEBUG_X11_SYNCHRON
127 #define X11_NUM_FUNCS (83)
128 #else
129 #define X11_NUM_FUNCS (82)
130 #endif
133 static const char *libc_func_names[] = {
134 #if USE_XSHM
135 "ftok",
136 "shmctl",
137 "shmget",
138 "shmat",
139 "shmdt",
140 #endif
141 "raise"
144 #if USE_XSHM
145 #define LIBC_NUM_FUNCS (6)
146 #else
147 #define LIBC_NUM_FUNCS (1)
148 #endif
150 #if !X11SOFTMOUSE
151 static const char *xcursor_func_names[] = {
152 "XcursorImageCreate",
153 "XcursorImageDestroy",
154 "XcursorImageLoadCursor"
157 #define XCURSOR_NUM_FUNCS (3)
158 #endif
160 void *HostLibBase;
162 void *x11_hostlib_load_so(const char *sofile, const char **names, int nfuncs, void **funcptr)
164 void *handle;
165 char *err;
166 int i;
168 D(bug("[X11host] %s('%s')\n", __PRETTY_FUNCTION__, sofile));
170 D(bug("[X11host] %s: attempting to load %d functions\n", __PRETTY_FUNCTION__, nfuncs));
172 if ((handle = HostLib_Open(sofile, &err)) == NULL) {
173 bug("[X11host] %s: failed to open '%s': %s\n", __PRETTY_FUNCTION__, sofile, err);
174 return NULL;
177 for (i = 0; i < nfuncs; i++) {
178 funcptr[i] = HostLib_GetPointer(handle, names[i], &err);
179 D(bug("[X11host] %s: 0x%p = '%s'\n", __PRETTY_FUNCTION__, funcptr[i], names[i]));
180 if (err != NULL) {
181 bug("[X11host] %s: failed to get symbol '%s' (%s)\n", __PRETTY_FUNCTION__, names[i], err);
182 HostLib_Close(handle, NULL);
183 return NULL;
187 return handle;
190 static int x11_hostlib_init(LIBBASETYPEPTR LIBBASE)
192 D(bug("[X11host] %s()\n", __PRETTY_FUNCTION__));
194 if ((HostLibBase = OpenResource("hostlib.resource")) == NULL) {
195 bug("[X11host] %s: failed to open hostlib.resource!\n", __PRETTY_FUNCTION__);
196 return FALSE;
199 #if !X11SOFTMOUSE
200 if ((xcursor_handle = x11_hostlib_load_so(XCURSOR_SOFILE,
201 xcursor_func_names, XCURSOR_NUM_FUNCS, (void **) &xcursor_func))
202 == NULL)
203 return FALSE;
204 #endif
206 if ((xf86vm_handle = x11_hostlib_load_so(XF86VM_SOFILE, xf86vm_func_names, XF86VM_NUM_FUNCS, (void **) &xf86vm_func)) == NULL)
207 return FALSE;
209 if ((x11_handle = x11_hostlib_load_so(X11_SOFILE, x11_func_names, X11_NUM_FUNCS, (void **) &x11_func)) == NULL)
210 return FALSE;
212 if ((libc_handle = x11_hostlib_load_so(LIBC_SOFILE, libc_func_names, LIBC_NUM_FUNCS, (void **) &libc_func)) == NULL) {
213 HostLib_Close(x11_handle, NULL);
214 return FALSE;
217 return TRUE;
220 static int x11_hostlib_expunge(LIBBASETYPEPTR LIBBASE)
222 D(bug("[X11host] %s()\n", __PRETTY_FUNCTION__));
224 #if !X11SOFTMOUSE
225 if (xcursor_handle != NULL)
226 HostLib_Close(xcursor_handle, NULL);
227 #endif
229 if (xf86vm_handle != NULL)
230 HostLib_Close(xf86vm_handle, NULL);
232 if (x11_handle != NULL)
233 HostLib_Close(x11_handle, NULL);
235 if (libc_handle != NULL)
236 HostLib_Close(libc_handle, NULL);
238 return TRUE;
241 ADD2INITLIB(x11_hostlib_init, 0)
242 ADD2EXPUNGELIB(x11_hostlib_expunge, 0)