Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: class definitions with duplicate names #1886

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions userspace/libsinsp/test/plugins/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,46 @@ limitations under the License.
#include <driver/ppm_events_public.h>
#include "test_plugins.h"

namespace {

struct plugin_state
{
std::string lasterr;
struct ss_plugin_metric metrics[2];
ss_plugin_metric metrics[2];
uint64_t count = 0;
};

static const char* plugin_get_required_api_version()
const char* plugin_get_required_api_version()
{
return PLUGIN_API_VERSION_STR;
}

static const char* plugin_get_version()
const char* plugin_get_version()
{
return "0.1.0";
}

static const char* plugin_get_name()
const char* plugin_get_name()
{
return "sample_metrics";
}

static const char* plugin_get_description()
const char* plugin_get_description()
{
return "some desc";
}

static const char* plugin_get_contact()
const char* plugin_get_contact()
{
return "some contact";
}

static const char* plugin_get_parse_event_sources()
const char* plugin_get_parse_event_sources()
{
return "[\"syscall\"]";
}

static uint16_t* plugin_get_parse_event_types(uint32_t* num_types, ss_plugin_t* s)
uint16_t* plugin_get_parse_event_types(uint32_t* num_types, ss_plugin_t* s)
{
static uint16_t types[] = {
PPME_SYSCALL_OPEN_E,
Expand All @@ -71,10 +73,10 @@ static uint16_t* plugin_get_parse_event_types(uint32_t* num_types, ss_plugin_t*
return &types[0];
}

static ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc)
ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc)
{
*rc = SS_PLUGIN_SUCCESS;
plugin_state *ret = new plugin_state();
auto ret = new plugin_state();

ret->metrics[0].type = SS_PLUGIN_METRIC_TYPE_NON_MONOTONIC;
ret->metrics[0].value_type = SS_PLUGIN_METRIC_VALUE_TYPE_U64;
Expand All @@ -89,34 +91,36 @@ static ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc
return ret;
}

static void plugin_destroy(ss_plugin_t* s)
void plugin_destroy(ss_plugin_t* s)
{
delete ((plugin_state *) s);
delete reinterpret_cast<plugin_state*>(s);
}

static const char* plugin_get_last_error(ss_plugin_t* s)
const char* plugin_get_last_error(ss_plugin_t* s)
{
return ((plugin_state *) s)->lasterr.c_str();
}

static ss_plugin_rc plugin_parse_event(ss_plugin_t *s, const ss_plugin_event_input *ev, const ss_plugin_event_parse_input* in)
ss_plugin_rc plugin_parse_event(ss_plugin_t *s, const ss_plugin_event_input *ev, const ss_plugin_event_parse_input* in)
{
plugin_state *ps = (plugin_state *) s;
auto ps = reinterpret_cast<plugin_state*>(s);
ps->count++;
ps->metrics[1].value.u64 = ps->count;

return SS_PLUGIN_SUCCESS;
}

static ss_plugin_metric* plugin_get_metrics(ss_plugin_t *s, uint32_t *num_metrics)
ss_plugin_metric* plugin_get_metrics(ss_plugin_t *s, uint32_t *num_metrics)
{
plugin_state *ps = (plugin_state *) s;
auto ps = reinterpret_cast<plugin_state*>(s);

*num_metrics = sizeof(ps->metrics) / sizeof(ss_plugin_metric);

return ps->metrics;
}

} // anonymous namespace

void get_plugin_api_sample_metrics(plugin_api& out)
{
memset(&out, 0, sizeof(plugin_api));
Expand All @@ -132,4 +136,4 @@ void get_plugin_api_sample_metrics(plugin_api& out)
out.get_parse_event_types = plugin_get_parse_event_types;
out.parse_event = plugin_parse_event;
out.get_metrics = plugin_get_metrics;
}
}
42 changes: 23 additions & 19 deletions userspace/libsinsp/test/plugins/plugin_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ limitations under the License.

#include "test_plugins.h"

namespace {

/**
* Example of plugin implementing only the field extraction capability, which:
* - Is compatible with the "sample" event source only
Expand All @@ -40,47 +42,47 @@ struct plugin_state
ss_plugin_log_fn_t log;
};

static const char* plugin_get_required_api_version()
const char* plugin_get_required_api_version()
{
return PLUGIN_API_VERSION_STR;
}

static const char* plugin_get_version()
const char* plugin_get_version()
{
return "0.1.0";
}

static const char* plugin_get_name()
const char* plugin_get_name()
{
return "sample_plugin_extract";
}

static const char* plugin_get_description()
const char* plugin_get_description()
{
return "some desc";
}

static const char* plugin_get_contact()
const char* plugin_get_contact()
{
return "some contact";
}

static const char* plugin_get_fields()
const char* plugin_get_fields()
{
return
"[" \
"{\"type\": \"string\", \"name\": \"sample.hello\", \"desc\": \"A constant hello world string\"}" \
"]";
}

static const char* plugin_get_extract_event_sources()
const char* plugin_get_extract_event_sources()
{
return "[\"sample\"]";
}

static uint16_t* plugin_get_extract_event_types(uint32_t* num_types, ss_plugin_t* s)
uint16_t* plugin_get_extract_event_types(uint32_t* num_types, ss_plugin_t* s)
{
plugin_state *ps = (plugin_state *) s;
auto ps = reinterpret_cast<plugin_state*>(s);
if (!ps->event_types.empty())
{
*num_types = (uint32_t) ps->event_types.size();
Expand All @@ -92,9 +94,9 @@ static uint16_t* plugin_get_extract_event_types(uint32_t* num_types, ss_plugin_t
return types;
}

static ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc)
ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc)
{
plugin_state *ret = new plugin_state();
auto ret = new plugin_state();

//save logger and owner in the state
ret->log = in->log_fn;
Expand Down Expand Up @@ -128,22 +130,22 @@ static ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc
return ret;
}

static void plugin_destroy(ss_plugin_t* s)
void plugin_destroy(ss_plugin_t* s)
{
plugin_state *ps = (plugin_state *) s;
auto ps = reinterpret_cast<plugin_state*>(s);
ps->log(ps->owner, NULL, "destroying plugin...", SS_PLUGIN_LOG_SEV_INFO);

delete ((plugin_state *) s);
delete ps;
}

static const char* plugin_get_last_error(ss_plugin_t* s)
const char* plugin_get_last_error(ss_plugin_t* s)
{
return ((plugin_state *) s)->lasterr.c_str();
}

static ss_plugin_rc plugin_extract_fields(ss_plugin_t *s, const ss_plugin_event_input *ev, const ss_plugin_field_extract_input* in)
ss_plugin_rc plugin_extract_fields(ss_plugin_t *s, const ss_plugin_event_input *ev, const ss_plugin_field_extract_input* in)
{
plugin_state *ps = (plugin_state *) s;
auto ps = reinterpret_cast<plugin_state*>(s);
for (uint32_t i = 0; i < in->num_fields; i++)
{
switch(in->fields[i].field_id)
Expand All @@ -162,14 +164,16 @@ static ss_plugin_rc plugin_extract_fields(ss_plugin_t *s, const ss_plugin_event_
return SS_PLUGIN_SUCCESS;
}

static ss_plugin_rc plugin_set_config(ss_plugin_t *s, const ss_plugin_set_config_input* i)
ss_plugin_rc plugin_set_config(ss_plugin_t *s, const ss_plugin_set_config_input* i)
{
plugin_state *ps = (plugin_state *) s;
auto ps = reinterpret_cast<plugin_state*>(s);
ps->log(ps->owner, NULL, "new config!", SS_PLUGIN_LOG_SEV_INFO);

return SS_PLUGIN_SUCCESS;
}

} // anonymous namespace

void get_plugin_api_sample_plugin_extract(plugin_api& out)
{
memset(&out, 0, sizeof(plugin_api));
Expand Down
40 changes: 22 additions & 18 deletions userspace/libsinsp/test/plugins/plugin_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ limitations under the License.

#include "test_plugins.h"

namespace {

static constexpr const char* s_evt_data = "hello world";

/**
Expand All @@ -46,49 +48,49 @@ struct instance_state
ss_plugin_event* evt;
};

static const char* plugin_get_required_api_version()
const char* plugin_get_required_api_version()
{
return PLUGIN_API_VERSION_STR;
}

static const char* plugin_get_version()
const char* plugin_get_version()
{
return "0.1.0";
}

static const char* plugin_get_name()
const char* plugin_get_name()
{
return "sample_plugin_source";
}

static const char* plugin_get_description()
const char* plugin_get_description()
{
return "some desc";
}

static const char* plugin_get_contact()
const char* plugin_get_contact()
{
return "some contact";
}

static uint32_t plugin_get_id()
uint32_t plugin_get_id()
{
return 999;
}

static const char* plugin_get_event_source()
const char* plugin_get_event_source()
{
return "sample";
}

static const char* plugin_get_last_error(ss_plugin_t* s)
const char* plugin_get_last_error(ss_plugin_t* s)
{
return ((plugin_state *) s)->lasterr.c_str();
}

static ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc)
ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc)
{
plugin_state *ret = new plugin_state();
auto ret = new plugin_state();

//save logger and owner in the state
ret->log = in->log_fn;
Expand All @@ -100,17 +102,17 @@ static ss_plugin_t* plugin_init(const ss_plugin_init_input* in, ss_plugin_rc* rc
return ret;
}

static void plugin_destroy(ss_plugin_t* s)
void plugin_destroy(ss_plugin_t* s)
{
plugin_state *ps = (plugin_state *) s;
auto ps = reinterpret_cast<plugin_state*>(s);
ps->log(ps->owner, NULL, "destroying plugin...", SS_PLUGIN_LOG_SEV_INFO);
delete ((plugin_state *) s);

delete ps;
}

static ss_instance_t* plugin_open(ss_plugin_t* s, const char* params, ss_plugin_rc* rc)
ss_instance_t* plugin_open(ss_plugin_t* s, const char* params, ss_plugin_rc* rc)
{
instance_state *ret = new instance_state();
auto ret = new instance_state();
ret->evt = (ss_plugin_event*) &ret->evt_buf;
ret->count = 10000;
auto count = atoi(params);
Expand All @@ -123,12 +125,12 @@ static ss_instance_t* plugin_open(ss_plugin_t* s, const char* params, ss_plugin_
return ret;
}

static void plugin_close(ss_plugin_t* s, ss_instance_t* i)
void plugin_close(ss_plugin_t* s, ss_instance_t* i)
{
delete ((instance_state *) i);
}

static ss_plugin_rc plugin_next_batch(ss_plugin_t* s, ss_instance_t* i, uint32_t *nevts, ss_plugin_event ***evts)
ss_plugin_rc plugin_next_batch(ss_plugin_t* s, ss_instance_t* i, uint32_t *nevts, ss_plugin_event ***evts)
{
instance_state *istate = (instance_state *) i;

Expand Down Expand Up @@ -159,6 +161,8 @@ static ss_plugin_rc plugin_next_batch(ss_plugin_t* s, ss_instance_t* i, uint32_t
return SS_PLUGIN_SUCCESS;
}

} // anonymous namespace

void get_plugin_api_sample_plugin_source(plugin_api& out)
{
memset(&out, 0, sizeof(plugin_api));
Expand Down
Loading
Loading