2
0

xtclient.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include "xtclient.h"
  36. typedef struct _appctlist {
  37. XtAppContext appct;
  38. struct _appctlist *next;
  39. } AppCtList;
  40. static AppCtList *registered_appct = NULL;
  41. /*****************************************************************************
  42. * forward declaration of static functions
  43. *****************************************************************************/
  44. static void xtcallback(XtPointer data, int *fid, XtInputId *id);
  45. static boolean_t new_appct(XtAppContext apptct);
  46. /*****************************************************************************
  47. * extern functions used in the library
  48. *****************************************************************************/
  49. /*
  50. * register callback for all file descriptors that's set
  51. * (since we don't know which one is ours).
  52. */
  53. void
  54. _DtCm_register_xtcallback(XtAppContext appct)
  55. {
  56. XtInputId id;
  57. int i;
  58. fd_set fdset = svc_fdset;
  59. DP(("xtclient.c: _DtCm_register_xtcallback()\n"));
  60. if (new_appct(appct) == B_FALSE)
  61. return;
  62. /* assuming only 1 bit is set */
  63. for (i = 0; i < FD_SETSIZE; i++) {
  64. if (FD_ISSET(i, &svc_fdset))
  65. {
  66. /* register callback with XtAppAddInput
  67. * for rpc input
  68. */
  69. id = XtAppAddInput(appct, i,
  70. (XtPointer)XtInputReadMask,
  71. xtcallback, NULL);
  72. DP(("xtclient.c: id %d for input at fd %d\n",
  73. id, i));
  74. }
  75. }
  76. }
  77. /*****************************************************************************
  78. * static functions used within the file
  79. *****************************************************************************/
  80. /*
  81. * callback for rpc events
  82. */
  83. static void
  84. xtcallback(XtPointer data, int *fid, XtInputId *id)
  85. {
  86. fd_set rpc_bits;
  87. DP(("xtcallback called\n"));
  88. FD_ZERO(&rpc_bits);
  89. FD_SET(*fid, &rpc_bits);
  90. svc_getreqset(&rpc_bits);
  91. }
  92. /*
  93. * need to lock registered_appct
  94. */
  95. static boolean_t
  96. new_appct(XtAppContext appct)
  97. {
  98. AppCtList *lptr;
  99. boolean_t newappct = B_TRUE;
  100. for (lptr = registered_appct; lptr != NULL; lptr = lptr->next) {
  101. if (lptr->appct == appct) {
  102. newappct = B_FALSE;
  103. break;
  104. }
  105. }
  106. if (newappct == B_TRUE) {
  107. lptr = (AppCtList *)calloc(1, sizeof(AppCtList));
  108. lptr->appct = appct;
  109. lptr->next = registered_appct;
  110. registered_appct = lptr;
  111. }
  112. return (newappct);
  113. }