mp_s_file.C 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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: mp_s_file.C /main/3 1995/10/23 11:54:43 rswiston $
  28. /*
  29. *
  30. * mp_s_file.cc
  31. *
  32. * Copyright (c) 1990 by Sun Microsystems, Inc.
  33. */
  34. #include <stdio.h>
  35. #include "mp_s_mp.h"
  36. #include "mp/mp_pattern.h"
  37. #include "mp_s_file.h"
  38. //
  39. // Use parent class (_Tt_file) for construction and destruction.
  40. //
  41. _Tt_s_file::_Tt_s_file()
  42. {
  43. }
  44. _Tt_s_file::_Tt_s_file(
  45. const _Tt_string &path
  46. )
  47. {
  48. networkPath = path;
  49. }
  50. _Tt_s_file::~_Tt_s_file()
  51. {
  52. }
  53. Tt_status
  54. _Tt_s_file::s_join(
  55. _Tt_s_procid_ptr &p
  56. )
  57. {
  58. _Tt_pattern_list_cursor pats(p->patterns());
  59. int scopes;
  60. int fpatterns_found = 0;
  61. while (pats.next()) {
  62. scopes = pats->scopes();
  63. if (scopes&(1<<TT_FILE)) {
  64. fpatterns_found = 1;
  65. }
  66. if (scopes&(1<<TT_FILE) ||
  67. scopes&(1<<TT_FILE_IN_SESSION)) {
  68. pats->add_file(networkPath);
  69. _tt_s_mp->mod_file_scope(networkPath, 1);
  70. }
  71. }
  72. if (fpatterns_found) {
  73. p->add_joined_file(networkPath);
  74. }
  75. // note: TT_WRN_NOTFOUND is returned if there are no
  76. // TT_FILE patterns that were updated. This is just an
  77. // indication to the client side that it doesn't need
  78. // to update the database. If patterns were found and
  79. // this is the first procid in the session to join
  80. // this file then TT_WRN_STALE_OBJID is returned
  81. // telling the client side to update the database.
  82. return((fpatterns_found) ?
  83. ((procs_joined() == 1) ? TT_WRN_STALE_OBJID : TT_OK)
  84. : TT_WRN_NOTFOUND);
  85. }
  86. Tt_status
  87. _Tt_s_file::s_quit(
  88. _Tt_s_procid_ptr &p
  89. )
  90. {
  91. _Tt_pattern_list_cursor pats(p->patterns());
  92. int scopes;
  93. int fpatterns_found = 0;
  94. while (pats.next()) {
  95. scopes = pats->scopes();
  96. if (scopes&(1<<TT_FILE)) {
  97. fpatterns_found = 1;
  98. }
  99. if (scopes&(1<<TT_FILE) ||
  100. scopes&(1<<TT_FILE_IN_SESSION)) {
  101. pats->del_file(networkPath);
  102. _tt_s_mp->mod_file_scope(networkPath, 0);
  103. }
  104. }
  105. if (fpatterns_found) {
  106. p->del_joined_file(networkPath);
  107. } else {
  108. return TT_WRN_NOTFOUND;
  109. }
  110. if (_tt_s_mp->in_file_scope(networkPath)) {
  111. return TT_OK;
  112. } else {
  113. // Tells _Tt_c_file::c_quit() to delete this session from file
  114. return TT_WRN_STALE_OBJID;
  115. }
  116. }
  117. int
  118. _Tt_s_file::procs_joined()
  119. {
  120. _Tt_s_procid_table_cursor procs(_tt_s_mp->active_procs);
  121. int nprocs = 0;
  122. while (procs.next()) {
  123. if (procs->joined_to_file(networkPath)) {
  124. nprocs++;
  125. }
  126. }
  127. return(nprocs);
  128. }