25 lines
include/plugin_interface.h
Declares IPlugin: the interface every plugin shared library must implement.
// IPlugin: interface all monitoring agent plugins must implement.
#pragma once
#include <cstdint>
 
// Plugin interface implemented by every dynamically loaded monitoring plugin.
// Lifecycle contract:
//   1. The registry calls create() (exported from the shared library) to obtain a pointer.
//   2. The plugin is used via this interface.
//   3. The registry calls destroy() on the plugin before calling dlclose().
//      Calling any virtual method after dlclose() is undefined behaviour.
class IPlugin {
public:
  virtual ~IPlugin() = default;
 
  // Returns the plugin's human-readable name (stable pointer into the plugin's DSO).
  virtual const char* name() const = 0;
 
  // Collects a metric sample; may block briefly while querying the OS.
  // Returns: raw metric value; negative on error.
  virtual int64_t collect() = 0;
 
  // Releases all plugin resources.
  // Must be called before the host calls dlclose() on this plugin's library.
  virtual void destroy() = 0;
};