/* * CDE - Common Desktop Environment * * Copyright (c) 1993-2012, The Open Group. All rights reserved. * * These libraries and programs are free software; you can * redistribute them and/or modify them under the terms of the GNU * Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * These libraries and programs are distributed in the hope that * they will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public * License along with these librararies and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ /* * File: spcd_event.c $XConsortium: spcd_event.c /main/4 1996/01/15 13:49:32 rswiston $ * Language: C * * (c) Copyright 1988, Hewlett-Packard Company, all rights reserved. * * (c) Copyright 1993, 1994 Hewlett-Packard Company * * (c) Copyright 1993, 1994 International Business Machines Corp. * * (c) Copyright 1993, 1994 Sun Microsystems, Inc. * * (c) Copyright 1993, 1994 Novell, Inc. * */ #define __need_fd_set #include /* NOTE: sbport.h must be the first include. */ #include #include #include /* for fd_set, FD_SET macros, et. al. */ #include #ifndef __hpux # define FD_SET_CAST(x) (x) #else # define FD_SET_CAST(x) ((int *)(x)) #endif /* __hpux */ struct {SbInputCallbackProc handler; void* data; } SPCD_input_handlers [FD_SETSIZE], SPCD_except_handlers[FD_SETSIZE]; int SPCD_max_fd = 1; fd_set Sb_Input_Mask, Sb_Except_Mask; SbInputId SPCD_AddInput(int fd, SbInputCallbackProc proc, void* data) {SPCD_input_handlers[fd].handler = proc; SPCD_input_handlers[fd].data = data; FD_SET(fd, &Sb_Input_Mask); if (SPCD_max_fd < fd) SPCD_max_fd = fd; return fd; } SbInputId SPCD_AddException(int fd, SbInputCallbackProc proc, void* data) {SPCD_except_handlers[fd].handler = proc; SPCD_except_handlers[fd].data = data; FD_SET(fd, &Sb_Except_Mask); if (SPCD_max_fd < fd) SPCD_max_fd = fd; return fd; } void SPCD_RemoveInput(SbInputId id) {FD_CLR(id, &Sb_Input_Mask); } void SPCD_RemoveException(SbInputId id) {FD_CLR(id, &Sb_Except_Mask); } void SPCD_MainLoopUntil(Boolean *flag) { int fd_vec_size = howmany(SPCD_max_fd, NFDBITS); fd_set input_mask, except_mask; int n, fd; int result; do { for (n=0; n