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 * Programmer: Raymond Lu
14 * 13 February 2013
15 *
16 * Purpose: Tests the plugin module (H5PL)
17 */
18
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include "H5PLextern.h"
22
23 #define H5Z_FILTER_DYNLIB1 257
24
25 static size_t H5Z_filter_dynlib1(unsigned int flags, size_t cd_nelmts,
26 const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf);
27
28 /* This message derives from H5Z */
29 const H5Z_class2_t H5Z_DYNLIB1[1] = {{
30 H5Z_CLASS_T_VERS, /* H5Z_class_t version */
31 H5Z_FILTER_DYNLIB1, /* Filter id number */
32 1, 1, /* Encoding and decoding enabled */
33 "dynlib1", /* Filter name for debugging */
34 NULL, /* The "can apply" callback */
35 NULL, /* The "set local" callback */
36 (H5Z_func_t)H5Z_filter_dynlib1, /* The actual filter function */
37 }};
38
H5PLget_plugin_type(void)39 H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;}
H5PLget_plugin_info(void)40 const void *H5PLget_plugin_info(void) {return H5Z_DYNLIB1;}
41
42 /*-------------------------------------------------------------------------
43 * Function: H5Z_filter_dynlib1
44 *
45 * Purpose: A dynlib1 filter method that adds on and subtract from
46 * the original value with another value. It will be built
47 * as a shared library. plugin.c test will load and use
48 * this filter library.
49 *
50 * Return: Success: Data chunk size
51 *
52 * Failure: 0
53 *
54 * Programmer: Raymond Lu
55 * 29 March 2013
56 *
57 *-------------------------------------------------------------------------
58 */
59 static size_t
H5Z_filter_dynlib1(unsigned int flags,size_t cd_nelmts,const unsigned int * cd_values,size_t nbytes,size_t * buf_size,void ** buf)60 H5Z_filter_dynlib1(unsigned int flags, size_t cd_nelmts,
61 const unsigned int *cd_values, size_t nbytes,
62 size_t *buf_size, void **buf)
63 {
64 int *int_ptr = (int *)*buf; /* Pointer to the data values */
65 size_t buf_left = *buf_size; /* Amount of data buffer left to process */
66 int add_on = 0;
67
68 /* Check for the correct number of parameters */
69 if(cd_nelmts == 0)
70 return(0);
71
72 /* Check that permanent parameters are set correctly */
73 if(cd_values[0] > 9)
74 return(0);
75
76 add_on = (int)cd_values[0];
77
78 if(flags & H5Z_FLAG_REVERSE) { /*read*/
79 /* Substract the "add on" value to all the data values */
80 while(buf_left > 0) {
81 *int_ptr++ -= add_on;
82 buf_left -= sizeof(int);
83 } /* end while */
84 } /* end if */
85 else { /*write*/
86 /* Add the "add on" value to all the data values */
87 while(buf_left > 0) {
88 *int_ptr++ += add_on;
89 buf_left -= sizeof(int);
90 } /* end while */
91 } /* end else */
92
93 return nbytes;
94 } /* end H5Z_filter_dynlib1() */
95
96