add library interface for introspection of loaded plugins

This commit is contained in:
Axel Kohlmeyer
2021-03-13 12:17:20 -05:00
parent e3d9c3126b
commit 76cff1ed1e
2 changed files with 57 additions and 0 deletions

View File

@ -38,6 +38,7 @@
#include "neighbor.h"
#include "region.h"
#include "output.h"
#include "plugin.h"
#include "thermo.h"
#include "timer.h"
#include "universe.h"
@ -4581,6 +4582,59 @@ int lammps_id_name(void *handle, const char *category, int idx,
return 0;
}
/* ---------------------------------------------------------------------- */
/** Count the number of loaded plugins
*
\verbatim embed:rst
This function counts how many plugins are currently loaded.
.. versionadded:: 10Mar2021
\endverbatim
*
* \return number of loaded plugins
*/
int lammps_plugin_count()
{
return plugin_get_num_plugins();
}
/* ---------------------------------------------------------------------- */
/** Look up the info of a loaded plugin by its index in the list of plugins
*
\verbatim embed:rst
This function copies the name of the *style* plugin with the index
*idx* into the provided C-style string buffer. The length of the buffer
must be provided as *buf_size* argument. If the name of the style
exceeds the length of the buffer, it will be truncated accordingly.
If the index is out of range, the function returns 0 and *buffer* is
set to an empty string, otherwise 1.
.. versionadded:: 10Mar2021
\endverbatim
*
* \param idx index of the plugin in the list all or *style* plugins
* \param stylebuf string buffer to copy the style of the plugin to
* \param namebuf string buffer to copy the name of the plugin to
* \param buf_size size of the provided string buffers
* \return 1 if successful, otherwise 0
*/
int lammps_plugin_name(int idx, char *stylebuf, char *namebuf, int buf_size)
{
stylebuf[0] = namebuf[0] = '\0';
const lammpsplugin_t *plugin = plugin_get_info(idx);
if (plugin) {
strncpy(stylebuf,plugin->style,buf_size);
strncpy(namebuf,plugin->name,buf_size);
return 1;
}
return 0;
}
// ----------------------------------------------------------------------
// utility functions
// ----------------------------------------------------------------------

View File

@ -205,6 +205,9 @@ int lammps_has_id(void *, const char *, const char *);
int lammps_id_count(void *, const char *);
int lammps_id_name(void *, const char *, int, char *, int);
int lammps_plugin_count();
int lammps_plugin_name(int, char *, char *, int);
/* ----------------------------------------------------------------------
* Utility functions
* ---------------------------------------------------------------------- */