Source
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 files COPYING and Copyright.html. COPYING can be found at the root *
8
+
* of the source code distribution tree; Copyright.html can be found at the *
9
+
* root level of an installed copy of the electronic document set and is *
10
+
* linked from the top-level documents page. It can also be found at *
11
+
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access *
12
+
* to either file, you may request a copy from help@hdfgroup.org. *
13
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
14
+
/*
15
+
* Purpose: Tests the plugin module (H5PL)
16
+
*/
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
static size_t H5Z_filter_dynlib4(unsigned int flags, size_t cd_nelmts,
27
+
const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf);
28
+
29
+
/* This message derives from H5Z */
30
+
const H5Z_class2_t H5Z_DYNLIB4[1] = {{
31
+
H5Z_CLASS_T_VERS, /* H5Z_class_t version */
32
+
H5Z_FILTER_DYNLIB4, /* Filter id number */
33
+
1, 1, /* Encoding and decoding enabled */
34
+
"dynlib4", /* Filter name for debugging */
35
+
NULL, /* The "can apply" callback */
36
+
NULL, /* The "set local" callback */
37
+
(H5Z_func_t)H5Z_filter_dynlib4, /* The actual filter function */
38
+
}};
39
+
40
+
H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;}
41
+
const void *H5PLget_plugin_info(void) {return H5Z_DYNLIB4;}
42
+
43
+
/*-------------------------------------------------------------------------
44
+
* Function: H5Z_filter_dynlib4
45
+
*
46
+
* Purpose: A dynlib4 filter method that adds on and subtract from
47
+
* the original value with another value. It will be built
48
+
* as a shared library. plugin.c test will load and use
49
+
* this filter library. Designed to call a HDF function.
50
+
*
51
+
* Return: Success: Data chunk size
52
+
*
53
+
* Failure: 0
54
+
*
55
+
*-------------------------------------------------------------------------
56
+
*/
57
+
static size_t
58
+
H5Z_filter_dynlib4(unsigned int flags, size_t cd_nelmts,
59
+
const unsigned int *cd_values, size_t nbytes,
60
+
size_t *buf_size, void **buf)
61
+
{
62
+
int *int_ptr = (int *)*buf; /* Pointer to the data values */
63
+
size_t buf_left = *buf_size; /* Amount of data buffer left to process */
64
+
int add_on = 0;
65
+
unsigned ver_info[3];
66
+
67
+
/* Check for the library version */
68
+
if(H5get_libversion(&ver_info[0], &ver_info[1], &ver_info[2]) < 0) {
69
+
PUSH_ERR("dynlib4", H5E_CALLBACK, "H5get_libversion");
70
+
return(0);
71
+
}
72
+
/* Check for the correct number of parameters */
73
+
if(cd_nelmts == 0)
74
+
return(0);
75
+
76
+
/* Check that permanent parameters are set correctly */
77
+
if(cd_values[0] > 9)
78
+
return(0);
79
+
80
+
if(ver_info[0] != cd_values[1] || ver_info[1] != cd_values[2]) {
81
+
PUSH_ERR("dynlib4", H5E_CALLBACK, "H5get_libversion does not match");
82
+
return(0);
83
+
}
84
+
85
+
add_on = (int)cd_values[0];
86
+
87
+
if(flags & H5Z_FLAG_REVERSE) { /*read*/
88
+
/* Substract the "add on" value to all the data values */
89
+
while(buf_left > 0) {
90
+
*int_ptr++ -= add_on;
91
+
buf_left -= sizeof(int);
92
+
} /* end while */
93
+
} /* end if */
94
+
else { /*write*/
95
+
/* Add the "add on" value to all the data values */
96
+
while(buf_left > 0) {
97
+
*int_ptr++ += add_on;
98
+
buf_left -= sizeof(int);
99
+
} /* end while */
100
+
} /* end else */
101
+
102
+
return nbytes;
103
+
} /* end H5Z_filter_dynlib4() */
104
+