2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * File: spc-xt.c $TOG: spc-xt.c /main/6 1998/03/16 14:41:02 mgreess $
27 * (c) Copyright 1989, Hewlett-Packard Company, all rights reserved.
29 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
30 * (c) Copyright 1993, 1994 International Business Machines Corp. *
31 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
32 * (c) Copyright 1993, 1994 Novell, Inc. *
37 #include <bms/sbport.h> /* NOTE: sbport.h must be the first include. */
40 /* #include <bms/SbEvent.h> */ /* This file now included by spcP.h */
41 #include "DtSvcLock.h"
45 extern int break_on_termination;
47 /* Utility functions */
49 /* First, declarations */
54 } SPC_Callback_Struct;
56 static SPC_Callback_Struct **SPC_Fd_Mapping = NULL;
58 #define SPC_LOOKUP_FD_MAPPING(fd) SPC_Fd_Mapping[(fd)]
60 static Boolean spc_xe_termination_flag;
62 /*-----------------------------------------------------------------------+*/
63 static int SPC_AddInput(int source,
64 SPC_Callback_Condition condition,
66 /*-----------------------------------------------------------------------+*/
68 SPC_Callback_Struct *structptr = NULL;
71 if (SPC_Fd_Mapping == NULL) {
72 SPC_Fd_Mapping = (SPC_Callback_Struct **)
73 XeMalloc (FD_SETSIZE * sizeof (SPC_Callback_Struct *));
74 memset(SPC_Fd_Mapping, NULL, FD_SETSIZE * sizeof(SPC_Callback_Struct *));
76 structptr=SPC_LOOKUP_FD_MAPPING(source);
79 structptr=(SPC_Callback_Struct *) XeMalloc(sizeof(SPC_Callback_Struct));
80 SPC_LOOKUP_FD_MAPPING(source)=structptr;
82 _DtSvcProcessUnlock();
89 structptr->read_id = id;
93 structptr->except_id = id;
104 /*-----------------------------------------------------------------------+*/
105 static SbInputId SPC_RemoveInput(int source,
106 SPC_Callback_Condition condition)
107 /*-----------------------------------------------------------------------+*/
109 SPC_Callback_Struct *structptr = NULL;
112 if (SPC_Fd_Mapping == NULL) {
113 SPC_Fd_Mapping = (SPC_Callback_Struct **)
114 XeMalloc (FD_SETSIZE * sizeof (SPC_Callback_Struct *));
115 memset(SPC_Fd_Mapping, NULL, FD_SETSIZE * sizeof(SPC_Callback_Struct *));
117 structptr=SPC_LOOKUP_FD_MAPPING(source);
118 _DtSvcProcessUnlock();
125 return structptr->read_id;
128 return structptr->except_id;
135 /*-----------------------------------------------------------------------+*/
136 static SPC_Select(void )
137 /*-----------------------------------------------------------------------+*/
139 break_on_termination=TRUE;
142 spc_xe_termination_flag= FALSE;
144 /* Use a function pointer so we don't have explict dependancy */
146 /* ---------------------------------------------------------- */
147 if (SbMainLoopUntil_hookfn == NULL)
148 (void) fprintf (stderr, "Error: SbMainLoopUntil = NULL\n");
150 (*SbMainLoopUntil_hookfn)(&spc_xe_termination_flag);
151 _DtSvcProcessUnlock();
153 break_on_termination=FALSE;
158 /*-----------------------------------------------------------------------+*/
159 int SPC_Wait_For_Termination(SPC_Channel_Ptr channel)
160 /*-----------------------------------------------------------------------+*/
164 call_parent_method(channel, wait_for_termination, (channel), result);
166 if(result==SPC_ERROR) return(SPC_ERROR);
170 if(SPC_Select() == SPC_ERROR)
173 } while(IS_ACTIVE(channel));
180 /*-----------------------------------------------------------------------+*/
181 void SPC_XtBreak(void)
182 /*-----------------------------------------------------------------------+*/
185 if(!spc_xe_termination_flag) {
186 spc_xe_termination_flag = TRUE;
187 if (SbBreakMainLoop_hookfn == NULL)
188 (void) fprintf (stderr, "Error: SbBreakMainLoop = NULL\n");
190 (*SbBreakMainLoop_hookfn)();
192 _DtSvcProcessUnlock();
197 /*-----------------------------------------------------------------------+*/
198 void SPC_XtAddInput(SPC_Channel_Ptr channel,
201 spc_handler_func_type handler,
202 SPC_Callback_Condition condition)
203 /*-----------------------------------------------------------------------+*/
212 /* fprintf(stderr, "SPC add input/terminator for %d\n", fd); */
213 if (SbAddInput_hookfn == NULL)
214 (void) fprintf (stderr, "Error: SbAddInput = NULL\n");
216 id = (*SbAddInput_hookfn)(fd, handler, channel);
220 /* fprintf(stderr, "SPC add exception for %d\n", fd); */
221 if (SbAddException_hookfn == NULL)
222 (void) fprintf (stderr, "Error: SbAddException = NULL\n");
224 id = (*SbAddException_hookfn)(fd, handler, channel);
229 *id_addr=SPC_AddInput(fd, condition, id);
233 /*-----------------------------------------------------------------------+*/
234 void SPC_XtRemoveInput(int *id_addr,
235 SPC_Callback_Condition condition)
236 /*-----------------------------------------------------------------------+*/
238 if((*id_addr) != -1) {
245 /* fprintf(stderr, "SPC remove input/terminator\n"); */
246 if (SbRemoveInput_hookfn == NULL)
247 (void) fprintf (stderr, "Error: SbRemoveInput = NULL\n");
249 (*SbRemoveInput_hookfn)(SPC_RemoveInput(*id_addr, condition));
253 /* fprintf(stderr, "SPC remove exception"); */
254 if (SbRemoveException_hookfn == NULL)
255 (void) fprintf (stderr, "Error: SbRemoveException = NULL\n");
257 (*SbRemoveException_hookfn)(SPC_RemoveInput(*id_addr, condition));