H5Zdevelop.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. * Copyright by The HDF Group. *
  3. * All rights reserved. *
  4. * *
  5. * This file is part of HDF5. The full HDF5 copyright notice, including *
  6. * terms governing use, modification, and redistribution, is contained in *
  7. * the COPYING file, which can be found at the root of the source code *
  8. * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
  9. * If you do not have access to either file, you may request a copy from *
  10. * help@hdfgroup.org. *
  11. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  12. /*
  13. * This file contains public declarations for the H5Z (data filter) developer
  14. * support routines.
  15. */
  16. #ifndef _H5Zdevelop_H
  17. #define _H5Zdevelop_H
  18. /* Include package's public header */
  19. #include "H5Zpublic.h"
  20. /*****************/
  21. /* Public Macros */
  22. /*****************/
  23. /**
  24. * Current version of the H5Z_class_t struct
  25. */
  26. #define H5Z_CLASS_T_VERS (1)
  27. /*******************/
  28. /* Public Typedefs */
  29. /*******************/
  30. /**
  31. * Structure for filter callback property
  32. */
  33. typedef struct H5Z_cb_t {
  34. H5Z_filter_func_t func;
  35. void * op_data;
  36. } H5Z_cb_t;
  37. /**
  38. * \brief This callback determines if a filter can be applied to the dataset
  39. * with the characteristics provided
  40. *
  41. * \dcpl_id
  42. * \type_id
  43. * \space_id
  44. *
  45. * \return \htri_t
  46. *
  47. * \details Before a dataset gets created, the \ref H5Z_can_apply_func_t
  48. * callbacks for any filters used in the dataset creation property list
  49. * are called with the dataset's dataset creation property list, the
  50. * dataset's datatype and a dataspace describing a chunk (for chunked
  51. * dataset storage).
  52. *
  53. * The \ref H5Z_can_apply_func_t callback must determine if the
  54. * combination of the dataset creation property list setting, the
  55. * datatype and the dataspace represent a valid combination to apply
  56. * this filter to. For example, some cases of invalid combinations may
  57. * involve the filter not operating correctly on certain datatypes (or
  58. * certain datatype sizes), or certain sizes of the chunk dataspace.
  59. *
  60. * The \ref H5Z_can_apply_func_t callback can be the NULL pointer, in
  61. * which case, the library will assume that it can apply to any
  62. * combination of dataset creation property list values, datatypes and
  63. * dataspaces.
  64. *
  65. * The \ref H5Z_can_apply_func_t callback returns positive a valid
  66. * combination, zero for an invalid combination and negative for an
  67. * error.
  68. */
  69. //! <!-- [H5Z_can_apply_func_t_snip] -->
  70. typedef htri_t (*H5Z_can_apply_func_t)(hid_t dcpl_id, hid_t type_id, hid_t space_id);
  71. //! <!-- [H5Z_can_apply_func_t_snip] -->
  72. /**
  73. * \brief The filter operation callback function, defining a filter's operation
  74. * on data
  75. *
  76. * \dcpl_id
  77. * \type_id
  78. * \space_id
  79. *
  80. * \return \herr_t
  81. *
  82. * \details After the \ref H5Z_can_apply_func_t callbacks are checked for new
  83. * datasets, the \ref H5Z_set_local_func_t callbacks for any filters
  84. * used in the dataset creation property list are called. These
  85. * callbacks receive the dataset's private copy of the dataset creation
  86. * property list passed in to H5Dcreate() (i.e. not the actual property
  87. * list passed in to H5Dcreate()) and the datatype ID passed in to
  88. * H5Dcreate() (which is not copied and should not be modified) and a
  89. * dataspace describing the chunk (for chunked dataset storage) (which
  90. * should also not be modified).
  91. *
  92. * The \ref H5Z_set_local_func_t callback must set any parameters that
  93. * are specific to this dataset, based on the combination of the
  94. * dataset creation property list values, the datatype and the
  95. * dataspace. For example, some filters perform different actions based
  96. * on different datatypes (or datatype sizes) or different number of
  97. * dimensions or dataspace sizes.
  98. *
  99. * The \ref H5Z_set_local_func_t callback can be the NULL pointer, in
  100. * which case, the library will assume that there are no
  101. * dataset-specific settings for this filter.
  102. *
  103. * The \ref H5Z_set_local_func_t callback must return non-negative on
  104. * success and negative for an error.
  105. */
  106. //! <!-- [H5Z_set_local_func_t_snip] -->
  107. typedef herr_t (*H5Z_set_local_func_t)(hid_t dcpl_id, hid_t type_id, hid_t space_id);
  108. //! <!-- [H5Z_set_local_func_t_snip] -->
  109. /**
  110. * \brief The filter operation callback function, defining a filter's operation
  111. * on data
  112. *
  113. * \param[in] flags Bit vector specifying certain general properties of the filter
  114. * \param[in] cd_nelmts Number of elements in \p cd_values
  115. * \param[in] cd_values Auxiliary data for the filter
  116. * \param[in] nbytes The number of valid bytes in \p buf to be filtered
  117. * \param[in,out] buf_size The size of \p buf
  118. * \param[in,out] buf The filter buffer
  119. *
  120. * \return Returns the number of valid bytes of data contained in \p buf. In the
  121. * case of failure, the return value is 0 (zero) and all pointer
  122. * arguments are left unchanged.
  123. *
  124. * \details A filter gets definition flags and invocation flags (defined
  125. * above), the client data array and size defined when the filter was
  126. * added to the pipeline, the size in bytes of the data on which to
  127. * operate, and pointers to a buffer and its allocated size.
  128. *
  129. * The filter should store the result in the supplied buffer if
  130. * possible, otherwise it can allocate a new buffer, freeing the
  131. * original. The allocated size of the new buffer should be returned
  132. * through the \p buf_size pointer and the new buffer through the \p
  133. * buf pointer.
  134. *
  135. * The return value from the filter is the number of bytes in the
  136. * output buffer. If an error occurs then the function should return
  137. * zero and leave all pointer arguments unchanged.
  138. */
  139. //! <!-- [H5Z_func_t_snip] -->
  140. typedef size_t (*H5Z_func_t)(unsigned int flags, size_t cd_nelmts, const unsigned int cd_values[],
  141. size_t nbytes, size_t *buf_size, void **buf);
  142. //! <!-- [H5Z_func_t_snip] -->
  143. /**
  144. * The filter table maps filter identification numbers to structs that
  145. * contain a pointers to the filter function and timing statistics.
  146. */
  147. //! <!-- [H5Z_class2_t_snip] -->
  148. typedef struct H5Z_class2_t {
  149. int version; /**< Version number of the H5Z_class_t struct */
  150. H5Z_filter_t id; /**< Filter ID number */
  151. unsigned encoder_present; /**< Does this filter have an encoder? */
  152. unsigned decoder_present; /**< Does this filter have a decoder? */
  153. const char * name; /**< Comment for debugging */
  154. H5Z_can_apply_func_t can_apply; /**< The "can apply" callback for a filter */
  155. H5Z_set_local_func_t set_local; /**< The "set local" callback for a filter */
  156. H5Z_func_t filter; /**< The actual filter function */
  157. } H5Z_class2_t;
  158. //! <!-- [H5Z_class2_t_snip] -->
  159. /********************/
  160. /* Public Variables */
  161. /********************/
  162. /*********************/
  163. /* Public Prototypes */
  164. /*********************/
  165. #ifdef __cplusplus
  166. extern "C" {
  167. #endif
  168. /**
  169. * \ingroup H5Z
  170. *
  171. * \brief Registers a new filter with the HDF5 library
  172. *
  173. * \param[in] cls A pointer to a buffer for the struct containing the
  174. * filter-definition
  175. *
  176. * \return \herr_t
  177. *
  178. * \details H5Zregister() registers a new filter with the HDF5 library.
  179. *
  180. * \details Making a new filter available to an application is a two-step
  181. * process. The first step is to write the three filter callback
  182. * functions described below: \c can_apply, \c set_local, and \c
  183. * filter. This call to H5Zregister(), registering the filter with the
  184. * library, is the second step. The can_apply and set_local fields can
  185. * be set to NULL if they are not required for the filter being
  186. * registered.
  187. *
  188. * H5Zregister() accepts a single parameter, a pointer to a buffer for
  189. * the \p cls data structure. That data structure must conform to one
  190. * of the following definitions:
  191. * \snippet this H5Z_class1_t_snip
  192. * or
  193. * \snippet this H5Z_class2_t_snip
  194. *
  195. * \c version is a library-defined value reporting the version number
  196. * of the #H5Z_class_t struct. This currently must be set to
  197. * #H5Z_CLASS_T_VERS.
  198. *
  199. * \c id is the identifier for the new filter. This is a user-defined
  200. * value between #H5Z_FILTER_RESERVED and #H5Z_FILTER_MAX. These
  201. * values are defined in the HDF5 source file H5Zpublic.h, but the
  202. * symbols #H5Z_FILTER_RESERVED and #H5Z_FILTER_MAX should always be
  203. * used instead of the literal values.
  204. *
  205. * \c encoder_present is a library-defined value indicating whether
  206. * the filter’s encoding capability is available to the application.
  207. *
  208. * \c decoder_present is a library-defined value indicating whether
  209. * the filter’s encoding capability is available to the application.
  210. *
  211. * \c name is a descriptive comment used for debugging, may contain a
  212. * descriptive name for the filter, and may be the null pointer.
  213. *
  214. * \c can_apply, described in detail below, is a user-defined callback
  215. * function which determines whether the combination of the dataset
  216. * creation property list values, the datatype, and the dataspace
  217. * represent a valid combination to apply this filter to.
  218. *
  219. * \c set_local, described in detail below, is a user-defined callback
  220. * function which sets any parameters that are specific to this
  221. * dataset, based on the combination of the dataset creation property
  222. * list values, the datatype, and the dataspace.
  223. *
  224. * \c filter, described in detail below, is a user-defined callback
  225. * function which performs the action of the filter.
  226. *
  227. * The statistics associated with a filter are not reset by this
  228. * function; they accumulate over the life of the library.
  229. *
  230. * #H5Z_class_t is a macro which maps to either H5Z_class1_t or
  231. * H5Z_class2_t, depending on the needs of the application. To affect
  232. * only this macro, H5Z_class_t_vers may be defined to either 1 or 2.
  233. * Otherwise, it will behave in the same manner as other API
  234. * compatibility macros. See API Compatibility Macros in HDF5 for more
  235. * information. H5Z_class1_t matches the #H5Z_class_t structure that is
  236. * used in the 1.6.x versions of the HDF5 library.
  237. *
  238. * H5Zregister() will automatically detect which structure type has
  239. * been passed in, regardless of the mapping of the #H5Z_class_t macro.
  240. * However, the application must make sure that the fields are filled
  241. * in according to the correct structure definition if the macro is
  242. * used to declare the structure.
  243. *
  244. * \Bold{The callback functions:}\n Before H5Zregister() can link a
  245. * filter into an application, three callback functions must be
  246. * defined as described in the HDF5 library header file H5Zpublic.h.
  247. *
  248. * When a filter is applied to the fractal heap for a group (e.g.,
  249. * when compressing group metadata) and if the can apply and set local
  250. * callback functions have been defined for that filter, HDF5 passes
  251. * the value -1 for all parameters for those callback functions. This
  252. * is done to ensure that the filter will not be applied to groups if
  253. * it relies on these parameters, as they are not applicable to group
  254. * fractal heaps; to operate on group fractal heaps, a filter must be
  255. * capable of operating on an opaque block of binary data.
  256. *
  257. * The \Emph{can apply} callback function must return a positive value
  258. * for a valid combination, zero for an invalid combination, and a
  259. * negative value for an error.
  260. * \snippet this H5Z_can_apply_func_t_snip
  261. *
  262. * Before a dataset is created, the \Emph{can apply} callbacks for any
  263. * filters used in the dataset creation property list are called with
  264. * the dataset's dataset creation property list, \c dcpl_id, the
  265. * dataset's datatype, \p type_id, and a dataspace describing a chunk,
  266. * \p space_id, (for chunked dataset storage).
  267. *
  268. * This callback must determine whether the combination of the dataset
  269. * creation property list settings, the datatype, and the dataspace
  270. * represent a valid combination to which to apply this filter. For
  271. * example, an invalid combination may involve the filter not
  272. * operating correctly on certain datatypes, on certain datatype
  273. * sizes, or on certain sizes of the chunk dataspace. If this filter
  274. * is enabled through H5Pset_filter() as optional and the can apply
  275. * function returns 0, the library will skip the filter in the filter
  276. * pipeline.
  277. *
  278. * This callback can be the NULL pointer, in which case the library
  279. * will assume that the filter can be applied to a dataset with any
  280. * combination of dataset creation property list values, datatypes,
  281. * and dataspaces.
  282. *
  283. * The \Emph{set local} callback function is defined as follows:
  284. * \snippet this H5Z_set_local_func_t_snip
  285. *
  286. * After the can apply callbacks are checked for a new dataset, the
  287. * \Emph{set local} callback functions for any filters used in the
  288. * dataset creation property list are called. These callbacks receive
  289. * \c dcpl_id, the dataset's private copy of the dataset creation
  290. * property list passed in to H5Dcreate() (i.e. not the actual
  291. * property list passed in to H5Dcreate()); \c type_id, the datatype
  292. * identifier passed in to H5Dcreate(), which is not copied and should
  293. * not be modified; and \c space_id, a dataspace describing the chunk
  294. * (for chunked dataset storage), which should also not be modified.
  295. *
  296. * The set local callback must set any filter parameters that are
  297. * specific to this dataset, based on the combination of the dataset
  298. * creation property list values, the datatype, and the dataspace. For
  299. * example, some filters perform different actions based on different
  300. * datatypes, datatype sizes, numbers of dimensions, or dataspace
  301. * sizes.
  302. *
  303. * The \Emph{set local} callback may be the NULL pointer, in which
  304. * case, the library will assume that there are no dataset-specific
  305. * settings for this filter.
  306. *
  307. * The \Emph{set local} callback function must return a non-negative
  308. * value on success and a negative value for an error.
  309. *
  310. * The \Emph{filter operation} callback function, defining the
  311. * filter's operation on the data, is defined as follows:
  312. * \snippet this H5Z_func_t_snip
  313. *
  314. * The parameters \c flags, \c cd_nelmts, and \c cd_values are the
  315. * same as for the function H5Pset_filter(). The one exception is that
  316. * an additional flag, #H5Z_FLAG_REVERSE, is set when the filter is
  317. * called as part of the input pipeline.
  318. *
  319. * The parameter \c buf points to the input buffer which has a size of
  320. * \c buf_size bytes, \c nbytes of which are valid data.
  321. *
  322. * The filter should perform the transformation in place if possible.
  323. * If the transformation cannot be done in place, then the filter
  324. * should allocate a new buffer with malloc() and assign it to \c buf,
  325. * assigning the allocated size of that buffer to \c buf_size. The old
  326. * buffer should be freed by calling free().
  327. *
  328. * If successful, the \Emph{filter operation} callback function
  329. * returns the number of valid bytes of data contained in \c buf. In
  330. * the case of failure, the return value is 0 (zero) and all pointer
  331. * arguments are left unchanged.
  332. *
  333. * \version 1.8.6 Return type for the \Emph{can apply} callback function,
  334. * \ref H5Z_can_apply_func_t, changed to \ref htri_t.
  335. * \version 1.8.5 Semantics of the \Emph{can apply} and \Emph{set local}
  336. * callback functions changed to accommodate the use of filters
  337. * with group fractal heaps.
  338. * \version 1.8.3 #H5Z_class_t renamed to H5Z_class2_t, H5Z_class1_t structure
  339. * introduced for backwards compatibility with release 1.6.x,
  340. * and #H5Z_class_t macro introduced in this release. Function
  341. * modified to accept either structure type.
  342. * \version 1.8.0 The fields \c version, \c encoder_present, and
  343. * \c decoder_present were added to the #H5Z_class_t \c struct
  344. * in this release.
  345. * \version 1.6.0 This function was substantially revised in Release 1.6.0 with
  346. * a new #H5Z_class_t struct and new set local and can apply
  347. * callback functions.
  348. *
  349. */
  350. H5_DLL herr_t H5Zregister(const void *cls);
  351. /**
  352. * \ingroup H5Z
  353. *
  354. * \brief Unregisters a filter.
  355. *
  356. * \param[in] id Identifier of the filter to be unregistered.
  357. * \return \herr_t
  358. *
  359. * \details H5Zunregister() unregisters the filter specified in \p id.
  360. *
  361. * \details This function first iterates through all opened datasets and
  362. * groups. If an open object that uses this filter is found, the
  363. * function will fail with a message indicating that an object using
  364. * the filter is still open. All open files are then flushed to make
  365. * sure that all cached data that may use this filter are written out.
  366. *
  367. * If the application is a parallel program, all processes that
  368. * participate in collective data write should call this function to
  369. * ensure that all data is flushed.
  370. *
  371. * After a call to H5Zunregister(), the filter specified in filter
  372. * will no longer be available to the application.
  373. *
  374. * \version 1.8.12 Function modified to check for open objects using the
  375. * filter.
  376. * \since 1.6.0
  377. */
  378. H5_DLL herr_t H5Zunregister(H5Z_filter_t id);
  379. #ifdef __cplusplus
  380. }
  381. #endif
  382. /* Symbols defined for compatibility with previous versions of the HDF5 API.
  383. *
  384. * Use of these symbols is deprecated.
  385. */
  386. #ifndef H5_NO_DEPRECATED_SYMBOLS
  387. /**
  388. * The filter table maps filter identification numbers to structs that
  389. * contain a pointers to the filter function and timing statistics.
  390. */
  391. //! <!-- [H5Z_class1_t_snip] -->
  392. typedef struct H5Z_class1_t {
  393. H5Z_filter_t id; /**< Filter ID number */
  394. const char * name; /**< Comment for debugging */
  395. H5Z_can_apply_func_t can_apply; /**< The "can apply" callback for a filter */
  396. H5Z_set_local_func_t set_local; /**< The "set local" callback for a filter */
  397. H5Z_func_t filter; /**< The actual filter function */
  398. } H5Z_class1_t;
  399. //! <!-- [H5Z_class1_t_snip] -->
  400. #endif /* H5_NO_DEPRECATED_SYMBOLS */
  401. #endif /* _H5Zdevelop_H */