repl5_replsupplier.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. /* repl5_replsupplier.c */
  39. /*
  40. A replsupplier is an object that knows how to manage outbound replication
  41. for one consumer.
  42. Methods:
  43. init()
  44. configure()
  45. start()
  46. stop()
  47. destroy()
  48. status()
  49. notify()
  50. */
  51. #include "slapi-plugin.h"
  52. #include "repl5.h"
  53. typedef struct repl_supplier {
  54. PRUint32 client_change_count; /* # of client-supplied changes */
  55. PRUint32 repl_change_count; /* # of replication updates */
  56. PRLock *lock;
  57. } repl_supplier;
  58. static void repl_supplier_free(Repl_Supplier **rsp);
  59. /*
  60. * Create and initialize this replsupplier object.
  61. */
  62. Repl_Supplier *
  63. replsupplier_init(Slapi_Entry *e)
  64. {
  65. Repl_Supplier *rs;
  66. if ((rs = (Repl_Supplier *)slapi_ch_malloc(sizeof(Repl_Supplier))) == NULL)
  67. {
  68. goto loser;
  69. }
  70. if ((rs->lock = PR_NewLock()) == NULL)
  71. {
  72. goto loser;
  73. }
  74. return rs;
  75. loser:
  76. repl_supplier_free(&rs);
  77. return NULL;
  78. }
  79. static void
  80. repl_supplier_free(Repl_Supplier **rsp)
  81. {
  82. if (NULL != rsp)
  83. {
  84. Repl_Supplier *rs = *rsp;
  85. if (NULL != rs)
  86. {
  87. if (NULL != rs->lock)
  88. {
  89. PR_DestroyLock(rs->lock);
  90. rs->lock = NULL;
  91. }
  92. slapi_ch_free((void **)rsp);
  93. }
  94. }
  95. }
  96. /*
  97. * Configure a repl_supplier object.
  98. */
  99. void
  100. replsupplier_configure(Repl_Supplier *rs, Slapi_PBlock *pb)
  101. {
  102. PR_ASSERT(NULL != rs);
  103. }
  104. /*
  105. * Start a repl_supplier object. This means that it's ok for
  106. * the repl_supplier to begin normal replication duties. It does
  107. * not necessarily mean that a replication session will occur
  108. * immediately.
  109. */
  110. void
  111. replsupplier_start(Repl_Supplier *rs)
  112. {
  113. PR_ASSERT(NULL != rs);
  114. }
  115. /*
  116. * Stop a repl_supplier object. This causes any active replication
  117. * sessions to be stopped ASAP, and puts the repl_supplier into a
  118. * stopped state. No additional replication activity will occur
  119. * until the replsupplier_start() function is called.
  120. */
  121. void
  122. replsupplier_stop(Repl_Supplier *rs)
  123. {
  124. PR_ASSERT(NULL != rs);
  125. }
  126. /*
  127. * Destroy a repl_supplier object. The object will be stopped, if it
  128. * is not already stopped.
  129. */
  130. void
  131. replsupplier_destroy(Repl_Supplier **rsp)
  132. {
  133. Repl_Supplier *rs;
  134. PR_ASSERT(NULL != rsp && NULL != *rsp);
  135. rs = *rsp;
  136. slapi_ch_free((void **)rsp);
  137. }
  138. /*
  139. * This method should be called by the repl_bos whenever it determines
  140. * that a change to the replicated area serviced by this repl_supplier
  141. * has occurred. This gives the repl_supplier a chance to implement a
  142. * scheduling policy.
  143. */
  144. void
  145. replsupplier_notify(Repl_Supplier *rs, PRUint32 eventmask)
  146. {
  147. PR_ASSERT(NULL != rs);
  148. }
  149. /*
  150. * This method is used to obtain the status of this particular
  151. * repl_supplier object. Eventually it will return some object containing
  152. * status information. For now, it's just a placeholder function.
  153. */
  154. PRUint32
  155. replsupplier_get_status(Repl_Supplier *rs)
  156. {
  157. PR_ASSERT(NULL != rs);
  158. return 0;
  159. }