forked from Unidata/netcdf-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend the netcdf API to support programmatic changes to the plugin s…
…earch path re: Unidata#2753 As suggested by Ed Hartnett, This PR extends the netcdf.h API to support programmatic control over the search path used to locate plugins. I created several different APIs, but finally settled on the following API as being the simplest possible. It has the disadvantage that it requires use of a global lock (not implemented) if used in a threaded environment. Specifically, note that modifying the plugin paths must be done "atomically". That is, in a multi-threaded environment, it is important that the sequence of actions involved in setting up the plugin paths must be done by a single processor or in some other way as to guarantee that two or more processors are not simultaneously accessing the plugin path read/write operations. As an example, assume there exists a mutex lock called PLUGINLOCK. Then any processor accessing the plugin paths should operate as follows: ```` lock(PLUGINLOCK); nc_plugin_path_read(...); <rebuild plugin path> nc_plugin_path_write(...); unlock(PLUGINLOCK); ```` The API proposed in this PR looks like this (from netcdf-c/include/netcdf_filter.h). * ````int nc_plugin_path_read(int formatx, size_t* ndirsp, char** dirs);```` This function returns the current sequence of directories in the internal plugin path list. Since this function does not modify the plugin path, it can be called at any time. The arguments are as follows: - _formatx_ specify which dispatch implementation to read: currently NC_FORMATX_NC_HDF5 or NC_FORMATX_NCZARR. - _ndirsp_ return the number of dirs in the internal path list - _dirs_ memory for storing the sequence of directies in the internal path list. In practice, this function needs to be called twice. The first time with npaths not NULL and pathlist set to NULL to get the size of the path list. The second time with pathlist not NULL to get the actual sequence of paths. * ````int nc_plugin_path_write(int formatx, size_t ndirs, char** const dirs);```` This function empties the current internal path sequence and replaces it with the sequence of directories argument. Using a paths argument of NULL or npaths argument of 0 will clear the set of plugin paths. The arguments are as follows: - _formatx_ specify which dispatch implementation to write: currently NC_FORMATX_NC_HDF5 or NC_FORMATX_NCZARR or 0 (zero). - _ndirs_ length of the dirs argument - _dirs_ a vector of directory path string used to overwrite the current internal path list If the value zero is used for the formatx argument, then the value being written is applied to all implemention: currently NC_FORMATX_NC_HDF5 and NC_FORMATX_NCZARR. In addition, two other API functions are defined. ```` int nc_plugin_path_initialize(void); int nc_plugin_path_finalize(void); ```` As a rule, the initialize and finalize functions do not need to be explicitly called by the user because they are called as part of *nc_initialize()/nc_finalize()*. In addition to the above changes, add a plugin path testcase: unit_tests/run_pluginpaths.sh+tst_pluginpaths.c. ## Misc. Changes 1. Added a version number for the formatx dispatcher. 2. Setup a per-dispatcher global state mechanism. 3. Add some path manipulation utilities to netcf_aux.h 4. Fix the construction of netcdf_json.h as a BUILT_SOURCE. 5. Fix some minor bugs in netcdf_json.h 6. Fix the construction of netcdf_proplist.h as a BUILT_SOURCE.
- Loading branch information
1 parent
17ce360
commit 25b433b
Showing
61 changed files
with
2,471 additions
and
937 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata | ||
See COPYRIGHT for license information. | ||
*/ | ||
|
||
/* | ||
Common functionality for plugin paths/ | ||
For internal use only. | ||
*/ | ||
|
||
#ifndef NCPLUGINS_H | ||
#define NCPLUGINS_H | ||
|
||
/* Opaque */ | ||
struct NClist; | ||
|
||
/* Define the plugin path management dispatch table */ | ||
|
||
typedef struct NC_PluginPathDispatch { | ||
int model; /* one of the NC_FORMATX #'s */ | ||
int dispatch_version; | ||
int (*initialize)(void** statep, const struct NClist* initialpaths); | ||
int (*finalize)(void** statep); | ||
int (*read)(void* state, size_t* ndirsp, char** dirs); | ||
int (*write)(void* state, size_t ndirs, char** const dirs); | ||
} NC_PluginPathDispatch; | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
/* Known Plugin Dispatchers */ | ||
#ifdef USE_HDF5 | ||
EXTERNL NC_PluginPathDispatch* NC4_hdf5_pluginpathtable; | ||
#endif | ||
#ifdef NETCDF_ENABLE_NCZARR | ||
EXTERNL NC_PluginPathDispatch* NCZ_pluginpathtable; | ||
#endif | ||
|
||
/* See the file netcdf_aux.h for plugin-related utility functions */ | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
|
||
#endif /*NCPLUGINS_H*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.