2 * File: spc-xt.c $TOG: spc-xt.c /main/6 1998/03/16 14:41:02 mgreess $
5 * (c) Copyright 1989, Hewlett-Packard Company, all rights reserved.
7 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
8 * (c) Copyright 1993, 1994 International Business Machines Corp. *
9 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
10 * (c) Copyright 1993, 1994 Novell, Inc. *
15 #include <bms/sbport.h> /* NOTE: sbport.h must be the first include. */
18 /* #include <bms/SbEvent.h> */ /* This file now included by spcP.h */
19 #include "DtSvcLock.h"
23 extern int break_on_termination;
25 /* Utility functions */
27 /* First, declarations */
32 } SPC_Callback_Struct;
34 static SPC_Callback_Struct **SPC_Fd_Mapping = NULL;
36 #define SPC_LOOKUP_FD_MAPPING(fd) SPC_Fd_Mapping[(fd)]
38 static Boolean spc_xe_termination_flag;
40 /*-----------------------------------------------------------------------+*/
41 static int SPC_AddInput(int source,
42 SPC_Callback_Condition condition,
44 /*-----------------------------------------------------------------------+*/
46 SPC_Callback_Struct *structptr = NULL;
49 if (SPC_Fd_Mapping == NULL) {
50 SPC_Fd_Mapping = (SPC_Callback_Struct **)
51 XeMalloc (FD_SETSIZE * sizeof (SPC_Callback_Struct *));
52 memset(SPC_Fd_Mapping, NULL, FD_SETSIZE * sizeof(SPC_Callback_Struct *));
54 structptr=SPC_LOOKUP_FD_MAPPING(source);
57 structptr=(SPC_Callback_Struct *) XeMalloc(sizeof(SPC_Callback_Struct));
58 SPC_LOOKUP_FD_MAPPING(source)=structptr;
60 _DtSvcProcessUnlock();
67 structptr->read_id = id;
71 structptr->except_id = id;
82 /*-----------------------------------------------------------------------+*/
83 static SbInputId SPC_RemoveInput(int source,
84 SPC_Callback_Condition condition)
85 /*-----------------------------------------------------------------------+*/
87 SPC_Callback_Struct *structptr = NULL;
90 if (SPC_Fd_Mapping == NULL) {
91 SPC_Fd_Mapping = (SPC_Callback_Struct **)
92 XeMalloc (FD_SETSIZE * sizeof (SPC_Callback_Struct *));
93 memset(SPC_Fd_Mapping, NULL, FD_SETSIZE * sizeof(SPC_Callback_Struct *));
95 structptr=SPC_LOOKUP_FD_MAPPING(source);
96 _DtSvcProcessUnlock();
103 return structptr->read_id;
106 return structptr->except_id;
113 /*-----------------------------------------------------------------------+*/
114 static SPC_Select(void )
115 /*-----------------------------------------------------------------------+*/
117 break_on_termination=TRUE;
120 spc_xe_termination_flag= FALSE;
122 /* Use a function pointer so we don't have explict dependancy */
124 /* ---------------------------------------------------------- */
125 if (SbMainLoopUntil_hookfn == NULL)
126 (void) fprintf (stderr, "Error: SbMainLoopUntil = NULL\n");
128 (*SbMainLoopUntil_hookfn)(&spc_xe_termination_flag);
129 _DtSvcProcessUnlock();
131 break_on_termination=FALSE;
136 /*-----------------------------------------------------------------------+*/
137 int SPC_Wait_For_Termination(SPC_Channel_Ptr channel)
138 /*-----------------------------------------------------------------------+*/
142 call_parent_method(channel, wait_for_termination, (channel), result);
144 if(result==SPC_ERROR) return(SPC_ERROR);
148 if(SPC_Select() == SPC_ERROR)
151 } while(IS_ACTIVE(channel));
158 /*-----------------------------------------------------------------------+*/
159 void SPC_XtBreak(void)
160 /*-----------------------------------------------------------------------+*/
163 if(!spc_xe_termination_flag) {
164 spc_xe_termination_flag = TRUE;
165 if (SbBreakMainLoop_hookfn == NULL)
166 (void) fprintf (stderr, "Error: SbBreakMainLoop = NULL\n");
168 (*SbBreakMainLoop_hookfn)();
170 _DtSvcProcessUnlock();
175 /*-----------------------------------------------------------------------+*/
176 void SPC_XtAddInput(SPC_Channel_Ptr channel,
179 spc_handler_func_type handler,
180 SPC_Callback_Condition condition)
181 /*-----------------------------------------------------------------------+*/
190 /* fprintf(stderr, "SPC add input/terminator for %d\n", fd); */
191 if (SbAddInput_hookfn == NULL)
192 (void) fprintf (stderr, "Error: SbAddInput = NULL\n");
194 id = (*SbAddInput_hookfn)(fd, handler, channel);
198 /* fprintf(stderr, "SPC add exception for %d\n", fd); */
199 if (SbAddException_hookfn == NULL)
200 (void) fprintf (stderr, "Error: SbAddException = NULL\n");
202 id = (*SbAddException_hookfn)(fd, handler, channel);
207 *id_addr=SPC_AddInput(fd, condition, id);
211 /*-----------------------------------------------------------------------+*/
212 void SPC_XtRemoveInput(int *id_addr,
213 SPC_Callback_Condition condition)
214 /*-----------------------------------------------------------------------+*/
216 if((*id_addr) != -1) {
223 /* fprintf(stderr, "SPC remove input/terminator\n"); */
224 if (SbRemoveInput_hookfn == NULL)
225 (void) fprintf (stderr, "Error: SbRemoveInput = NULL\n");
227 (*SbRemoveInput_hookfn)(SPC_RemoveInput(*id_addr, condition));
231 /* fprintf(stderr, "SPC remove exception"); */
232 if (SbRemoveException_hookfn == NULL)
233 (void) fprintf (stderr, "Error: SbRemoveException = NULL\n");
235 (*SbRemoveException_hookfn)(SPC_RemoveInput(*id_addr, condition));