我正在尝试合并不同的分支来创建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 §ionName);
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;
};