1/*
2
3Copyright 1989, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25*/
26
27/*
28 * Author:  Jim Fulton, MIT X Consortium
29 */
30
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34#include <stdio.h>
35#include <X11/Xlib.h>
36#include <X11/Xos.h>
37#include <X11/Xmu/CvtCache.h>
38#include <stdlib.h>
39
40/*
41 * Prototypes
42 */
43static int _CloseDisplay(XmuDisplayQueue*, XmuDisplayQueueEntry*);
44static int _FreeCCDQ(XmuDisplayQueue*);
45static void _InitializeCvtCache(XmuCvtCache*);
46
47/*
48 * Initialization
49 */
50static XmuDisplayQueue *dq = NULL;
51
52
53/*
54 * internal utility callbacks
55 */
56
57static int
58_FreeCCDQ(XmuDisplayQueue *q)
59{
60    XmuDQDestroy (dq, False);
61    dq = NULL;
62    return (0);
63}
64
65
66static int
67_CloseDisplay(XmuDisplayQueue *q, XmuDisplayQueueEntry *e)
68{
69    XmuCvtCache *c;
70
71    if (e && (c = (XmuCvtCache *)(e->data))) {
72	_XmuStringToBitmapFreeCache (c);
73	/* insert calls to free any cached memory */
74
75    }
76    return 0;
77}
78
79static void
80_InitializeCvtCache(register XmuCvtCache *c)
81{
82    _XmuStringToBitmapInitCache (c);
83    /* insert calls to init any cached memory */
84}
85
86
87/*
88 * XmuCCLookupDisplay - return the cache entry for the indicated display;
89 * initialize the cache if necessary
90 */
91XmuCvtCache *
92_XmuCCLookupDisplay(Display *dpy)
93{
94    XmuDisplayQueueEntry *e;
95
96    /*
97     * If no displays have been added before this, create the display queue.
98     */
99    if (!dq) {
100	dq = XmuDQCreate (_CloseDisplay, _FreeCCDQ, NULL);
101	if (!dq) return NULL;
102    }
103
104    /*
105     * See if the display is already there
106     */
107    e = XmuDQLookupDisplay (dq, dpy);	/* see if it's there */
108    if (!e) {				/* else create it */
109	XmuCvtCache *c = malloc (sizeof (XmuCvtCache));
110	if (!c) return NULL;
111
112	/*
113	 * Add the display to the queue
114	 */
115	e = XmuDQAddDisplay (dq, dpy, (XPointer) c);
116	if (!e) {
117	    free (c);
118	    return NULL;
119	}
120
121	/*
122	 * initialize fields in cache
123	 */
124	_InitializeCvtCache (c);
125    }
126
127    /*
128     * got it
129     */
130    return (XmuCvtCache *)(e->data);
131}
132
133
134