9
9
* If you do not have access to either file, you may request a copy from *
10
10
* help@hdfgroup.org. *
11
11
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
+
12
13
/*
13
- * Purpose: Tests the plugin module (H5PL)
14
+ * Purpose: Test group filter plugin for the filter_pluging.c test.
14
15
*/
15
16
16
17
#include <stdlib.h>
17
18
#include <stdio.h>
18
- #include "H5PLextern.h"
19
+ #include <string.h>
19
20
20
- #define H5Z_FILTER_DYNLIB4 260
21
+ #include "H5PLextern.h"
21
22
22
- #define PUSH_ERR (func , minor , str ) \
23
- H5Epush2(H5E_DEFAULT, __FILE__, func, __LINE__, H5E_ERR_CLS, H5E_PLUGIN, minor, str)
23
+ #define FILTER4_ID 260
24
+ #define SUFFIX_LEN 8
25
+ #define GROUP_SUFFIX ".h5group"
24
26
25
- static size_t H5Z_filter_dynlib4 (unsigned int flags , size_t cd_nelmts , const unsigned int * cd_values ,
26
- size_t nbytes , size_t * buf_size , void * * buf );
27
+ static size_t append_to_group_name (unsigned int flags , size_t cd_nelmts , const unsigned int * cd_values ,
28
+ size_t nbytes , size_t * buf_size , void * * buf );
27
29
28
- /* This message derives from H5Z */
29
- const H5Z_class2_t H5Z_DYNLIB4 [1 ] = {{
30
- H5Z_CLASS_T_VERS , /* H5Z_class_t version */
31
- H5Z_FILTER_DYNLIB4 , /* Filter id number */
32
- 1 , 1 , /* Encoding and decoding enabled */
33
- "dynlib4" , /* Filter name for debugging */
34
- NULL , /* The "can apply" callback */
35
- NULL , /* The "set local" callback */
36
- H5Z_filter_dynlib4 , /* The actual filter function */
30
+ /* Filter class struct */
31
+ const H5Z_class2_t FILTER_INFO [1 ] = {{
32
+ H5Z_CLASS_T_VERS , /* H5Z_class_t version */
33
+ FILTER4_ID , /* Filter ID number */
34
+ 1 , /* Encoding enabled */
35
+ 1 , /* Decoding enabled */
36
+ "test filter plugin 4" , /* Filter name for debugging */
37
+ NULL , /* The "can apply" callback */
38
+ NULL , /* The "set local" callback */
39
+ append_to_group_name , /* The actual filter function */
37
40
}};
38
41
39
42
H5PL_type_t
@@ -44,66 +47,66 @@ H5PLget_plugin_type(void)
44
47
const void *
45
48
H5PLget_plugin_info (void )
46
49
{
47
- return H5Z_DYNLIB4 ;
50
+ return FILTER_INFO ;
48
51
}
49
52
50
53
/*-------------------------------------------------------------------------
51
- * Function: H5Z_filter_dynlib4
54
+ * Function: append_to_group_name
52
55
*
53
- * Purpose: A dynlib4 filter method that adds on and subtract from
54
- * the original value with another value. It will be built
55
- * as a shared library. plugin.c test will load and use
56
- * this filter library. Designed to call a HDF function.
56
+ * Purpose: On write:
57
+ * Appends the suffix ".h5group" to the group name
58
+ * On read:
59
+ * Removes the ".h5group" suffix from the group name
57
60
*
58
- * Return: Success: Data chunk size
59
- *
60
- * Failure: 0
61
+ * Return: Success: Data size in bytes
62
+ * Failure: 0
61
63
*
62
64
*-------------------------------------------------------------------------
63
65
*/
64
66
static size_t
65
- H5Z_filter_dynlib4 (unsigned int flags , size_t cd_nelmts , const unsigned int * cd_values , size_t nbytes ,
66
- size_t * buf_size , void * * buf )
67
+ append_to_group_name (unsigned int flags , size_t cd_nelmts , const unsigned int * cd_values , size_t nbytes ,
68
+ size_t * buf_size , void * * buf )
67
69
{
68
- int * int_ptr = (int * )* buf ; /* Pointer to the data values */
69
- size_t buf_left = * buf_size ; /* Amount of data buffer left to process */
70
- int add_on = 0 ;
71
- unsigned ver_info [3 ];
72
-
73
- /* Check for the library version */
74
- if (H5get_libversion (& ver_info [0 ], & ver_info [1 ], & ver_info [2 ]) < 0 ) {
75
- PUSH_ERR ("dynlib4" , H5E_CALLBACK , "H5get_libversion" );
76
- return (0 );
77
- }
70
+ size_t new_name_size = 0 ; /* Return value */
71
+
78
72
/* Check for the correct number of parameters */
79
- if (cd_nelmts == 0 )
80
- return (0 );
73
+ if (cd_nelmts > 0 )
74
+ return 0 ;
75
+
76
+ /* Assignment to eliminate unused parameter warning. */
77
+ (void )cd_values ;
78
+
79
+ if (flags & H5Z_FLAG_REVERSE ) {
80
+ /* READ - Remove the suffix from the group name */
81
+ new_name_size = * buf_size = nbytes - SUFFIX_LEN ;
82
+ }
83
+ else {
84
+ /* WRITE - Append the suffix to the group name */
85
+ void * outbuf = NULL ; /* Pointer to new buffer */
86
+ unsigned char * dst = NULL ; /* Temporary pointer to destination buffer */
87
+
88
+ /* Get memory for the new, larger string buffer using the
89
+ * library's memory allocator.
90
+ */
91
+ if (NULL == (dst = (unsigned char * )(outbuf = H5allocate_memory (nbytes + SUFFIX_LEN , 0 ))))
92
+ return 0 ;
93
+
94
+ /* Copy raw data */
95
+ memcpy ((void * )dst , (const void * )(* buf ), nbytes );
96
+
97
+ /* Append suffix to raw data for storage */
98
+ dst += nbytes ;
99
+ memcpy ((void * )dst , (const void * )GROUP_SUFFIX , SUFFIX_LEN );
81
100
82
- /* Check that permanent parameters are set correctly */
83
- if (cd_values [0 ] > 9 )
84
- return (0 );
101
+ /* Free the passed-in buffer using the library's allocator */
102
+ H5free_memory (* buf );
85
103
86
- if (ver_info [0 ] != cd_values [1 ] || ver_info [1 ] != cd_values [2 ]) {
87
- PUSH_ERR ("dynlib4" , H5E_CALLBACK , "H5get_libversion does not match" );
88
- return (0 );
104
+ /* Set return values */
105
+ * buf_size = nbytes + SUFFIX_LEN ;
106
+ * buf = outbuf ;
107
+ outbuf = NULL ;
108
+ new_name_size = * buf_size ;
89
109
}
90
110
91
- add_on = (int )cd_values [0 ];
92
-
93
- if (flags & H5Z_FLAG_REVERSE ) { /*read*/
94
- /* Subtract the "add on" value to all the data values */
95
- while (buf_left > 0 ) {
96
- * int_ptr ++ -= add_on ;
97
- buf_left -= sizeof (int );
98
- } /* end while */
99
- } /* end if */
100
- else { /*write*/
101
- /* Add the "add on" value to all the data values */
102
- while (buf_left > 0 ) {
103
- * int_ptr ++ += add_on ;
104
- buf_left -= sizeof (int );
105
- } /* end while */
106
- } /* end else */
107
-
108
- return nbytes ;
109
- } /* end H5Z_filter_dynlib4() */
111
+ return new_name_size ;
112
+ } /* append_to_group_name() */
0 commit comments