CoEd.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
  24. /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
  25. /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  26. /*%% (c) Copyright 1993, 1994 Novell, Inc. */
  27. /*%% $XConsortium: CoEd.h /main/3 1995/10/20 17:06:02 rswiston $ */
  28. /* -*-C++-*-
  29. *
  30. * CoEd.h
  31. *
  32. * Copyright (c) 1991,1993 by Sun Microsystems. All Rights Reserved.
  33. *
  34. * Permission to use, copy, modify, distribute, and sell this software
  35. * and its documentation for any purpose is hereby granted without
  36. * fee, provided that the above copyright notice appear in all copies
  37. * and that both that copyright notice and this permission notice
  38. * appear in supporting documentation, and that the names of Sun
  39. * Microsystems and its subsidiaries not be used in advertising or
  40. * publicity pertaining to distribution of the software without
  41. * specific, written prior permission. Sun Microsystems and its
  42. * subsidiaries make no representations about the suitability of this
  43. * software for any purpose. It is provided "as is" without express
  44. * or implied warranty.
  45. *
  46. * Sun Microsystems and its subsidiaries disclaim all warranties with
  47. * regard to this software, including all implied warranties of
  48. * merchantability and fitness. In no event shall Sun Microsystems or
  49. * its subsidiaries be liable for any special, indirect or
  50. * consequential damages or any damages whatsoever resulting from loss
  51. * of use, data or profits, whether in an action of contract,
  52. * negligence or other tortious action, arising out of or in
  53. * connection with the use or performance of this software.
  54. */
  55. #ifndef CoEd_h
  56. #define CoEd_h
  57. #include <desktop/tt_c.h>
  58. typedef enum {
  59. CoEdOK = TT_OK,
  60. CoEdWarnTimeout = TT_WRN_APPFIRST, // 512
  61. CoEdErrFile = TT_ERR_APPFIRST, // 1536
  62. CoEdErrNoMem,
  63. CoEdErrBadPointer,
  64. CoEdErrXDR,
  65. CoEdErrBadMsg,
  66. CoEdErrFailure
  67. } CoEdStatus;
  68. #ifdef InLibCoEd
  69. //
  70. // CoEdTextBuffer is a class that clients of libCoEd implement.
  71. // libCoEd invokes appropriate CoEdTextBuffer methods when it detects
  72. // operations on the CoEdTextBuffer's associated text file.
  73. //
  74. class CoEdTextBuffer {
  75. public:
  76. CoEdStatus insertText( long start, long end, const char *text );
  77. CoEdStatus save();
  78. CoEdStatus revert();
  79. CoEdStatus rename( const char *newPath );
  80. };
  81. #else
  82. class CoEdTextBuffer;
  83. #endif InLibCoEd
  84. class CoEdTextVersion;
  85. class CoEdChangeHistory;
  86. class CoEdChangeQueue;
  87. class CoEdTextChange;
  88. class CoEdSiteIDList;
  89. //
  90. // CoEdFile is the class that libCoEd implements for its clients.
  91. // Clients invoke appropriate CoEdFile methods after they have
  92. // performed the corresponding user operation on the file.
  93. //
  94. class CoEdFile {
  95. friend class CoEdFileList;
  96. public:
  97. CoEdFile( const char *path, CoEdTextBuffer *textBuf,
  98. CoEdStatus &status, int timeOutSec = 0 );
  99. ~CoEdFile();
  100. CoEdStatus insertText( long start, long end, const char *text );
  101. CoEdStatus save();
  102. CoEdStatus revert();
  103. CoEdStatus rename( const char *newPath );
  104. private:
  105. char *_path;
  106. CoEdTextBuffer *_textBuf;
  107. CoEdTextVersion *_version;
  108. CoEdTextVersion *_versionInQ;
  109. CoEdSiteIDList *_coEditors;
  110. CoEdChangeHistory *_appliedChanges;
  111. CoEdChangeQueue *_unAppliedChanges;
  112. int _numLocalChanges;
  113. int _joining;
  114. CoEdFile *_next;
  115. CoEdFile *_prev;
  116. CoEdStatus _handleMsg( Tt_message msg );
  117. CoEdStatus _handleRequest( Tt_message msg );
  118. CoEdStatus _handleJoin( Tt_message msg );
  119. CoEdStatus _handleVersionVote( Tt_message msg );
  120. CoEdStatus _handleNotice( Tt_message msg );
  121. CoEdStatus _handleChanged( Tt_message msg );
  122. CoEdStatus _handlePollVersion( Tt_message msg );
  123. CoEdStatus _handleChange( CoEdTextChange *change,
  124. int changeIsFromQueue = 0 );
  125. };
  126. CoEdStatus coEdInit( char* &returnProcID, int &pFd2Watch );
  127. CoEdStatus coEdFini();
  128. CoEdStatus coEdHandleActiveFD( int fd );
  129. const char *coEdStatusMessage( CoEdStatus status );
  130. #endif CoEd_h