rmd.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef OPENAIS_RMD_H_DEFINED
  35. #define OPENAIS_RMD_H_DEFINED
  36. #include <netinet/in.h>
  37. typedef unsigned int rmd_handle_t;
  38. typedef enum {
  39. RMD_DISPATCH_ONE,
  40. RMD_DISPATCH_ALL,
  41. RMD_DISPATCH_BLOCKING
  42. } rmd_dispatch_t;
  43. typedef enum {
  44. RMD_OK = 1,
  45. RMD_ERR_LIBRARY = 2,
  46. RMD_ERR_TIMEOUT = 5,
  47. RMD_ERR_TRY_AGAIN = 6,
  48. RMD_ERR_INVALID_PARAM = 7,
  49. RMD_ERR_NO_MEMORY = 8,
  50. RMD_ERR_BAD_HANDLE = 9,
  51. RMD_ERR_ACCESS = 11,
  52. RMD_ERR_NOT_EXIST = 12,
  53. RMD_ERR_EXIST = 14,
  54. RMD_ERR_TOOBIG = 31
  55. } rmd_error_t;
  56. /*
  57. * This callback occurs when a synchronized read is executed
  58. */
  59. typedef void (*rmd_read_synchronized_t) (
  60. rmd_invocation_t invocation,
  61. void *key, void key_len,
  62. void *data_conents, int data_len, int data_start);
  63. /*
  64. * This callback occurs when a commit is completed after
  65. * an rmd_commit_async call
  66. */
  67. typedef void (*rmd_commit_async_t) (
  68. rmd_invocation_t invocation,
  69. rmd_error_t error);
  70. typedef struct {
  71. rmd_read_synchronized_t rmd_read_synchronized;
  72. rmd_commit_async_t rmd_commit_async;
  73. } rmd_callbacks_t;
  74. /*
  75. * Create a new replicated memory database connection
  76. */
  77. rmd_error_t rmd_initialize (
  78. rmd_handle_t *handle,
  79. rmd_callbacks_t *callbacks);
  80. /*
  81. * Close a replicated memory database connection
  82. */
  83. rmd_error_t rmd_finalize (
  84. rmd_handle_t *handle);
  85. /*
  86. * Get a file descriptor on which to poll. rmd_handle_t is NOT a
  87. * file descriptor and may not be used directly.
  88. */
  89. rmd_error_t rmd_fd_get (
  90. rmd_handle_t *handle,
  91. int *fd);
  92. /*
  93. * Dispatch synchronized reads and async commitments
  94. */
  95. rmd_error_t rmd_dispatch (
  96. rmd_handle_t *handle,
  97. rmd_dispatch_t dispatch_types);
  98. /*
  99. * Abort all updates in the currently outstanding transaction
  100. */
  101. rmd_error_t rmd_abort (
  102. rmd_handle_t *handle);
  103. /*
  104. * Commit all updates for the transaction to the cluster. Commit
  105. * blocks until committed data is replicated to all processors.
  106. */
  107. rmd_error_t rmd_commit (
  108. rmd_handle_t *handle);
  109. /*
  110. * Commit all updates for the transaction to the cluster. Call returns
  111. * immediately and response of commitment complete (or error) comes in
  112. * callback
  113. */
  114. rmd_error_t rmd_commit_async (
  115. rmd_handle_t *handle,
  116. rmd_handle_t *invocation);
  117. /*
  118. * Read the value for a key without synchronizing within the
  119. * transaction. This offers optimal performance. If rmd_commit has not
  120. * been called for write operations, rmd_read will only return committed
  121. * data.
  122. */
  123. rmd_error_t rmd_read (
  124. rmd_handle_t *handle,
  125. void *key_name, int key_len,
  126. void *data_contents, int data_contents_size, int data_start,
  127. int *data_len);
  128. /*
  129. * Write a key/value pair to the cluster, but only when the trasaction
  130. * is commited with rmd_commit. If key/value * doesn't exist create it.
  131. */
  132. rmd_error_t rmd_write (
  133. rmd_handle_t *handle,
  134. void *key_name, int key_len,
  135. void *data_contents, int data_len, int data_start);
  136. /*
  137. * Read the value for a key and synchronize the read within the
  138. * transaction. The read data is deliver by callback. Callbacks
  139. * are uniquely identified by invocation which is set by the API.
  140. */
  141. rmd_error_t rmd_read_synchronized (
  142. rmd_handle_t *handle,
  143. rmd_invocation_t *invocation,
  144. void *key_name, int key_len,
  145. void *data_contents, int data_contents_size, int data_start,
  146. int *data_len);
  147. /*
  148. * Delete a key and value pair. Operation occurs immediately.
  149. */
  150. rmd_error_t rmd_delete (
  151. rmd_handle_t *handle,
  152. void *key_name, int key_len);
  153. #endif /* OPENAIS_RMD_H_DEFINED */