diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2015-03-16 17:57:46 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2015-03-16 17:57:46 (GMT) |
commit | b1cd5f4f8a305b295e3a5aecc5ce7e7d9cd9e8c6 (patch) | |
tree | b15d7ff77e1dde6c79cbe05839ac5344168cd5ab /src | |
parent | 25281fc525faf80c9bf96729d3616c2eded6e9fa (diff) | |
download | hdf5-b1cd5f4f8a305b295e3a5aecc5ce7e7d9cd9e8c6.zip hdf5-b1cd5f4f8a305b295e3a5aecc5ce7e7d9cd9e8c6.tar.gz hdf5-b1cd5f4f8a305b295e3a5aecc5ce7e7d9cd9e8c6.tar.bz2 |
[svn-r26460] HDFFV-8520: Add api to control plugins
h5committest
Diffstat (limited to 'src')
-rw-r--r-- | src/H5PL.c | 184 | ||||
-rw-r--r-- | src/H5PLextern.h | 15 | ||||
-rw-r--r-- | src/H5PLprivate.h | 17 | ||||
-rw-r--r-- | src/H5PLpublic.h | 53 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/Makefile.in | 2 | ||||
-rw-r--r-- | src/hdf5.h | 3 |
7 files changed, 173 insertions, 103 deletions
@@ -23,11 +23,12 @@ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5PLprivate.h" /* Plugin */ -#include "H5Zprivate.h" /* Filter pipeline */ +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5PLprivate.h" /* Plugin */ +#include "H5Zprivate.h" /* Filter pipeline */ + /****************/ /* Local Macros */ @@ -96,6 +97,7 @@ typedef const void *(__cdecl *H5PL_get_plugin_info_t)(void); typedef const void *(*H5PL_get_plugin_info_t)(void); #endif /* H5_HAVE_WIN32_API */ +/* Whether to preload pathnames for plugin libraries */ #define H5PL_DEFAULT_PATH H5_DEFAULT_PLUGINDIR /* Special symbol to indicate no plugin loading */ @@ -107,9 +109,9 @@ typedef const void *(*H5PL_get_plugin_info_t)(void); /* Type for the list of info for opened plugin libraries */ typedef struct H5PL_table_t { - H5PL_type_t pl_type; /* plugin type */ - int pl_id; /* ID for the plugin */ - H5PL_HANDLE handle; /* plugin handle */ + H5PL_type_t pl_type; /* plugin type */ + int pl_id; /* ID for the plugin */ + H5PL_HANDLE handle; /* plugin handle */ } H5PL_table_t; @@ -139,8 +141,8 @@ static herr_t H5PL__close(H5PL_HANDLE handle); /*******************/ /* Table for opened plugin libraries */ -static size_t H5PL_table_alloc_g = 0; -static size_t H5PL_table_used_g = 0; +static size_t H5PL_table_alloc_g = 0; +static size_t H5PL_table_used_g = 0; static H5PL_table_t *H5PL_table_g = NULL; /* Table of location paths for plugin libraries */ @@ -148,8 +150,8 @@ static char *H5PL_path_table_g[H5PL_MAX_PATH_NUM]; static size_t H5PL_num_paths_g = 0; static hbool_t H5PL_path_found_g = FALSE; -/* Whether to preload pathnames for plugin libraries */ -static hbool_t H5PL_no_plugin_g = FALSE; +/* Enable all plugin libraries */ +static unsigned int H5PL_plugin_g = H5PL_ALL_PLUGIN; /*-------------------------------------------------------------------------- @@ -176,7 +178,7 @@ H5PL__init_interface(void) if(NULL != (preload_path = HDgetenv("HDF5_PLUGIN_PRELOAD"))) { /* Special symbal "::" means no plugin during data reading. */ if(!HDstrcmp(preload_path, H5PL_NO_PLUGIN)) - H5PL_no_plugin_g = TRUE; + H5PL_plugin_g = 0; } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) @@ -184,46 +186,83 @@ H5PL__init_interface(void) /*------------------------------------------------------------------------- - * Function: H5PL_no_plugin + * Function: H5PLset_loading_state * - * Purpose: Quick way for filter module to query whether to load plugin + * Purpose: Control the loading of dynamic plugin types. * - * Return: TRUE: No plugin loading during data reading + * This function will not allow plugin types if the pathname from the HDF5_PLUGIN_PRELOAD + * environment variable is set to the special "::" string. * - * FALSE: Load plugin during data reading + * plugin bit = 0, will prevent the use of that dynamic plugin type. + * plugin bit = 1, will allow the use of that dynamic plugin type. * - * Programmer: Raymond Lu - * 20 February 2013 + * H5PL_TYPE_FILTER changes just dynamic filters + * A H5PL_ALL_PLUGIN will enable all dynamic plugin types + * A zero value will disable all dynamic plugin types + * + * Return: Non-negative or success * *------------------------------------------------------------------------- */ -htri_t -H5PL_no_plugin(void) +herr_t +H5PLset_loading_state(unsigned int plugin_type) { - htri_t ret_value; + char *preload_path; + herr_t ret_value = SUCCEED; /* Return value */ + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "Iu", plugin_type); + /* change the bit value of the requested plugin type(s) */ + H5PL_plugin_g = plugin_type; + /* check if special ENV variable is set and disable all plugin types */ + if(NULL != (preload_path = HDgetenv("HDF5_PLUGIN_PRELOAD"))) { + /* Special symbol "::" means no plugin during data reading. */ + if(!HDstrcmp(preload_path, H5PL_NO_PLUGIN)) + H5PL_plugin_g = 0; + } +done: + FUNC_LEAVE_API(ret_value) +} /* end H5PLset_loading_state() */ - FUNC_ENTER_NOAPI(FAIL) - ret_value = (htri_t)H5PL_no_plugin_g; +/*------------------------------------------------------------------------- + * Function: H5PLget_loading_state + * + * Purpose: Query state of the loading of dynamic plugin types. + * + * This function will return the state of the global flag. + * + * Return: Zero if all plugin types are disabled, negative if all + * plugin types are enabled, positive if one or more of the plugin types are enabled. + * + *------------------------------------------------------------------------- + */ +herr_t +H5PLget_loading_state(unsigned int *plugin_type) +{ + herr_t ret_value = SUCCEED; /* Return value */ + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "*Iu", plugin_type); -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5PL_no_plugin() */ + if(plugin_type) + *plugin_type = H5PL_plugin_g; + done: + FUNC_LEAVE_API(ret_value) +} /* end H5PLget_loading_state() */ /*------------------------------------------------------------------------- - * Function: H5PL_term_interface + * Function: H5PL_term_interface * - * Purpose: Terminate the H5PL interface: release all memory, reset all - * global variables to initial values. This only happens if all - * types have been destroyed from other interfaces. + * Purpose: Terminate the H5PL interface: release all memory, reset all + * global variables to initial values. This only happens if all + * types have been destroyed from other interfaces. * - * Return: Success: Positive if any action was taken that might - * affect some other interface; zero otherwise. + * Return: Success: Positive if any action was taken that might + * affect some other interface; zero otherwise. * - * Failure: Negative. + * Failure: Negative. * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 20 February 2013 * *------------------------------------------------------------------------- @@ -238,13 +277,13 @@ H5PL_term_interface(void) if(H5_interface_initialize_g) { size_t u; /* Local index variable */ - /* Close opened dynamic libraries */ + /* Close opened dynamic libraries */ for(u = 0; u < H5PL_table_used_g; u++) H5PL__close((H5PL_table_g[u]).handle); - /* Free the table of dynamic libraries */ - H5PL_table_g = (H5PL_table_t *)H5MM_xfree(H5PL_table_g); - H5PL_table_used_g = H5PL_table_alloc_g = 0; + /* Free the table of dynamic libraries */ + H5PL_table_g = (H5PL_table_t *)H5MM_xfree(H5PL_table_g); + H5PL_table_used_g = H5PL_table_alloc_g = 0; /* Free the table of search paths */ for(u = 0; u < H5PL_num_paths_g; u++) @@ -253,7 +292,7 @@ H5PL_term_interface(void) H5PL_num_paths_g = 0; H5PL_path_found_g = FALSE; - H5_interface_initialize_g = 0; + H5_interface_initialize_g = 0; i = 1; } /* end if */ @@ -262,15 +301,15 @@ H5PL_term_interface(void) /*------------------------------------------------------------------------- - * Function: H5PL_load + * Function: H5PL_load * - * Purpose: Given the plugin type and identifier, this function searches + * Purpose: Given the plugin type and identifier, this function searches * and/or loads a dynamic plugin library first among the already * opened libraries then in the designated location paths. * - * Return: Non-NULL on success/NULL on failure + * Return: Non-NULL on success/NULL on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -284,9 +323,14 @@ H5PL_load(H5PL_type_t type, int id) FUNC_ENTER_NOAPI(NULL) - /* Check for "no plugins" indicated" */ - if(H5PL_no_plugin_g) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id) + switch (type) { + case H5PL_TYPE_FILTER: + if((H5PL_plugin_g & H5PL_FILTER_PLUGIN) == 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id) + break; + default: + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin '%d' is not valid", id) + } /* Initialize the location paths for dynamic libraries, if they aren't * already set up. @@ -325,13 +369,13 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__init_path_table + * Function: H5PL__init_path_table * - * Purpose: Initialize the path table. + * Purpose: Initialize the path table. * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * - * Programmer: Quincey Koziol + * Programmer: Quincey Koziol * 18 March 2013 * *------------------------------------------------------------------------- @@ -380,18 +424,18 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__find + * Function: H5PL__find * * Purpose: Given a path, this function opens the directory and envokes * another function to go through all files to find the right * plugin library. Two function definitions are for Unix and * Windows. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * negative on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -491,7 +535,7 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) /* Allocate & initialize the path name */ pathname_len = HDstrlen(dir) + HDstrlen(fdFile.cFileName) + 2; - if(NULL == (pathname = (char *)H5MM_malloc(pathname_len))) + if(NULL == (pathname = (char *)H5MM_malloc(pathname_len))) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") HDsnprintf(pathname, pathname_len, "%s\\%s", dir, fdFile.cFileName); @@ -506,7 +550,7 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) HGOTO_DONE(TRUE) } /* end if */ else - HDassert(pathname); + HDassert(pathname); pathname = (char *)H5MM_xfree(pathname); } /* end if */ } while(FindNextFileA(hFind, &fdFile)); /* Find the next file. */ @@ -523,17 +567,17 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__open + * Function: H5PL__open * * Purpose: Iterates through all files to find the right plugin library. * It loads the dynamic plugin library and keeps it on the list - * of loaded libraries. + * of loaded libraries. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * negative on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -611,16 +655,16 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__search_table + * Function: H5PL__search_table * * Purpose: Search in the list of already opened dynamic libraries * to see if the one we are looking for is already opened. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * Negative on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- @@ -642,12 +686,12 @@ H5PL__search_table(H5PL_type_t plugin_type, int type_id, const void **info) const H5Z_class2_t *plugin_info; if(NULL == (get_plugin_info = (H5PL_get_plugin_info_t)H5PL_GET_LIB_FUNC((H5PL_table_g[i]).handle, "H5PLget_plugin_info"))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get function for H5PLget_plugin_info") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get function for H5PLget_plugin_info") - if(NULL == (plugin_info = (const H5Z_class2_t *)(*get_plugin_info)())) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get plugin info") + if(NULL == (plugin_info = (const H5Z_class2_t *)(*get_plugin_info)())) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get plugin info") - *info = plugin_info; + *info = plugin_info; HGOTO_DONE(TRUE) } /* end if */ } /* end for */ @@ -659,13 +703,13 @@ done: /*------------------------------------------------------------------------- - * Function: H5PL__close + * Function: H5PL__close * * Purpose: Closes the handle for dynamic library * - * Return: Non-negative on success/Negative on failure + * Return: Non-negative on success/Negative on failure * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 13 February 2013 * *------------------------------------------------------------------------- diff --git a/src/H5PLextern.h b/src/H5PLextern.h index 7f10575..3264435 100644 --- a/src/H5PLextern.h +++ b/src/H5PLextern.h @@ -22,20 +22,6 @@ /* Include HDF5 header */ #include "hdf5.h" -#ifndef H5_VMS - -/*******************/ -/* Public Typedefs */ -/*******************/ - -/* Plugin type */ -typedef enum H5PL_type_t { - H5PL_TYPE_ERROR = -1, /*error */ - H5PL_TYPE_FILTER = 0, /*filter */ - H5PL_TYPE_NONE = 1 /*this must be last! */ -} H5PL_type_t; - - /* plugins always export */ #if defined (_MSC_VER) /* MSVC Compiler Case */ #define H5PLUGIN_DLL __declspec(dllexport) @@ -55,7 +41,6 @@ H5PLUGIN_DLL const void *H5PLget_plugin_info(void); #ifdef __cplusplus } #endif -#endif /*H5_VMS*/ #endif /* _H5PLextern_H */ diff --git a/src/H5PLprivate.h b/src/H5PLprivate.h index a1b77ea..77e115b 100644 --- a/src/H5PLprivate.h +++ b/src/H5PLprivate.h @@ -19,23 +19,12 @@ #ifndef _H5PLprivate_H #define _H5PLprivate_H -/* Keep the following in sync with the package's "external" header */ - -/*******************/ -/* Public Typedefs */ -/*******************/ - -/* Plugin type */ -typedef enum H5PL_type_t { - H5PL_TYPE_ERROR = -1, /*error */ - H5PL_TYPE_FILTER = 0, /*filter */ - H5PL_TYPE_NONE = 1 /*this must be last! */ -} H5PL_type_t; +/* Include package's public header */ +#include "H5PLpublic.h" /* Private headers needed by this file */ #include "H5private.h" /* Generic Functions */ -#ifndef H5_VMS /**************************/ /* Library Private Macros */ @@ -58,8 +47,6 @@ typedef enum H5PL_type_t { /* Internal API routines */ H5_DLL const void *H5PL_load(H5PL_type_t plugin_type, int type_id); -H5_DLL htri_t H5PL_no_plugin(void); -#endif /*H5_VMS*/ #endif /* _H5PLprivate_H */ diff --git a/src/H5PLpublic.h b/src/H5PLpublic.h new file mode 100644 index 0000000..0296819 --- /dev/null +++ b/src/H5PLpublic.h @@ -0,0 +1,53 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic document set and is * + * linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access * + * to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* Programmer: Raymond Lu <songyulu@hdfgroup.org> + * 13 February 2013 + */ + +#ifndef _H5PLpublic_H +#define _H5PLpublic_H + +/* Public headers needed by this file */ +#include "H5public.h" /* Generic Functions */ + +/*******************/ +/* Public Typedefs */ +/*******************/ + +/* Plugin type used by the plugin library */ +typedef enum H5PL_type_t { + H5PL_TYPE_ERROR = -1, /*error */ + H5PL_TYPE_FILTER = 0, /*filter */ + H5PL_TYPE_NONE = 1 /*this must be last! */ +} H5PL_type_t; + +/* Common dynamic plugin type flags used by the set/get_loading_state functions */ +#define H5PL_FILTER_PLUGIN 0x0001 +#define H5PL_ALL_PLUGIN 0xFFFF + +#ifdef __cplusplus +extern "C" { +#endif + +/* plugin state */ +H5_DLL herr_t H5PLset_loading_state(unsigned int plugin_type); +H5_DLL herr_t H5PLget_loading_state(unsigned int *plugin_type/*out*/); + +#ifdef __cplusplus +} +#endif + +#endif /* _H5PLpublic_H */ + diff --git a/src/Makefile.am b/src/Makefile.am index 004a01b..bc94252 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -114,7 +114,7 @@ include_HEADERS = hdf5.h H5api_adpt.h H5overflow.h H5pubconf.h H5public.h H5vers H5FDmulti.h H5FDsec2.h H5FDstdio.h \ H5Gpublic.h H5Ipublic.h H5Lpublic.h \ H5MMpublic.h H5Opublic.h H5Ppublic.h \ - H5PLextern.h \ + H5PLextern.h H5PLpublic.h \ H5Rpublic.h H5Spublic.h \ H5Tpublic.h H5Zpublic.h diff --git a/src/Makefile.in b/src/Makefile.in index 31335c8..10a307e 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -813,7 +813,7 @@ include_HEADERS = hdf5.h H5api_adpt.h H5overflow.h H5pubconf.h H5public.h H5vers H5FDmulti.h H5FDsec2.h H5FDstdio.h \ H5Gpublic.h H5Ipublic.h H5Lpublic.h \ H5MMpublic.h H5Opublic.h H5Ppublic.h \ - H5PLextern.h \ + H5PLextern.h H5PLpublic.h \ H5Rpublic.h H5Spublic.h \ H5Tpublic.h H5Zpublic.h @@ -33,7 +33,8 @@ #include "H5Lpublic.h" /* Links */ #include "H5MMpublic.h" /* Memory management */ #include "H5Opublic.h" /* Object headers */ -#include "H5Ppublic.h" /* Property lists */ +#include "H5Ppublic.h" /* Property lists */ +#include "H5PLpublic.h" /* Plugins */ #include "H5Rpublic.h" /* References */ #include "H5Spublic.h" /* Dataspaces */ #include "H5Tpublic.h" /* Datatypes */ |