2
0

xtclient.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $XConsortium: xtclient.c /main/1 1996/04/21 19:24:58 drk $ */
  24. /*
  25. * (c) Copyright 1993, 1994 Hewlett-Packard Company
  26. * (c) Copyright 1993, 1994 International Business Machines Corp.
  27. * (c) Copyright 1993, 1994 Novell, Inc.
  28. * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  29. */
  30. #include <EUSCompat.h>
  31. #include <stdlib.h>
  32. #include <X11/Intrinsic.h>
  33. #include <rpc/rpc.h>
  34. #include "debug.h"
  35. typedef struct _appctlist {
  36. XtAppContext appct;
  37. struct _appctlist *next;
  38. } AppCtList;
  39. static AppCtList *registered_appct = NULL;
  40. /*****************************************************************************
  41. * forward declaration of static functions
  42. *****************************************************************************/
  43. static void xtcallback(XtPointer data, int *fid, XtInputId *id);
  44. static boolean_t new_appct(XtAppContext apptct);
  45. /*****************************************************************************
  46. * extern functions used in the library
  47. *****************************************************************************/
  48. /*
  49. * register callback for all file descriptors that's set
  50. * (since we don't know which one is ours).
  51. */
  52. extern void
  53. _DtCm_register_xtcallback(XtAppContext appct)
  54. {
  55. XtInputId id;
  56. int i;
  57. fd_set fdset = svc_fdset;
  58. DP(("xtclient.c: _DtCm_register_xtcallback()\n"));
  59. if (new_appct(appct) == B_FALSE)
  60. return;
  61. /* assuming only 1 bit is set */
  62. for (i = 0; i < FD_SETSIZE; i++) {
  63. if (FD_ISSET(i, &svc_fdset))
  64. {
  65. /* register callback with XtAppAddInput
  66. * for rpc input
  67. */
  68. id = XtAppAddInput(appct, i,
  69. (XtPointer)XtInputReadMask,
  70. xtcallback, NULL);
  71. DP(("xtclient.c: id %d for input at fd %d\n",
  72. id, i));
  73. }
  74. }
  75. }
  76. /*****************************************************************************
  77. * static functions used within the file
  78. *****************************************************************************/
  79. /*
  80. * callback for rpc events
  81. */
  82. static void
  83. xtcallback(XtPointer data, int *fid, XtInputId *id)
  84. {
  85. fd_set rpc_bits;
  86. DP(("xtcallback called\n"));
  87. FD_ZERO(&rpc_bits);
  88. FD_SET(*fid, &rpc_bits);
  89. svc_getreqset(&rpc_bits);
  90. }
  91. /*
  92. * need to lock registered_appct
  93. */
  94. static boolean_t
  95. new_appct(XtAppContext appct)
  96. {
  97. AppCtList *lptr;
  98. boolean_t newappct = B_TRUE;
  99. for (lptr = registered_appct; lptr != NULL; lptr = lptr->next) {
  100. if (lptr->appct == appct) {
  101. newappct = B_FALSE;
  102. break;
  103. }
  104. }
  105. if (newappct == B_TRUE) {
  106. lptr = (AppCtList *)calloc(1, sizeof(AppCtList));
  107. lptr->appct = appct;
  108. lptr->next = registered_appct;
  109. registered_appct = lptr;
  110. }
  111. return (newappct);
  112. }