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 libraries 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, 0, 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, 0, 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 /*-----------------------------------------------------------------------+*/
138 /*-----------------------------------------------------------------------+*/
140 break_on_termination=TRUE;
143 spc_xe_termination_flag= FALSE;
145 /* Use a function pointer so we don't have explict dependancy */
147 /* ---------------------------------------------------------- */
148 if (SbMainLoopUntil_hookfn == NULL)
149 (void) fprintf (stderr, "Error: SbMainLoopUntil = NULL\n");
151 (*SbMainLoopUntil_hookfn)(&spc_xe_termination_flag);
152 _DtSvcProcessUnlock();
154 break_on_termination=FALSE;
159 /*-----------------------------------------------------------------------+*/
160 int SPC_Wait_For_Termination(SPC_Channel_Ptr channel)
161 /*-----------------------------------------------------------------------+*/
165 call_parent_method(channel, wait_for_termination, (channel), result);
167 if(result==SPC_ERROR) return(SPC_ERROR);
171 if(SPC_Select() == SPC_ERROR)
174 } while(IS_ACTIVE(channel));
181 /*-----------------------------------------------------------------------+*/
182 void SPC_XtBreak(void)
183 /*-----------------------------------------------------------------------+*/
186 if(!spc_xe_termination_flag) {
187 spc_xe_termination_flag = TRUE;
188 if (SbBreakMainLoop_hookfn == NULL)
189 (void) fprintf (stderr, "Error: SbBreakMainLoop = NULL\n");
191 (*SbBreakMainLoop_hookfn)();
193 _DtSvcProcessUnlock();
198 /*-----------------------------------------------------------------------+*/
199 void SPC_XtAddInput(SPC_Channel_Ptr channel,
202 spc_handler_func_type handler,
203 SPC_Callback_Condition condition)
204 /*-----------------------------------------------------------------------+*/
213 /* fprintf(stderr, "SPC add input/terminator for %d\n", fd); */
214 if (SbAddInput_hookfn == NULL)
215 (void) fprintf (stderr, "Error: SbAddInput = NULL\n");
217 id = (*SbAddInput_hookfn)(fd, handler, channel);
221 /* fprintf(stderr, "SPC add exception for %d\n", fd); */
222 if (SbAddException_hookfn == NULL)
223 (void) fprintf (stderr, "Error: SbAddException = NULL\n");
225 id = (*SbAddException_hookfn)(fd, handler, channel);
230 *id_addr=SPC_AddInput(fd, condition, id);
234 /*-----------------------------------------------------------------------+*/
235 void SPC_XtRemoveInput(int *id_addr,
236 SPC_Callback_Condition condition)
237 /*-----------------------------------------------------------------------+*/
239 if((*id_addr) != -1) {
246 /* fprintf(stderr, "SPC remove input/terminator\n"); */
247 if (SbRemoveInput_hookfn == NULL)
248 (void) fprintf (stderr, "Error: SbRemoveInput = NULL\n");
250 (*SbRemoveInput_hookfn)(SPC_RemoveInput(*id_addr, condition));
254 /* fprintf(stderr, "SPC remove exception"); */
255 if (SbRemoveException_hookfn == NULL)
256 (void) fprintf (stderr, "Error: SbRemoveException = NULL\n");
258 (*SbRemoveException_hookfn)(SPC_RemoveInput(*id_addr, condition));