SvcTT.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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: SvcTT.c /main/3 1995/10/26 15:30:18 rswiston $ */
  24. /*%% */
  25. /*%% RESTRICTED CONFIDENTIAL INFORMATION: */
  26. /*%% */
  27. /*%% The information in this document is subject to special */
  28. /*%% restrictions in a confidential disclosure agreement between */
  29. /*%% HP, IBM, Sun, USL, SCO and Univel. Do not distribute this */
  30. /*%% document outside HP, IBM, Sun, USL, SCO, or Univel without */
  31. /*%% Sun's specific written approval. This document and all copies */
  32. /*%% and derivative works thereof must be returned or destroyed at */
  33. /*%% Sun's request. */
  34. /*%% */
  35. /* (c) Copyright 1993, 1994 Hewlett-Packard Company */
  36. /* (c) Copyright 1993, 1994 International Business Machines Corp. */
  37. /* (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  38. /* (c) Copyright 1993, 1994 Novell, Inc. */
  39. /*%% */
  40. #include <sys/time.h>
  41. #include <Dt/SvcTT.h>
  42. /*
  43. * Ensure that there is a valid ToolTalk connection open.
  44. * If none is open, creates one and adds it to the XtAppContext
  45. * of widget. Returns
  46. * TT_OK Success.
  47. * TT_ERR_NOMP ToolTalk could not be initialized.
  48. * TT_ERR_POINTER widget was null.
  49. */
  50. Tt_status
  51. _DtSvcInitToolTalk(
  52. Widget widget
  53. )
  54. {
  55. char *procid;
  56. Tt_status status;
  57. int fd;
  58. XtAppContext ctxt;
  59. procid = tt_default_procid();
  60. status = tt_ptr_error( procid );
  61. if (status == TT_OK) {
  62. tt_free( procid );
  63. }
  64. if ((status == TT_ERR_NOMP) || (status == TT_ERR_PROCID)) {
  65. if (widget == 0) {
  66. return TT_ERR_POINTER;
  67. }
  68. procid = tt_open(); /* do not tt_free(); Xt will pass it back */
  69. status = tt_ptr_error( procid );
  70. if (status != TT_OK) {
  71. return status;
  72. }
  73. fd = tt_fd();
  74. status = tt_int_error( fd );
  75. if (status != TT_OK) {
  76. return status;
  77. }
  78. ctxt = XtWidgetToApplicationContext( widget );
  79. XtAppAddInput( ctxt, fd, (XtPointer)XtInputReadMask,
  80. tttk_Xt_input_handler, procid );
  81. }
  82. return TT_OK;
  83. }