0

我正在尝试合并不同的分支以创建新版本的 munin-node-win32。

我目前正在努力让这个叉子工作。 https://github.com/hugohallqvist/munin-node-win32/tree/hugodevel

但我收到以下错误。

src\core\MuninPluginManager.cpp(135): error C2259: 'PerfCounterCustomMuninNodePlugin': cannot instantiate abstract class
src\core\MuninPluginManager.cpp(135): note: due to following members:
src\core\MuninPluginManager.cpp(135): note: 'bool MuninNodePlugin::AutoConf(void)': is abstract
c:\users\username\projekte\munin-node-win3264\src\core\MuninNodePlugin.h(14): note: see declaration of 'MuninNodePlugin::AutoConf'

我认为这些是重要的代码片段。

MuninNodePlugin.h

class MuninNodePlugin {
public:
  virtual ~MuninNodePlugin() {};

  /// This method should always be thread-safe
  virtual bool IsLoaded() = 0;
  /// This method should also always be thread-safe
  virtual const char *GetName() = 0;
  virtual bool AutoConf() = 0;
  virtual int GetConfig(char *buffer, int len) = 0;
  virtual int GetValues(char *buffer, int len) = 0;  
  virtual bool IsThreadSafe();
};

MuninPluginManager.cpp

// Add all the PerfCounterCustom Plugins
  {
    const char *perfPrefix = PerfCounterCustomMuninNodePlugin::SectionPrefix;
    size_t perfPrefixLen = strlen(perfPrefix);
    for (size_t i = 0; i < g_Config.GetNumKeys(); i++) {
      std::string keyName = g_Config.GetKeyName(i);
      if (keyName.compare(0, perfPrefixLen, perfPrefix) == 0) {
        PerfCounterCustomMuninNodePlugin *plugin = new PerfCounterCustomMuninNodePlugin(keyName);
        if (plugin->IsLoaded()) {
          AddPlugin(plugin);
        } else {
          _Module.LogError("Failed to load Custom PerfCounter plugin: [%s]", keyName.c_str());
          delete plugin;
        }
      }
    }
  }

我对 C++ 几乎一无所知,所以我不明白已经发布的针对此错误的解决方案。我更喜欢快速修复,例如“更改此行,它应该可以工作”。

奇怪的是,直接在另一个块上方的这段代码没有抛出错误,甚至几乎完全相同。:/

  // Add all the regular PerfCounter Plugins
  {
    const char *perfPrefix = PerfCounterMuninNodePlugin::SectionPrefix;
    size_t perfPrefixLen = strlen(perfPrefix);
    for (size_t i = 0; i < g_Config.GetNumKeys(); i++) {
      std::string keyName = g_Config.GetKeyName(i);
      if (keyName.compare(0, perfPrefixLen, perfPrefix) == 0) {
        PerfCounterMuninNodePlugin *plugin = new PerfCounterMuninNodePlugin(keyName);
        if (plugin->IsLoaded()) {
          AddPlugin(plugin);
        } else {
          _Module.LogError("Failed to load PerfCounter plugin: [%s]", keyName.c_str());
          delete plugin;
        }
      }
    }
  }

PerfCounterCustomMuninNodePlugin.h

#pragma once
#include "core/MuninNodePlugin.h"

struct Field {
  std::string name;
  std::string preParsedArgs;

  // PerfCounter API params
  struct Counter {
    std::string path;
    HCOUNTER handle;
    DWORD format;
    double multiply;
  } counter;
};

class PerfCounterCustomMuninNodePlugin : public MuninNodePluginHelper
{
public:

  /// \param sectionName The INI File section name for this plugin
  PerfCounterCustomMuninNodePlugin(const std::string &sectionName);
  virtual ~PerfCounterCustomMuninNodePlugin();

  virtual int GetConfig(char *buffer, int len);
  virtual int GetValues(char *buffer, int len);
  virtual bool IsLoaded() { return m_Loaded; };

  static const char *SectionPrefix;
private:
  bool OpenCounter();

  bool m_Loaded;
  std::string m_SectionName;

  HQUERY m_PerfQuery;

  // All the fields are represented here
  std::map<std::string, Field> m_Fields;

  // Precomputed graph parameters
  std::string m_GraphParameters;
};
4

0 回答 0