repl5_replsupplier.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* repl5_replsupplier.c */
  42. /*
  43. A replsupplier is an object that knows how to manage outbound replication
  44. for one consumer.
  45. Methods:
  46. init()
  47. configure()
  48. start()
  49. stop()
  50. destroy()
  51. status()
  52. notify()
  53. */
  54. #include "slapi-plugin.h"
  55. #include "repl5.h"
  56. typedef struct repl_supplier {
  57. PRUint32 client_change_count; /* # of client-supplied changes */
  58. PRUint32 repl_change_count; /* # of replication updates */
  59. PRLock *lock;
  60. } repl_supplier;
  61. static void repl_supplier_free(Repl_Supplier **rsp);
  62. /*
  63. * Create and initialize this replsupplier object.
  64. */
  65. Repl_Supplier *
  66. replsupplier_init(Slapi_Entry *e)
  67. {
  68. Repl_Supplier *rs;
  69. if ((rs = (Repl_Supplier *)slapi_ch_malloc(sizeof(Repl_Supplier))) == NULL)
  70. {
  71. goto loser;
  72. }
  73. if ((rs->lock = PR_NewLock()) == NULL)
  74. {
  75. goto loser;
  76. }
  77. return rs;
  78. loser:
  79. repl_supplier_free(&rs);
  80. return NULL;
  81. }
  82. static void
  83. repl_supplier_free(Repl_Supplier **rsp)
  84. {
  85. if (NULL != rsp)
  86. {
  87. Repl_Supplier *rs = *rsp;
  88. if (NULL != rs)
  89. {
  90. if (NULL != rs->lock)
  91. {
  92. PR_DestroyLock(rs->lock);
  93. rs->lock = NULL;
  94. }
  95. slapi_ch_free((void **)rsp);
  96. }
  97. }
  98. }
  99. /*
  100. * Configure a repl_supplier object.
  101. */
  102. void
  103. replsupplier_configure(Repl_Supplier *rs, Slapi_PBlock *pb)
  104. {
  105. PR_ASSERT(NULL != rs);
  106. }
  107. /*
  108. * Start a repl_supplier object. This means that it's ok for
  109. * the repl_supplier to begin normal replication duties. It does
  110. * not necessarily mean that a replication session will occur
  111. * immediately.
  112. */
  113. void
  114. replsupplier_start(Repl_Supplier *rs)
  115. {
  116. PR_ASSERT(NULL != rs);
  117. }
  118. /*
  119. * Stop a repl_supplier object. This causes any active replication
  120. * sessions to be stopped ASAP, and puts the repl_supplier into a
  121. * stopped state. No additional replication activity will occur
  122. * until the replsupplier_start() function is called.
  123. */
  124. void
  125. replsupplier_stop(Repl_Supplier *rs)
  126. {
  127. PR_ASSERT(NULL != rs);
  128. }
  129. /*
  130. * Destroy a repl_supplier object. The object will be stopped, if it
  131. * is not already stopped.
  132. */
  133. void
  134. replsupplier_destroy(Repl_Supplier **rsp)
  135. {
  136. Repl_Supplier *rs;
  137. PR_ASSERT(NULL != rsp && NULL != *rsp);
  138. rs = *rsp;
  139. slapi_ch_free((void **)rsp);
  140. }
  141. /*
  142. * This method should be called by the repl_bos whenever it determines
  143. * that a change to the replicated area serviced by this repl_supplier
  144. * has occurred. This gives the repl_supplier a chance to implement a
  145. * scheduling policy.
  146. */
  147. void
  148. replsupplier_notify(Repl_Supplier *rs, PRUint32 eventmask)
  149. {
  150. PR_ASSERT(NULL != rs);
  151. }
  152. /*
  153. * This method is used to obtain the status of this particular
  154. * repl_supplier object. Eventually it will return some object containing
  155. * status information. For now, it's just a placeholder function.
  156. */
  157. PRUint32
  158. replsupplier_get_status(Repl_Supplier *rs)
  159. {
  160. PR_ASSERT(NULL != rs);
  161. return 0;
  162. }