pcp_easy 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Ryan Doyle
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- */
18
-
19
- #ifndef PCPEASY_RUBY_METRIC_H
20
- #define PCPEASY_RUBY_METRIC_H 1
21
-
22
- #include <ruby.h>
23
- #include <pcp/pmapi.h>
24
-
25
- void pcpeasy_metric_init(VALUE rb_cPCPEasy);
26
- VALUE pcpeasy_metric_new(char *metric_name, pmValueSet *pm_value_set);
27
-
28
- #endif
@@ -1,102 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Ryan Doyle
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- */
18
-
19
- #include <ruby.h>
20
- #include <pcp/pmapi.h>
21
- #include "exceptions.h"
22
-
23
- #define CONSTRUCTOR_ARGS 2
24
- #define READ_ONLY 1, 0
25
-
26
-
27
- VALUE easy_metric_value_class;
28
-
29
-
30
- static VALUE instance_name(char *instance) {
31
- if(instance == NULL) {
32
- return Qnil;
33
- }
34
- return rb_tainted_str_new_cstr(instance);
35
- }
36
-
37
- static VALUE value(int value_format, pmValue *pm_value, int type) {
38
- pmAtomValue pm_atom_value;
39
- int error;
40
-
41
- if((error = pmExtractValue(value_format, pm_value, type, &pm_atom_value, type)) < 0) {
42
- pcpeasy_raise_from_pmapi_error(error);
43
- }
44
-
45
- switch(type) {
46
- case PM_TYPE_32:
47
- return LONG2NUM(pm_atom_value.l);
48
- case PM_TYPE_U32:
49
- return ULONG2NUM(pm_atom_value.ul);
50
- case PM_TYPE_64:
51
- return LL2NUM(pm_atom_value.ll);
52
- case PM_TYPE_U64:
53
- return ULL2NUM(pm_atom_value.ull);
54
- case PM_TYPE_FLOAT:
55
- return DBL2NUM(pm_atom_value.f);
56
- case PM_TYPE_DOUBLE:
57
- return DBL2NUM(pm_atom_value.d);
58
- case PM_TYPE_STRING:
59
- return rb_tainted_str_new_cstr(pm_atom_value.vbp->vbuf);
60
- default:
61
- rb_raise(pcpeasy_error, "Metric type %d not supported", type);
62
- }
63
- }
64
-
65
- static int is_field_equal(const char *name, VALUE self, VALUE other) {
66
- return TYPE(rb_funcall(rb_iv_get(self, name), rb_intern("=="), 1, rb_iv_get(other, name))) == T_TRUE;
67
- }
68
-
69
- static VALUE initialize(VALUE self, VALUE value, VALUE instance) {
70
- rb_iv_set(self, "@value", value);
71
- rb_iv_set(self, "@instance", instance);
72
-
73
- return self;
74
- }
75
-
76
- static VALUE equal(VALUE self, VALUE other) {
77
- if(rb_class_of(other) != easy_metric_value_class)
78
- return Qfalse;
79
- if(!is_field_equal("@value", self, other))
80
- return Qfalse;
81
- if(!is_field_equal("@instance", self, other))
82
- return Qfalse;
83
-
84
- return Qtrue;
85
- }
86
-
87
- VALUE pcpeasy_metric_value_new(char *instance, int value_format, pmValue *pm_value, int type) {
88
- VALUE args[CONSTRUCTOR_ARGS];
89
- args[0] = value(value_format, pm_value, type);
90
- args[1] = instance_name(instance);
91
-
92
- return rb_class_new_instance(CONSTRUCTOR_ARGS, args, easy_metric_value_class);
93
- }
94
-
95
- void pcpeasy_metric_value_init(VALUE rb_cPCPEasyMetric) {
96
- easy_metric_value_class = rb_define_class_under(rb_cPCPEasyMetric, "Value", rb_cObject);
97
-
98
- rb_define_method(easy_metric_value_class, "initialize", initialize, CONSTRUCTOR_ARGS);
99
- rb_define_method(easy_metric_value_class, "==", equal, 1);
100
- rb_define_attr(easy_metric_value_class, "value", READ_ONLY);
101
- rb_define_attr(easy_metric_value_class, "instance", READ_ONLY);
102
- }
@@ -1,28 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Ryan Doyle
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- */
18
-
19
- #ifndef PCPEZ_RUBY_METRIC_VALUE_H
20
- #define PCPEZ_RUBY_METRIC_VALUE_H 1
21
-
22
- #include <ruby.h>
23
- #include <pcp/pmapi.h>
24
-
25
- VALUE pcpeasy_metric_value_new(char *instance_name, int value_format, pmValue *pm_value, int type);
26
- void pcpeasy_metric_value_init(VALUE rb_cPCPEasyMetric);
27
-
28
- #endif
@@ -1,34 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Ryan Doyle
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- */
18
-
19
- #include <ruby.h>
20
-
21
- #include "exceptions.h"
22
- #include "metric.h"
23
- #include "agent.h"
24
-
25
- VALUE pcpeasy_class = Qnil;
26
-
27
-
28
-
29
- void Init_pcp_easy() {
30
- pcpeasy_class = rb_define_module("PCPEasy");
31
- pcpeasy_exceptions_init(pcpeasy_class);
32
- pcpeasy_metric_init(pcpeasy_class);
33
- pcpeasy_agent_init(pcpeasy_class);
34
- }