x11.hidd: clean up includes to fix build under linux-armhf
[AROS.git] / arch / all-hosted / hidd / x11 / x11_hostlib.c
blob5f04cf001f43a25ac594425a0da0a830a25d8031
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;
18 struct x11_func x11_func;
19 struct libc_func libc_func;
20 struct xf86vm_func xf86vm_func;
22 static const char *xf86vm_func_names[] = {
23 "XF86VidModeGetAllModeLines",
24 "XF86VidModeSwitchToMode",
25 "XF86VidModeSetViewPort",
26 "XF86VidModeQueryVersion",
27 "XF86VidModeQueryExtension"
30 #define XF86VM_NUM_FUNCS (5)
32 static const char *x11_func_names[] = {
33 "XCreateImage",
34 "XInitImage",
35 "XGetImage",
36 "XOpenDisplay",
37 "XDisplayName",
38 "XInternAtom",
39 "XCreateColormap",
40 "XCreatePixmapCursor",
41 "XCreateFontCursor",
42 "XCreateGC",
43 "XCreatePixmap",
44 "XCreateSimpleWindow",
45 "XCreateWindow",
46 "XLookupKeysym",
47 "XMaxRequestSize",
48 "XVisualIDFromVisual",
49 "XSetErrorHandler",
50 "XSetIOErrorHandler",
51 "XSetWMHints",
52 "XGetWMHints",
53 "XSetWMNormalHints",
54 "XSetWMProtocols",
55 "XAutoRepeatOff",
56 "XAutoRepeatOn",
57 "XChangeGC",
58 "XChangeProperty",
59 "XChangeWindowAttributes",
60 "XClearArea",
61 "XCloseDisplay",
62 "XConfigureWindow",
63 "XConvertSelection",
64 "XCopyArea",
65 "XCopyPlane",
66 "XDefineCursor",
67 "XDeleteProperty",
68 "XDestroyWindow",
69 "XDrawArc",
70 "XDrawLine",
71 "XDrawPoint",
72 "XDrawString",
73 "XEventsQueued",
74 "XFillRectangle",
75 "XFlush",
76 "XFree",
77 "XFreeColormap",
78 "XFreeGC",
79 "XFreePixmap",
80 "XGetErrorText",
81 "XGetVisualInfo",
82 "XGetWindowProperty",
83 "XGetWindowAttributes",
84 "XGrabKeyboard",
85 "XGrabPointer",
86 "XMapRaised",
87 "XMapWindow",
88 "XNextEvent",
89 "XParseGeometry",
90 "XPending",
91 "XPutImage",
92 "XRecolorCursor",
93 "XRefreshKeyboardMapping",
94 "XSelectInput",
95 "XSendEvent",
96 "XSetBackground",
97 "XSetClipMask",
98 "XSetClipRectangles",
99 "XSetFillStyle",
100 "XSetForeground",
101 "XSetFunction",
102 "XSetIconName",
103 "XSetSelectionOwner",
104 "XStoreColor",
105 "XStoreName",
106 "XSync",
107 "XAllocColor",
108 "XLookupString",
109 "XQueryExtension",
110 "XDefaultScreen",
111 "XRootWindow",
112 "XAllocClassHint",
113 "XSetClassHint",
114 "XSetInputFocus"
115 #if DEBUG_X11_SYNCHRON
116 , "XSynchronize"
117 #endif
120 #if DEBUG_X11_SYNCHRON
121 #define X11_NUM_FUNCS (83)
122 #else
123 #define X11_NUM_FUNCS (82)
124 #endif
127 static const char *libc_func_names[] = {
128 #if USE_XSHM
129 "ftok",
130 "shmctl",
131 "shmget",
132 "shmat",
133 "shmdt",
134 #endif
135 "raise"
138 #if USE_XSHM
139 #define LIBC_NUM_FUNCS (6)
140 #else
141 #define LIBC_NUM_FUNCS (1)
142 #endif
144 void *HostLibBase;
146 void *x11_hostlib_load_so(const char *sofile, const char **names, int nfuncs, void **funcptr)
148 void *handle;
149 char *err;
150 int i;
152 D(bug("[X11host] %s('%s')\n", __PRETTY_FUNCTION__, sofile));
154 D(bug("[X11host] %s: attempting to load %d functions\n", __PRETTY_FUNCTION__, nfuncs));
156 if ((handle = HostLib_Open(sofile, &err)) == NULL) {
157 bug("[X11host] %s: failed to open '%s': %s\n", __PRETTY_FUNCTION__, sofile, err);
158 return NULL;
161 for (i = 0; i < nfuncs; i++) {
162 funcptr[i] = HostLib_GetPointer(handle, names[i], &err);
163 D(bug("[X11host] %s: 0x%p = '%s'\n", __PRETTY_FUNCTION__, funcptr[i], names[i]));
164 if (err != NULL) {
165 bug("[X11host] %s: failed to get symbol '%s' (%s)\n", __PRETTY_FUNCTION__, names[i], err);
166 HostLib_Close(handle, NULL);
167 return NULL;
171 return handle;
174 static int x11_hostlib_init(LIBBASETYPEPTR LIBBASE)
176 D(bug("[X11host] %s()\n", __PRETTY_FUNCTION__));
178 if ((HostLibBase = OpenResource("hostlib.resource")) == NULL) {
179 bug("[X11host] %s: failed to open hostlib.resource!\n", __PRETTY_FUNCTION__);
180 return FALSE;
182 if ((xf86vm_handle = x11_hostlib_load_so(XF86VM_SOFILE, xf86vm_func_names, XF86VM_NUM_FUNCS, (void **) &xf86vm_func)) == NULL)
183 return FALSE;
185 if ((x11_handle = x11_hostlib_load_so(X11_SOFILE, x11_func_names, X11_NUM_FUNCS, (void **) &x11_func)) == NULL)
186 return FALSE;
188 if ((libc_handle = x11_hostlib_load_so(LIBC_SOFILE, libc_func_names, LIBC_NUM_FUNCS, (void **) &libc_func)) == NULL) {
189 HostLib_Close(x11_handle, NULL);
190 return FALSE;
193 return TRUE;
196 static int x11_hostlib_expunge(LIBBASETYPEPTR LIBBASE)
198 D(bug("[X11host] %s()\n", __PRETTY_FUNCTION__));
200 if (xf86vm_handle != NULL)
201 HostLib_Close(xf86vm_handle, NULL);
203 if (x11_handle != NULL)
204 HostLib_Close(x11_handle, NULL);
206 if (libc_handle != NULL)
207 HostLib_Close(libc_handle, NULL);
209 return TRUE;
212 ADD2INITLIB(x11_hostlib_init, 0)
213 ADD2EXPUNGELIB(x11_hostlib_expunge, 0)