PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/stable-1-0/openslp/common/slp_database.h

#
C++ Header | 216 lines | 32 code | 30 blank | 154 comment | 0 complexity | 365f81640ecf9ffacfc72b96d7e17624 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-2.1
  1. /***************************************************************************/
  2. /* */
  3. /* Project: OpenSLP - OpenSource implementation of Service Location */
  4. /* Protocol */
  5. /* */
  6. /* File: slp_database.h */
  7. /* */
  8. /* Abstract: An SLP message database. The SLP message database holds */
  9. /* actual SLP "wire" message buffers as well as structures */
  10. /* that interpret the message buffer. The database exposes */
  11. /* an interface suitable linked-list based implementation */
  12. /* */
  13. /*-------------------------------------------------------------------------*/
  14. /* */
  15. /* Please submit patches to http://www.openslp.org */
  16. /* */
  17. /*-------------------------------------------------------------------------*/
  18. /* */
  19. /* Copyright (C) 2000 Caldera Systems, Inc */
  20. /* All rights reserved. */
  21. /* */
  22. /* Redistribution and use in source and binary forms, with or without */
  23. /* modification, are permitted provided that the following conditions are */
  24. /* met: */
  25. /* */
  26. /* Redistributions of source code must retain the above copyright */
  27. /* notice, this list of conditions and the following disclaimer. */
  28. /* */
  29. /* Redistributions in binary form must reproduce the above copyright */
  30. /* notice, this list of conditions and the following disclaimer in */
  31. /* the documentation and/or other materials provided with the */
  32. /* distribution. */
  33. /* */
  34. /* Neither the name of Caldera Systems nor the names of its */
  35. /* contributors may be used to endorse or promote products derived */
  36. /* from this software without specific prior written permission. */
  37. /* */
  38. /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
  39. /* `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
  40. /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
  41. /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALDERA */
  42. /* SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
  43. /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
  44. /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
  45. /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
  46. /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  47. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
  48. /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  49. /* */
  50. /***************************************************************************/
  51. #ifndef SLP_DATABASE_H_INCLUDED
  52. #define SLP_DATABASE_H_INCLUDED
  53. #include "slp_message.h"
  54. #include "slp_buffer.h"
  55. #include "slp_linkedlist.h"
  56. /*=========================================================================*/
  57. typedef struct _SLPDatabaseEntry
  58. /*=========================================================================*/
  59. {
  60. SLPListItem listitem;
  61. SLPMessage msg;
  62. SLPBuffer buf;
  63. }SLPDatabaseEntry;
  64. /*=========================================================================*/
  65. typedef SLPList SLPDatabase;
  66. /*=========================================================================*/
  67. /*=========================================================================*/
  68. typedef struct _SLPDatabaseHandle
  69. /*=========================================================================*/
  70. {
  71. SLPDatabase* database;
  72. SLPDatabaseEntry* current;
  73. }* SLPDatabaseHandle;
  74. /*=========================================================================*/
  75. int SLPDatabaseInit(SLPDatabase* database);
  76. /* Initialize a SLPDatabase. */
  77. /* */
  78. /* Parameters: database (IN) pointer to the database to initialize */
  79. /* */
  80. /* */
  81. /* Returns: zero on success. Non-zero on error */
  82. /*=========================================================================*/
  83. /*=========================================================================*/
  84. void SLPDatabaseDeinit(SLPDatabase* database);
  85. /* Deinitialze a SLPDatabase */
  86. /* */
  87. /* Parameters: database (IN) pointer to the database to de-initialize */
  88. /* */
  89. /* Returns: none */
  90. /*=========================================================================*/
  91. /*=========================================================================*/
  92. SLPDatabaseEntry* SLPDatabaseEntryCreate(SLPMessage msg,
  93. SLPBuffer buf);
  94. /* Create a SLPDatabaseEntry. */
  95. /* */
  96. /* Parameters: msg (IN) The interpreting message structure for buf */
  97. /* buf (IN) The SLP message buffer */
  98. /* */
  99. /* Returns: Pointer to a new SLPDatabaseEntry. NULL if out of memory */
  100. /* */
  101. /* Note: VERY IMPORTANT. The msg and especially the buf are owned by the */
  102. /* returned SLPDatabaseEntry and MUST NOT be freed by the caller */
  103. /* via SLPMessageFree() or SLPBufferFree()! Instead, the caller */
  104. /* should use SLPDatabaseEntryDestroy() only to free memory */
  105. /*=========================================================================*/
  106. /*=========================================================================*/
  107. void SLPDatabaseEntryDestroy(SLPDatabaseEntry* entry);
  108. /* Free resources associated with the specified entry */
  109. /* */
  110. /* Parameters: entry (IN) pointer to the entry to destroy */
  111. /* */
  112. /* Returns: none */
  113. /*=========================================================================*/
  114. /*=========================================================================*/
  115. SLPDatabaseHandle SLPDatabaseOpen(SLPDatabase* database);
  116. /* Open a handle that is used with subsequent calls to SLPDatabaseEnum(), */
  117. /* SLPDatabaseAdd() and SLPDatabaseRemove() */
  118. /* */
  119. /* Parameters (IN) pointer an initialized SLPDatabase */
  120. /* */
  121. /* Returns: Valid handle. NULL on error. */
  122. /* */
  123. /* Note: It is important to make sure that handles returned by this */
  124. /* function are used and closed as quickly as possible. Future */
  125. /* may use handles to ensure syncronized access to the database */
  126. /* in threaded environments */
  127. /*=========================================================================*/
  128. /*=========================================================================*/
  129. SLPDatabaseEntry* SLPDatabaseEnum(SLPDatabaseHandle dh);
  130. /* Used to enumerate through entries of a SLPDatabase */
  131. /* */
  132. /* Parameters: dh (IN) A handle obtained via SLPDatabaseOpen() */
  133. /* */
  134. /* Returns: Pointer to a SLPDatabase entry or NULL if end of enumeration */
  135. /* has been reached. */
  136. /*=========================================================================*/
  137. /*=========================================================================*/
  138. void SLPDatabaseRewind(SLPDatabaseHandle dh);
  139. /* Reset handle so SLPDatabaseEnum starts at the beginning again */
  140. /* */
  141. /* Parameters: eh (IN) A handle obtained via SLPDatabaseOpen() */
  142. /* */
  143. /* Returns: None */
  144. /*=========================================================================*/
  145. /*=========================================================================*/
  146. void SLPDatabaseClose(SLPDatabaseHandle dh);
  147. /* Closes a handle obtained from SLPDatabaseOpen() */
  148. /* */
  149. /* Parameters: dh (IN) a handle obtained from SLPDatabaseOpenEnum() */
  150. /* */
  151. /* Returns: None */
  152. /*=========================================================================*/
  153. /*=========================================================================*/
  154. void SLPDatabaseRemove(SLPDatabaseHandle dh,
  155. SLPDatabaseEntry* entry);
  156. /* Removes the specified entry */
  157. /* */
  158. /* Parameters: dh (IN) The SLPDatabaseEnumHandle used to obtain */
  159. /* the entry in the first place */
  160. /* entry (IN) The entry to remove */
  161. /* */
  162. /* Returns: None */
  163. /* */
  164. /* Note: During removal SLPDatabaseEntryDestroy() is called on entry. */
  165. /* This means that you MUST NOT use entry after it is removed */
  166. /*=========================================================================*/
  167. /*=========================================================================*/
  168. void SLPDatabaseAdd(SLPDatabaseHandle dh,
  169. SLPDatabaseEntry* entry);
  170. /* Add the specified entry */
  171. /* */
  172. /* Parameters: dh (IN) handle obtained from SLPDatabseOpen() */
  173. /* entry (IN) the entry to add */
  174. /* */
  175. /* Return: None */
  176. /* */
  177. /* Note: DO NOT call SLPDatabaseEntryDestroy() on an entry that has been */
  178. /* added to the database. Instead call SLPDatabaseDeinit() or */
  179. /* SLPDatabaseRemove() to free resources associated with an added */
  180. /* entry */
  181. /*=========================================================================*/
  182. /*=========================================================================*/
  183. int SLPDatabaseCount(SLPDatabaseHandle dh);
  184. /* Returns the number of entries that are in the database */
  185. /*=========================================================================*/
  186. #endif