[PATCH 2/5] dix: Extract callback.c from within dixutils.c
Fernando Carrijo
fcarrijo at yahoo.com.br
Tue Jul 27 22:42:20 PDT 2010
The file dixutils.c has grown into an incohesive and bloated beast. The time has
come to refactor some of its routines to their own files. This patch gives a new
home for all of those which deal with callback management.
---
dix/Makefile.am | 1 +
dix/callback.c | 333 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
dix/dixutils.c | 234 --------------------------------------
3 files changed, 334 insertions(+), 234 deletions(-)
create mode 100644 dix/callback.c
diff --git a/dix/Makefile.am b/dix/Makefile.am
index 8164a34..2716ea5 100644
--- a/dix/Makefile.am
+++ b/dix/Makefile.am
@@ -8,6 +8,7 @@ libmain_la_SOURCES = \
libdix_la_SOURCES = \
atom.c \
blockhandler.c \
+ callback.c \
colormap.c \
cursor.c \
deprecated.c \
diff --git a/dix/callback.c b/dix/callback.c
new file mode 100644
index 0000000..8404039
--- /dev/null
+++ b/dix/callback.c
@@ -0,0 +1,333 @@
+/***********************************************************
+
+Copyright 1987, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/*
+
+(c)Copyright 1988,1991 Adobe Systems Incorporated. All rights reserved.
+
+Permission to use, copy, modify, distribute, and sublicense this software and its
+documentation for any purpose and without fee is hereby granted, provided that
+the above copyright notices appear in all copies and that both those copyright
+notices and this permission notice appear in supporting documentation and that
+the name of Adobe Systems Incorporated not be used in advertising or publicity
+pertaining to distribution of the software without specific, written prior
+permission. No trademark license to use the Adobe trademarks is hereby
+granted. If the Adobe trademark "Display PostScript"(tm) is used to describe
+this software, its functionality or for any other purpose, such use shall be
+limited to a statement that this software works in conjunction with the Display
+PostScript system. Proper trademark attribution to reflect Adobe's ownership
+of the trademark shall be given whenever any such reference to the Display
+PostScript system is made.
+
+ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY
+PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ADOBE
+DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-
+INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE TO YOU
+OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,NEGLIGENCE, STRICT
+LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT PROVIDE ANY TRAINING OR OTHER
+SUPPORT FOR THE SOFTWARE.
+
+Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
+Incorporated which may be registered in certain jurisdictions.
+
+Author: Adobe Systems Incorporated
+
+*/
+
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "misc.h"
+#include "windowstr.h"
+#include "dixstruct.h"
+#include "pixmapstr.h"
+#include "gcstruct.h"
+#include "scrnintstr.h"
+#define XK_LATIN1
+#include <X11/keysymdef.h>
+#include "xace.h"
+
+/*
+ * Generic Callback Manager
+ */
+
+/* ===== Private Procedures ===== */
+
+static int numCallbackListsToCleanup = 0;
+static CallbackListPtr **listsToCleanup = NULL;
+
+static Bool
+_AddCallback(
+ CallbackListPtr *pcbl,
+ CallbackProcPtr callback,
+ pointer data)
+{
+ CallbackPtr cbr;
+
+ cbr = malloc(sizeof(CallbackRec));
+ if (!cbr)
+ return FALSE;
+ cbr->proc = callback;
+ cbr->data = data;
+ cbr->next = (*pcbl)->list;
+ cbr->deleted = FALSE;
+ (*pcbl)->list = cbr;
+ return TRUE;
+}
+
+static Bool
+_DeleteCallback(
+ CallbackListPtr *pcbl,
+ CallbackProcPtr callback,
+ pointer data)
+{
+ CallbackListPtr cbl = *pcbl;
+ CallbackPtr cbr, pcbr;
+
+ for (pcbr = NULL, cbr = cbl->list;
+ cbr != NULL;
+ pcbr = cbr, cbr = cbr->next)
+ {
+ if ((cbr->proc == callback) && (cbr->data == data))
+ break;
+ }
+ if (cbr != NULL)
+ {
+ if (cbl->inCallback)
+ {
+ ++(cbl->numDeleted);
+ cbr->deleted = TRUE;
+ }
+ else
+ {
+ if (pcbr == NULL)
+ cbl->list = cbr->next;
+ else
+ pcbr->next = cbr->next;
+ free(cbr);
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void
+_CallCallbacks(
+ CallbackListPtr *pcbl,
+ pointer call_data)
+{
+ CallbackListPtr cbl = *pcbl;
+ CallbackPtr cbr, pcbr;
+
+ ++(cbl->inCallback);
+ for (cbr = cbl->list; cbr != NULL; cbr = cbr->next)
+ {
+ (*(cbr->proc)) (pcbl, cbr->data, call_data);
+ }
+ --(cbl->inCallback);
+
+ if (cbl->inCallback) return;
+
+ /* Was the entire list marked for deletion? */
+
+ if (cbl->deleted)
+ {
+ DeleteCallbackList(pcbl);
+ return;
+ }
+
+ /* Were some individual callbacks on the list marked for deletion?
+ * If so, do the deletions.
+ */
+
+ if (cbl->numDeleted)
+ {
+ for (pcbr = NULL, cbr = cbl->list; (cbr != NULL) && cbl->numDeleted; )
+ {
+ if (cbr->deleted)
+ {
+ if (pcbr)
+ {
+ cbr = cbr->next;
+ free(pcbr->next);
+ pcbr->next = cbr;
+ } else
+ {
+ cbr = cbr->next;
+ free(cbl->list);
+ cbl->list = cbr;
+ }
+ cbl->numDeleted--;
+ }
+ else /* this one wasn't deleted */
+ {
+ pcbr = cbr;
+ cbr = cbr->next;
+ }
+ }
+ }
+}
+
+static void
+_DeleteCallbackList(
+ CallbackListPtr *pcbl)
+{
+ CallbackListPtr cbl = *pcbl;
+ CallbackPtr cbr, nextcbr;
+ int i;
+
+ if (cbl->inCallback)
+ {
+ cbl->deleted = TRUE;
+ return;
+ }
+
+ for (i = 0; i < numCallbackListsToCleanup; i++)
+ {
+ if (listsToCleanup[i] == pcbl)
+ {
+ listsToCleanup[i] = NULL;
+ break;
+ }
+ }
+
+ for (cbr = cbl->list; cbr != NULL; cbr = nextcbr)
+ {
+ nextcbr = cbr->next;
+ free(cbr);
+ }
+ free(cbl);
+ *pcbl = NULL;
+}
+
+static Bool
+CreateCallbackList(CallbackListPtr *pcbl)
+{
+ CallbackListPtr cbl;
+ int i;
+
+ if (!pcbl) return FALSE;
+ cbl = malloc(sizeof(CallbackListRec));
+ if (!cbl) return FALSE;
+ cbl->inCallback = 0;
+ cbl->deleted = FALSE;
+ cbl->numDeleted = 0;
+ cbl->list = NULL;
+ *pcbl = cbl;
+
+ for (i = 0; i < numCallbackListsToCleanup; i++)
+ {
+ if (!listsToCleanup[i])
+ {
+ listsToCleanup[i] = pcbl;
+ return TRUE;
+ }
+ }
+
+ listsToCleanup = (CallbackListPtr **)xnfrealloc(listsToCleanup,
+ sizeof(CallbackListPtr *) * (numCallbackListsToCleanup+1));
+ listsToCleanup[numCallbackListsToCleanup] = pcbl;
+ numCallbackListsToCleanup++;
+ return TRUE;
+}
+
+/* ===== Public Procedures ===== */
+
+Bool
+AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
+{
+ if (!pcbl) return FALSE;
+ if (!*pcbl)
+ { /* list hasn't been created yet; go create it */
+ if (!CreateCallbackList(pcbl))
+ return FALSE;
+ }
+ return _AddCallback(pcbl, callback, data);
+}
+
+Bool
+DeleteCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
+{
+ if (!pcbl || !*pcbl) return FALSE;
+ return _DeleteCallback(pcbl, callback, data);
+}
+
+void
+CallCallbacks(CallbackListPtr *pcbl, pointer call_data)
+{
+ if (!pcbl || !*pcbl) return;
+ _CallCallbacks(pcbl, call_data);
+}
+
+void
+DeleteCallbackList(CallbackListPtr *pcbl)
+{
+ if (!pcbl || !*pcbl) return;
+ _DeleteCallbackList(pcbl);
+}
+
+void
+InitCallbackManager(void)
+{
+ int i;
+
+ for (i = 0; i < numCallbackListsToCleanup; i++)
+ {
+ DeleteCallbackList(listsToCleanup[i]);
+ }
+ free(listsToCleanup);
+
+ numCallbackListsToCleanup = 0;
+ listsToCleanup = NULL;
+}
diff --git a/dix/dixutils.c b/dix/dixutils.c
index 9ce63e2..c9075ec 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -520,237 +520,3 @@ ClientIsAsleep (ClientPtr client)
return TRUE;
return FALSE;
}
-
-/*
- * Generic Callback Manager
- */
-
-/* ===== Private Procedures ===== */
-
-static int numCallbackListsToCleanup = 0;
-static CallbackListPtr **listsToCleanup = NULL;
-
-static Bool
-_AddCallback(
- CallbackListPtr *pcbl,
- CallbackProcPtr callback,
- pointer data)
-{
- CallbackPtr cbr;
-
- cbr = malloc(sizeof(CallbackRec));
- if (!cbr)
- return FALSE;
- cbr->proc = callback;
- cbr->data = data;
- cbr->next = (*pcbl)->list;
- cbr->deleted = FALSE;
- (*pcbl)->list = cbr;
- return TRUE;
-}
-
-static Bool
-_DeleteCallback(
- CallbackListPtr *pcbl,
- CallbackProcPtr callback,
- pointer data)
-{
- CallbackListPtr cbl = *pcbl;
- CallbackPtr cbr, pcbr;
-
- for (pcbr = NULL, cbr = cbl->list;
- cbr != NULL;
- pcbr = cbr, cbr = cbr->next)
- {
- if ((cbr->proc == callback) && (cbr->data == data))
- break;
- }
- if (cbr != NULL)
- {
- if (cbl->inCallback)
- {
- ++(cbl->numDeleted);
- cbr->deleted = TRUE;
- }
- else
- {
- if (pcbr == NULL)
- cbl->list = cbr->next;
- else
- pcbr->next = cbr->next;
- free(cbr);
- }
- return TRUE;
- }
- return FALSE;
-}
-
-static void
-_CallCallbacks(
- CallbackListPtr *pcbl,
- pointer call_data)
-{
- CallbackListPtr cbl = *pcbl;
- CallbackPtr cbr, pcbr;
-
- ++(cbl->inCallback);
- for (cbr = cbl->list; cbr != NULL; cbr = cbr->next)
- {
- (*(cbr->proc)) (pcbl, cbr->data, call_data);
- }
- --(cbl->inCallback);
-
- if (cbl->inCallback) return;
-
- /* Was the entire list marked for deletion? */
-
- if (cbl->deleted)
- {
- DeleteCallbackList(pcbl);
- return;
- }
-
- /* Were some individual callbacks on the list marked for deletion?
- * If so, do the deletions.
- */
-
- if (cbl->numDeleted)
- {
- for (pcbr = NULL, cbr = cbl->list; (cbr != NULL) && cbl->numDeleted; )
- {
- if (cbr->deleted)
- {
- if (pcbr)
- {
- cbr = cbr->next;
- free(pcbr->next);
- pcbr->next = cbr;
- } else
- {
- cbr = cbr->next;
- free(cbl->list);
- cbl->list = cbr;
- }
- cbl->numDeleted--;
- }
- else /* this one wasn't deleted */
- {
- pcbr = cbr;
- cbr = cbr->next;
- }
- }
- }
-}
-
-static void
-_DeleteCallbackList(
- CallbackListPtr *pcbl)
-{
- CallbackListPtr cbl = *pcbl;
- CallbackPtr cbr, nextcbr;
- int i;
-
- if (cbl->inCallback)
- {
- cbl->deleted = TRUE;
- return;
- }
-
- for (i = 0; i < numCallbackListsToCleanup; i++)
- {
- if (listsToCleanup[i] == pcbl)
- {
- listsToCleanup[i] = NULL;
- break;
- }
- }
-
- for (cbr = cbl->list; cbr != NULL; cbr = nextcbr)
- {
- nextcbr = cbr->next;
- free(cbr);
- }
- free(cbl);
- *pcbl = NULL;
-}
-
-static Bool
-CreateCallbackList(CallbackListPtr *pcbl)
-{
- CallbackListPtr cbl;
- int i;
-
- if (!pcbl) return FALSE;
- cbl = malloc(sizeof(CallbackListRec));
- if (!cbl) return FALSE;
- cbl->inCallback = 0;
- cbl->deleted = FALSE;
- cbl->numDeleted = 0;
- cbl->list = NULL;
- *pcbl = cbl;
-
- for (i = 0; i < numCallbackListsToCleanup; i++)
- {
- if (!listsToCleanup[i])
- {
- listsToCleanup[i] = pcbl;
- return TRUE;
- }
- }
-
- listsToCleanup = (CallbackListPtr **)xnfrealloc(listsToCleanup,
- sizeof(CallbackListPtr *) * (numCallbackListsToCleanup+1));
- listsToCleanup[numCallbackListsToCleanup] = pcbl;
- numCallbackListsToCleanup++;
- return TRUE;
-}
-
-/* ===== Public Procedures ===== */
-
-Bool
-AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
-{
- if (!pcbl) return FALSE;
- if (!*pcbl)
- { /* list hasn't been created yet; go create it */
- if (!CreateCallbackList(pcbl))
- return FALSE;
- }
- return _AddCallback(pcbl, callback, data);
-}
-
-Bool
-DeleteCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
-{
- if (!pcbl || !*pcbl) return FALSE;
- return _DeleteCallback(pcbl, callback, data);
-}
-
-void
-CallCallbacks(CallbackListPtr *pcbl, pointer call_data)
-{
- if (!pcbl || !*pcbl) return;
- _CallCallbacks(pcbl, call_data);
-}
-
-void
-DeleteCallbackList(CallbackListPtr *pcbl)
-{
- if (!pcbl || !*pcbl) return;
- _DeleteCallbackList(pcbl);
-}
-
-void
-InitCallbackManager(void)
-{
- int i;
-
- for (i = 0; i < numCallbackListsToCleanup; i++)
- {
- DeleteCallbackList(listsToCleanup[i]);
- }
- free(listsToCleanup);
-
- numCallbackListsToCleanup = 0;
- listsToCleanup = NULL;
-}
--
1.7.0.4
More information about the xorg-devel
mailing list